Blame view
sources/lib/private/files/cache/legacy.php
3.17 KB
|
03e52840d
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php
/**
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Files\Cache;
/**
* Provide read only support for the old filecache
*/
class Legacy {
private $user;
private $cacheHasItems = null;
public function __construct($user) {
$this->user = $user;
}
|
|
31b7f2792
|
22 23 24 25 26 |
/** * get the numbers of items in the legacy cache * * @return int */ |
|
03e52840d
|
27 |
function getCount() {
|
|
31b7f2792
|
28 29 |
$sql = 'SELECT COUNT(`id`) AS `count` FROM `*PREFIX*fscache` WHERE `user` = ?'; $result = \OC_DB::executeAudited($sql, array($this->user)); |
|
03e52840d
|
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
if ($row = $result->fetchRow()) {
return $row['count'];
} else {
return 0;
}
}
/**
* check if a legacy cache is present and holds items
*
* @return bool
*/
function hasItems() {
if (!is_null($this->cacheHasItems)) {
return $this->cacheHasItems;
}
try {
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ?',1);
} catch (\Exception $e) {
$this->cacheHasItems = false;
return false;
}
try {
$result = $query->execute(array($this->user));
} catch (\Exception $e) {
$this->cacheHasItems = false;
return false;
}
if ($result === false || property_exists($result, 'error_message_prefix')) {
$this->cacheHasItems = false;
return false;
}
$this->cacheHasItems = (bool)$result->fetchRow();
return $this->cacheHasItems;
}
/**
|
|
31b7f2792
|
69 70 |
* get an item from the legacy cache * |
|
03e52840d
|
71 72 73 74 75 |
* @param string|int $path
* @return array
*/
function get($path) {
if (is_numeric($path)) {
|
|
31b7f2792
|
76 |
$sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `id` = ?'; |
|
03e52840d
|
77 |
} else {
|
|
31b7f2792
|
78 |
$sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `path` = ?'; |
|
03e52840d
|
79 |
} |
|
31b7f2792
|
80 |
$result = \OC_DB::executeAudited($sql, array($path)); |
|
03e52840d
|
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
$data = $result->fetchRow();
$data['etag'] = $this->getEtag($data['path'], $data['user']);
return $data;
}
/**
* Get the ETag for the given path
*
* @param type $path
* @return string
*/
function getEtag($path, $user = null) {
static $query = null;
$pathDetails = explode('/', $path, 4);
if((!$user) && !isset($pathDetails[1])) {
//no user!? Too odd, return empty string.
return '';
} else if(!$user) {
//guess user from path, if no user passed.
$user = $pathDetails[1];
}
if(!isset($pathDetails[3]) || is_null($pathDetails[3])) {
$relativePath = '';
} else {
$relativePath = $pathDetails[3];
}
if(is_null($query)){
$query = \OC_DB::prepare('SELECT `propertyvalue` FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = \'{DAV:}getetag\'');
}
|
|
31b7f2792
|
113 |
$result = \OC_DB::executeAudited($query,array($user, '/' . $relativePath)); |
|
03e52840d
|
114 115 116 117 118 119 120 121 |
if ($row = $result->fetchRow()) {
return trim($row['propertyvalue'], '"');
} else {
return '';
}
}
/**
|
|
31b7f2792
|
122 123 |
* get all child items of an item from the legacy cache * |
|
03e52840d
|
124 125 126 127 |
* @param int $id
* @return array
*/
function getChildren($id) {
|
|
31b7f2792
|
128 |
$result = \OC_DB::executeAudited('SELECT * FROM `*PREFIX*fscache` WHERE `parent` = ?', array($id));
|
|
03e52840d
|
129 130 131 132 133 134 135 |
$data = $result->fetchAll();
foreach ($data as $i => $item) {
$data[$i]['etag'] = $this->getEtag($item['path'], $item['user']);
}
return $data;
}
}
|