@@ -104,6 +104,10 @@ |
||
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | + /** |
|
| 108 | + * @param string $href |
|
| 109 | + * @param string $path |
|
| 110 | + */ |
|
| 107 | 111 | public function getPropertyDefinitionsForScope($href, $path) { |
| 108 | 112 | // all valid scopes support the same schema |
| 109 | 113 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | /** @var Folder $folder $results */ |
| 150 | 150 | $results = $folder->search($query); |
| 151 | 151 | |
| 152 | - return array_map(function (Node $node) { |
|
| 152 | + return array_map(function(Node $node) { |
|
| 153 | 153 | if ($node instanceof Folder) { |
| 154 | 154 | return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node)); |
| 155 | 155 | } else { |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | 165 | private function getHrefForNode(Node $node) { |
| 166 | - $base = '/files/' . $this->user->getUID(); |
|
| 167 | - return $base . $this->view->getRelativePath($node->getPath()); |
|
| 166 | + $base = '/files/'.$this->user->getUID(); |
|
| 167 | + return $base.$this->view->getRelativePath($node->getPath()); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -204,19 +204,19 @@ discard block |
||
| 204 | 204 | case Operator::OPERATION_LESS_THAN: |
| 205 | 205 | case Operator::OPERATION_IS_LIKE: |
| 206 | 206 | if (count($operator->arguments) !== 2) { |
| 207 | - throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
| 207 | + throw new \InvalidArgumentException('Invalid number of arguments for '.$trimmedType.' operation'); |
|
| 208 | 208 | } |
| 209 | 209 | if (gettype($operator->arguments[0]) !== 'string') { |
| 210 | - throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
| 210 | + throw new \InvalidArgumentException('Invalid argument 1 for '.$trimmedType.' operation, expected property'); |
|
| 211 | 211 | } |
| 212 | 212 | if (!($operator->arguments[1] instanceof Literal)) { |
| 213 | - throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
| 213 | + throw new \InvalidArgumentException('Invalid argument 2 for '.$trimmedType.' operation, expected literal'); |
|
| 214 | 214 | } |
| 215 | 215 | return new SearchComparison($trimmedType, $this->mapPropertyNameToCollumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
| 216 | 216 | case Operator::OPERATION_IS_COLLECTION: |
| 217 | 217 | return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
| 218 | 218 | default: |
| 219 | - throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType. ' (' . $operator->type . ')'); |
|
| 219 | + throw new \InvalidArgumentException('Unsupported operation '.$trimmedType.' ('.$operator->type.')'); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | case FilesPlugin::SIZE_PROPERTYNAME: |
| 243 | 243 | return 'size'; |
| 244 | 244 | default: |
| 245 | - throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
| 245 | + throw new \InvalidArgumentException('Unsupported property for search or order: '.$propertyName); |
|
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | 248 | |
@@ -48,218 +48,218 @@ |
||
| 48 | 48 | use SearchDAV\XML\Order; |
| 49 | 49 | |
| 50 | 50 | class FileSearchBackend implements ISearchBackend { |
| 51 | - /** @var Tree */ |
|
| 52 | - private $tree; |
|
| 51 | + /** @var Tree */ |
|
| 52 | + private $tree; |
|
| 53 | 53 | |
| 54 | - /** @var IUser */ |
|
| 55 | - private $user; |
|
| 54 | + /** @var IUser */ |
|
| 55 | + private $user; |
|
| 56 | 56 | |
| 57 | - /** @var IRootFolder */ |
|
| 58 | - private $rootFolder; |
|
| 57 | + /** @var IRootFolder */ |
|
| 58 | + private $rootFolder; |
|
| 59 | 59 | |
| 60 | - /** @var IManager */ |
|
| 61 | - private $shareManager; |
|
| 60 | + /** @var IManager */ |
|
| 61 | + private $shareManager; |
|
| 62 | 62 | |
| 63 | - /** @var View */ |
|
| 64 | - private $view; |
|
| 63 | + /** @var View */ |
|
| 64 | + private $view; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * FileSearchBackend constructor. |
|
| 68 | - * |
|
| 69 | - * @param Tree $tree |
|
| 70 | - * @param IUser $user |
|
| 71 | - * @param IRootFolder $rootFolder |
|
| 72 | - * @param IManager $shareManager |
|
| 73 | - * @param View $view |
|
| 74 | - * @internal param IRootFolder $rootFolder |
|
| 75 | - */ |
|
| 76 | - public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) { |
|
| 77 | - $this->tree = $tree; |
|
| 78 | - $this->user = $user; |
|
| 79 | - $this->rootFolder = $rootFolder; |
|
| 80 | - $this->shareManager = $shareManager; |
|
| 81 | - $this->view = $view; |
|
| 82 | - } |
|
| 66 | + /** |
|
| 67 | + * FileSearchBackend constructor. |
|
| 68 | + * |
|
| 69 | + * @param Tree $tree |
|
| 70 | + * @param IUser $user |
|
| 71 | + * @param IRootFolder $rootFolder |
|
| 72 | + * @param IManager $shareManager |
|
| 73 | + * @param View $view |
|
| 74 | + * @internal param IRootFolder $rootFolder |
|
| 75 | + */ |
|
| 76 | + public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) { |
|
| 77 | + $this->tree = $tree; |
|
| 78 | + $this->user = $user; |
|
| 79 | + $this->rootFolder = $rootFolder; |
|
| 80 | + $this->shareManager = $shareManager; |
|
| 81 | + $this->view = $view; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Search endpoint will be remote.php/dav |
|
| 86 | - * |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function getArbiterPath() { |
|
| 90 | - return ''; |
|
| 91 | - } |
|
| 84 | + /** |
|
| 85 | + * Search endpoint will be remote.php/dav |
|
| 86 | + * |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function getArbiterPath() { |
|
| 90 | + return ''; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function isValidScope($href, $depth, $path) { |
|
| 94 | - // only allow scopes inside the dav server |
|
| 95 | - if (is_null($path)) { |
|
| 96 | - return false; |
|
| 97 | - } |
|
| 93 | + public function isValidScope($href, $depth, $path) { |
|
| 94 | + // only allow scopes inside the dav server |
|
| 95 | + if (is_null($path)) { |
|
| 96 | + return false; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - try { |
|
| 100 | - $node = $this->tree->getNodeForPath($path); |
|
| 101 | - return $node instanceof Directory; |
|
| 102 | - } catch (NotFound $e) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - } |
|
| 99 | + try { |
|
| 100 | + $node = $this->tree->getNodeForPath($path); |
|
| 101 | + return $node instanceof Directory; |
|
| 102 | + } catch (NotFound $e) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function getPropertyDefinitionsForScope($href, $path) { |
|
| 108 | - // all valid scopes support the same schema |
|
| 107 | + public function getPropertyDefinitionsForScope($href, $path) { |
|
| 108 | + // all valid scopes support the same schema |
|
| 109 | 109 | |
| 110 | - //todo dynamically load all propfind properties that are supported |
|
| 111 | - return [ |
|
| 112 | - // queryable properties |
|
| 113 | - new SearchPropertyDefinition('{DAV:}displayname', true, false, true), |
|
| 114 | - new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), |
|
| 115 | - new SearchPropertyDefinition('{DAV:}getlastmodifed', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), |
|
| 116 | - new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 110 | + //todo dynamically load all propfind properties that are supported |
|
| 111 | + return [ |
|
| 112 | + // queryable properties |
|
| 113 | + new SearchPropertyDefinition('{DAV:}displayname', true, false, true), |
|
| 114 | + new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), |
|
| 115 | + new SearchPropertyDefinition('{DAV:}getlastmodifed', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), |
|
| 116 | + new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 117 | 117 | |
| 118 | - // select only properties |
|
| 119 | - new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false), |
|
| 120 | - new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false), |
|
| 121 | - new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false), |
|
| 122 | - new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false), |
|
| 123 | - new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false), |
|
| 124 | - new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false), |
|
| 125 | - new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false), |
|
| 126 | - new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false), |
|
| 127 | - new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
| 128 | - new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 129 | - new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 130 | - ]; |
|
| 131 | - } |
|
| 118 | + // select only properties |
|
| 119 | + new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false), |
|
| 120 | + new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false), |
|
| 121 | + new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false), |
|
| 122 | + new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false), |
|
| 123 | + new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false), |
|
| 124 | + new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false), |
|
| 125 | + new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false), |
|
| 126 | + new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false), |
|
| 127 | + new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
| 128 | + new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 129 | + new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
| 130 | + ]; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @param BasicSearch $search |
|
| 135 | - * @return SearchResult[] |
|
| 136 | - */ |
|
| 137 | - public function search(BasicSearch $search) { |
|
| 138 | - if (count($search->from) !== 1) { |
|
| 139 | - throw new \InvalidArgumentException('Searching more than one folder is not supported'); |
|
| 140 | - } |
|
| 141 | - $query = $this->transformQuery($search); |
|
| 142 | - $scope = $search->from[0]; |
|
| 143 | - if ($scope->path === null) { |
|
| 144 | - throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead'); |
|
| 145 | - } |
|
| 146 | - $node = $this->tree->getNodeForPath($scope->path); |
|
| 147 | - if (!$node instanceof Directory) { |
|
| 148 | - throw new \InvalidArgumentException('Search is only supported on directories'); |
|
| 149 | - } |
|
| 133 | + /** |
|
| 134 | + * @param BasicSearch $search |
|
| 135 | + * @return SearchResult[] |
|
| 136 | + */ |
|
| 137 | + public function search(BasicSearch $search) { |
|
| 138 | + if (count($search->from) !== 1) { |
|
| 139 | + throw new \InvalidArgumentException('Searching more than one folder is not supported'); |
|
| 140 | + } |
|
| 141 | + $query = $this->transformQuery($search); |
|
| 142 | + $scope = $search->from[0]; |
|
| 143 | + if ($scope->path === null) { |
|
| 144 | + throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead'); |
|
| 145 | + } |
|
| 146 | + $node = $this->tree->getNodeForPath($scope->path); |
|
| 147 | + if (!$node instanceof Directory) { |
|
| 148 | + throw new \InvalidArgumentException('Search is only supported on directories'); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $fileInfo = $node->getFileInfo(); |
|
| 152 | - $folder = $this->rootFolder->get($fileInfo->getPath()); |
|
| 153 | - /** @var Folder $folder $results */ |
|
| 154 | - $results = $folder->search($query); |
|
| 151 | + $fileInfo = $node->getFileInfo(); |
|
| 152 | + $folder = $this->rootFolder->get($fileInfo->getPath()); |
|
| 153 | + /** @var Folder $folder $results */ |
|
| 154 | + $results = $folder->search($query); |
|
| 155 | 155 | |
| 156 | - return array_map(function (Node $node) { |
|
| 157 | - if ($node instanceof Folder) { |
|
| 158 | - return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node)); |
|
| 159 | - } else { |
|
| 160 | - return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node)); |
|
| 161 | - } |
|
| 162 | - }, $results); |
|
| 163 | - } |
|
| 156 | + return array_map(function (Node $node) { |
|
| 157 | + if ($node instanceof Folder) { |
|
| 158 | + return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node)); |
|
| 159 | + } else { |
|
| 160 | + return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node)); |
|
| 161 | + } |
|
| 162 | + }, $results); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * @param Node $node |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - private function getHrefForNode(Node $node) { |
|
| 170 | - $base = '/files/' . $this->user->getUID(); |
|
| 171 | - return $base . $this->view->getRelativePath($node->getPath()); |
|
| 172 | - } |
|
| 165 | + /** |
|
| 166 | + * @param Node $node |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + private function getHrefForNode(Node $node) { |
|
| 170 | + $base = '/files/' . $this->user->getUID(); |
|
| 171 | + return $base . $this->view->getRelativePath($node->getPath()); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * @param BasicSearch $query |
|
| 176 | - * @return ISearchQuery |
|
| 177 | - */ |
|
| 178 | - private function transformQuery(BasicSearch $query) { |
|
| 179 | - // TODO offset, limit |
|
| 180 | - $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy); |
|
| 181 | - return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders); |
|
| 182 | - } |
|
| 174 | + /** |
|
| 175 | + * @param BasicSearch $query |
|
| 176 | + * @return ISearchQuery |
|
| 177 | + */ |
|
| 178 | + private function transformQuery(BasicSearch $query) { |
|
| 179 | + // TODO offset, limit |
|
| 180 | + $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy); |
|
| 181 | + return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * @param Order $order |
|
| 186 | - * @return ISearchOrder |
|
| 187 | - */ |
|
| 188 | - private function mapSearchOrder(Order $order) { |
|
| 189 | - return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToCollumn($order->property)); |
|
| 190 | - } |
|
| 184 | + /** |
|
| 185 | + * @param Order $order |
|
| 186 | + * @return ISearchOrder |
|
| 187 | + */ |
|
| 188 | + private function mapSearchOrder(Order $order) { |
|
| 189 | + return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToCollumn($order->property)); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * @param Operator $operator |
|
| 194 | - * @return ISearchOperator |
|
| 195 | - */ |
|
| 196 | - private function transformSearchOperation(Operator $operator) { |
|
| 197 | - list(, $trimmedType) = explode('}', $operator->type); |
|
| 198 | - switch ($operator->type) { |
|
| 199 | - case Operator::OPERATION_AND: |
|
| 200 | - case Operator::OPERATION_OR: |
|
| 201 | - case Operator::OPERATION_NOT: |
|
| 202 | - $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments); |
|
| 203 | - return new SearchBinaryOperator($trimmedType, $arguments); |
|
| 204 | - case Operator::OPERATION_EQUAL: |
|
| 205 | - case Operator::OPERATION_GREATER_OR_EQUAL_THAN: |
|
| 206 | - case Operator::OPERATION_GREATER_THAN: |
|
| 207 | - case Operator::OPERATION_LESS_OR_EQUAL_THAN: |
|
| 208 | - case Operator::OPERATION_LESS_THAN: |
|
| 209 | - case Operator::OPERATION_IS_LIKE: |
|
| 210 | - if (count($operator->arguments) !== 2) { |
|
| 211 | - throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
| 212 | - } |
|
| 213 | - if (gettype($operator->arguments[0]) !== 'string') { |
|
| 214 | - throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
| 215 | - } |
|
| 216 | - if (!($operator->arguments[1] instanceof Literal)) { |
|
| 217 | - throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
| 218 | - } |
|
| 219 | - return new SearchComparison($trimmedType, $this->mapPropertyNameToCollumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
|
| 220 | - case Operator::OPERATION_IS_COLLECTION: |
|
| 221 | - return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
|
| 222 | - default: |
|
| 223 | - throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType. ' (' . $operator->type . ')'); |
|
| 224 | - } |
|
| 225 | - } |
|
| 192 | + /** |
|
| 193 | + * @param Operator $operator |
|
| 194 | + * @return ISearchOperator |
|
| 195 | + */ |
|
| 196 | + private function transformSearchOperation(Operator $operator) { |
|
| 197 | + list(, $trimmedType) = explode('}', $operator->type); |
|
| 198 | + switch ($operator->type) { |
|
| 199 | + case Operator::OPERATION_AND: |
|
| 200 | + case Operator::OPERATION_OR: |
|
| 201 | + case Operator::OPERATION_NOT: |
|
| 202 | + $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments); |
|
| 203 | + return new SearchBinaryOperator($trimmedType, $arguments); |
|
| 204 | + case Operator::OPERATION_EQUAL: |
|
| 205 | + case Operator::OPERATION_GREATER_OR_EQUAL_THAN: |
|
| 206 | + case Operator::OPERATION_GREATER_THAN: |
|
| 207 | + case Operator::OPERATION_LESS_OR_EQUAL_THAN: |
|
| 208 | + case Operator::OPERATION_LESS_THAN: |
|
| 209 | + case Operator::OPERATION_IS_LIKE: |
|
| 210 | + if (count($operator->arguments) !== 2) { |
|
| 211 | + throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
| 212 | + } |
|
| 213 | + if (gettype($operator->arguments[0]) !== 'string') { |
|
| 214 | + throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
| 215 | + } |
|
| 216 | + if (!($operator->arguments[1] instanceof Literal)) { |
|
| 217 | + throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
| 218 | + } |
|
| 219 | + return new SearchComparison($trimmedType, $this->mapPropertyNameToCollumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
|
| 220 | + case Operator::OPERATION_IS_COLLECTION: |
|
| 221 | + return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
|
| 222 | + default: |
|
| 223 | + throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType. ' (' . $operator->type . ')'); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * @param string $propertyName |
|
| 229 | - * @return string |
|
| 230 | - */ |
|
| 231 | - private function mapPropertyNameToCollumn($propertyName) { |
|
| 232 | - switch ($propertyName) { |
|
| 233 | - case '{DAV:}displayname': |
|
| 234 | - return 'name'; |
|
| 235 | - case '{DAV:}getcontenttype': |
|
| 236 | - return 'mimetype'; |
|
| 237 | - case '{DAV:}getlastmodifed': |
|
| 238 | - return 'mtime'; |
|
| 239 | - case FilesPlugin::SIZE_PROPERTYNAME: |
|
| 240 | - return 'size'; |
|
| 241 | - default: |
|
| 242 | - throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
| 243 | - } |
|
| 244 | - } |
|
| 227 | + /** |
|
| 228 | + * @param string $propertyName |
|
| 229 | + * @return string |
|
| 230 | + */ |
|
| 231 | + private function mapPropertyNameToCollumn($propertyName) { |
|
| 232 | + switch ($propertyName) { |
|
| 233 | + case '{DAV:}displayname': |
|
| 234 | + return 'name'; |
|
| 235 | + case '{DAV:}getcontenttype': |
|
| 236 | + return 'mimetype'; |
|
| 237 | + case '{DAV:}getlastmodifed': |
|
| 238 | + return 'mtime'; |
|
| 239 | + case FilesPlugin::SIZE_PROPERTYNAME: |
|
| 240 | + return 'size'; |
|
| 241 | + default: |
|
| 242 | + throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - private function castValue($propertyName, $value) { |
|
| 247 | - $allProps = $this->getPropertyDefinitionsForScope('', ''); |
|
| 248 | - foreach ($allProps as $prop) { |
|
| 249 | - if ($prop->name === $propertyName) { |
|
| 250 | - $dataType = $prop->dataType; |
|
| 251 | - switch ($dataType) { |
|
| 252 | - case SearchPropertyDefinition::DATATYPE_BOOLEAN: |
|
| 253 | - return $value === 'yes'; |
|
| 254 | - case SearchPropertyDefinition::DATATYPE_DECIMAL: |
|
| 255 | - case SearchPropertyDefinition::DATATYPE_INTEGER: |
|
| 256 | - case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: |
|
| 257 | - return 0 + $value; |
|
| 258 | - default: |
|
| 259 | - return $value; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - return $value; |
|
| 264 | - } |
|
| 246 | + private function castValue($propertyName, $value) { |
|
| 247 | + $allProps = $this->getPropertyDefinitionsForScope('', ''); |
|
| 248 | + foreach ($allProps as $prop) { |
|
| 249 | + if ($prop->name === $propertyName) { |
|
| 250 | + $dataType = $prop->dataType; |
|
| 251 | + switch ($dataType) { |
|
| 252 | + case SearchPropertyDefinition::DATATYPE_BOOLEAN: |
|
| 253 | + return $value === 'yes'; |
|
| 254 | + case SearchPropertyDefinition::DATATYPE_DECIMAL: |
|
| 255 | + case SearchPropertyDefinition::DATATYPE_INTEGER: |
|
| 256 | + case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: |
|
| 257 | + return 0 + $value; |
|
| 258 | + default: |
|
| 259 | + return $value; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + return $value; |
|
| 264 | + } |
|
| 265 | 265 | } |
@@ -420,6 +420,9 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | + /** |
|
| 424 | + * @param string $path |
|
| 425 | + */ |
|
| 423 | 426 | private function getParentPath($path) { |
| 424 | 427 | $parent = dirname($path); |
| 425 | 428 | if ($parent === '.') { |
@@ -598,7 +601,7 @@ discard block |
||
| 598 | 601 | * search for files matching $pattern |
| 599 | 602 | * |
| 600 | 603 | * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') |
| 601 | - * @return ICacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 604 | + * @return CacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 602 | 605 | */ |
| 603 | 606 | public function search($pattern) { |
| 604 | 607 | // normalize pattern |
@@ -639,7 +642,7 @@ discard block |
||
| 639 | 642 | * |
| 640 | 643 | * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
| 641 | 644 | * where it will search for all mimetypes in the group ('image/*') |
| 642 | - * @return ICacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 645 | + * @return CacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 643 | 646 | */ |
| 644 | 647 | public function searchByMime($mimetype) { |
| 645 | 648 | if (strpos($mimetype, '/')) { |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) { |
| 163 | 163 | //fix types |
| 164 | - $data['fileid'] = (int)$data['fileid']; |
|
| 165 | - $data['parent'] = (int)$data['parent']; |
|
| 164 | + $data['fileid'] = (int) $data['fileid']; |
|
| 165 | + $data['parent'] = (int) $data['parent']; |
|
| 166 | 166 | $data['size'] = 0 + $data['size']; |
| 167 | - $data['mtime'] = (int)$data['mtime']; |
|
| 168 | - $data['storage_mtime'] = (int)$data['storage_mtime']; |
|
| 169 | - $data['encryptedVersion'] = (int)$data['encrypted']; |
|
| 170 | - $data['encrypted'] = (bool)$data['encrypted']; |
|
| 167 | + $data['mtime'] = (int) $data['mtime']; |
|
| 168 | + $data['storage_mtime'] = (int) $data['storage_mtime']; |
|
| 169 | + $data['encryptedVersion'] = (int) $data['encrypted']; |
|
| 170 | + $data['encrypted'] = (bool) $data['encrypted']; |
|
| 171 | 171 | $data['storage_id'] = $data['storage']; |
| 172 | - $data['storage'] = (int)$data['storage']; |
|
| 172 | + $data['storage'] = (int) $data['storage']; |
|
| 173 | 173 | $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); |
| 174 | 174 | $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); |
| 175 | 175 | if ($data['storage_mtime'] == 0) { |
| 176 | 176 | $data['storage_mtime'] = $data['mtime']; |
| 177 | 177 | } |
| 178 | - $data['permissions'] = (int)$data['permissions']; |
|
| 178 | + $data['permissions'] = (int) $data['permissions']; |
|
| 179 | 179 | return new CacheEntry($data); |
| 180 | 180 | } |
| 181 | 181 | |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC'; |
| 204 | 204 | $result = $this->connection->executeQuery($sql, [$fileId]); |
| 205 | 205 | $files = $result->fetchAll(); |
| 206 | - return array_map(function (array $data) { |
|
| 207 | - return self::cacheEntryFromData($data, $this->mimetypeLoader);; |
|
| 206 | + return array_map(function(array $data) { |
|
| 207 | + return self::cacheEntryFromData($data, $this->mimetypeLoader); ; |
|
| 208 | 208 | }, $files); |
| 209 | 209 | } else { |
| 210 | 210 | return array(); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | $queryParts[] = '`storage`'; |
| 264 | 264 | $params[] = $this->getNumericStorageId(); |
| 265 | 265 | |
| 266 | - $queryParts = array_map(function ($item) { |
|
| 266 | + $queryParts = array_map(function($item) { |
|
| 267 | 267 | return trim($item, "`"); |
| 268 | 268 | }, $queryParts); |
| 269 | 269 | $values = array_combine($queryParts, $params); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | 'path_hash', |
| 273 | 273 | ]) |
| 274 | 274 | ) { |
| 275 | - return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 275 | + return (int) $this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // The file was created in the mean time |
@@ -310,10 +310,10 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | // don't update if the data we try to set is the same as the one in the record |
| 312 | 312 | // some databases (Postgres) don't like superfluous updates |
| 313 | - $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' . |
|
| 314 | - 'WHERE (' . |
|
| 315 | - implode(' <> ? OR ', $queryParts) . ' <> ? OR ' . |
|
| 316 | - implode(' IS NULL OR ', $queryParts) . ' IS NULL' . |
|
| 313 | + $sql = 'UPDATE `*PREFIX*filecache` SET '.implode(' = ?, ', $queryParts).'=? '. |
|
| 314 | + 'WHERE ('. |
|
| 315 | + implode(' <> ? OR ', $queryParts).' <> ? OR '. |
|
| 316 | + implode(' IS NULL OR ', $queryParts).' IS NULL'. |
|
| 317 | 317 | ') AND `fileid` = ? '; |
| 318 | 318 | $this->connection->executeQuery($sql, $params); |
| 319 | 319 | |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | $params[] = $value; |
| 367 | - $queryParts[] = '`' . $name . '`'; |
|
| 367 | + $queryParts[] = '`'.$name.'`'; |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | return array($queryParts, $params); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | return -1; |
| 407 | 407 | } else { |
| 408 | 408 | $parent = $this->getParentPath($file); |
| 409 | - return (int)$this->getId($parent); |
|
| 409 | + return (int) $this->getId($parent); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | private function getSubFolders($entry) { |
| 454 | 454 | $children = $this->getFolderContentsById($entry['fileid']); |
| 455 | - return array_filter($children, function ($child) { |
|
| 455 | + return array_filter($children, function($child) { |
|
| 456 | 456 | return $child['mimetype'] === 'httpd/unix-directory'; |
| 457 | 457 | }); |
| 458 | 458 | } |
@@ -519,14 +519,14 @@ discard block |
||
| 519 | 519 | if ($sourceData['mimetype'] === 'httpd/unix-directory') { |
| 520 | 520 | //find all child entries |
| 521 | 521 | $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; |
| 522 | - $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']); |
|
| 522 | + $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath).'/%']); |
|
| 523 | 523 | $childEntries = $result->fetchAll(); |
| 524 | 524 | $sourceLength = strlen($sourcePath); |
| 525 | 525 | $this->connection->beginTransaction(); |
| 526 | 526 | $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); |
| 527 | 527 | |
| 528 | 528 | foreach ($childEntries as $child) { |
| 529 | - $newTargetPath = $targetPath . substr($child['path'], $sourceLength); |
|
| 529 | + $newTargetPath = $targetPath.substr($child['path'], $sourceLength); |
|
| 530 | 530 | $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]); |
| 531 | 531 | } |
| 532 | 532 | $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
| 571 | 571 | $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
| 572 | 572 | if ($row = $result->fetch()) { |
| 573 | - if ((int)$row['size'] === -1) { |
|
| 573 | + if ((int) $row['size'] === -1) { |
|
| 574 | 574 | return self::SHALLOW; |
| 575 | 575 | } else { |
| 576 | 576 | return self::COMPLETE; |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | private function searchResultToCacheEntries(Statement $result) { |
| 616 | 616 | $files = $result->fetchAll(); |
| 617 | 617 | |
| 618 | - return array_map(function (array $data) { |
|
| 618 | + return array_map(function(array $data) { |
|
| 619 | 619 | return self::cacheEntryFromData($data, $this->mimetypeLoader); |
| 620 | 620 | }, $files); |
| 621 | 621 | } |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | $where = '`mimepart` = ?'; |
| 635 | 635 | } |
| 636 | 636 | $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
| 637 | - FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'; |
|
| 637 | + FROM `*PREFIX*filecache` WHERE ' . $where.' AND `storage` = ?'; |
|
| 638 | 638 | $mimetype = $this->mimetypeLoader->getId($mimetype); |
| 639 | 639 | $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); |
| 640 | 640 | |
@@ -670,20 +670,20 @@ discard block |
||
| 670 | 670 | * @return ICacheEntry[] file data |
| 671 | 671 | */ |
| 672 | 672 | public function searchByTag($tag, $userId) { |
| 673 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . |
|
| 674 | - '`mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, ' . |
|
| 675 | - '`encrypted`, `etag`, `permissions`, `checksum` ' . |
|
| 676 | - 'FROM `*PREFIX*filecache` `file`, ' . |
|
| 677 | - '`*PREFIX*vcategory_to_object` `tagmap`, ' . |
|
| 678 | - '`*PREFIX*vcategory` `tag` ' . |
|
| 673 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, '. |
|
| 674 | + '`mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, '. |
|
| 675 | + '`encrypted`, `etag`, `permissions`, `checksum` '. |
|
| 676 | + 'FROM `*PREFIX*filecache` `file`, '. |
|
| 677 | + '`*PREFIX*vcategory_to_object` `tagmap`, '. |
|
| 678 | + '`*PREFIX*vcategory` `tag` '. |
|
| 679 | 679 | // JOIN filecache to vcategory_to_object |
| 680 | - 'WHERE `file`.`fileid` = `tagmap`.`objid` ' . |
|
| 680 | + 'WHERE `file`.`fileid` = `tagmap`.`objid` '. |
|
| 681 | 681 | // JOIN vcategory_to_object to vcategory |
| 682 | - 'AND `tagmap`.`type` = `tag`.`type` ' . |
|
| 683 | - 'AND `tagmap`.`categoryid` = `tag`.`id` ' . |
|
| 682 | + 'AND `tagmap`.`type` = `tag`.`type` '. |
|
| 683 | + 'AND `tagmap`.`categoryid` = `tag`.`id` '. |
|
| 684 | 684 | // conditions |
| 685 | - 'AND `file`.`storage` = ? ' . |
|
| 686 | - 'AND `tag`.`type` = \'files\' ' . |
|
| 685 | + 'AND `file`.`storage` = ? '. |
|
| 686 | + 'AND `tag`.`type` = \'files\' '. |
|
| 687 | 687 | 'AND `tag`.`uid` = ? '; |
| 688 | 688 | if (is_int($tag)) { |
| 689 | 689 | $sql .= 'AND `tag`.`id` = ? '; |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | |
| 702 | 702 | $files = $result->fetchAll(); |
| 703 | 703 | |
| 704 | - return array_map(function (array $data) { |
|
| 704 | + return array_map(function(array $data) { |
|
| 705 | 705 | return self::cacheEntryFromData($data, $this->mimetypeLoader); |
| 706 | 706 | }, $files); |
| 707 | 707 | } |
@@ -737,8 +737,8 @@ discard block |
||
| 737 | 737 | } |
| 738 | 738 | if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') { |
| 739 | 739 | $id = $entry['fileid']; |
| 740 | - $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' . |
|
| 741 | - 'FROM `*PREFIX*filecache` ' . |
|
| 740 | + $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 '. |
|
| 741 | + 'FROM `*PREFIX*filecache` '. |
|
| 742 | 742 | 'WHERE `parent` = ? AND `storage` = ?'; |
| 743 | 743 | $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
| 744 | 744 | if ($row = $result->fetch()) { |
@@ -54,807 +54,807 @@ |
||
| 54 | 54 | * - ChangePropagator: updates the mtime and etags of parent folders whenever a change to the cache is made to the cache by the updater |
| 55 | 55 | */ |
| 56 | 56 | class Cache implements ICache { |
| 57 | - use MoveFromCacheTrait { |
|
| 58 | - MoveFromCacheTrait::moveFromCache as moveFromCacheFallback; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var array partial data for the cache |
|
| 63 | - */ |
|
| 64 | - protected $partial = array(); |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $storageId; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var Storage $storageCache |
|
| 73 | - */ |
|
| 74 | - protected $storageCache; |
|
| 75 | - |
|
| 76 | - /** @var IMimeTypeLoader */ |
|
| 77 | - protected $mimetypeLoader; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @var IDBConnection |
|
| 81 | - */ |
|
| 82 | - protected $connection; |
|
| 83 | - |
|
| 84 | - /** @var QuerySearchHelper */ |
|
| 85 | - protected $querySearchHelper; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param \OC\Files\Storage\Storage|string $storage |
|
| 89 | - */ |
|
| 90 | - public function __construct($storage) { |
|
| 91 | - if ($storage instanceof \OC\Files\Storage\Storage) { |
|
| 92 | - $this->storageId = $storage->getId(); |
|
| 93 | - } else { |
|
| 94 | - $this->storageId = $storage; |
|
| 95 | - } |
|
| 96 | - if (strlen($this->storageId) > 64) { |
|
| 97 | - $this->storageId = md5($this->storageId); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $this->storageCache = new Storage($storage); |
|
| 101 | - $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 102 | - $this->connection = \OC::$server->getDatabaseConnection(); |
|
| 103 | - $this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get the numeric storage id for this cache's storage |
|
| 108 | - * |
|
| 109 | - * @return int |
|
| 110 | - */ |
|
| 111 | - public function getNumericStorageId() { |
|
| 112 | - return $this->storageCache->getNumericId(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * get the stored metadata of a file or folder |
|
| 117 | - * |
|
| 118 | - * @param string | int $file either the path of a file or folder or the file id for a file or folder |
|
| 119 | - * @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache |
|
| 120 | - */ |
|
| 121 | - public function get($file) { |
|
| 122 | - if (is_string($file) or $file == '') { |
|
| 123 | - // normalize file |
|
| 124 | - $file = $this->normalize($file); |
|
| 125 | - |
|
| 126 | - $where = 'WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 127 | - $params = array($this->getNumericStorageId(), md5($file)); |
|
| 128 | - } else { //file id |
|
| 129 | - $where = 'WHERE `fileid` = ?'; |
|
| 130 | - $params = array($file); |
|
| 131 | - } |
|
| 132 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, |
|
| 57 | + use MoveFromCacheTrait { |
|
| 58 | + MoveFromCacheTrait::moveFromCache as moveFromCacheFallback; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var array partial data for the cache |
|
| 63 | + */ |
|
| 64 | + protected $partial = array(); |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $storageId; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var Storage $storageCache |
|
| 73 | + */ |
|
| 74 | + protected $storageCache; |
|
| 75 | + |
|
| 76 | + /** @var IMimeTypeLoader */ |
|
| 77 | + protected $mimetypeLoader; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @var IDBConnection |
|
| 81 | + */ |
|
| 82 | + protected $connection; |
|
| 83 | + |
|
| 84 | + /** @var QuerySearchHelper */ |
|
| 85 | + protected $querySearchHelper; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param \OC\Files\Storage\Storage|string $storage |
|
| 89 | + */ |
|
| 90 | + public function __construct($storage) { |
|
| 91 | + if ($storage instanceof \OC\Files\Storage\Storage) { |
|
| 92 | + $this->storageId = $storage->getId(); |
|
| 93 | + } else { |
|
| 94 | + $this->storageId = $storage; |
|
| 95 | + } |
|
| 96 | + if (strlen($this->storageId) > 64) { |
|
| 97 | + $this->storageId = md5($this->storageId); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $this->storageCache = new Storage($storage); |
|
| 101 | + $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 102 | + $this->connection = \OC::$server->getDatabaseConnection(); |
|
| 103 | + $this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get the numeric storage id for this cache's storage |
|
| 108 | + * |
|
| 109 | + * @return int |
|
| 110 | + */ |
|
| 111 | + public function getNumericStorageId() { |
|
| 112 | + return $this->storageCache->getNumericId(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * get the stored metadata of a file or folder |
|
| 117 | + * |
|
| 118 | + * @param string | int $file either the path of a file or folder or the file id for a file or folder |
|
| 119 | + * @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache |
|
| 120 | + */ |
|
| 121 | + public function get($file) { |
|
| 122 | + if (is_string($file) or $file == '') { |
|
| 123 | + // normalize file |
|
| 124 | + $file = $this->normalize($file); |
|
| 125 | + |
|
| 126 | + $where = 'WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 127 | + $params = array($this->getNumericStorageId(), md5($file)); |
|
| 128 | + } else { //file id |
|
| 129 | + $where = 'WHERE `fileid` = ?'; |
|
| 130 | + $params = array($file); |
|
| 131 | + } |
|
| 132 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, |
|
| 133 | 133 | `storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
| 134 | 134 | FROM `*PREFIX*filecache` ' . $where; |
| 135 | - $result = $this->connection->executeQuery($sql, $params); |
|
| 136 | - $data = $result->fetch(); |
|
| 137 | - |
|
| 138 | - //FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO |
|
| 139 | - //PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false |
|
| 140 | - if ($data === null) { |
|
| 141 | - $data = false; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - //merge partial data |
|
| 145 | - if (!$data and is_string($file)) { |
|
| 146 | - if (isset($this->partial[$file])) { |
|
| 147 | - $data = $this->partial[$file]; |
|
| 148 | - } |
|
| 149 | - return $data; |
|
| 150 | - } else { |
|
| 151 | - return self::cacheEntryFromData($data, $this->mimetypeLoader); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Create a CacheEntry from database row |
|
| 157 | - * |
|
| 158 | - * @param array $data |
|
| 159 | - * @param IMimeTypeLoader $mimetypeLoader |
|
| 160 | - * @return CacheEntry |
|
| 161 | - */ |
|
| 162 | - public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) { |
|
| 163 | - //fix types |
|
| 164 | - $data['fileid'] = (int)$data['fileid']; |
|
| 165 | - $data['parent'] = (int)$data['parent']; |
|
| 166 | - $data['size'] = 0 + $data['size']; |
|
| 167 | - $data['mtime'] = (int)$data['mtime']; |
|
| 168 | - $data['storage_mtime'] = (int)$data['storage_mtime']; |
|
| 169 | - $data['encryptedVersion'] = (int)$data['encrypted']; |
|
| 170 | - $data['encrypted'] = (bool)$data['encrypted']; |
|
| 171 | - $data['storage_id'] = $data['storage']; |
|
| 172 | - $data['storage'] = (int)$data['storage']; |
|
| 173 | - $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); |
|
| 174 | - $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); |
|
| 175 | - if ($data['storage_mtime'] == 0) { |
|
| 176 | - $data['storage_mtime'] = $data['mtime']; |
|
| 177 | - } |
|
| 178 | - $data['permissions'] = (int)$data['permissions']; |
|
| 179 | - return new CacheEntry($data); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * get the metadata of all files stored in $folder |
|
| 184 | - * |
|
| 185 | - * @param string $folder |
|
| 186 | - * @return ICacheEntry[] |
|
| 187 | - */ |
|
| 188 | - public function getFolderContents($folder) { |
|
| 189 | - $fileId = $this->getId($folder); |
|
| 190 | - return $this->getFolderContentsById($fileId); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * get the metadata of all files stored in $folder |
|
| 195 | - * |
|
| 196 | - * @param int $fileId the file id of the folder |
|
| 197 | - * @return ICacheEntry[] |
|
| 198 | - */ |
|
| 199 | - public function getFolderContentsById($fileId) { |
|
| 200 | - if ($fileId > -1) { |
|
| 201 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, |
|
| 135 | + $result = $this->connection->executeQuery($sql, $params); |
|
| 136 | + $data = $result->fetch(); |
|
| 137 | + |
|
| 138 | + //FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO |
|
| 139 | + //PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false |
|
| 140 | + if ($data === null) { |
|
| 141 | + $data = false; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + //merge partial data |
|
| 145 | + if (!$data and is_string($file)) { |
|
| 146 | + if (isset($this->partial[$file])) { |
|
| 147 | + $data = $this->partial[$file]; |
|
| 148 | + } |
|
| 149 | + return $data; |
|
| 150 | + } else { |
|
| 151 | + return self::cacheEntryFromData($data, $this->mimetypeLoader); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Create a CacheEntry from database row |
|
| 157 | + * |
|
| 158 | + * @param array $data |
|
| 159 | + * @param IMimeTypeLoader $mimetypeLoader |
|
| 160 | + * @return CacheEntry |
|
| 161 | + */ |
|
| 162 | + public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) { |
|
| 163 | + //fix types |
|
| 164 | + $data['fileid'] = (int)$data['fileid']; |
|
| 165 | + $data['parent'] = (int)$data['parent']; |
|
| 166 | + $data['size'] = 0 + $data['size']; |
|
| 167 | + $data['mtime'] = (int)$data['mtime']; |
|
| 168 | + $data['storage_mtime'] = (int)$data['storage_mtime']; |
|
| 169 | + $data['encryptedVersion'] = (int)$data['encrypted']; |
|
| 170 | + $data['encrypted'] = (bool)$data['encrypted']; |
|
| 171 | + $data['storage_id'] = $data['storage']; |
|
| 172 | + $data['storage'] = (int)$data['storage']; |
|
| 173 | + $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); |
|
| 174 | + $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); |
|
| 175 | + if ($data['storage_mtime'] == 0) { |
|
| 176 | + $data['storage_mtime'] = $data['mtime']; |
|
| 177 | + } |
|
| 178 | + $data['permissions'] = (int)$data['permissions']; |
|
| 179 | + return new CacheEntry($data); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * get the metadata of all files stored in $folder |
|
| 184 | + * |
|
| 185 | + * @param string $folder |
|
| 186 | + * @return ICacheEntry[] |
|
| 187 | + */ |
|
| 188 | + public function getFolderContents($folder) { |
|
| 189 | + $fileId = $this->getId($folder); |
|
| 190 | + return $this->getFolderContentsById($fileId); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * get the metadata of all files stored in $folder |
|
| 195 | + * |
|
| 196 | + * @param int $fileId the file id of the folder |
|
| 197 | + * @return ICacheEntry[] |
|
| 198 | + */ |
|
| 199 | + public function getFolderContentsById($fileId) { |
|
| 200 | + if ($fileId > -1) { |
|
| 201 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, |
|
| 202 | 202 | `storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
| 203 | 203 | FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC'; |
| 204 | - $result = $this->connection->executeQuery($sql, [$fileId]); |
|
| 205 | - $files = $result->fetchAll(); |
|
| 206 | - return array_map(function (array $data) { |
|
| 207 | - return self::cacheEntryFromData($data, $this->mimetypeLoader);; |
|
| 208 | - }, $files); |
|
| 209 | - } else { |
|
| 210 | - return array(); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * insert or update meta data for a file or folder |
|
| 216 | - * |
|
| 217 | - * @param string $file |
|
| 218 | - * @param array $data |
|
| 219 | - * |
|
| 220 | - * @return int file id |
|
| 221 | - * @throws \RuntimeException |
|
| 222 | - */ |
|
| 223 | - public function put($file, array $data) { |
|
| 224 | - if (($id = $this->getId($file)) > -1) { |
|
| 225 | - $this->update($id, $data); |
|
| 226 | - return $id; |
|
| 227 | - } else { |
|
| 228 | - return $this->insert($file, $data); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * insert meta data for a new file or folder |
|
| 234 | - * |
|
| 235 | - * @param string $file |
|
| 236 | - * @param array $data |
|
| 237 | - * |
|
| 238 | - * @return int file id |
|
| 239 | - * @throws \RuntimeException |
|
| 240 | - */ |
|
| 241 | - public function insert($file, array $data) { |
|
| 242 | - // normalize file |
|
| 243 | - $file = $this->normalize($file); |
|
| 244 | - |
|
| 245 | - if (isset($this->partial[$file])) { //add any saved partial data |
|
| 246 | - $data = array_merge($this->partial[$file], $data); |
|
| 247 | - unset($this->partial[$file]); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $requiredFields = array('size', 'mtime', 'mimetype'); |
|
| 251 | - foreach ($requiredFields as $field) { |
|
| 252 | - if (!isset($data[$field])) { //data not complete save as partial and return |
|
| 253 | - $this->partial[$file] = $data; |
|
| 254 | - return -1; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $data['path'] = $file; |
|
| 259 | - $data['parent'] = $this->getParentId($file); |
|
| 260 | - $data['name'] = \OC_Util::basename($file); |
|
| 261 | - |
|
| 262 | - list($queryParts, $params) = $this->buildParts($data); |
|
| 263 | - $queryParts[] = '`storage`'; |
|
| 264 | - $params[] = $this->getNumericStorageId(); |
|
| 265 | - |
|
| 266 | - $queryParts = array_map(function ($item) { |
|
| 267 | - return trim($item, "`"); |
|
| 268 | - }, $queryParts); |
|
| 269 | - $values = array_combine($queryParts, $params); |
|
| 270 | - if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [ |
|
| 271 | - 'storage', |
|
| 272 | - 'path_hash', |
|
| 273 | - ]) |
|
| 274 | - ) { |
|
| 275 | - return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // The file was created in the mean time |
|
| 279 | - if (($id = $this->getId($file)) > -1) { |
|
| 280 | - $this->update($id, $data); |
|
| 281 | - return $id; |
|
| 282 | - } else { |
|
| 283 | - throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.'); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * update the metadata of an existing file or folder in the cache |
|
| 289 | - * |
|
| 290 | - * @param int $id the fileid of the existing file or folder |
|
| 291 | - * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged |
|
| 292 | - */ |
|
| 293 | - public function update($id, array $data) { |
|
| 294 | - |
|
| 295 | - if (isset($data['path'])) { |
|
| 296 | - // normalize path |
|
| 297 | - $data['path'] = $this->normalize($data['path']); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - if (isset($data['name'])) { |
|
| 301 | - // normalize path |
|
| 302 | - $data['name'] = $this->normalize($data['name']); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - list($queryParts, $params) = $this->buildParts($data); |
|
| 306 | - // duplicate $params because we need the parts twice in the SQL statement |
|
| 307 | - // once for the SET part, once in the WHERE clause |
|
| 308 | - $params = array_merge($params, $params); |
|
| 309 | - $params[] = $id; |
|
| 310 | - |
|
| 311 | - // don't update if the data we try to set is the same as the one in the record |
|
| 312 | - // some databases (Postgres) don't like superfluous updates |
|
| 313 | - $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' . |
|
| 314 | - 'WHERE (' . |
|
| 315 | - implode(' <> ? OR ', $queryParts) . ' <> ? OR ' . |
|
| 316 | - implode(' IS NULL OR ', $queryParts) . ' IS NULL' . |
|
| 317 | - ') AND `fileid` = ? '; |
|
| 318 | - $this->connection->executeQuery($sql, $params); |
|
| 319 | - |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * extract query parts and params array from data array |
|
| 324 | - * |
|
| 325 | - * @param array $data |
|
| 326 | - * @return array [$queryParts, $params] |
|
| 327 | - * $queryParts: string[], the (escaped) column names to be set in the query |
|
| 328 | - * $params: mixed[], the new values for the columns, to be passed as params to the query |
|
| 329 | - */ |
|
| 330 | - protected function buildParts(array $data) { |
|
| 331 | - $fields = array( |
|
| 332 | - 'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted', |
|
| 333 | - 'etag', 'permissions', 'checksum'); |
|
| 334 | - |
|
| 335 | - $doNotCopyStorageMTime = false; |
|
| 336 | - if (array_key_exists('mtime', $data) && $data['mtime'] === null) { |
|
| 337 | - // this horrific magic tells it to not copy storage_mtime to mtime |
|
| 338 | - unset($data['mtime']); |
|
| 339 | - $doNotCopyStorageMTime = true; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $params = array(); |
|
| 343 | - $queryParts = array(); |
|
| 344 | - foreach ($data as $name => $value) { |
|
| 345 | - if (array_search($name, $fields) !== false) { |
|
| 346 | - if ($name === 'path') { |
|
| 347 | - $params[] = md5($value); |
|
| 348 | - $queryParts[] = '`path_hash`'; |
|
| 349 | - } elseif ($name === 'mimetype') { |
|
| 350 | - $params[] = $this->mimetypeLoader->getId(substr($value, 0, strpos($value, '/'))); |
|
| 351 | - $queryParts[] = '`mimepart`'; |
|
| 352 | - $value = $this->mimetypeLoader->getId($value); |
|
| 353 | - } elseif ($name === 'storage_mtime') { |
|
| 354 | - if (!$doNotCopyStorageMTime && !isset($data['mtime'])) { |
|
| 355 | - $params[] = $value; |
|
| 356 | - $queryParts[] = '`mtime`'; |
|
| 357 | - } |
|
| 358 | - } elseif ($name === 'encrypted') { |
|
| 359 | - if (isset($data['encryptedVersion'])) { |
|
| 360 | - $value = $data['encryptedVersion']; |
|
| 361 | - } else { |
|
| 362 | - // Boolean to integer conversion |
|
| 363 | - $value = $value ? 1 : 0; |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - $params[] = $value; |
|
| 367 | - $queryParts[] = '`' . $name . '`'; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - return array($queryParts, $params); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * get the file id for a file |
|
| 375 | - * |
|
| 376 | - * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file |
|
| 377 | - * |
|
| 378 | - * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 379 | - * |
|
| 380 | - * @param string $file |
|
| 381 | - * @return int |
|
| 382 | - */ |
|
| 383 | - public function getId($file) { |
|
| 384 | - // normalize file |
|
| 385 | - $file = $this->normalize($file); |
|
| 386 | - |
|
| 387 | - $pathHash = md5($file); |
|
| 388 | - |
|
| 389 | - $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 390 | - $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 391 | - if ($row = $result->fetch()) { |
|
| 392 | - return $row['fileid']; |
|
| 393 | - } else { |
|
| 394 | - return -1; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * get the id of the parent folder of a file |
|
| 400 | - * |
|
| 401 | - * @param string $file |
|
| 402 | - * @return int |
|
| 403 | - */ |
|
| 404 | - public function getParentId($file) { |
|
| 405 | - if ($file === '') { |
|
| 406 | - return -1; |
|
| 407 | - } else { |
|
| 408 | - $parent = $this->getParentPath($file); |
|
| 409 | - return (int)$this->getId($parent); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - private function getParentPath($path) { |
|
| 414 | - $parent = dirname($path); |
|
| 415 | - if ($parent === '.') { |
|
| 416 | - $parent = ''; |
|
| 417 | - } |
|
| 418 | - return $parent; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * check if a file is available in the cache |
|
| 423 | - * |
|
| 424 | - * @param string $file |
|
| 425 | - * @return bool |
|
| 426 | - */ |
|
| 427 | - public function inCache($file) { |
|
| 428 | - return $this->getId($file) != -1; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * remove a file or folder from the cache |
|
| 433 | - * |
|
| 434 | - * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 435 | - * |
|
| 436 | - * @param string $file |
|
| 437 | - */ |
|
| 438 | - public function remove($file) { |
|
| 439 | - $entry = $this->get($file); |
|
| 440 | - $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 441 | - $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 442 | - if ($entry['mimetype'] === 'httpd/unix-directory') { |
|
| 443 | - $this->removeChildren($entry); |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Get all sub folders of a folder |
|
| 449 | - * |
|
| 450 | - * @param array $entry the cache entry of the folder to get the subfolders for |
|
| 451 | - * @return array[] the cache entries for the subfolders |
|
| 452 | - */ |
|
| 453 | - private function getSubFolders($entry) { |
|
| 454 | - $children = $this->getFolderContentsById($entry['fileid']); |
|
| 455 | - return array_filter($children, function ($child) { |
|
| 456 | - return $child['mimetype'] === 'httpd/unix-directory'; |
|
| 457 | - }); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Recursively remove all children of a folder |
|
| 462 | - * |
|
| 463 | - * @param array $entry the cache entry of the folder to remove the children of |
|
| 464 | - * @throws \OC\DatabaseException |
|
| 465 | - */ |
|
| 466 | - private function removeChildren($entry) { |
|
| 467 | - $subFolders = $this->getSubFolders($entry); |
|
| 468 | - foreach ($subFolders as $folder) { |
|
| 469 | - $this->removeChildren($folder); |
|
| 470 | - } |
|
| 471 | - $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `parent` = ?'; |
|
| 472 | - $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Move a file or folder in the cache |
|
| 477 | - * |
|
| 478 | - * @param string $source |
|
| 479 | - * @param string $target |
|
| 480 | - */ |
|
| 481 | - public function move($source, $target) { |
|
| 482 | - $this->moveFromCache($this, $source, $target); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Get the storage id and path needed for a move |
|
| 487 | - * |
|
| 488 | - * @param string $path |
|
| 489 | - * @return array [$storageId, $internalPath] |
|
| 490 | - */ |
|
| 491 | - protected function getMoveInfo($path) { |
|
| 492 | - return [$this->getNumericStorageId(), $path]; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Move a file or folder in the cache |
|
| 497 | - * |
|
| 498 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 499 | - * @param string $sourcePath |
|
| 500 | - * @param string $targetPath |
|
| 501 | - * @throws \OC\DatabaseException |
|
| 502 | - */ |
|
| 503 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 504 | - if ($sourceCache instanceof Cache) { |
|
| 505 | - // normalize source and target |
|
| 506 | - $sourcePath = $this->normalize($sourcePath); |
|
| 507 | - $targetPath = $this->normalize($targetPath); |
|
| 508 | - |
|
| 509 | - $sourceData = $sourceCache->get($sourcePath); |
|
| 510 | - $sourceId = $sourceData['fileid']; |
|
| 511 | - $newParentId = $this->getParentId($targetPath); |
|
| 512 | - |
|
| 513 | - list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath); |
|
| 514 | - list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath); |
|
| 515 | - |
|
| 516 | - // sql for final update |
|
| 517 | - $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?'; |
|
| 518 | - |
|
| 519 | - if ($sourceData['mimetype'] === 'httpd/unix-directory') { |
|
| 520 | - //find all child entries |
|
| 521 | - $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; |
|
| 522 | - $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']); |
|
| 523 | - $childEntries = $result->fetchAll(); |
|
| 524 | - $sourceLength = strlen($sourcePath); |
|
| 525 | - $this->connection->beginTransaction(); |
|
| 526 | - $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); |
|
| 527 | - |
|
| 528 | - foreach ($childEntries as $child) { |
|
| 529 | - $newTargetPath = $targetPath . substr($child['path'], $sourceLength); |
|
| 530 | - $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]); |
|
| 531 | - } |
|
| 532 | - $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 533 | - $this->connection->commit(); |
|
| 534 | - } else { |
|
| 535 | - $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 536 | - } |
|
| 537 | - } else { |
|
| 538 | - $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * remove all entries for files that are stored on the storage from the cache |
|
| 544 | - */ |
|
| 545 | - public function clear() { |
|
| 546 | - $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 547 | - $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 548 | - |
|
| 549 | - $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; |
|
| 550 | - $this->connection->executeQuery($sql, array($this->storageId)); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Get the scan status of a file |
|
| 555 | - * |
|
| 556 | - * - Cache::NOT_FOUND: File is not in the cache |
|
| 557 | - * - Cache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 558 | - * - Cache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 559 | - * - Cache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 560 | - * |
|
| 561 | - * @param string $file |
|
| 562 | - * |
|
| 563 | - * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 564 | - */ |
|
| 565 | - public function getStatus($file) { |
|
| 566 | - // normalize file |
|
| 567 | - $file = $this->normalize($file); |
|
| 568 | - |
|
| 569 | - $pathHash = md5($file); |
|
| 570 | - $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 571 | - $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 572 | - if ($row = $result->fetch()) { |
|
| 573 | - if ((int)$row['size'] === -1) { |
|
| 574 | - return self::SHALLOW; |
|
| 575 | - } else { |
|
| 576 | - return self::COMPLETE; |
|
| 577 | - } |
|
| 578 | - } else { |
|
| 579 | - if (isset($this->partial[$file])) { |
|
| 580 | - return self::PARTIAL; |
|
| 581 | - } else { |
|
| 582 | - return self::NOT_FOUND; |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * search for files matching $pattern |
|
| 589 | - * |
|
| 590 | - * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') |
|
| 591 | - * @return ICacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 592 | - */ |
|
| 593 | - public function search($pattern) { |
|
| 594 | - // normalize pattern |
|
| 595 | - $pattern = $this->normalize($pattern); |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - $sql = ' |
|
| 204 | + $result = $this->connection->executeQuery($sql, [$fileId]); |
|
| 205 | + $files = $result->fetchAll(); |
|
| 206 | + return array_map(function (array $data) { |
|
| 207 | + return self::cacheEntryFromData($data, $this->mimetypeLoader);; |
|
| 208 | + }, $files); |
|
| 209 | + } else { |
|
| 210 | + return array(); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * insert or update meta data for a file or folder |
|
| 216 | + * |
|
| 217 | + * @param string $file |
|
| 218 | + * @param array $data |
|
| 219 | + * |
|
| 220 | + * @return int file id |
|
| 221 | + * @throws \RuntimeException |
|
| 222 | + */ |
|
| 223 | + public function put($file, array $data) { |
|
| 224 | + if (($id = $this->getId($file)) > -1) { |
|
| 225 | + $this->update($id, $data); |
|
| 226 | + return $id; |
|
| 227 | + } else { |
|
| 228 | + return $this->insert($file, $data); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * insert meta data for a new file or folder |
|
| 234 | + * |
|
| 235 | + * @param string $file |
|
| 236 | + * @param array $data |
|
| 237 | + * |
|
| 238 | + * @return int file id |
|
| 239 | + * @throws \RuntimeException |
|
| 240 | + */ |
|
| 241 | + public function insert($file, array $data) { |
|
| 242 | + // normalize file |
|
| 243 | + $file = $this->normalize($file); |
|
| 244 | + |
|
| 245 | + if (isset($this->partial[$file])) { //add any saved partial data |
|
| 246 | + $data = array_merge($this->partial[$file], $data); |
|
| 247 | + unset($this->partial[$file]); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $requiredFields = array('size', 'mtime', 'mimetype'); |
|
| 251 | + foreach ($requiredFields as $field) { |
|
| 252 | + if (!isset($data[$field])) { //data not complete save as partial and return |
|
| 253 | + $this->partial[$file] = $data; |
|
| 254 | + return -1; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $data['path'] = $file; |
|
| 259 | + $data['parent'] = $this->getParentId($file); |
|
| 260 | + $data['name'] = \OC_Util::basename($file); |
|
| 261 | + |
|
| 262 | + list($queryParts, $params) = $this->buildParts($data); |
|
| 263 | + $queryParts[] = '`storage`'; |
|
| 264 | + $params[] = $this->getNumericStorageId(); |
|
| 265 | + |
|
| 266 | + $queryParts = array_map(function ($item) { |
|
| 267 | + return trim($item, "`"); |
|
| 268 | + }, $queryParts); |
|
| 269 | + $values = array_combine($queryParts, $params); |
|
| 270 | + if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [ |
|
| 271 | + 'storage', |
|
| 272 | + 'path_hash', |
|
| 273 | + ]) |
|
| 274 | + ) { |
|
| 275 | + return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // The file was created in the mean time |
|
| 279 | + if (($id = $this->getId($file)) > -1) { |
|
| 280 | + $this->update($id, $data); |
|
| 281 | + return $id; |
|
| 282 | + } else { |
|
| 283 | + throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.'); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * update the metadata of an existing file or folder in the cache |
|
| 289 | + * |
|
| 290 | + * @param int $id the fileid of the existing file or folder |
|
| 291 | + * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged |
|
| 292 | + */ |
|
| 293 | + public function update($id, array $data) { |
|
| 294 | + |
|
| 295 | + if (isset($data['path'])) { |
|
| 296 | + // normalize path |
|
| 297 | + $data['path'] = $this->normalize($data['path']); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + if (isset($data['name'])) { |
|
| 301 | + // normalize path |
|
| 302 | + $data['name'] = $this->normalize($data['name']); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + list($queryParts, $params) = $this->buildParts($data); |
|
| 306 | + // duplicate $params because we need the parts twice in the SQL statement |
|
| 307 | + // once for the SET part, once in the WHERE clause |
|
| 308 | + $params = array_merge($params, $params); |
|
| 309 | + $params[] = $id; |
|
| 310 | + |
|
| 311 | + // don't update if the data we try to set is the same as the one in the record |
|
| 312 | + // some databases (Postgres) don't like superfluous updates |
|
| 313 | + $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' . |
|
| 314 | + 'WHERE (' . |
|
| 315 | + implode(' <> ? OR ', $queryParts) . ' <> ? OR ' . |
|
| 316 | + implode(' IS NULL OR ', $queryParts) . ' IS NULL' . |
|
| 317 | + ') AND `fileid` = ? '; |
|
| 318 | + $this->connection->executeQuery($sql, $params); |
|
| 319 | + |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * extract query parts and params array from data array |
|
| 324 | + * |
|
| 325 | + * @param array $data |
|
| 326 | + * @return array [$queryParts, $params] |
|
| 327 | + * $queryParts: string[], the (escaped) column names to be set in the query |
|
| 328 | + * $params: mixed[], the new values for the columns, to be passed as params to the query |
|
| 329 | + */ |
|
| 330 | + protected function buildParts(array $data) { |
|
| 331 | + $fields = array( |
|
| 332 | + 'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted', |
|
| 333 | + 'etag', 'permissions', 'checksum'); |
|
| 334 | + |
|
| 335 | + $doNotCopyStorageMTime = false; |
|
| 336 | + if (array_key_exists('mtime', $data) && $data['mtime'] === null) { |
|
| 337 | + // this horrific magic tells it to not copy storage_mtime to mtime |
|
| 338 | + unset($data['mtime']); |
|
| 339 | + $doNotCopyStorageMTime = true; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $params = array(); |
|
| 343 | + $queryParts = array(); |
|
| 344 | + foreach ($data as $name => $value) { |
|
| 345 | + if (array_search($name, $fields) !== false) { |
|
| 346 | + if ($name === 'path') { |
|
| 347 | + $params[] = md5($value); |
|
| 348 | + $queryParts[] = '`path_hash`'; |
|
| 349 | + } elseif ($name === 'mimetype') { |
|
| 350 | + $params[] = $this->mimetypeLoader->getId(substr($value, 0, strpos($value, '/'))); |
|
| 351 | + $queryParts[] = '`mimepart`'; |
|
| 352 | + $value = $this->mimetypeLoader->getId($value); |
|
| 353 | + } elseif ($name === 'storage_mtime') { |
|
| 354 | + if (!$doNotCopyStorageMTime && !isset($data['mtime'])) { |
|
| 355 | + $params[] = $value; |
|
| 356 | + $queryParts[] = '`mtime`'; |
|
| 357 | + } |
|
| 358 | + } elseif ($name === 'encrypted') { |
|
| 359 | + if (isset($data['encryptedVersion'])) { |
|
| 360 | + $value = $data['encryptedVersion']; |
|
| 361 | + } else { |
|
| 362 | + // Boolean to integer conversion |
|
| 363 | + $value = $value ? 1 : 0; |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + $params[] = $value; |
|
| 367 | + $queryParts[] = '`' . $name . '`'; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + return array($queryParts, $params); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * get the file id for a file |
|
| 375 | + * |
|
| 376 | + * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file |
|
| 377 | + * |
|
| 378 | + * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 379 | + * |
|
| 380 | + * @param string $file |
|
| 381 | + * @return int |
|
| 382 | + */ |
|
| 383 | + public function getId($file) { |
|
| 384 | + // normalize file |
|
| 385 | + $file = $this->normalize($file); |
|
| 386 | + |
|
| 387 | + $pathHash = md5($file); |
|
| 388 | + |
|
| 389 | + $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 390 | + $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 391 | + if ($row = $result->fetch()) { |
|
| 392 | + return $row['fileid']; |
|
| 393 | + } else { |
|
| 394 | + return -1; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * get the id of the parent folder of a file |
|
| 400 | + * |
|
| 401 | + * @param string $file |
|
| 402 | + * @return int |
|
| 403 | + */ |
|
| 404 | + public function getParentId($file) { |
|
| 405 | + if ($file === '') { |
|
| 406 | + return -1; |
|
| 407 | + } else { |
|
| 408 | + $parent = $this->getParentPath($file); |
|
| 409 | + return (int)$this->getId($parent); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + private function getParentPath($path) { |
|
| 414 | + $parent = dirname($path); |
|
| 415 | + if ($parent === '.') { |
|
| 416 | + $parent = ''; |
|
| 417 | + } |
|
| 418 | + return $parent; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * check if a file is available in the cache |
|
| 423 | + * |
|
| 424 | + * @param string $file |
|
| 425 | + * @return bool |
|
| 426 | + */ |
|
| 427 | + public function inCache($file) { |
|
| 428 | + return $this->getId($file) != -1; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * remove a file or folder from the cache |
|
| 433 | + * |
|
| 434 | + * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 435 | + * |
|
| 436 | + * @param string $file |
|
| 437 | + */ |
|
| 438 | + public function remove($file) { |
|
| 439 | + $entry = $this->get($file); |
|
| 440 | + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 441 | + $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 442 | + if ($entry['mimetype'] === 'httpd/unix-directory') { |
|
| 443 | + $this->removeChildren($entry); |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Get all sub folders of a folder |
|
| 449 | + * |
|
| 450 | + * @param array $entry the cache entry of the folder to get the subfolders for |
|
| 451 | + * @return array[] the cache entries for the subfolders |
|
| 452 | + */ |
|
| 453 | + private function getSubFolders($entry) { |
|
| 454 | + $children = $this->getFolderContentsById($entry['fileid']); |
|
| 455 | + return array_filter($children, function ($child) { |
|
| 456 | + return $child['mimetype'] === 'httpd/unix-directory'; |
|
| 457 | + }); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Recursively remove all children of a folder |
|
| 462 | + * |
|
| 463 | + * @param array $entry the cache entry of the folder to remove the children of |
|
| 464 | + * @throws \OC\DatabaseException |
|
| 465 | + */ |
|
| 466 | + private function removeChildren($entry) { |
|
| 467 | + $subFolders = $this->getSubFolders($entry); |
|
| 468 | + foreach ($subFolders as $folder) { |
|
| 469 | + $this->removeChildren($folder); |
|
| 470 | + } |
|
| 471 | + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `parent` = ?'; |
|
| 472 | + $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Move a file or folder in the cache |
|
| 477 | + * |
|
| 478 | + * @param string $source |
|
| 479 | + * @param string $target |
|
| 480 | + */ |
|
| 481 | + public function move($source, $target) { |
|
| 482 | + $this->moveFromCache($this, $source, $target); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Get the storage id and path needed for a move |
|
| 487 | + * |
|
| 488 | + * @param string $path |
|
| 489 | + * @return array [$storageId, $internalPath] |
|
| 490 | + */ |
|
| 491 | + protected function getMoveInfo($path) { |
|
| 492 | + return [$this->getNumericStorageId(), $path]; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Move a file or folder in the cache |
|
| 497 | + * |
|
| 498 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 499 | + * @param string $sourcePath |
|
| 500 | + * @param string $targetPath |
|
| 501 | + * @throws \OC\DatabaseException |
|
| 502 | + */ |
|
| 503 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 504 | + if ($sourceCache instanceof Cache) { |
|
| 505 | + // normalize source and target |
|
| 506 | + $sourcePath = $this->normalize($sourcePath); |
|
| 507 | + $targetPath = $this->normalize($targetPath); |
|
| 508 | + |
|
| 509 | + $sourceData = $sourceCache->get($sourcePath); |
|
| 510 | + $sourceId = $sourceData['fileid']; |
|
| 511 | + $newParentId = $this->getParentId($targetPath); |
|
| 512 | + |
|
| 513 | + list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath); |
|
| 514 | + list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath); |
|
| 515 | + |
|
| 516 | + // sql for final update |
|
| 517 | + $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?'; |
|
| 518 | + |
|
| 519 | + if ($sourceData['mimetype'] === 'httpd/unix-directory') { |
|
| 520 | + //find all child entries |
|
| 521 | + $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; |
|
| 522 | + $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']); |
|
| 523 | + $childEntries = $result->fetchAll(); |
|
| 524 | + $sourceLength = strlen($sourcePath); |
|
| 525 | + $this->connection->beginTransaction(); |
|
| 526 | + $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); |
|
| 527 | + |
|
| 528 | + foreach ($childEntries as $child) { |
|
| 529 | + $newTargetPath = $targetPath . substr($child['path'], $sourceLength); |
|
| 530 | + $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]); |
|
| 531 | + } |
|
| 532 | + $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 533 | + $this->connection->commit(); |
|
| 534 | + } else { |
|
| 535 | + $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 536 | + } |
|
| 537 | + } else { |
|
| 538 | + $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * remove all entries for files that are stored on the storage from the cache |
|
| 544 | + */ |
|
| 545 | + public function clear() { |
|
| 546 | + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 547 | + $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 548 | + |
|
| 549 | + $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; |
|
| 550 | + $this->connection->executeQuery($sql, array($this->storageId)); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Get the scan status of a file |
|
| 555 | + * |
|
| 556 | + * - Cache::NOT_FOUND: File is not in the cache |
|
| 557 | + * - Cache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 558 | + * - Cache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 559 | + * - Cache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 560 | + * |
|
| 561 | + * @param string $file |
|
| 562 | + * |
|
| 563 | + * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 564 | + */ |
|
| 565 | + public function getStatus($file) { |
|
| 566 | + // normalize file |
|
| 567 | + $file = $this->normalize($file); |
|
| 568 | + |
|
| 569 | + $pathHash = md5($file); |
|
| 570 | + $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 571 | + $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 572 | + if ($row = $result->fetch()) { |
|
| 573 | + if ((int)$row['size'] === -1) { |
|
| 574 | + return self::SHALLOW; |
|
| 575 | + } else { |
|
| 576 | + return self::COMPLETE; |
|
| 577 | + } |
|
| 578 | + } else { |
|
| 579 | + if (isset($this->partial[$file])) { |
|
| 580 | + return self::PARTIAL; |
|
| 581 | + } else { |
|
| 582 | + return self::NOT_FOUND; |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * search for files matching $pattern |
|
| 589 | + * |
|
| 590 | + * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') |
|
| 591 | + * @return ICacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 592 | + */ |
|
| 593 | + public function search($pattern) { |
|
| 594 | + // normalize pattern |
|
| 595 | + $pattern = $this->normalize($pattern); |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + $sql = ' |
|
| 599 | 599 | SELECT `fileid`, `storage`, `path`, `parent`, `name`, |
| 600 | 600 | `mimetype`, `storage_mtime`, `mimepart`, `size`, `mtime`, |
| 601 | 601 | `encrypted`, `etag`, `permissions`, `checksum` |
| 602 | 602 | FROM `*PREFIX*filecache` |
| 603 | 603 | WHERE `storage` = ? AND `name` ILIKE ?'; |
| 604 | - $result = $this->connection->executeQuery($sql, |
|
| 605 | - [$this->getNumericStorageId(), $pattern] |
|
| 606 | - ); |
|
| 607 | - |
|
| 608 | - return $this->searchResultToCacheEntries($result); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * @param Statement $result |
|
| 613 | - * @return CacheEntry[] |
|
| 614 | - */ |
|
| 615 | - private function searchResultToCacheEntries(Statement $result) { |
|
| 616 | - $files = $result->fetchAll(); |
|
| 617 | - |
|
| 618 | - return array_map(function (array $data) { |
|
| 619 | - return self::cacheEntryFromData($data, $this->mimetypeLoader); |
|
| 620 | - }, $files); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * search for files by mimetype |
|
| 625 | - * |
|
| 626 | - * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 627 | - * where it will search for all mimetypes in the group ('image/*') |
|
| 628 | - * @return ICacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 629 | - */ |
|
| 630 | - public function searchByMime($mimetype) { |
|
| 631 | - if (strpos($mimetype, '/')) { |
|
| 632 | - $where = '`mimetype` = ?'; |
|
| 633 | - } else { |
|
| 634 | - $where = '`mimepart` = ?'; |
|
| 635 | - } |
|
| 636 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
|
| 604 | + $result = $this->connection->executeQuery($sql, |
|
| 605 | + [$this->getNumericStorageId(), $pattern] |
|
| 606 | + ); |
|
| 607 | + |
|
| 608 | + return $this->searchResultToCacheEntries($result); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * @param Statement $result |
|
| 613 | + * @return CacheEntry[] |
|
| 614 | + */ |
|
| 615 | + private function searchResultToCacheEntries(Statement $result) { |
|
| 616 | + $files = $result->fetchAll(); |
|
| 617 | + |
|
| 618 | + return array_map(function (array $data) { |
|
| 619 | + return self::cacheEntryFromData($data, $this->mimetypeLoader); |
|
| 620 | + }, $files); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * search for files by mimetype |
|
| 625 | + * |
|
| 626 | + * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 627 | + * where it will search for all mimetypes in the group ('image/*') |
|
| 628 | + * @return ICacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 629 | + */ |
|
| 630 | + public function searchByMime($mimetype) { |
|
| 631 | + if (strpos($mimetype, '/')) { |
|
| 632 | + $where = '`mimetype` = ?'; |
|
| 633 | + } else { |
|
| 634 | + $where = '`mimepart` = ?'; |
|
| 635 | + } |
|
| 636 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
|
| 637 | 637 | FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'; |
| 638 | - $mimetype = $this->mimetypeLoader->getId($mimetype); |
|
| 639 | - $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); |
|
| 640 | - |
|
| 641 | - return $this->searchResultToCacheEntries($result); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - public function searchQuery(ISearchQuery $searchQuery) { |
|
| 645 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 646 | - |
|
| 647 | - $query = $builder->select(['fileid', 'storage', 'path', 'parent', 'name', 'mimetype', 'mimepart', 'size', 'mtime', 'storage_mtime', 'encrypted', 'etag', 'permissions', 'checksum']) |
|
| 648 | - ->from('filecache') |
|
| 649 | - ->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId()))) |
|
| 650 | - ->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation())); |
|
| 651 | - |
|
| 652 | - if ($searchQuery->getLimit()) { |
|
| 653 | - $query->setMaxResults($searchQuery->getLimit()); |
|
| 654 | - } |
|
| 655 | - if ($searchQuery->getOffset()) { |
|
| 656 | - $query->setFirstResult($searchQuery->getOffset()); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $result = $query->execute(); |
|
| 660 | - return $this->searchResultToCacheEntries($result); |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Search for files by tag of a given users. |
|
| 665 | - * |
|
| 666 | - * Note that every user can tag files differently. |
|
| 667 | - * |
|
| 668 | - * @param string|int $tag name or tag id |
|
| 669 | - * @param string $userId owner of the tags |
|
| 670 | - * @return ICacheEntry[] file data |
|
| 671 | - */ |
|
| 672 | - public function searchByTag($tag, $userId) { |
|
| 673 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . |
|
| 674 | - '`mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, ' . |
|
| 675 | - '`encrypted`, `etag`, `permissions`, `checksum` ' . |
|
| 676 | - 'FROM `*PREFIX*filecache` `file`, ' . |
|
| 677 | - '`*PREFIX*vcategory_to_object` `tagmap`, ' . |
|
| 678 | - '`*PREFIX*vcategory` `tag` ' . |
|
| 679 | - // JOIN filecache to vcategory_to_object |
|
| 680 | - 'WHERE `file`.`fileid` = `tagmap`.`objid` ' . |
|
| 681 | - // JOIN vcategory_to_object to vcategory |
|
| 682 | - 'AND `tagmap`.`type` = `tag`.`type` ' . |
|
| 683 | - 'AND `tagmap`.`categoryid` = `tag`.`id` ' . |
|
| 684 | - // conditions |
|
| 685 | - 'AND `file`.`storage` = ? ' . |
|
| 686 | - 'AND `tag`.`type` = \'files\' ' . |
|
| 687 | - 'AND `tag`.`uid` = ? '; |
|
| 688 | - if (is_int($tag)) { |
|
| 689 | - $sql .= 'AND `tag`.`id` = ? '; |
|
| 690 | - } else { |
|
| 691 | - $sql .= 'AND `tag`.`category` = ? '; |
|
| 692 | - } |
|
| 693 | - $result = $this->connection->executeQuery( |
|
| 694 | - $sql, |
|
| 695 | - [ |
|
| 696 | - $this->getNumericStorageId(), |
|
| 697 | - $userId, |
|
| 698 | - $tag |
|
| 699 | - ] |
|
| 700 | - ); |
|
| 701 | - |
|
| 702 | - $files = $result->fetchAll(); |
|
| 703 | - |
|
| 704 | - return array_map(function (array $data) { |
|
| 705 | - return self::cacheEntryFromData($data, $this->mimetypeLoader); |
|
| 706 | - }, $files); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Re-calculate the folder size and the size of all parent folders |
|
| 711 | - * |
|
| 712 | - * @param string|boolean $path |
|
| 713 | - * @param array $data (optional) meta data of the folder |
|
| 714 | - */ |
|
| 715 | - public function correctFolderSize($path, $data = null) { |
|
| 716 | - $this->calculateFolderSize($path, $data); |
|
| 717 | - if ($path !== '') { |
|
| 718 | - $parent = dirname($path); |
|
| 719 | - if ($parent === '.' or $parent === '/') { |
|
| 720 | - $parent = ''; |
|
| 721 | - } |
|
| 722 | - $this->correctFolderSize($parent); |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * calculate the size of a folder and set it in the cache |
|
| 728 | - * |
|
| 729 | - * @param string $path |
|
| 730 | - * @param array $entry (optional) meta data of the folder |
|
| 731 | - * @return int |
|
| 732 | - */ |
|
| 733 | - public function calculateFolderSize($path, $entry = null) { |
|
| 734 | - $totalSize = 0; |
|
| 735 | - if (is_null($entry) or !isset($entry['fileid'])) { |
|
| 736 | - $entry = $this->get($path); |
|
| 737 | - } |
|
| 738 | - if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') { |
|
| 739 | - $id = $entry['fileid']; |
|
| 740 | - $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' . |
|
| 741 | - 'FROM `*PREFIX*filecache` ' . |
|
| 742 | - 'WHERE `parent` = ? AND `storage` = ?'; |
|
| 743 | - $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 744 | - if ($row = $result->fetch()) { |
|
| 745 | - $result->closeCursor(); |
|
| 746 | - list($sum, $min) = array_values($row); |
|
| 747 | - $sum = 0 + $sum; |
|
| 748 | - $min = 0 + $min; |
|
| 749 | - if ($min === -1) { |
|
| 750 | - $totalSize = $min; |
|
| 751 | - } else { |
|
| 752 | - $totalSize = $sum; |
|
| 753 | - } |
|
| 754 | - $update = array(); |
|
| 755 | - if ($entry['size'] !== $totalSize) { |
|
| 756 | - $update['size'] = $totalSize; |
|
| 757 | - } |
|
| 758 | - if (count($update) > 0) { |
|
| 759 | - $this->update($id, $update); |
|
| 760 | - } |
|
| 761 | - } else { |
|
| 762 | - $result->closeCursor(); |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - return $totalSize; |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * get all file ids on the files on the storage |
|
| 770 | - * |
|
| 771 | - * @return int[] |
|
| 772 | - */ |
|
| 773 | - public function getAll() { |
|
| 774 | - $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 775 | - $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 776 | - $ids = array(); |
|
| 777 | - while ($row = $result->fetch()) { |
|
| 778 | - $ids[] = $row['fileid']; |
|
| 779 | - } |
|
| 780 | - return $ids; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * find a folder in the cache which has not been fully scanned |
|
| 785 | - * |
|
| 786 | - * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 787 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 788 | - * likely the folder where we stopped scanning previously |
|
| 789 | - * |
|
| 790 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 791 | - */ |
|
| 792 | - public function getIncomplete() { |
|
| 793 | - $query = $this->connection->prepare('SELECT `path` FROM `*PREFIX*filecache`' |
|
| 794 | - . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC', 1); |
|
| 795 | - $query->execute([$this->getNumericStorageId()]); |
|
| 796 | - if ($row = $query->fetch()) { |
|
| 797 | - return $row['path']; |
|
| 798 | - } else { |
|
| 799 | - return false; |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * get the path of a file on this storage by it's file id |
|
| 805 | - * |
|
| 806 | - * @param int $id the file id of the file or folder to search |
|
| 807 | - * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache |
|
| 808 | - */ |
|
| 809 | - public function getPathById($id) { |
|
| 810 | - $sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?'; |
|
| 811 | - $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 812 | - if ($row = $result->fetch()) { |
|
| 813 | - // Oracle stores empty strings as null... |
|
| 814 | - if ($row['path'] === null) { |
|
| 815 | - return ''; |
|
| 816 | - } |
|
| 817 | - return $row['path']; |
|
| 818 | - } else { |
|
| 819 | - return null; |
|
| 820 | - } |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * get the storage id of the storage for a file and the internal path of the file |
|
| 825 | - * unlike getPathById this does not limit the search to files on this storage and |
|
| 826 | - * instead does a global search in the cache table |
|
| 827 | - * |
|
| 828 | - * @param int $id |
|
| 829 | - * @deprecated use getPathById() instead |
|
| 830 | - * @return array first element holding the storage id, second the path |
|
| 831 | - */ |
|
| 832 | - static public function getById($id) { |
|
| 833 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 834 | - $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 835 | - $result = $connection->executeQuery($sql, array($id)); |
|
| 836 | - if ($row = $result->fetch()) { |
|
| 837 | - $numericId = $row['storage']; |
|
| 838 | - $path = $row['path']; |
|
| 839 | - } else { |
|
| 840 | - return null; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - if ($id = Storage::getStorageId($numericId)) { |
|
| 844 | - return array($id, $path); |
|
| 845 | - } else { |
|
| 846 | - return null; |
|
| 847 | - } |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * normalize the given path |
|
| 852 | - * |
|
| 853 | - * @param string $path |
|
| 854 | - * @return string |
|
| 855 | - */ |
|
| 856 | - public function normalize($path) { |
|
| 857 | - |
|
| 858 | - return trim(\OC_Util::normalizeUnicode($path), '/'); |
|
| 859 | - } |
|
| 638 | + $mimetype = $this->mimetypeLoader->getId($mimetype); |
|
| 639 | + $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); |
|
| 640 | + |
|
| 641 | + return $this->searchResultToCacheEntries($result); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + public function searchQuery(ISearchQuery $searchQuery) { |
|
| 645 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 646 | + |
|
| 647 | + $query = $builder->select(['fileid', 'storage', 'path', 'parent', 'name', 'mimetype', 'mimepart', 'size', 'mtime', 'storage_mtime', 'encrypted', 'etag', 'permissions', 'checksum']) |
|
| 648 | + ->from('filecache') |
|
| 649 | + ->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId()))) |
|
| 650 | + ->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation())); |
|
| 651 | + |
|
| 652 | + if ($searchQuery->getLimit()) { |
|
| 653 | + $query->setMaxResults($searchQuery->getLimit()); |
|
| 654 | + } |
|
| 655 | + if ($searchQuery->getOffset()) { |
|
| 656 | + $query->setFirstResult($searchQuery->getOffset()); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + $result = $query->execute(); |
|
| 660 | + return $this->searchResultToCacheEntries($result); |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Search for files by tag of a given users. |
|
| 665 | + * |
|
| 666 | + * Note that every user can tag files differently. |
|
| 667 | + * |
|
| 668 | + * @param string|int $tag name or tag id |
|
| 669 | + * @param string $userId owner of the tags |
|
| 670 | + * @return ICacheEntry[] file data |
|
| 671 | + */ |
|
| 672 | + public function searchByTag($tag, $userId) { |
|
| 673 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . |
|
| 674 | + '`mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, ' . |
|
| 675 | + '`encrypted`, `etag`, `permissions`, `checksum` ' . |
|
| 676 | + 'FROM `*PREFIX*filecache` `file`, ' . |
|
| 677 | + '`*PREFIX*vcategory_to_object` `tagmap`, ' . |
|
| 678 | + '`*PREFIX*vcategory` `tag` ' . |
|
| 679 | + // JOIN filecache to vcategory_to_object |
|
| 680 | + 'WHERE `file`.`fileid` = `tagmap`.`objid` ' . |
|
| 681 | + // JOIN vcategory_to_object to vcategory |
|
| 682 | + 'AND `tagmap`.`type` = `tag`.`type` ' . |
|
| 683 | + 'AND `tagmap`.`categoryid` = `tag`.`id` ' . |
|
| 684 | + // conditions |
|
| 685 | + 'AND `file`.`storage` = ? ' . |
|
| 686 | + 'AND `tag`.`type` = \'files\' ' . |
|
| 687 | + 'AND `tag`.`uid` = ? '; |
|
| 688 | + if (is_int($tag)) { |
|
| 689 | + $sql .= 'AND `tag`.`id` = ? '; |
|
| 690 | + } else { |
|
| 691 | + $sql .= 'AND `tag`.`category` = ? '; |
|
| 692 | + } |
|
| 693 | + $result = $this->connection->executeQuery( |
|
| 694 | + $sql, |
|
| 695 | + [ |
|
| 696 | + $this->getNumericStorageId(), |
|
| 697 | + $userId, |
|
| 698 | + $tag |
|
| 699 | + ] |
|
| 700 | + ); |
|
| 701 | + |
|
| 702 | + $files = $result->fetchAll(); |
|
| 703 | + |
|
| 704 | + return array_map(function (array $data) { |
|
| 705 | + return self::cacheEntryFromData($data, $this->mimetypeLoader); |
|
| 706 | + }, $files); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Re-calculate the folder size and the size of all parent folders |
|
| 711 | + * |
|
| 712 | + * @param string|boolean $path |
|
| 713 | + * @param array $data (optional) meta data of the folder |
|
| 714 | + */ |
|
| 715 | + public function correctFolderSize($path, $data = null) { |
|
| 716 | + $this->calculateFolderSize($path, $data); |
|
| 717 | + if ($path !== '') { |
|
| 718 | + $parent = dirname($path); |
|
| 719 | + if ($parent === '.' or $parent === '/') { |
|
| 720 | + $parent = ''; |
|
| 721 | + } |
|
| 722 | + $this->correctFolderSize($parent); |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * calculate the size of a folder and set it in the cache |
|
| 728 | + * |
|
| 729 | + * @param string $path |
|
| 730 | + * @param array $entry (optional) meta data of the folder |
|
| 731 | + * @return int |
|
| 732 | + */ |
|
| 733 | + public function calculateFolderSize($path, $entry = null) { |
|
| 734 | + $totalSize = 0; |
|
| 735 | + if (is_null($entry) or !isset($entry['fileid'])) { |
|
| 736 | + $entry = $this->get($path); |
|
| 737 | + } |
|
| 738 | + if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') { |
|
| 739 | + $id = $entry['fileid']; |
|
| 740 | + $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' . |
|
| 741 | + 'FROM `*PREFIX*filecache` ' . |
|
| 742 | + 'WHERE `parent` = ? AND `storage` = ?'; |
|
| 743 | + $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 744 | + if ($row = $result->fetch()) { |
|
| 745 | + $result->closeCursor(); |
|
| 746 | + list($sum, $min) = array_values($row); |
|
| 747 | + $sum = 0 + $sum; |
|
| 748 | + $min = 0 + $min; |
|
| 749 | + if ($min === -1) { |
|
| 750 | + $totalSize = $min; |
|
| 751 | + } else { |
|
| 752 | + $totalSize = $sum; |
|
| 753 | + } |
|
| 754 | + $update = array(); |
|
| 755 | + if ($entry['size'] !== $totalSize) { |
|
| 756 | + $update['size'] = $totalSize; |
|
| 757 | + } |
|
| 758 | + if (count($update) > 0) { |
|
| 759 | + $this->update($id, $update); |
|
| 760 | + } |
|
| 761 | + } else { |
|
| 762 | + $result->closeCursor(); |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + return $totalSize; |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * get all file ids on the files on the storage |
|
| 770 | + * |
|
| 771 | + * @return int[] |
|
| 772 | + */ |
|
| 773 | + public function getAll() { |
|
| 774 | + $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 775 | + $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 776 | + $ids = array(); |
|
| 777 | + while ($row = $result->fetch()) { |
|
| 778 | + $ids[] = $row['fileid']; |
|
| 779 | + } |
|
| 780 | + return $ids; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * find a folder in the cache which has not been fully scanned |
|
| 785 | + * |
|
| 786 | + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 787 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 788 | + * likely the folder where we stopped scanning previously |
|
| 789 | + * |
|
| 790 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 791 | + */ |
|
| 792 | + public function getIncomplete() { |
|
| 793 | + $query = $this->connection->prepare('SELECT `path` FROM `*PREFIX*filecache`' |
|
| 794 | + . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC', 1); |
|
| 795 | + $query->execute([$this->getNumericStorageId()]); |
|
| 796 | + if ($row = $query->fetch()) { |
|
| 797 | + return $row['path']; |
|
| 798 | + } else { |
|
| 799 | + return false; |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * get the path of a file on this storage by it's file id |
|
| 805 | + * |
|
| 806 | + * @param int $id the file id of the file or folder to search |
|
| 807 | + * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache |
|
| 808 | + */ |
|
| 809 | + public function getPathById($id) { |
|
| 810 | + $sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?'; |
|
| 811 | + $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 812 | + if ($row = $result->fetch()) { |
|
| 813 | + // Oracle stores empty strings as null... |
|
| 814 | + if ($row['path'] === null) { |
|
| 815 | + return ''; |
|
| 816 | + } |
|
| 817 | + return $row['path']; |
|
| 818 | + } else { |
|
| 819 | + return null; |
|
| 820 | + } |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * get the storage id of the storage for a file and the internal path of the file |
|
| 825 | + * unlike getPathById this does not limit the search to files on this storage and |
|
| 826 | + * instead does a global search in the cache table |
|
| 827 | + * |
|
| 828 | + * @param int $id |
|
| 829 | + * @deprecated use getPathById() instead |
|
| 830 | + * @return array first element holding the storage id, second the path |
|
| 831 | + */ |
|
| 832 | + static public function getById($id) { |
|
| 833 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 834 | + $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 835 | + $result = $connection->executeQuery($sql, array($id)); |
|
| 836 | + if ($row = $result->fetch()) { |
|
| 837 | + $numericId = $row['storage']; |
|
| 838 | + $path = $row['path']; |
|
| 839 | + } else { |
|
| 840 | + return null; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + if ($id = Storage::getStorageId($numericId)) { |
|
| 844 | + return array($id, $path); |
|
| 845 | + } else { |
|
| 846 | + return null; |
|
| 847 | + } |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * normalize the given path |
|
| 852 | + * |
|
| 853 | + * @param string $path |
|
| 854 | + * @return string |
|
| 855 | + */ |
|
| 856 | + public function normalize($path) { |
|
| 857 | + |
|
| 858 | + return trim(\OC_Util::normalizeUnicode($path), '/'); |
|
| 859 | + } |
|
| 860 | 860 | } |
@@ -22,7 +22,6 @@ |
||
| 22 | 22 | use OC\Files\Cache\CacheEntry; |
| 23 | 23 | use OCP\Constants; |
| 24 | 24 | use OCP\Files\Cache\ICache; |
| 25 | -use OCP\Files\Cache\ICacheEntry; |
|
| 26 | 25 | use OCP\Files\FileInfo; |
| 27 | 26 | use OCP\Files\Search\ISearchQuery; |
| 28 | 27 | |
@@ -27,101 +27,101 @@ |
||
| 27 | 27 | use OCP\Files\Search\ISearchQuery; |
| 28 | 28 | |
| 29 | 29 | class NullCache implements ICache { |
| 30 | - public function getNumericStorageId() { |
|
| 31 | - return -1; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function get($file) { |
|
| 35 | - return $file !== '' ? null : |
|
| 36 | - new CacheEntry([ |
|
| 37 | - 'fileid' => -1, |
|
| 38 | - 'parent' => -1, |
|
| 39 | - 'name' => '', |
|
| 40 | - 'path' => '', |
|
| 41 | - 'size' => '0', |
|
| 42 | - 'mtime' => time(), |
|
| 43 | - 'storage_mtime' => time(), |
|
| 44 | - 'etag' => '', |
|
| 45 | - 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
| 46 | - 'mimepart' => 'httpd', |
|
| 47 | - 'permissions' => Constants::PERMISSION_READ |
|
| 48 | - ]); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function getFolderContents($folder) { |
|
| 52 | - return []; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function getFolderContentsById($fileId) { |
|
| 56 | - return []; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function put($file, array $data) { |
|
| 60 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function insert($file, array $data) { |
|
| 64 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function update($id, array $data) { |
|
| 68 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function getId($file) { |
|
| 72 | - return -1; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function getParentId($file) { |
|
| 76 | - return -1; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function inCache($file) { |
|
| 80 | - return $file === ''; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function remove($file) { |
|
| 84 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function move($source, $target) { |
|
| 88 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 92 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function getStatus($file) { |
|
| 96 | - return ICache::COMPLETE; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function search($pattern) { |
|
| 100 | - return []; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function searchByMime($mimetype) { |
|
| 104 | - return []; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function searchQuery(ISearchQuery $query) { |
|
| 108 | - return []; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function searchByTag($tag, $userId) { |
|
| 112 | - return []; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function getIncomplete() { |
|
| 116 | - return []; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function getPathById($id) { |
|
| 120 | - return ''; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function normalize($path) { |
|
| 124 | - return $path; |
|
| 125 | - } |
|
| 30 | + public function getNumericStorageId() { |
|
| 31 | + return -1; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function get($file) { |
|
| 35 | + return $file !== '' ? null : |
|
| 36 | + new CacheEntry([ |
|
| 37 | + 'fileid' => -1, |
|
| 38 | + 'parent' => -1, |
|
| 39 | + 'name' => '', |
|
| 40 | + 'path' => '', |
|
| 41 | + 'size' => '0', |
|
| 42 | + 'mtime' => time(), |
|
| 43 | + 'storage_mtime' => time(), |
|
| 44 | + 'etag' => '', |
|
| 45 | + 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
| 46 | + 'mimepart' => 'httpd', |
|
| 47 | + 'permissions' => Constants::PERMISSION_READ |
|
| 48 | + ]); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function getFolderContents($folder) { |
|
| 52 | + return []; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function getFolderContentsById($fileId) { |
|
| 56 | + return []; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function put($file, array $data) { |
|
| 60 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function insert($file, array $data) { |
|
| 64 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function update($id, array $data) { |
|
| 68 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function getId($file) { |
|
| 72 | + return -1; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function getParentId($file) { |
|
| 76 | + return -1; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function inCache($file) { |
|
| 80 | + return $file === ''; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function remove($file) { |
|
| 84 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function move($source, $target) { |
|
| 88 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 92 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function getStatus($file) { |
|
| 96 | + return ICache::COMPLETE; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function search($pattern) { |
|
| 100 | + return []; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function searchByMime($mimetype) { |
|
| 104 | + return []; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function searchQuery(ISearchQuery $query) { |
|
| 108 | + return []; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function searchByTag($tag, $userId) { |
|
| 112 | + return []; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function getIncomplete() { |
|
| 116 | + return []; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function getPathById($id) { |
|
| 120 | + return ''; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function normalize($path) { |
|
| 124 | + return $path; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
@@ -25,22 +25,22 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchOrder { |
| 28 | - const DIRECTION_ASCENDING = 'asc'; |
|
| 29 | - const DIRECTION_DESCENDING = 'desc'; |
|
| 28 | + const DIRECTION_ASCENDING = 'asc'; |
|
| 29 | + const DIRECTION_DESCENDING = 'desc'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The direction to sort in, either ISearchOrder::DIRECTION_ASCENDING or ISearchOrder::DIRECTION_DESCENDING |
|
| 33 | - * |
|
| 34 | - * @return string |
|
| 35 | - * @since 12.0.0 |
|
| 36 | - */ |
|
| 37 | - public function getDirection(); |
|
| 31 | + /** |
|
| 32 | + * The direction to sort in, either ISearchOrder::DIRECTION_ASCENDING or ISearchOrder::DIRECTION_DESCENDING |
|
| 33 | + * |
|
| 34 | + * @return string |
|
| 35 | + * @since 12.0.0 |
|
| 36 | + */ |
|
| 37 | + public function getDirection(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * The field to sort on |
|
| 41 | - * |
|
| 42 | - * @return string |
|
| 43 | - * @since 12.0.0 |
|
| 44 | - */ |
|
| 45 | - public function getField(); |
|
| 39 | + /** |
|
| 40 | + * The field to sort on |
|
| 41 | + * |
|
| 42 | + * @return string |
|
| 43 | + * @since 12.0.0 |
|
| 44 | + */ |
|
| 45 | + public function getField(); |
|
| 46 | 46 | } |
@@ -25,36 +25,36 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchComparison extends ISearchOperator { |
| 28 | - const COMPARE_EQUAL = 'eq'; |
|
| 29 | - const COMPARE_GREATER_THAN = 'gt'; |
|
| 30 | - const COMPARE_GREATER_THAN_EQUAL = 'gte'; |
|
| 31 | - const COMPARE_LESS_THAN = 'lt'; |
|
| 32 | - const COMPARE_LESS_THAN_EQUAL = 'lte'; |
|
| 33 | - const COMPARE_LIKE = 'like'; |
|
| 28 | + const COMPARE_EQUAL = 'eq'; |
|
| 29 | + const COMPARE_GREATER_THAN = 'gt'; |
|
| 30 | + const COMPARE_GREATER_THAN_EQUAL = 'gte'; |
|
| 31 | + const COMPARE_LESS_THAN = 'lt'; |
|
| 32 | + const COMPARE_LESS_THAN_EQUAL = 'lte'; |
|
| 33 | + const COMPARE_LIKE = 'like'; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get the type of comparison, one of the ISearchComparison::COMPARE_* constants |
|
| 37 | - * |
|
| 38 | - * @return string |
|
| 39 | - * @since 12.0.0 |
|
| 40 | - */ |
|
| 41 | - public function getType(); |
|
| 35 | + /** |
|
| 36 | + * Get the type of comparison, one of the ISearchComparison::COMPARE_* constants |
|
| 37 | + * |
|
| 38 | + * @return string |
|
| 39 | + * @since 12.0.0 |
|
| 40 | + */ |
|
| 41 | + public function getType(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Get the name of the field to compare with |
|
| 45 | - * |
|
| 46 | - * i.e. 'size', 'name' or 'mimetype' |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - * @since 12.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getField(); |
|
| 43 | + /** |
|
| 44 | + * Get the name of the field to compare with |
|
| 45 | + * |
|
| 46 | + * i.e. 'size', 'name' or 'mimetype' |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + * @since 12.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getField(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get the value to compare the field with |
|
| 55 | - * |
|
| 56 | - * @return string|integer|\DateTime |
|
| 57 | - * @since 12.0.0 |
|
| 58 | - */ |
|
| 59 | - public function getValue(); |
|
| 53 | + /** |
|
| 54 | + * Get the value to compare the field with |
|
| 55 | + * |
|
| 56 | + * @return string|integer|\DateTime |
|
| 57 | + * @since 12.0.0 |
|
| 58 | + */ |
|
| 59 | + public function getValue(); |
|
| 60 | 60 | } |
@@ -25,33 +25,33 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchQuery { |
| 28 | - /** |
|
| 29 | - * @return ISearchOperator |
|
| 30 | - * @since 12.0.0 |
|
| 31 | - */ |
|
| 32 | - public function getSearchOperation(); |
|
| 28 | + /** |
|
| 29 | + * @return ISearchOperator |
|
| 30 | + * @since 12.0.0 |
|
| 31 | + */ |
|
| 32 | + public function getSearchOperation(); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get the maximum number of results to return |
|
| 36 | - * |
|
| 37 | - * @return integer |
|
| 38 | - * @since 12.0.0 |
|
| 39 | - */ |
|
| 40 | - public function getLimit(); |
|
| 34 | + /** |
|
| 35 | + * Get the maximum number of results to return |
|
| 36 | + * |
|
| 37 | + * @return integer |
|
| 38 | + * @since 12.0.0 |
|
| 39 | + */ |
|
| 40 | + public function getLimit(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Get the offset for returned results |
|
| 44 | - * |
|
| 45 | - * @return integer |
|
| 46 | - * @since 12.0.0 |
|
| 47 | - */ |
|
| 48 | - public function getOffset(); |
|
| 42 | + /** |
|
| 43 | + * Get the offset for returned results |
|
| 44 | + * |
|
| 45 | + * @return integer |
|
| 46 | + * @since 12.0.0 |
|
| 47 | + */ |
|
| 48 | + public function getOffset(); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * The fields and directions to order by |
|
| 52 | - * |
|
| 53 | - * @return ISearchOrder[] |
|
| 54 | - * @since 12.0.0 |
|
| 55 | - */ |
|
| 56 | - public function getOrder(); |
|
| 50 | + /** |
|
| 51 | + * The fields and directions to order by |
|
| 52 | + * |
|
| 53 | + * @return ISearchOrder[] |
|
| 54 | + * @since 12.0.0 |
|
| 55 | + */ |
|
| 56 | + public function getOrder(); |
|
| 57 | 57 | } |
@@ -25,27 +25,27 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchBinaryOperator extends ISearchOperator { |
| 28 | - const OPERATOR_AND = 'and'; |
|
| 29 | - const OPERATOR_OR = 'or'; |
|
| 30 | - const OPERATOR_NOT = 'not'; |
|
| 28 | + const OPERATOR_AND = 'and'; |
|
| 29 | + const OPERATOR_OR = 'or'; |
|
| 30 | + const OPERATOR_NOT = 'not'; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The type of binary operator |
|
| 34 | - * |
|
| 35 | - * One of the ISearchBinaryOperator::OPERATOR_* constants |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - * @since 12.0.0 |
|
| 39 | - */ |
|
| 40 | - public function getType(); |
|
| 32 | + /** |
|
| 33 | + * The type of binary operator |
|
| 34 | + * |
|
| 35 | + * One of the ISearchBinaryOperator::OPERATOR_* constants |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + * @since 12.0.0 |
|
| 39 | + */ |
|
| 40 | + public function getType(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The arguments for the binary operator |
|
| 44 | - * |
|
| 45 | - * One argument for the 'not' operator and two for 'and' and 'or' |
|
| 46 | - * |
|
| 47 | - * @return ISearchOperator[] |
|
| 48 | - * @since 12.0.0 |
|
| 49 | - */ |
|
| 50 | - public function getArguments(); |
|
| 42 | + /** |
|
| 43 | + * The arguments for the binary operator |
|
| 44 | + * |
|
| 45 | + * One argument for the 'not' operator and two for 'and' and 'or' |
|
| 46 | + * |
|
| 47 | + * @return ISearchOperator[] |
|
| 48 | + * @since 12.0.0 |
|
| 49 | + */ |
|
| 50 | + public function getArguments(); |
|
| 51 | 51 | } |
@@ -36,152 +36,152 @@ |
||
| 36 | 36 | * @since 6.0.0 |
| 37 | 37 | */ |
| 38 | 38 | interface Folder extends Node { |
| 39 | - /** |
|
| 40 | - * Get the full path of an item in the folder within owncloud's filesystem |
|
| 41 | - * |
|
| 42 | - * @param string $path relative path of an item in the folder |
|
| 43 | - * @return string |
|
| 44 | - * @throws \OCP\Files\NotPermittedException |
|
| 45 | - * @since 6.0.0 |
|
| 46 | - */ |
|
| 47 | - public function getFullPath($path); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Get the path of an item in the folder relative to the folder |
|
| 51 | - * |
|
| 52 | - * @param string $path absolute path of an item in the folder |
|
| 53 | - * @throws \OCP\Files\NotFoundException |
|
| 54 | - * @return string |
|
| 55 | - * @since 6.0.0 |
|
| 56 | - */ |
|
| 57 | - public function getRelativePath($path); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * check if a node is a (grand-)child of the folder |
|
| 61 | - * |
|
| 62 | - * @param \OCP\Files\Node $node |
|
| 63 | - * @return bool |
|
| 64 | - * @since 6.0.0 |
|
| 65 | - */ |
|
| 66 | - public function isSubNode($node); |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * get the content of this directory |
|
| 70 | - * |
|
| 71 | - * @throws \OCP\Files\NotFoundException |
|
| 72 | - * @return \OCP\Files\Node[] |
|
| 73 | - * @since 6.0.0 |
|
| 74 | - */ |
|
| 75 | - public function getDirectoryListing(); |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get the node at $path |
|
| 79 | - * |
|
| 80 | - * @param string $path relative path of the file or folder |
|
| 81 | - * @return \OCP\Files\Node |
|
| 82 | - * @throws \OCP\Files\NotFoundException |
|
| 83 | - * @since 6.0.0 |
|
| 84 | - */ |
|
| 85 | - public function get($path); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Check if a file or folder exists in the folder |
|
| 89 | - * |
|
| 90 | - * @param string $path relative path of the file or folder |
|
| 91 | - * @return bool |
|
| 92 | - * @since 6.0.0 |
|
| 93 | - */ |
|
| 94 | - public function nodeExists($path); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Create a new folder |
|
| 98 | - * |
|
| 99 | - * @param string $path relative path of the new folder |
|
| 100 | - * @return \OCP\Files\Folder |
|
| 101 | - * @throws \OCP\Files\NotPermittedException |
|
| 102 | - * @since 6.0.0 |
|
| 103 | - */ |
|
| 104 | - public function newFolder($path); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Create a new file |
|
| 108 | - * |
|
| 109 | - * @param string $path relative path of the new file |
|
| 110 | - * @return \OCP\Files\File |
|
| 111 | - * @throws \OCP\Files\NotPermittedException |
|
| 112 | - * @since 6.0.0 |
|
| 113 | - */ |
|
| 114 | - public function newFile($path); |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * search for files with the name matching $query |
|
| 118 | - * |
|
| 119 | - * @param string|ISearchQuery $query |
|
| 120 | - * @return \OCP\Files\Node[] |
|
| 121 | - * @since 6.0.0 |
|
| 122 | - */ |
|
| 123 | - public function search($query); |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * search for files by mimetype |
|
| 127 | - * $mimetype can either be a full mimetype (image/png) or a wildcard mimetype (image) |
|
| 128 | - * |
|
| 129 | - * @param string $mimetype |
|
| 130 | - * @return \OCP\Files\Node[] |
|
| 131 | - * @since 6.0.0 |
|
| 132 | - */ |
|
| 133 | - public function searchByMime($mimetype); |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * search for files by tag |
|
| 137 | - * |
|
| 138 | - * @param string|int $tag tag name or tag id |
|
| 139 | - * @param string $userId owner of the tags |
|
| 140 | - * @return \OCP\Files\Node[] |
|
| 141 | - * @since 8.0.0 |
|
| 142 | - */ |
|
| 143 | - public function searchByTag($tag, $userId); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * get a file or folder inside the folder by it's internal id |
|
| 147 | - * |
|
| 148 | - * @param int $id |
|
| 149 | - * @return \OCP\Files\Node[] |
|
| 150 | - * @since 6.0.0 |
|
| 151 | - */ |
|
| 152 | - public function getById($id); |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Get the amount of free space inside the folder |
|
| 156 | - * |
|
| 157 | - * @return int |
|
| 158 | - * @since 6.0.0 |
|
| 159 | - */ |
|
| 160 | - public function getFreeSpace(); |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Check if new files or folders can be created within the folder |
|
| 164 | - * |
|
| 165 | - * @return bool |
|
| 166 | - * @since 6.0.0 |
|
| 167 | - */ |
|
| 168 | - public function isCreatable(); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Add a suffix to the name in case the file exists |
|
| 172 | - * |
|
| 173 | - * @param string $name |
|
| 174 | - * @return string |
|
| 175 | - * @throws NotPermittedException |
|
| 176 | - * @since 8.1.0 |
|
| 177 | - */ |
|
| 178 | - public function getNonExistingName($name); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @param int $limit |
|
| 182 | - * @param int $offset |
|
| 183 | - * @return \OCP\Files\Node[] |
|
| 184 | - * @since 9.1.0 |
|
| 185 | - */ |
|
| 186 | - public function getRecent($limit, $offset = 0); |
|
| 39 | + /** |
|
| 40 | + * Get the full path of an item in the folder within owncloud's filesystem |
|
| 41 | + * |
|
| 42 | + * @param string $path relative path of an item in the folder |
|
| 43 | + * @return string |
|
| 44 | + * @throws \OCP\Files\NotPermittedException |
|
| 45 | + * @since 6.0.0 |
|
| 46 | + */ |
|
| 47 | + public function getFullPath($path); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Get the path of an item in the folder relative to the folder |
|
| 51 | + * |
|
| 52 | + * @param string $path absolute path of an item in the folder |
|
| 53 | + * @throws \OCP\Files\NotFoundException |
|
| 54 | + * @return string |
|
| 55 | + * @since 6.0.0 |
|
| 56 | + */ |
|
| 57 | + public function getRelativePath($path); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * check if a node is a (grand-)child of the folder |
|
| 61 | + * |
|
| 62 | + * @param \OCP\Files\Node $node |
|
| 63 | + * @return bool |
|
| 64 | + * @since 6.0.0 |
|
| 65 | + */ |
|
| 66 | + public function isSubNode($node); |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * get the content of this directory |
|
| 70 | + * |
|
| 71 | + * @throws \OCP\Files\NotFoundException |
|
| 72 | + * @return \OCP\Files\Node[] |
|
| 73 | + * @since 6.0.0 |
|
| 74 | + */ |
|
| 75 | + public function getDirectoryListing(); |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get the node at $path |
|
| 79 | + * |
|
| 80 | + * @param string $path relative path of the file or folder |
|
| 81 | + * @return \OCP\Files\Node |
|
| 82 | + * @throws \OCP\Files\NotFoundException |
|
| 83 | + * @since 6.0.0 |
|
| 84 | + */ |
|
| 85 | + public function get($path); |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Check if a file or folder exists in the folder |
|
| 89 | + * |
|
| 90 | + * @param string $path relative path of the file or folder |
|
| 91 | + * @return bool |
|
| 92 | + * @since 6.0.0 |
|
| 93 | + */ |
|
| 94 | + public function nodeExists($path); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Create a new folder |
|
| 98 | + * |
|
| 99 | + * @param string $path relative path of the new folder |
|
| 100 | + * @return \OCP\Files\Folder |
|
| 101 | + * @throws \OCP\Files\NotPermittedException |
|
| 102 | + * @since 6.0.0 |
|
| 103 | + */ |
|
| 104 | + public function newFolder($path); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Create a new file |
|
| 108 | + * |
|
| 109 | + * @param string $path relative path of the new file |
|
| 110 | + * @return \OCP\Files\File |
|
| 111 | + * @throws \OCP\Files\NotPermittedException |
|
| 112 | + * @since 6.0.0 |
|
| 113 | + */ |
|
| 114 | + public function newFile($path); |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * search for files with the name matching $query |
|
| 118 | + * |
|
| 119 | + * @param string|ISearchQuery $query |
|
| 120 | + * @return \OCP\Files\Node[] |
|
| 121 | + * @since 6.0.0 |
|
| 122 | + */ |
|
| 123 | + public function search($query); |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * search for files by mimetype |
|
| 127 | + * $mimetype can either be a full mimetype (image/png) or a wildcard mimetype (image) |
|
| 128 | + * |
|
| 129 | + * @param string $mimetype |
|
| 130 | + * @return \OCP\Files\Node[] |
|
| 131 | + * @since 6.0.0 |
|
| 132 | + */ |
|
| 133 | + public function searchByMime($mimetype); |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * search for files by tag |
|
| 137 | + * |
|
| 138 | + * @param string|int $tag tag name or tag id |
|
| 139 | + * @param string $userId owner of the tags |
|
| 140 | + * @return \OCP\Files\Node[] |
|
| 141 | + * @since 8.0.0 |
|
| 142 | + */ |
|
| 143 | + public function searchByTag($tag, $userId); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * get a file or folder inside the folder by it's internal id |
|
| 147 | + * |
|
| 148 | + * @param int $id |
|
| 149 | + * @return \OCP\Files\Node[] |
|
| 150 | + * @since 6.0.0 |
|
| 151 | + */ |
|
| 152 | + public function getById($id); |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Get the amount of free space inside the folder |
|
| 156 | + * |
|
| 157 | + * @return int |
|
| 158 | + * @since 6.0.0 |
|
| 159 | + */ |
|
| 160 | + public function getFreeSpace(); |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Check if new files or folders can be created within the folder |
|
| 164 | + * |
|
| 165 | + * @return bool |
|
| 166 | + * @since 6.0.0 |
|
| 167 | + */ |
|
| 168 | + public function isCreatable(); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Add a suffix to the name in case the file exists |
|
| 172 | + * |
|
| 173 | + * @param string $name |
|
| 174 | + * @return string |
|
| 175 | + * @throws NotPermittedException |
|
| 176 | + * @since 8.1.0 |
|
| 177 | + */ |
|
| 178 | + public function getNonExistingName($name); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @param int $limit |
|
| 182 | + * @param int $offset |
|
| 183 | + * @return \OCP\Files\Node[] |
|
| 184 | + * @since 9.1.0 |
|
| 185 | + */ |
|
| 186 | + public function getRecent($limit, $offset = 0); |
|
| 187 | 187 | } |
@@ -37,233 +37,233 @@ |
||
| 37 | 37 | * @since 9.0.0 |
| 38 | 38 | */ |
| 39 | 39 | interface ICache { |
| 40 | - const NOT_FOUND = 0; |
|
| 41 | - const PARTIAL = 1; //only partial data available, file not cached in the database |
|
| 42 | - const SHALLOW = 2; //folder in cache, but not all child files are completely scanned |
|
| 43 | - const COMPLETE = 3; |
|
| 40 | + const NOT_FOUND = 0; |
|
| 41 | + const PARTIAL = 1; //only partial data available, file not cached in the database |
|
| 42 | + const SHALLOW = 2; //folder in cache, but not all child files are completely scanned |
|
| 43 | + const COMPLETE = 3; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Get the numeric storage id for this cache's storage |
|
| 47 | - * |
|
| 48 | - * @return int |
|
| 49 | - * @since 9.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getNumericStorageId(); |
|
| 45 | + /** |
|
| 46 | + * Get the numeric storage id for this cache's storage |
|
| 47 | + * |
|
| 48 | + * @return int |
|
| 49 | + * @since 9.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getNumericStorageId(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * get the stored metadata of a file or folder |
|
| 55 | - * |
|
| 56 | - * @param string | int $file either the path of a file or folder or the file id for a file or folder |
|
| 57 | - * @return ICacheEntry|false the cache entry or false if the file is not found in the cache |
|
| 58 | - * @since 9.0.0 |
|
| 59 | - */ |
|
| 60 | - public function get($file); |
|
| 53 | + /** |
|
| 54 | + * get the stored metadata of a file or folder |
|
| 55 | + * |
|
| 56 | + * @param string | int $file either the path of a file or folder or the file id for a file or folder |
|
| 57 | + * @return ICacheEntry|false the cache entry or false if the file is not found in the cache |
|
| 58 | + * @since 9.0.0 |
|
| 59 | + */ |
|
| 60 | + public function get($file); |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * get the metadata of all files stored in $folder |
|
| 64 | - * |
|
| 65 | - * Only returns files one level deep, no recursion |
|
| 66 | - * |
|
| 67 | - * @param string $folder |
|
| 68 | - * @return ICacheEntry[] |
|
| 69 | - * @since 9.0.0 |
|
| 70 | - */ |
|
| 71 | - public function getFolderContents($folder); |
|
| 62 | + /** |
|
| 63 | + * get the metadata of all files stored in $folder |
|
| 64 | + * |
|
| 65 | + * Only returns files one level deep, no recursion |
|
| 66 | + * |
|
| 67 | + * @param string $folder |
|
| 68 | + * @return ICacheEntry[] |
|
| 69 | + * @since 9.0.0 |
|
| 70 | + */ |
|
| 71 | + public function getFolderContents($folder); |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * get the metadata of all files stored in $folder |
|
| 75 | - * |
|
| 76 | - * Only returns files one level deep, no recursion |
|
| 77 | - * |
|
| 78 | - * @param int $fileId the file id of the folder |
|
| 79 | - * @return ICacheEntry[] |
|
| 80 | - * @since 9.0.0 |
|
| 81 | - */ |
|
| 82 | - public function getFolderContentsById($fileId); |
|
| 73 | + /** |
|
| 74 | + * get the metadata of all files stored in $folder |
|
| 75 | + * |
|
| 76 | + * Only returns files one level deep, no recursion |
|
| 77 | + * |
|
| 78 | + * @param int $fileId the file id of the folder |
|
| 79 | + * @return ICacheEntry[] |
|
| 80 | + * @since 9.0.0 |
|
| 81 | + */ |
|
| 82 | + public function getFolderContentsById($fileId); |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * store meta data for a file or folder |
|
| 86 | - * This will automatically call either insert or update depending on if the file exists |
|
| 87 | - * |
|
| 88 | - * @param string $file |
|
| 89 | - * @param array $data |
|
| 90 | - * |
|
| 91 | - * @return int file id |
|
| 92 | - * @throws \RuntimeException |
|
| 93 | - * @since 9.0.0 |
|
| 94 | - */ |
|
| 95 | - public function put($file, array $data); |
|
| 84 | + /** |
|
| 85 | + * store meta data for a file or folder |
|
| 86 | + * This will automatically call either insert or update depending on if the file exists |
|
| 87 | + * |
|
| 88 | + * @param string $file |
|
| 89 | + * @param array $data |
|
| 90 | + * |
|
| 91 | + * @return int file id |
|
| 92 | + * @throws \RuntimeException |
|
| 93 | + * @since 9.0.0 |
|
| 94 | + */ |
|
| 95 | + public function put($file, array $data); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * insert meta data for a new file or folder |
|
| 99 | - * |
|
| 100 | - * @param string $file |
|
| 101 | - * @param array $data |
|
| 102 | - * |
|
| 103 | - * @return int file id |
|
| 104 | - * @throws \RuntimeException |
|
| 105 | - * @since 9.0.0 |
|
| 106 | - */ |
|
| 107 | - public function insert($file, array $data); |
|
| 97 | + /** |
|
| 98 | + * insert meta data for a new file or folder |
|
| 99 | + * |
|
| 100 | + * @param string $file |
|
| 101 | + * @param array $data |
|
| 102 | + * |
|
| 103 | + * @return int file id |
|
| 104 | + * @throws \RuntimeException |
|
| 105 | + * @since 9.0.0 |
|
| 106 | + */ |
|
| 107 | + public function insert($file, array $data); |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * update the metadata of an existing file or folder in the cache |
|
| 111 | - * |
|
| 112 | - * @param int $id the fileid of the existing file or folder |
|
| 113 | - * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged |
|
| 114 | - * @since 9.0.0 |
|
| 115 | - */ |
|
| 116 | - public function update($id, array $data); |
|
| 109 | + /** |
|
| 110 | + * update the metadata of an existing file or folder in the cache |
|
| 111 | + * |
|
| 112 | + * @param int $id the fileid of the existing file or folder |
|
| 113 | + * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged |
|
| 114 | + * @since 9.0.0 |
|
| 115 | + */ |
|
| 116 | + public function update($id, array $data); |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * get the file id for a file |
|
| 120 | - * |
|
| 121 | - * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file |
|
| 122 | - * |
|
| 123 | - * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 124 | - * |
|
| 125 | - * @param string $file |
|
| 126 | - * @return int |
|
| 127 | - * @since 9.0.0 |
|
| 128 | - */ |
|
| 129 | - public function getId($file); |
|
| 118 | + /** |
|
| 119 | + * get the file id for a file |
|
| 120 | + * |
|
| 121 | + * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file |
|
| 122 | + * |
|
| 123 | + * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 124 | + * |
|
| 125 | + * @param string $file |
|
| 126 | + * @return int |
|
| 127 | + * @since 9.0.0 |
|
| 128 | + */ |
|
| 129 | + public function getId($file); |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * get the id of the parent folder of a file |
|
| 133 | - * |
|
| 134 | - * @param string $file |
|
| 135 | - * @return int |
|
| 136 | - * @since 9.0.0 |
|
| 137 | - */ |
|
| 138 | - public function getParentId($file); |
|
| 131 | + /** |
|
| 132 | + * get the id of the parent folder of a file |
|
| 133 | + * |
|
| 134 | + * @param string $file |
|
| 135 | + * @return int |
|
| 136 | + * @since 9.0.0 |
|
| 137 | + */ |
|
| 138 | + public function getParentId($file); |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * check if a file is available in the cache |
|
| 142 | - * |
|
| 143 | - * @param string $file |
|
| 144 | - * @return bool |
|
| 145 | - * @since 9.0.0 |
|
| 146 | - */ |
|
| 147 | - public function inCache($file); |
|
| 140 | + /** |
|
| 141 | + * check if a file is available in the cache |
|
| 142 | + * |
|
| 143 | + * @param string $file |
|
| 144 | + * @return bool |
|
| 145 | + * @since 9.0.0 |
|
| 146 | + */ |
|
| 147 | + public function inCache($file); |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * remove a file or folder from the cache |
|
| 151 | - * |
|
| 152 | - * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 153 | - * |
|
| 154 | - * @param string $file |
|
| 155 | - * @since 9.0.0 |
|
| 156 | - */ |
|
| 157 | - public function remove($file); |
|
| 149 | + /** |
|
| 150 | + * remove a file or folder from the cache |
|
| 151 | + * |
|
| 152 | + * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 153 | + * |
|
| 154 | + * @param string $file |
|
| 155 | + * @since 9.0.0 |
|
| 156 | + */ |
|
| 157 | + public function remove($file); |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Move a file or folder in the cache |
|
| 161 | - * |
|
| 162 | - * @param string $source |
|
| 163 | - * @param string $target |
|
| 164 | - * @since 9.0.0 |
|
| 165 | - */ |
|
| 166 | - public function move($source, $target); |
|
| 159 | + /** |
|
| 160 | + * Move a file or folder in the cache |
|
| 161 | + * |
|
| 162 | + * @param string $source |
|
| 163 | + * @param string $target |
|
| 164 | + * @since 9.0.0 |
|
| 165 | + */ |
|
| 166 | + public function move($source, $target); |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Move a file or folder in the cache |
|
| 170 | - * |
|
| 171 | - * Note that this should make sure the entries are removed from the source cache |
|
| 172 | - * |
|
| 173 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 174 | - * @param string $sourcePath |
|
| 175 | - * @param string $targetPath |
|
| 176 | - * @throws \OC\DatabaseException |
|
| 177 | - * @since 9.0.0 |
|
| 178 | - */ |
|
| 179 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath); |
|
| 168 | + /** |
|
| 169 | + * Move a file or folder in the cache |
|
| 170 | + * |
|
| 171 | + * Note that this should make sure the entries are removed from the source cache |
|
| 172 | + * |
|
| 173 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 174 | + * @param string $sourcePath |
|
| 175 | + * @param string $targetPath |
|
| 176 | + * @throws \OC\DatabaseException |
|
| 177 | + * @since 9.0.0 |
|
| 178 | + */ |
|
| 179 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath); |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Get the scan status of a file |
|
| 183 | - * |
|
| 184 | - * - ICache::NOT_FOUND: File is not in the cache |
|
| 185 | - * - ICache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 186 | - * - ICache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 187 | - * - ICache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 188 | - * |
|
| 189 | - * @param string $file |
|
| 190 | - * |
|
| 191 | - * @return int ICache::NOT_FOUND, ICache::PARTIAL, ICache::SHALLOW or ICache::COMPLETE |
|
| 192 | - * @since 9.0.0 |
|
| 193 | - */ |
|
| 194 | - public function getStatus($file); |
|
| 181 | + /** |
|
| 182 | + * Get the scan status of a file |
|
| 183 | + * |
|
| 184 | + * - ICache::NOT_FOUND: File is not in the cache |
|
| 185 | + * - ICache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 186 | + * - ICache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 187 | + * - ICache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 188 | + * |
|
| 189 | + * @param string $file |
|
| 190 | + * |
|
| 191 | + * @return int ICache::NOT_FOUND, ICache::PARTIAL, ICache::SHALLOW or ICache::COMPLETE |
|
| 192 | + * @since 9.0.0 |
|
| 193 | + */ |
|
| 194 | + public function getStatus($file); |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * search for files matching $pattern, files are matched if their filename matches the search pattern |
|
| 198 | - * |
|
| 199 | - * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') |
|
| 200 | - * @return ICacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 201 | - * @since 9.0.0 |
|
| 202 | - * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 203 | - */ |
|
| 204 | - public function search($pattern); |
|
| 196 | + /** |
|
| 197 | + * search for files matching $pattern, files are matched if their filename matches the search pattern |
|
| 198 | + * |
|
| 199 | + * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') |
|
| 200 | + * @return ICacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 201 | + * @since 9.0.0 |
|
| 202 | + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 203 | + */ |
|
| 204 | + public function search($pattern); |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * search for files by mimetype |
|
| 208 | - * |
|
| 209 | - * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 210 | - * where it will search for all mimetypes in the group ('image/*') |
|
| 211 | - * @return ICacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 212 | - * @since 9.0.0 |
|
| 213 | - * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 214 | - */ |
|
| 215 | - public function searchByMime($mimetype); |
|
| 206 | + /** |
|
| 207 | + * search for files by mimetype |
|
| 208 | + * |
|
| 209 | + * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 210 | + * where it will search for all mimetypes in the group ('image/*') |
|
| 211 | + * @return ICacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 212 | + * @since 9.0.0 |
|
| 213 | + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 214 | + */ |
|
| 215 | + public function searchByMime($mimetype); |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Search for files with a flexible query |
|
| 219 | - * |
|
| 220 | - * @param ISearchQuery $query |
|
| 221 | - * @return ICacheEntry[] |
|
| 222 | - * @throw \InvalidArgumentException if the cache is unable to perform the query |
|
| 223 | - * @since 12.0.0 |
|
| 224 | - */ |
|
| 225 | - public function searchQuery(ISearchQuery $query); |
|
| 217 | + /** |
|
| 218 | + * Search for files with a flexible query |
|
| 219 | + * |
|
| 220 | + * @param ISearchQuery $query |
|
| 221 | + * @return ICacheEntry[] |
|
| 222 | + * @throw \InvalidArgumentException if the cache is unable to perform the query |
|
| 223 | + * @since 12.0.0 |
|
| 224 | + */ |
|
| 225 | + public function searchQuery(ISearchQuery $query); |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Search for files by tag of a given users. |
|
| 229 | - * |
|
| 230 | - * Note that every user can tag files differently. |
|
| 231 | - * |
|
| 232 | - * @param string|int $tag name or tag id |
|
| 233 | - * @param string $userId owner of the tags |
|
| 234 | - * @return ICacheEntry[] file data |
|
| 235 | - * @since 9.0.0 |
|
| 236 | - * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 237 | - */ |
|
| 238 | - public function searchByTag($tag, $userId); |
|
| 227 | + /** |
|
| 228 | + * Search for files by tag of a given users. |
|
| 229 | + * |
|
| 230 | + * Note that every user can tag files differently. |
|
| 231 | + * |
|
| 232 | + * @param string|int $tag name or tag id |
|
| 233 | + * @param string $userId owner of the tags |
|
| 234 | + * @return ICacheEntry[] file data |
|
| 235 | + * @since 9.0.0 |
|
| 236 | + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 237 | + */ |
|
| 238 | + public function searchByTag($tag, $userId); |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * find a folder in the cache which has not been fully scanned |
|
| 242 | - * |
|
| 243 | - * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 244 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 245 | - * likely the folder where we stopped scanning previously |
|
| 246 | - * |
|
| 247 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 248 | - * @since 9.0.0 |
|
| 249 | - */ |
|
| 250 | - public function getIncomplete(); |
|
| 240 | + /** |
|
| 241 | + * find a folder in the cache which has not been fully scanned |
|
| 242 | + * |
|
| 243 | + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 244 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 245 | + * likely the folder where we stopped scanning previously |
|
| 246 | + * |
|
| 247 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 248 | + * @since 9.0.0 |
|
| 249 | + */ |
|
| 250 | + public function getIncomplete(); |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * get the path of a file on this storage by it's file id |
|
| 254 | - * |
|
| 255 | - * @param int $id the file id of the file or folder to search |
|
| 256 | - * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache |
|
| 257 | - * @since 9.0.0 |
|
| 258 | - */ |
|
| 259 | - public function getPathById($id); |
|
| 252 | + /** |
|
| 253 | + * get the path of a file on this storage by it's file id |
|
| 254 | + * |
|
| 255 | + * @param int $id the file id of the file or folder to search |
|
| 256 | + * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache |
|
| 257 | + * @since 9.0.0 |
|
| 258 | + */ |
|
| 259 | + public function getPathById($id); |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * normalize the given path for usage in the cache |
|
| 263 | - * |
|
| 264 | - * @param string $path |
|
| 265 | - * @return string |
|
| 266 | - * @since 9.0.0 |
|
| 267 | - */ |
|
| 268 | - public function normalize($path); |
|
| 261 | + /** |
|
| 262 | + * normalize the given path for usage in the cache |
|
| 263 | + * |
|
| 264 | + * @param string $path |
|
| 265 | + * @return string |
|
| 266 | + * @since 9.0.0 |
|
| 267 | + */ |
|
| 268 | + public function normalize($path); |
|
| 269 | 269 | } |