@@ -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, '/')) { |
@@ -54,822 +54,822 @@ |
||
| 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['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); |
|
| 173 | - $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); |
|
| 174 | - if ($data['storage_mtime'] == 0) { |
|
| 175 | - $data['storage_mtime'] = $data['mtime']; |
|
| 176 | - } |
|
| 177 | - $data['permissions'] = (int)$data['permissions']; |
|
| 178 | - return new CacheEntry($data); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * get the metadata of all files stored in $folder |
|
| 183 | - * |
|
| 184 | - * @param string $folder |
|
| 185 | - * @return ICacheEntry[] |
|
| 186 | - */ |
|
| 187 | - public function getFolderContents($folder) { |
|
| 188 | - $fileId = $this->getId($folder); |
|
| 189 | - return $this->getFolderContentsById($fileId); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * get the metadata of all files stored in $folder |
|
| 194 | - * |
|
| 195 | - * @param int $fileId the file id of the folder |
|
| 196 | - * @return ICacheEntry[] |
|
| 197 | - */ |
|
| 198 | - public function getFolderContentsById($fileId) { |
|
| 199 | - if ($fileId > -1) { |
|
| 200 | - $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['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); |
|
| 173 | + $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); |
|
| 174 | + if ($data['storage_mtime'] == 0) { |
|
| 175 | + $data['storage_mtime'] = $data['mtime']; |
|
| 176 | + } |
|
| 177 | + $data['permissions'] = (int)$data['permissions']; |
|
| 178 | + return new CacheEntry($data); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * get the metadata of all files stored in $folder |
|
| 183 | + * |
|
| 184 | + * @param string $folder |
|
| 185 | + * @return ICacheEntry[] |
|
| 186 | + */ |
|
| 187 | + public function getFolderContents($folder) { |
|
| 188 | + $fileId = $this->getId($folder); |
|
| 189 | + return $this->getFolderContentsById($fileId); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * get the metadata of all files stored in $folder |
|
| 194 | + * |
|
| 195 | + * @param int $fileId the file id of the folder |
|
| 196 | + * @return ICacheEntry[] |
|
| 197 | + */ |
|
| 198 | + public function getFolderContentsById($fileId) { |
|
| 199 | + if ($fileId > -1) { |
|
| 200 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, |
|
| 201 | 201 | `storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
| 202 | 202 | FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC'; |
| 203 | - $result = $this->connection->executeQuery($sql, [$fileId]); |
|
| 204 | - $files = $result->fetchAll(); |
|
| 205 | - foreach ($files as &$file) { |
|
| 206 | - $file['mimetype'] = $this->mimetypeLoader->getMimetypeById($file['mimetype']); |
|
| 207 | - $file['mimepart'] = $this->mimetypeLoader->getMimetypeById($file['mimepart']); |
|
| 208 | - if ($file['storage_mtime'] == 0) { |
|
| 209 | - $file['storage_mtime'] = $file['mtime']; |
|
| 210 | - } |
|
| 211 | - $file['permissions'] = (int)$file['permissions']; |
|
| 212 | - $file['mtime'] = (int)$file['mtime']; |
|
| 213 | - $file['storage_mtime'] = (int)$file['storage_mtime']; |
|
| 214 | - $file['size'] = 0 + $file['size']; |
|
| 215 | - } |
|
| 216 | - return array_map(function (array $data) { |
|
| 217 | - return new CacheEntry($data); |
|
| 218 | - }, $files); |
|
| 219 | - } else { |
|
| 220 | - return array(); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * insert or update meta data for a file or folder |
|
| 226 | - * |
|
| 227 | - * @param string $file |
|
| 228 | - * @param array $data |
|
| 229 | - * |
|
| 230 | - * @return int file id |
|
| 231 | - * @throws \RuntimeException |
|
| 232 | - */ |
|
| 233 | - public function put($file, array $data) { |
|
| 234 | - if (($id = $this->getId($file)) > -1) { |
|
| 235 | - $this->update($id, $data); |
|
| 236 | - return $id; |
|
| 237 | - } else { |
|
| 238 | - return $this->insert($file, $data); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * insert meta data for a new file or folder |
|
| 244 | - * |
|
| 245 | - * @param string $file |
|
| 246 | - * @param array $data |
|
| 247 | - * |
|
| 248 | - * @return int file id |
|
| 249 | - * @throws \RuntimeException |
|
| 250 | - */ |
|
| 251 | - public function insert($file, array $data) { |
|
| 252 | - // normalize file |
|
| 253 | - $file = $this->normalize($file); |
|
| 254 | - |
|
| 255 | - if (isset($this->partial[$file])) { //add any saved partial data |
|
| 256 | - $data = array_merge($this->partial[$file], $data); |
|
| 257 | - unset($this->partial[$file]); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $requiredFields = array('size', 'mtime', 'mimetype'); |
|
| 261 | - foreach ($requiredFields as $field) { |
|
| 262 | - if (!isset($data[$field])) { //data not complete save as partial and return |
|
| 263 | - $this->partial[$file] = $data; |
|
| 264 | - return -1; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $data['path'] = $file; |
|
| 269 | - $data['parent'] = $this->getParentId($file); |
|
| 270 | - $data['name'] = \OC_Util::basename($file); |
|
| 271 | - |
|
| 272 | - list($queryParts, $params) = $this->buildParts($data); |
|
| 273 | - $queryParts[] = '`storage`'; |
|
| 274 | - $params[] = $this->getNumericStorageId(); |
|
| 275 | - |
|
| 276 | - $queryParts = array_map(function ($item) { |
|
| 277 | - return trim($item, "`"); |
|
| 278 | - }, $queryParts); |
|
| 279 | - $values = array_combine($queryParts, $params); |
|
| 280 | - if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [ |
|
| 281 | - 'storage', |
|
| 282 | - 'path_hash', |
|
| 283 | - ]) |
|
| 284 | - ) { |
|
| 285 | - return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - // The file was created in the mean time |
|
| 289 | - if (($id = $this->getId($file)) > -1) { |
|
| 290 | - $this->update($id, $data); |
|
| 291 | - return $id; |
|
| 292 | - } else { |
|
| 293 | - 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.'); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * update the metadata of an existing file or folder in the cache |
|
| 299 | - * |
|
| 300 | - * @param int $id the fileid of the existing file or folder |
|
| 301 | - * @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 |
|
| 302 | - */ |
|
| 303 | - public function update($id, array $data) { |
|
| 304 | - |
|
| 305 | - if (isset($data['path'])) { |
|
| 306 | - // normalize path |
|
| 307 | - $data['path'] = $this->normalize($data['path']); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - if (isset($data['name'])) { |
|
| 311 | - // normalize path |
|
| 312 | - $data['name'] = $this->normalize($data['name']); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - list($queryParts, $params) = $this->buildParts($data); |
|
| 316 | - // duplicate $params because we need the parts twice in the SQL statement |
|
| 317 | - // once for the SET part, once in the WHERE clause |
|
| 318 | - $params = array_merge($params, $params); |
|
| 319 | - $params[] = $id; |
|
| 320 | - |
|
| 321 | - // don't update if the data we try to set is the same as the one in the record |
|
| 322 | - // some databases (Postgres) don't like superfluous updates |
|
| 323 | - $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' . |
|
| 324 | - 'WHERE (' . |
|
| 325 | - implode(' <> ? OR ', $queryParts) . ' <> ? OR ' . |
|
| 326 | - implode(' IS NULL OR ', $queryParts) . ' IS NULL' . |
|
| 327 | - ') AND `fileid` = ? '; |
|
| 328 | - $this->connection->executeQuery($sql, $params); |
|
| 329 | - |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * extract query parts and params array from data array |
|
| 334 | - * |
|
| 335 | - * @param array $data |
|
| 336 | - * @return array [$queryParts, $params] |
|
| 337 | - * $queryParts: string[], the (escaped) column names to be set in the query |
|
| 338 | - * $params: mixed[], the new values for the columns, to be passed as params to the query |
|
| 339 | - */ |
|
| 340 | - protected function buildParts(array $data) { |
|
| 341 | - $fields = array( |
|
| 342 | - 'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted', |
|
| 343 | - 'etag', 'permissions', 'checksum'); |
|
| 344 | - |
|
| 345 | - $doNotCopyStorageMTime = false; |
|
| 346 | - if (array_key_exists('mtime', $data) && $data['mtime'] === null) { |
|
| 347 | - // this horrific magic tells it to not copy storage_mtime to mtime |
|
| 348 | - unset($data['mtime']); |
|
| 349 | - $doNotCopyStorageMTime = true; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $params = array(); |
|
| 353 | - $queryParts = array(); |
|
| 354 | - foreach ($data as $name => $value) { |
|
| 355 | - if (array_search($name, $fields) !== false) { |
|
| 356 | - if ($name === 'path') { |
|
| 357 | - $params[] = md5($value); |
|
| 358 | - $queryParts[] = '`path_hash`'; |
|
| 359 | - } elseif ($name === 'mimetype') { |
|
| 360 | - $params[] = $this->mimetypeLoader->getId(substr($value, 0, strpos($value, '/'))); |
|
| 361 | - $queryParts[] = '`mimepart`'; |
|
| 362 | - $value = $this->mimetypeLoader->getId($value); |
|
| 363 | - } elseif ($name === 'storage_mtime') { |
|
| 364 | - if (!$doNotCopyStorageMTime && !isset($data['mtime'])) { |
|
| 365 | - $params[] = $value; |
|
| 366 | - $queryParts[] = '`mtime`'; |
|
| 367 | - } |
|
| 368 | - } elseif ($name === 'encrypted') { |
|
| 369 | - if (isset($data['encryptedVersion'])) { |
|
| 370 | - $value = $data['encryptedVersion']; |
|
| 371 | - } else { |
|
| 372 | - // Boolean to integer conversion |
|
| 373 | - $value = $value ? 1 : 0; |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - $params[] = $value; |
|
| 377 | - $queryParts[] = '`' . $name . '`'; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - return array($queryParts, $params); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * get the file id for a file |
|
| 385 | - * |
|
| 386 | - * 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 |
|
| 387 | - * |
|
| 388 | - * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 389 | - * |
|
| 390 | - * @param string $file |
|
| 391 | - * @return int |
|
| 392 | - */ |
|
| 393 | - public function getId($file) { |
|
| 394 | - // normalize file |
|
| 395 | - $file = $this->normalize($file); |
|
| 396 | - |
|
| 397 | - $pathHash = md5($file); |
|
| 398 | - |
|
| 399 | - $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 400 | - $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 401 | - if ($row = $result->fetch()) { |
|
| 402 | - return $row['fileid']; |
|
| 403 | - } else { |
|
| 404 | - return -1; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * get the id of the parent folder of a file |
|
| 410 | - * |
|
| 411 | - * @param string $file |
|
| 412 | - * @return int |
|
| 413 | - */ |
|
| 414 | - public function getParentId($file) { |
|
| 415 | - if ($file === '') { |
|
| 416 | - return -1; |
|
| 417 | - } else { |
|
| 418 | - $parent = $this->getParentPath($file); |
|
| 419 | - return (int)$this->getId($parent); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - private function getParentPath($path) { |
|
| 424 | - $parent = dirname($path); |
|
| 425 | - if ($parent === '.') { |
|
| 426 | - $parent = ''; |
|
| 427 | - } |
|
| 428 | - return $parent; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * check if a file is available in the cache |
|
| 433 | - * |
|
| 434 | - * @param string $file |
|
| 435 | - * @return bool |
|
| 436 | - */ |
|
| 437 | - public function inCache($file) { |
|
| 438 | - return $this->getId($file) != -1; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * remove a file or folder from the cache |
|
| 443 | - * |
|
| 444 | - * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 445 | - * |
|
| 446 | - * @param string $file |
|
| 447 | - */ |
|
| 448 | - public function remove($file) { |
|
| 449 | - $entry = $this->get($file); |
|
| 450 | - $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 451 | - $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 452 | - if ($entry['mimetype'] === 'httpd/unix-directory') { |
|
| 453 | - $this->removeChildren($entry); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Get all sub folders of a folder |
|
| 459 | - * |
|
| 460 | - * @param array $entry the cache entry of the folder to get the subfolders for |
|
| 461 | - * @return array[] the cache entries for the subfolders |
|
| 462 | - */ |
|
| 463 | - private function getSubFolders($entry) { |
|
| 464 | - $children = $this->getFolderContentsById($entry['fileid']); |
|
| 465 | - return array_filter($children, function ($child) { |
|
| 466 | - return $child['mimetype'] === 'httpd/unix-directory'; |
|
| 467 | - }); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Recursively remove all children of a folder |
|
| 472 | - * |
|
| 473 | - * @param array $entry the cache entry of the folder to remove the children of |
|
| 474 | - * @throws \OC\DatabaseException |
|
| 475 | - */ |
|
| 476 | - private function removeChildren($entry) { |
|
| 477 | - $subFolders = $this->getSubFolders($entry); |
|
| 478 | - foreach ($subFolders as $folder) { |
|
| 479 | - $this->removeChildren($folder); |
|
| 480 | - } |
|
| 481 | - $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `parent` = ?'; |
|
| 482 | - $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Move a file or folder in the cache |
|
| 487 | - * |
|
| 488 | - * @param string $source |
|
| 489 | - * @param string $target |
|
| 490 | - */ |
|
| 491 | - public function move($source, $target) { |
|
| 492 | - $this->moveFromCache($this, $source, $target); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Get the storage id and path needed for a move |
|
| 497 | - * |
|
| 498 | - * @param string $path |
|
| 499 | - * @return array [$storageId, $internalPath] |
|
| 500 | - */ |
|
| 501 | - protected function getMoveInfo($path) { |
|
| 502 | - return [$this->getNumericStorageId(), $path]; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Move a file or folder in the cache |
|
| 507 | - * |
|
| 508 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 509 | - * @param string $sourcePath |
|
| 510 | - * @param string $targetPath |
|
| 511 | - * @throws \OC\DatabaseException |
|
| 512 | - */ |
|
| 513 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 514 | - if ($sourceCache instanceof Cache) { |
|
| 515 | - // normalize source and target |
|
| 516 | - $sourcePath = $this->normalize($sourcePath); |
|
| 517 | - $targetPath = $this->normalize($targetPath); |
|
| 518 | - |
|
| 519 | - $sourceData = $sourceCache->get($sourcePath); |
|
| 520 | - $sourceId = $sourceData['fileid']; |
|
| 521 | - $newParentId = $this->getParentId($targetPath); |
|
| 522 | - |
|
| 523 | - list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath); |
|
| 524 | - list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath); |
|
| 525 | - |
|
| 526 | - // sql for final update |
|
| 527 | - $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?'; |
|
| 528 | - |
|
| 529 | - if ($sourceData['mimetype'] === 'httpd/unix-directory') { |
|
| 530 | - //find all child entries |
|
| 531 | - $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; |
|
| 532 | - $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']); |
|
| 533 | - $childEntries = $result->fetchAll(); |
|
| 534 | - $sourceLength = strlen($sourcePath); |
|
| 535 | - $this->connection->beginTransaction(); |
|
| 536 | - $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); |
|
| 537 | - |
|
| 538 | - foreach ($childEntries as $child) { |
|
| 539 | - $newTargetPath = $targetPath . substr($child['path'], $sourceLength); |
|
| 540 | - $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]); |
|
| 541 | - } |
|
| 542 | - $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 543 | - $this->connection->commit(); |
|
| 544 | - } else { |
|
| 545 | - $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 546 | - } |
|
| 547 | - } else { |
|
| 548 | - $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * remove all entries for files that are stored on the storage from the cache |
|
| 554 | - */ |
|
| 555 | - public function clear() { |
|
| 556 | - $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 557 | - $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 558 | - |
|
| 559 | - $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; |
|
| 560 | - $this->connection->executeQuery($sql, array($this->storageId)); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Get the scan status of a file |
|
| 565 | - * |
|
| 566 | - * - Cache::NOT_FOUND: File is not in the cache |
|
| 567 | - * - Cache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 568 | - * - Cache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 569 | - * - Cache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 570 | - * |
|
| 571 | - * @param string $file |
|
| 572 | - * |
|
| 573 | - * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 574 | - */ |
|
| 575 | - public function getStatus($file) { |
|
| 576 | - // normalize file |
|
| 577 | - $file = $this->normalize($file); |
|
| 578 | - |
|
| 579 | - $pathHash = md5($file); |
|
| 580 | - $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 581 | - $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 582 | - if ($row = $result->fetch()) { |
|
| 583 | - if ((int)$row['size'] === -1) { |
|
| 584 | - return self::SHALLOW; |
|
| 585 | - } else { |
|
| 586 | - return self::COMPLETE; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - if (isset($this->partial[$file])) { |
|
| 590 | - return self::PARTIAL; |
|
| 591 | - } else { |
|
| 592 | - return self::NOT_FOUND; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * search for files matching $pattern |
|
| 599 | - * |
|
| 600 | - * @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 |
|
| 602 | - */ |
|
| 603 | - public function search($pattern) { |
|
| 604 | - // normalize pattern |
|
| 605 | - $pattern = $this->normalize($pattern); |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - $sql = ' |
|
| 203 | + $result = $this->connection->executeQuery($sql, [$fileId]); |
|
| 204 | + $files = $result->fetchAll(); |
|
| 205 | + foreach ($files as &$file) { |
|
| 206 | + $file['mimetype'] = $this->mimetypeLoader->getMimetypeById($file['mimetype']); |
|
| 207 | + $file['mimepart'] = $this->mimetypeLoader->getMimetypeById($file['mimepart']); |
|
| 208 | + if ($file['storage_mtime'] == 0) { |
|
| 209 | + $file['storage_mtime'] = $file['mtime']; |
|
| 210 | + } |
|
| 211 | + $file['permissions'] = (int)$file['permissions']; |
|
| 212 | + $file['mtime'] = (int)$file['mtime']; |
|
| 213 | + $file['storage_mtime'] = (int)$file['storage_mtime']; |
|
| 214 | + $file['size'] = 0 + $file['size']; |
|
| 215 | + } |
|
| 216 | + return array_map(function (array $data) { |
|
| 217 | + return new CacheEntry($data); |
|
| 218 | + }, $files); |
|
| 219 | + } else { |
|
| 220 | + return array(); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * insert or update meta data for a file or folder |
|
| 226 | + * |
|
| 227 | + * @param string $file |
|
| 228 | + * @param array $data |
|
| 229 | + * |
|
| 230 | + * @return int file id |
|
| 231 | + * @throws \RuntimeException |
|
| 232 | + */ |
|
| 233 | + public function put($file, array $data) { |
|
| 234 | + if (($id = $this->getId($file)) > -1) { |
|
| 235 | + $this->update($id, $data); |
|
| 236 | + return $id; |
|
| 237 | + } else { |
|
| 238 | + return $this->insert($file, $data); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * insert meta data for a new file or folder |
|
| 244 | + * |
|
| 245 | + * @param string $file |
|
| 246 | + * @param array $data |
|
| 247 | + * |
|
| 248 | + * @return int file id |
|
| 249 | + * @throws \RuntimeException |
|
| 250 | + */ |
|
| 251 | + public function insert($file, array $data) { |
|
| 252 | + // normalize file |
|
| 253 | + $file = $this->normalize($file); |
|
| 254 | + |
|
| 255 | + if (isset($this->partial[$file])) { //add any saved partial data |
|
| 256 | + $data = array_merge($this->partial[$file], $data); |
|
| 257 | + unset($this->partial[$file]); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $requiredFields = array('size', 'mtime', 'mimetype'); |
|
| 261 | + foreach ($requiredFields as $field) { |
|
| 262 | + if (!isset($data[$field])) { //data not complete save as partial and return |
|
| 263 | + $this->partial[$file] = $data; |
|
| 264 | + return -1; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $data['path'] = $file; |
|
| 269 | + $data['parent'] = $this->getParentId($file); |
|
| 270 | + $data['name'] = \OC_Util::basename($file); |
|
| 271 | + |
|
| 272 | + list($queryParts, $params) = $this->buildParts($data); |
|
| 273 | + $queryParts[] = '`storage`'; |
|
| 274 | + $params[] = $this->getNumericStorageId(); |
|
| 275 | + |
|
| 276 | + $queryParts = array_map(function ($item) { |
|
| 277 | + return trim($item, "`"); |
|
| 278 | + }, $queryParts); |
|
| 279 | + $values = array_combine($queryParts, $params); |
|
| 280 | + if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [ |
|
| 281 | + 'storage', |
|
| 282 | + 'path_hash', |
|
| 283 | + ]) |
|
| 284 | + ) { |
|
| 285 | + return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + // The file was created in the mean time |
|
| 289 | + if (($id = $this->getId($file)) > -1) { |
|
| 290 | + $this->update($id, $data); |
|
| 291 | + return $id; |
|
| 292 | + } else { |
|
| 293 | + 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.'); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * update the metadata of an existing file or folder in the cache |
|
| 299 | + * |
|
| 300 | + * @param int $id the fileid of the existing file or folder |
|
| 301 | + * @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 |
|
| 302 | + */ |
|
| 303 | + public function update($id, array $data) { |
|
| 304 | + |
|
| 305 | + if (isset($data['path'])) { |
|
| 306 | + // normalize path |
|
| 307 | + $data['path'] = $this->normalize($data['path']); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + if (isset($data['name'])) { |
|
| 311 | + // normalize path |
|
| 312 | + $data['name'] = $this->normalize($data['name']); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + list($queryParts, $params) = $this->buildParts($data); |
|
| 316 | + // duplicate $params because we need the parts twice in the SQL statement |
|
| 317 | + // once for the SET part, once in the WHERE clause |
|
| 318 | + $params = array_merge($params, $params); |
|
| 319 | + $params[] = $id; |
|
| 320 | + |
|
| 321 | + // don't update if the data we try to set is the same as the one in the record |
|
| 322 | + // some databases (Postgres) don't like superfluous updates |
|
| 323 | + $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' . |
|
| 324 | + 'WHERE (' . |
|
| 325 | + implode(' <> ? OR ', $queryParts) . ' <> ? OR ' . |
|
| 326 | + implode(' IS NULL OR ', $queryParts) . ' IS NULL' . |
|
| 327 | + ') AND `fileid` = ? '; |
|
| 328 | + $this->connection->executeQuery($sql, $params); |
|
| 329 | + |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * extract query parts and params array from data array |
|
| 334 | + * |
|
| 335 | + * @param array $data |
|
| 336 | + * @return array [$queryParts, $params] |
|
| 337 | + * $queryParts: string[], the (escaped) column names to be set in the query |
|
| 338 | + * $params: mixed[], the new values for the columns, to be passed as params to the query |
|
| 339 | + */ |
|
| 340 | + protected function buildParts(array $data) { |
|
| 341 | + $fields = array( |
|
| 342 | + 'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted', |
|
| 343 | + 'etag', 'permissions', 'checksum'); |
|
| 344 | + |
|
| 345 | + $doNotCopyStorageMTime = false; |
|
| 346 | + if (array_key_exists('mtime', $data) && $data['mtime'] === null) { |
|
| 347 | + // this horrific magic tells it to not copy storage_mtime to mtime |
|
| 348 | + unset($data['mtime']); |
|
| 349 | + $doNotCopyStorageMTime = true; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + $params = array(); |
|
| 353 | + $queryParts = array(); |
|
| 354 | + foreach ($data as $name => $value) { |
|
| 355 | + if (array_search($name, $fields) !== false) { |
|
| 356 | + if ($name === 'path') { |
|
| 357 | + $params[] = md5($value); |
|
| 358 | + $queryParts[] = '`path_hash`'; |
|
| 359 | + } elseif ($name === 'mimetype') { |
|
| 360 | + $params[] = $this->mimetypeLoader->getId(substr($value, 0, strpos($value, '/'))); |
|
| 361 | + $queryParts[] = '`mimepart`'; |
|
| 362 | + $value = $this->mimetypeLoader->getId($value); |
|
| 363 | + } elseif ($name === 'storage_mtime') { |
|
| 364 | + if (!$doNotCopyStorageMTime && !isset($data['mtime'])) { |
|
| 365 | + $params[] = $value; |
|
| 366 | + $queryParts[] = '`mtime`'; |
|
| 367 | + } |
|
| 368 | + } elseif ($name === 'encrypted') { |
|
| 369 | + if (isset($data['encryptedVersion'])) { |
|
| 370 | + $value = $data['encryptedVersion']; |
|
| 371 | + } else { |
|
| 372 | + // Boolean to integer conversion |
|
| 373 | + $value = $value ? 1 : 0; |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + $params[] = $value; |
|
| 377 | + $queryParts[] = '`' . $name . '`'; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + return array($queryParts, $params); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * get the file id for a file |
|
| 385 | + * |
|
| 386 | + * 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 |
|
| 387 | + * |
|
| 388 | + * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 389 | + * |
|
| 390 | + * @param string $file |
|
| 391 | + * @return int |
|
| 392 | + */ |
|
| 393 | + public function getId($file) { |
|
| 394 | + // normalize file |
|
| 395 | + $file = $this->normalize($file); |
|
| 396 | + |
|
| 397 | + $pathHash = md5($file); |
|
| 398 | + |
|
| 399 | + $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 400 | + $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 401 | + if ($row = $result->fetch()) { |
|
| 402 | + return $row['fileid']; |
|
| 403 | + } else { |
|
| 404 | + return -1; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * get the id of the parent folder of a file |
|
| 410 | + * |
|
| 411 | + * @param string $file |
|
| 412 | + * @return int |
|
| 413 | + */ |
|
| 414 | + public function getParentId($file) { |
|
| 415 | + if ($file === '') { |
|
| 416 | + return -1; |
|
| 417 | + } else { |
|
| 418 | + $parent = $this->getParentPath($file); |
|
| 419 | + return (int)$this->getId($parent); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + private function getParentPath($path) { |
|
| 424 | + $parent = dirname($path); |
|
| 425 | + if ($parent === '.') { |
|
| 426 | + $parent = ''; |
|
| 427 | + } |
|
| 428 | + return $parent; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * check if a file is available in the cache |
|
| 433 | + * |
|
| 434 | + * @param string $file |
|
| 435 | + * @return bool |
|
| 436 | + */ |
|
| 437 | + public function inCache($file) { |
|
| 438 | + return $this->getId($file) != -1; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * remove a file or folder from the cache |
|
| 443 | + * |
|
| 444 | + * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 445 | + * |
|
| 446 | + * @param string $file |
|
| 447 | + */ |
|
| 448 | + public function remove($file) { |
|
| 449 | + $entry = $this->get($file); |
|
| 450 | + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 451 | + $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 452 | + if ($entry['mimetype'] === 'httpd/unix-directory') { |
|
| 453 | + $this->removeChildren($entry); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Get all sub folders of a folder |
|
| 459 | + * |
|
| 460 | + * @param array $entry the cache entry of the folder to get the subfolders for |
|
| 461 | + * @return array[] the cache entries for the subfolders |
|
| 462 | + */ |
|
| 463 | + private function getSubFolders($entry) { |
|
| 464 | + $children = $this->getFolderContentsById($entry['fileid']); |
|
| 465 | + return array_filter($children, function ($child) { |
|
| 466 | + return $child['mimetype'] === 'httpd/unix-directory'; |
|
| 467 | + }); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Recursively remove all children of a folder |
|
| 472 | + * |
|
| 473 | + * @param array $entry the cache entry of the folder to remove the children of |
|
| 474 | + * @throws \OC\DatabaseException |
|
| 475 | + */ |
|
| 476 | + private function removeChildren($entry) { |
|
| 477 | + $subFolders = $this->getSubFolders($entry); |
|
| 478 | + foreach ($subFolders as $folder) { |
|
| 479 | + $this->removeChildren($folder); |
|
| 480 | + } |
|
| 481 | + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `parent` = ?'; |
|
| 482 | + $this->connection->executeQuery($sql, array($entry['fileid'])); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Move a file or folder in the cache |
|
| 487 | + * |
|
| 488 | + * @param string $source |
|
| 489 | + * @param string $target |
|
| 490 | + */ |
|
| 491 | + public function move($source, $target) { |
|
| 492 | + $this->moveFromCache($this, $source, $target); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Get the storage id and path needed for a move |
|
| 497 | + * |
|
| 498 | + * @param string $path |
|
| 499 | + * @return array [$storageId, $internalPath] |
|
| 500 | + */ |
|
| 501 | + protected function getMoveInfo($path) { |
|
| 502 | + return [$this->getNumericStorageId(), $path]; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Move a file or folder in the cache |
|
| 507 | + * |
|
| 508 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 509 | + * @param string $sourcePath |
|
| 510 | + * @param string $targetPath |
|
| 511 | + * @throws \OC\DatabaseException |
|
| 512 | + */ |
|
| 513 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 514 | + if ($sourceCache instanceof Cache) { |
|
| 515 | + // normalize source and target |
|
| 516 | + $sourcePath = $this->normalize($sourcePath); |
|
| 517 | + $targetPath = $this->normalize($targetPath); |
|
| 518 | + |
|
| 519 | + $sourceData = $sourceCache->get($sourcePath); |
|
| 520 | + $sourceId = $sourceData['fileid']; |
|
| 521 | + $newParentId = $this->getParentId($targetPath); |
|
| 522 | + |
|
| 523 | + list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath); |
|
| 524 | + list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath); |
|
| 525 | + |
|
| 526 | + // sql for final update |
|
| 527 | + $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?'; |
|
| 528 | + |
|
| 529 | + if ($sourceData['mimetype'] === 'httpd/unix-directory') { |
|
| 530 | + //find all child entries |
|
| 531 | + $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; |
|
| 532 | + $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']); |
|
| 533 | + $childEntries = $result->fetchAll(); |
|
| 534 | + $sourceLength = strlen($sourcePath); |
|
| 535 | + $this->connection->beginTransaction(); |
|
| 536 | + $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); |
|
| 537 | + |
|
| 538 | + foreach ($childEntries as $child) { |
|
| 539 | + $newTargetPath = $targetPath . substr($child['path'], $sourceLength); |
|
| 540 | + $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]); |
|
| 541 | + } |
|
| 542 | + $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 543 | + $this->connection->commit(); |
|
| 544 | + } else { |
|
| 545 | + $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
|
| 546 | + } |
|
| 547 | + } else { |
|
| 548 | + $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * remove all entries for files that are stored on the storage from the cache |
|
| 554 | + */ |
|
| 555 | + public function clear() { |
|
| 556 | + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 557 | + $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 558 | + |
|
| 559 | + $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; |
|
| 560 | + $this->connection->executeQuery($sql, array($this->storageId)); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Get the scan status of a file |
|
| 565 | + * |
|
| 566 | + * - Cache::NOT_FOUND: File is not in the cache |
|
| 567 | + * - Cache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 568 | + * - Cache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 569 | + * - Cache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 570 | + * |
|
| 571 | + * @param string $file |
|
| 572 | + * |
|
| 573 | + * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 574 | + */ |
|
| 575 | + public function getStatus($file) { |
|
| 576 | + // normalize file |
|
| 577 | + $file = $this->normalize($file); |
|
| 578 | + |
|
| 579 | + $pathHash = md5($file); |
|
| 580 | + $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
|
| 581 | + $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
|
| 582 | + if ($row = $result->fetch()) { |
|
| 583 | + if ((int)$row['size'] === -1) { |
|
| 584 | + return self::SHALLOW; |
|
| 585 | + } else { |
|
| 586 | + return self::COMPLETE; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + if (isset($this->partial[$file])) { |
|
| 590 | + return self::PARTIAL; |
|
| 591 | + } else { |
|
| 592 | + return self::NOT_FOUND; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * search for files matching $pattern |
|
| 599 | + * |
|
| 600 | + * @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 |
|
| 602 | + */ |
|
| 603 | + public function search($pattern) { |
|
| 604 | + // normalize pattern |
|
| 605 | + $pattern = $this->normalize($pattern); |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + $sql = ' |
|
| 609 | 609 | SELECT `fileid`, `storage`, `path`, `parent`, `name`, |
| 610 | 610 | `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, |
| 611 | 611 | `etag`, `permissions`, `checksum` |
| 612 | 612 | FROM `*PREFIX*filecache` |
| 613 | 613 | WHERE `storage` = ? AND `name` ILIKE ?'; |
| 614 | - $result = $this->connection->executeQuery($sql, |
|
| 615 | - [$this->getNumericStorageId(), $pattern] |
|
| 616 | - ); |
|
| 617 | - |
|
| 618 | - return $this->searchResultToCacheEntries($result); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @param Statement $result |
|
| 623 | - * @return CacheEntry[] |
|
| 624 | - */ |
|
| 625 | - private function searchResultToCacheEntries(Statement $result) { |
|
| 626 | - $files = []; |
|
| 627 | - while ($row = $result->fetch()) { |
|
| 628 | - $row['mimetype'] = $this->mimetypeLoader->getMimetypeById($row['mimetype']); |
|
| 629 | - $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); |
|
| 630 | - $files[] = $row; |
|
| 631 | - } |
|
| 632 | - return array_map(function (array $data) { |
|
| 633 | - return new CacheEntry($data); |
|
| 634 | - }, $files); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * search for files by mimetype |
|
| 639 | - * |
|
| 640 | - * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 641 | - * 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 |
|
| 643 | - */ |
|
| 644 | - public function searchByMime($mimetype) { |
|
| 645 | - if (strpos($mimetype, '/')) { |
|
| 646 | - $where = '`mimetype` = ?'; |
|
| 647 | - } else { |
|
| 648 | - $where = '`mimepart` = ?'; |
|
| 649 | - } |
|
| 650 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
|
| 614 | + $result = $this->connection->executeQuery($sql, |
|
| 615 | + [$this->getNumericStorageId(), $pattern] |
|
| 616 | + ); |
|
| 617 | + |
|
| 618 | + return $this->searchResultToCacheEntries($result); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @param Statement $result |
|
| 623 | + * @return CacheEntry[] |
|
| 624 | + */ |
|
| 625 | + private function searchResultToCacheEntries(Statement $result) { |
|
| 626 | + $files = []; |
|
| 627 | + while ($row = $result->fetch()) { |
|
| 628 | + $row['mimetype'] = $this->mimetypeLoader->getMimetypeById($row['mimetype']); |
|
| 629 | + $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); |
|
| 630 | + $files[] = $row; |
|
| 631 | + } |
|
| 632 | + return array_map(function (array $data) { |
|
| 633 | + return new CacheEntry($data); |
|
| 634 | + }, $files); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * search for files by mimetype |
|
| 639 | + * |
|
| 640 | + * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 641 | + * 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 |
|
| 643 | + */ |
|
| 644 | + public function searchByMime($mimetype) { |
|
| 645 | + if (strpos($mimetype, '/')) { |
|
| 646 | + $where = '`mimetype` = ?'; |
|
| 647 | + } else { |
|
| 648 | + $where = '`mimepart` = ?'; |
|
| 649 | + } |
|
| 650 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
|
| 651 | 651 | FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'; |
| 652 | - $mimetype = $this->mimetypeLoader->getId($mimetype); |
|
| 653 | - $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); |
|
| 654 | - |
|
| 655 | - return $this->searchResultToCacheEntries($result); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - public function searchQuery(ISearchQuery $searchQuery) { |
|
| 659 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 660 | - |
|
| 661 | - $query = $builder->select(['fileid', 'storage', 'path', 'parent', 'name', 'mimetype', 'mimepart', 'size', 'mtime', 'encrypted', 'etag', 'permissions', 'checksum']) |
|
| 662 | - ->from('filecache') |
|
| 663 | - ->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId()))) |
|
| 664 | - ->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation())); |
|
| 665 | - |
|
| 666 | - if ($searchQuery->getLimit()) { |
|
| 667 | - $query->setMaxResults($searchQuery->getLimit()); |
|
| 668 | - } |
|
| 669 | - if ($searchQuery->getOffset()) { |
|
| 670 | - $query->setFirstResult($searchQuery->getOffset()); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - $result = $query->execute(); |
|
| 674 | - return $this->searchResultToCacheEntries($result); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - /** |
|
| 678 | - * Search for files by tag of a given users. |
|
| 679 | - * |
|
| 680 | - * Note that every user can tag files differently. |
|
| 681 | - * |
|
| 682 | - * @param string|int $tag name or tag id |
|
| 683 | - * @param string $userId owner of the tags |
|
| 684 | - * @return ICacheEntry[] file data |
|
| 685 | - */ |
|
| 686 | - public function searchByTag($tag, $userId) { |
|
| 687 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . |
|
| 688 | - '`mimetype`, `mimepart`, `size`, `mtime`, ' . |
|
| 689 | - '`encrypted`, `etag`, `permissions`, `checksum` ' . |
|
| 690 | - 'FROM `*PREFIX*filecache` `file`, ' . |
|
| 691 | - '`*PREFIX*vcategory_to_object` `tagmap`, ' . |
|
| 692 | - '`*PREFIX*vcategory` `tag` ' . |
|
| 693 | - // JOIN filecache to vcategory_to_object |
|
| 694 | - 'WHERE `file`.`fileid` = `tagmap`.`objid` ' . |
|
| 695 | - // JOIN vcategory_to_object to vcategory |
|
| 696 | - 'AND `tagmap`.`type` = `tag`.`type` ' . |
|
| 697 | - 'AND `tagmap`.`categoryid` = `tag`.`id` ' . |
|
| 698 | - // conditions |
|
| 699 | - 'AND `file`.`storage` = ? ' . |
|
| 700 | - 'AND `tag`.`type` = \'files\' ' . |
|
| 701 | - 'AND `tag`.`uid` = ? '; |
|
| 702 | - if (is_int($tag)) { |
|
| 703 | - $sql .= 'AND `tag`.`id` = ? '; |
|
| 704 | - } else { |
|
| 705 | - $sql .= 'AND `tag`.`category` = ? '; |
|
| 706 | - } |
|
| 707 | - $result = $this->connection->executeQuery( |
|
| 708 | - $sql, |
|
| 709 | - [ |
|
| 710 | - $this->getNumericStorageId(), |
|
| 711 | - $userId, |
|
| 712 | - $tag |
|
| 713 | - ] |
|
| 714 | - ); |
|
| 715 | - $files = array(); |
|
| 716 | - while ($row = $result->fetch()) { |
|
| 717 | - $files[] = $row; |
|
| 718 | - } |
|
| 719 | - return array_map(function (array $data) { |
|
| 720 | - return new CacheEntry($data); |
|
| 721 | - }, $files); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Re-calculate the folder size and the size of all parent folders |
|
| 726 | - * |
|
| 727 | - * @param string|boolean $path |
|
| 728 | - * @param array $data (optional) meta data of the folder |
|
| 729 | - */ |
|
| 730 | - public function correctFolderSize($path, $data = null) { |
|
| 731 | - $this->calculateFolderSize($path, $data); |
|
| 732 | - if ($path !== '') { |
|
| 733 | - $parent = dirname($path); |
|
| 734 | - if ($parent === '.' or $parent === '/') { |
|
| 735 | - $parent = ''; |
|
| 736 | - } |
|
| 737 | - $this->correctFolderSize($parent); |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * calculate the size of a folder and set it in the cache |
|
| 743 | - * |
|
| 744 | - * @param string $path |
|
| 745 | - * @param array $entry (optional) meta data of the folder |
|
| 746 | - * @return int |
|
| 747 | - */ |
|
| 748 | - public function calculateFolderSize($path, $entry = null) { |
|
| 749 | - $totalSize = 0; |
|
| 750 | - if (is_null($entry) or !isset($entry['fileid'])) { |
|
| 751 | - $entry = $this->get($path); |
|
| 752 | - } |
|
| 753 | - if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') { |
|
| 754 | - $id = $entry['fileid']; |
|
| 755 | - $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' . |
|
| 756 | - 'FROM `*PREFIX*filecache` ' . |
|
| 757 | - 'WHERE `parent` = ? AND `storage` = ?'; |
|
| 758 | - $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 759 | - if ($row = $result->fetch()) { |
|
| 760 | - $result->closeCursor(); |
|
| 761 | - list($sum, $min) = array_values($row); |
|
| 762 | - $sum = 0 + $sum; |
|
| 763 | - $min = 0 + $min; |
|
| 764 | - if ($min === -1) { |
|
| 765 | - $totalSize = $min; |
|
| 766 | - } else { |
|
| 767 | - $totalSize = $sum; |
|
| 768 | - } |
|
| 769 | - $update = array(); |
|
| 770 | - if ($entry['size'] !== $totalSize) { |
|
| 771 | - $update['size'] = $totalSize; |
|
| 772 | - } |
|
| 773 | - if (count($update) > 0) { |
|
| 774 | - $this->update($id, $update); |
|
| 775 | - } |
|
| 776 | - } else { |
|
| 777 | - $result->closeCursor(); |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - return $totalSize; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * get all file ids on the files on the storage |
|
| 785 | - * |
|
| 786 | - * @return int[] |
|
| 787 | - */ |
|
| 788 | - public function getAll() { |
|
| 789 | - $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 790 | - $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 791 | - $ids = array(); |
|
| 792 | - while ($row = $result->fetch()) { |
|
| 793 | - $ids[] = $row['fileid']; |
|
| 794 | - } |
|
| 795 | - return $ids; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * find a folder in the cache which has not been fully scanned |
|
| 800 | - * |
|
| 801 | - * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 802 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 803 | - * likely the folder where we stopped scanning previously |
|
| 804 | - * |
|
| 805 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 806 | - */ |
|
| 807 | - public function getIncomplete() { |
|
| 808 | - $query = $this->connection->prepare('SELECT `path` FROM `*PREFIX*filecache`' |
|
| 809 | - . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC', 1); |
|
| 810 | - $query->execute([$this->getNumericStorageId()]); |
|
| 811 | - if ($row = $query->fetch()) { |
|
| 812 | - return $row['path']; |
|
| 813 | - } else { |
|
| 814 | - return false; |
|
| 815 | - } |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * get the path of a file on this storage by it's file id |
|
| 820 | - * |
|
| 821 | - * @param int $id the file id of the file or folder to search |
|
| 822 | - * @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 |
|
| 823 | - */ |
|
| 824 | - public function getPathById($id) { |
|
| 825 | - $sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?'; |
|
| 826 | - $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 827 | - if ($row = $result->fetch()) { |
|
| 828 | - // Oracle stores empty strings as null... |
|
| 829 | - if ($row['path'] === null) { |
|
| 830 | - return ''; |
|
| 831 | - } |
|
| 832 | - return $row['path']; |
|
| 833 | - } else { |
|
| 834 | - return null; |
|
| 835 | - } |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * get the storage id of the storage for a file and the internal path of the file |
|
| 840 | - * unlike getPathById this does not limit the search to files on this storage and |
|
| 841 | - * instead does a global search in the cache table |
|
| 842 | - * |
|
| 843 | - * @param int $id |
|
| 844 | - * @deprecated use getPathById() instead |
|
| 845 | - * @return array first element holding the storage id, second the path |
|
| 846 | - */ |
|
| 847 | - static public function getById($id) { |
|
| 848 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 849 | - $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 850 | - $result = $connection->executeQuery($sql, array($id)); |
|
| 851 | - if ($row = $result->fetch()) { |
|
| 852 | - $numericId = $row['storage']; |
|
| 853 | - $path = $row['path']; |
|
| 854 | - } else { |
|
| 855 | - return null; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - if ($id = Storage::getStorageId($numericId)) { |
|
| 859 | - return array($id, $path); |
|
| 860 | - } else { |
|
| 861 | - return null; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * normalize the given path |
|
| 867 | - * |
|
| 868 | - * @param string $path |
|
| 869 | - * @return string |
|
| 870 | - */ |
|
| 871 | - public function normalize($path) { |
|
| 872 | - |
|
| 873 | - return trim(\OC_Util::normalizeUnicode($path), '/'); |
|
| 874 | - } |
|
| 652 | + $mimetype = $this->mimetypeLoader->getId($mimetype); |
|
| 653 | + $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); |
|
| 654 | + |
|
| 655 | + return $this->searchResultToCacheEntries($result); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + public function searchQuery(ISearchQuery $searchQuery) { |
|
| 659 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 660 | + |
|
| 661 | + $query = $builder->select(['fileid', 'storage', 'path', 'parent', 'name', 'mimetype', 'mimepart', 'size', 'mtime', 'encrypted', 'etag', 'permissions', 'checksum']) |
|
| 662 | + ->from('filecache') |
|
| 663 | + ->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId()))) |
|
| 664 | + ->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation())); |
|
| 665 | + |
|
| 666 | + if ($searchQuery->getLimit()) { |
|
| 667 | + $query->setMaxResults($searchQuery->getLimit()); |
|
| 668 | + } |
|
| 669 | + if ($searchQuery->getOffset()) { |
|
| 670 | + $query->setFirstResult($searchQuery->getOffset()); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + $result = $query->execute(); |
|
| 674 | + return $this->searchResultToCacheEntries($result); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + /** |
|
| 678 | + * Search for files by tag of a given users. |
|
| 679 | + * |
|
| 680 | + * Note that every user can tag files differently. |
|
| 681 | + * |
|
| 682 | + * @param string|int $tag name or tag id |
|
| 683 | + * @param string $userId owner of the tags |
|
| 684 | + * @return ICacheEntry[] file data |
|
| 685 | + */ |
|
| 686 | + public function searchByTag($tag, $userId) { |
|
| 687 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . |
|
| 688 | + '`mimetype`, `mimepart`, `size`, `mtime`, ' . |
|
| 689 | + '`encrypted`, `etag`, `permissions`, `checksum` ' . |
|
| 690 | + 'FROM `*PREFIX*filecache` `file`, ' . |
|
| 691 | + '`*PREFIX*vcategory_to_object` `tagmap`, ' . |
|
| 692 | + '`*PREFIX*vcategory` `tag` ' . |
|
| 693 | + // JOIN filecache to vcategory_to_object |
|
| 694 | + 'WHERE `file`.`fileid` = `tagmap`.`objid` ' . |
|
| 695 | + // JOIN vcategory_to_object to vcategory |
|
| 696 | + 'AND `tagmap`.`type` = `tag`.`type` ' . |
|
| 697 | + 'AND `tagmap`.`categoryid` = `tag`.`id` ' . |
|
| 698 | + // conditions |
|
| 699 | + 'AND `file`.`storage` = ? ' . |
|
| 700 | + 'AND `tag`.`type` = \'files\' ' . |
|
| 701 | + 'AND `tag`.`uid` = ? '; |
|
| 702 | + if (is_int($tag)) { |
|
| 703 | + $sql .= 'AND `tag`.`id` = ? '; |
|
| 704 | + } else { |
|
| 705 | + $sql .= 'AND `tag`.`category` = ? '; |
|
| 706 | + } |
|
| 707 | + $result = $this->connection->executeQuery( |
|
| 708 | + $sql, |
|
| 709 | + [ |
|
| 710 | + $this->getNumericStorageId(), |
|
| 711 | + $userId, |
|
| 712 | + $tag |
|
| 713 | + ] |
|
| 714 | + ); |
|
| 715 | + $files = array(); |
|
| 716 | + while ($row = $result->fetch()) { |
|
| 717 | + $files[] = $row; |
|
| 718 | + } |
|
| 719 | + return array_map(function (array $data) { |
|
| 720 | + return new CacheEntry($data); |
|
| 721 | + }, $files); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Re-calculate the folder size and the size of all parent folders |
|
| 726 | + * |
|
| 727 | + * @param string|boolean $path |
|
| 728 | + * @param array $data (optional) meta data of the folder |
|
| 729 | + */ |
|
| 730 | + public function correctFolderSize($path, $data = null) { |
|
| 731 | + $this->calculateFolderSize($path, $data); |
|
| 732 | + if ($path !== '') { |
|
| 733 | + $parent = dirname($path); |
|
| 734 | + if ($parent === '.' or $parent === '/') { |
|
| 735 | + $parent = ''; |
|
| 736 | + } |
|
| 737 | + $this->correctFolderSize($parent); |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * calculate the size of a folder and set it in the cache |
|
| 743 | + * |
|
| 744 | + * @param string $path |
|
| 745 | + * @param array $entry (optional) meta data of the folder |
|
| 746 | + * @return int |
|
| 747 | + */ |
|
| 748 | + public function calculateFolderSize($path, $entry = null) { |
|
| 749 | + $totalSize = 0; |
|
| 750 | + if (is_null($entry) or !isset($entry['fileid'])) { |
|
| 751 | + $entry = $this->get($path); |
|
| 752 | + } |
|
| 753 | + if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') { |
|
| 754 | + $id = $entry['fileid']; |
|
| 755 | + $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' . |
|
| 756 | + 'FROM `*PREFIX*filecache` ' . |
|
| 757 | + 'WHERE `parent` = ? AND `storage` = ?'; |
|
| 758 | + $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 759 | + if ($row = $result->fetch()) { |
|
| 760 | + $result->closeCursor(); |
|
| 761 | + list($sum, $min) = array_values($row); |
|
| 762 | + $sum = 0 + $sum; |
|
| 763 | + $min = 0 + $min; |
|
| 764 | + if ($min === -1) { |
|
| 765 | + $totalSize = $min; |
|
| 766 | + } else { |
|
| 767 | + $totalSize = $sum; |
|
| 768 | + } |
|
| 769 | + $update = array(); |
|
| 770 | + if ($entry['size'] !== $totalSize) { |
|
| 771 | + $update['size'] = $totalSize; |
|
| 772 | + } |
|
| 773 | + if (count($update) > 0) { |
|
| 774 | + $this->update($id, $update); |
|
| 775 | + } |
|
| 776 | + } else { |
|
| 777 | + $result->closeCursor(); |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + return $totalSize; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * get all file ids on the files on the storage |
|
| 785 | + * |
|
| 786 | + * @return int[] |
|
| 787 | + */ |
|
| 788 | + public function getAll() { |
|
| 789 | + $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?'; |
|
| 790 | + $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId())); |
|
| 791 | + $ids = array(); |
|
| 792 | + while ($row = $result->fetch()) { |
|
| 793 | + $ids[] = $row['fileid']; |
|
| 794 | + } |
|
| 795 | + return $ids; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * find a folder in the cache which has not been fully scanned |
|
| 800 | + * |
|
| 801 | + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 802 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 803 | + * likely the folder where we stopped scanning previously |
|
| 804 | + * |
|
| 805 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 806 | + */ |
|
| 807 | + public function getIncomplete() { |
|
| 808 | + $query = $this->connection->prepare('SELECT `path` FROM `*PREFIX*filecache`' |
|
| 809 | + . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC', 1); |
|
| 810 | + $query->execute([$this->getNumericStorageId()]); |
|
| 811 | + if ($row = $query->fetch()) { |
|
| 812 | + return $row['path']; |
|
| 813 | + } else { |
|
| 814 | + return false; |
|
| 815 | + } |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * get the path of a file on this storage by it's file id |
|
| 820 | + * |
|
| 821 | + * @param int $id the file id of the file or folder to search |
|
| 822 | + * @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 |
|
| 823 | + */ |
|
| 824 | + public function getPathById($id) { |
|
| 825 | + $sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?'; |
|
| 826 | + $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
|
| 827 | + if ($row = $result->fetch()) { |
|
| 828 | + // Oracle stores empty strings as null... |
|
| 829 | + if ($row['path'] === null) { |
|
| 830 | + return ''; |
|
| 831 | + } |
|
| 832 | + return $row['path']; |
|
| 833 | + } else { |
|
| 834 | + return null; |
|
| 835 | + } |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * get the storage id of the storage for a file and the internal path of the file |
|
| 840 | + * unlike getPathById this does not limit the search to files on this storage and |
|
| 841 | + * instead does a global search in the cache table |
|
| 842 | + * |
|
| 843 | + * @param int $id |
|
| 844 | + * @deprecated use getPathById() instead |
|
| 845 | + * @return array first element holding the storage id, second the path |
|
| 846 | + */ |
|
| 847 | + static public function getById($id) { |
|
| 848 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 849 | + $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; |
|
| 850 | + $result = $connection->executeQuery($sql, array($id)); |
|
| 851 | + if ($row = $result->fetch()) { |
|
| 852 | + $numericId = $row['storage']; |
|
| 853 | + $path = $row['path']; |
|
| 854 | + } else { |
|
| 855 | + return null; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + if ($id = Storage::getStorageId($numericId)) { |
|
| 859 | + return array($id, $path); |
|
| 860 | + } else { |
|
| 861 | + return null; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * normalize the given path |
|
| 867 | + * |
|
| 868 | + * @param string $path |
|
| 869 | + * @return string |
|
| 870 | + */ |
|
| 871 | + public function normalize($path) { |
|
| 872 | + |
|
| 873 | + return trim(\OC_Util::normalizeUnicode($path), '/'); |
|
| 874 | + } |
|
| 875 | 875 | } |
@@ -161,20 +161,20 @@ 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 | 172 | $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); |
| 173 | 173 | $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); |
| 174 | 174 | if ($data['storage_mtime'] == 0) { |
| 175 | 175 | $data['storage_mtime'] = $data['mtime']; |
| 176 | 176 | } |
| 177 | - $data['permissions'] = (int)$data['permissions']; |
|
| 177 | + $data['permissions'] = (int) $data['permissions']; |
|
| 178 | 178 | return new CacheEntry($data); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -208,12 +208,12 @@ discard block |
||
| 208 | 208 | if ($file['storage_mtime'] == 0) { |
| 209 | 209 | $file['storage_mtime'] = $file['mtime']; |
| 210 | 210 | } |
| 211 | - $file['permissions'] = (int)$file['permissions']; |
|
| 212 | - $file['mtime'] = (int)$file['mtime']; |
|
| 213 | - $file['storage_mtime'] = (int)$file['storage_mtime']; |
|
| 211 | + $file['permissions'] = (int) $file['permissions']; |
|
| 212 | + $file['mtime'] = (int) $file['mtime']; |
|
| 213 | + $file['storage_mtime'] = (int) $file['storage_mtime']; |
|
| 214 | 214 | $file['size'] = 0 + $file['size']; |
| 215 | 215 | } |
| 216 | - return array_map(function (array $data) { |
|
| 216 | + return array_map(function(array $data) { |
|
| 217 | 217 | return new CacheEntry($data); |
| 218 | 218 | }, $files); |
| 219 | 219 | } else { |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | $queryParts[] = '`storage`'; |
| 274 | 274 | $params[] = $this->getNumericStorageId(); |
| 275 | 275 | |
| 276 | - $queryParts = array_map(function ($item) { |
|
| 276 | + $queryParts = array_map(function($item) { |
|
| 277 | 277 | return trim($item, "`"); |
| 278 | 278 | }, $queryParts); |
| 279 | 279 | $values = array_combine($queryParts, $params); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | 'path_hash', |
| 283 | 283 | ]) |
| 284 | 284 | ) { |
| 285 | - return (int)$this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 285 | + return (int) $this->connection->lastInsertId('*PREFIX*filecache'); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // The file was created in the mean time |
@@ -320,10 +320,10 @@ discard block |
||
| 320 | 320 | |
| 321 | 321 | // don't update if the data we try to set is the same as the one in the record |
| 322 | 322 | // some databases (Postgres) don't like superfluous updates |
| 323 | - $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' . |
|
| 324 | - 'WHERE (' . |
|
| 325 | - implode(' <> ? OR ', $queryParts) . ' <> ? OR ' . |
|
| 326 | - implode(' IS NULL OR ', $queryParts) . ' IS NULL' . |
|
| 323 | + $sql = 'UPDATE `*PREFIX*filecache` SET '.implode(' = ?, ', $queryParts).'=? '. |
|
| 324 | + 'WHERE ('. |
|
| 325 | + implode(' <> ? OR ', $queryParts).' <> ? OR '. |
|
| 326 | + implode(' IS NULL OR ', $queryParts).' IS NULL'. |
|
| 327 | 327 | ') AND `fileid` = ? '; |
| 328 | 328 | $this->connection->executeQuery($sql, $params); |
| 329 | 329 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | $params[] = $value; |
| 377 | - $queryParts[] = '`' . $name . '`'; |
|
| 377 | + $queryParts[] = '`'.$name.'`'; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | return array($queryParts, $params); |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | return -1; |
| 417 | 417 | } else { |
| 418 | 418 | $parent = $this->getParentPath($file); |
| 419 | - return (int)$this->getId($parent); |
|
| 419 | + return (int) $this->getId($parent); |
|
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | private function getSubFolders($entry) { |
| 464 | 464 | $children = $this->getFolderContentsById($entry['fileid']); |
| 465 | - return array_filter($children, function ($child) { |
|
| 465 | + return array_filter($children, function($child) { |
|
| 466 | 466 | return $child['mimetype'] === 'httpd/unix-directory'; |
| 467 | 467 | }); |
| 468 | 468 | } |
@@ -529,14 +529,14 @@ discard block |
||
| 529 | 529 | if ($sourceData['mimetype'] === 'httpd/unix-directory') { |
| 530 | 530 | //find all child entries |
| 531 | 531 | $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; |
| 532 | - $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']); |
|
| 532 | + $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath).'/%']); |
|
| 533 | 533 | $childEntries = $result->fetchAll(); |
| 534 | 534 | $sourceLength = strlen($sourcePath); |
| 535 | 535 | $this->connection->beginTransaction(); |
| 536 | 536 | $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); |
| 537 | 537 | |
| 538 | 538 | foreach ($childEntries as $child) { |
| 539 | - $newTargetPath = $targetPath . substr($child['path'], $sourceLength); |
|
| 539 | + $newTargetPath = $targetPath.substr($child['path'], $sourceLength); |
|
| 540 | 540 | $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]); |
| 541 | 541 | } |
| 542 | 542 | $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'; |
| 581 | 581 | $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash)); |
| 582 | 582 | if ($row = $result->fetch()) { |
| 583 | - if ((int)$row['size'] === -1) { |
|
| 583 | + if ((int) $row['size'] === -1) { |
|
| 584 | 584 | return self::SHALLOW; |
| 585 | 585 | } else { |
| 586 | 586 | return self::COMPLETE; |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); |
| 630 | 630 | $files[] = $row; |
| 631 | 631 | } |
| 632 | - return array_map(function (array $data) { |
|
| 632 | + return array_map(function(array $data) { |
|
| 633 | 633 | return new CacheEntry($data); |
| 634 | 634 | }, $files); |
| 635 | 635 | } |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | $where = '`mimepart` = ?'; |
| 649 | 649 | } |
| 650 | 650 | $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` |
| 651 | - FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'; |
|
| 651 | + FROM `*PREFIX*filecache` WHERE ' . $where.' AND `storage` = ?'; |
|
| 652 | 652 | $mimetype = $this->mimetypeLoader->getId($mimetype); |
| 653 | 653 | $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); |
| 654 | 654 | |
@@ -684,20 +684,20 @@ discard block |
||
| 684 | 684 | * @return ICacheEntry[] file data |
| 685 | 685 | */ |
| 686 | 686 | public function searchByTag($tag, $userId) { |
| 687 | - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . |
|
| 688 | - '`mimetype`, `mimepart`, `size`, `mtime`, ' . |
|
| 689 | - '`encrypted`, `etag`, `permissions`, `checksum` ' . |
|
| 690 | - 'FROM `*PREFIX*filecache` `file`, ' . |
|
| 691 | - '`*PREFIX*vcategory_to_object` `tagmap`, ' . |
|
| 692 | - '`*PREFIX*vcategory` `tag` ' . |
|
| 687 | + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, '. |
|
| 688 | + '`mimetype`, `mimepart`, `size`, `mtime`, '. |
|
| 689 | + '`encrypted`, `etag`, `permissions`, `checksum` '. |
|
| 690 | + 'FROM `*PREFIX*filecache` `file`, '. |
|
| 691 | + '`*PREFIX*vcategory_to_object` `tagmap`, '. |
|
| 692 | + '`*PREFIX*vcategory` `tag` '. |
|
| 693 | 693 | // JOIN filecache to vcategory_to_object |
| 694 | - 'WHERE `file`.`fileid` = `tagmap`.`objid` ' . |
|
| 694 | + 'WHERE `file`.`fileid` = `tagmap`.`objid` '. |
|
| 695 | 695 | // JOIN vcategory_to_object to vcategory |
| 696 | - 'AND `tagmap`.`type` = `tag`.`type` ' . |
|
| 697 | - 'AND `tagmap`.`categoryid` = `tag`.`id` ' . |
|
| 696 | + 'AND `tagmap`.`type` = `tag`.`type` '. |
|
| 697 | + 'AND `tagmap`.`categoryid` = `tag`.`id` '. |
|
| 698 | 698 | // conditions |
| 699 | - 'AND `file`.`storage` = ? ' . |
|
| 700 | - 'AND `tag`.`type` = \'files\' ' . |
|
| 699 | + 'AND `file`.`storage` = ? '. |
|
| 700 | + 'AND `tag`.`type` = \'files\' '. |
|
| 701 | 701 | 'AND `tag`.`uid` = ? '; |
| 702 | 702 | if (is_int($tag)) { |
| 703 | 703 | $sql .= 'AND `tag`.`id` = ? '; |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | while ($row = $result->fetch()) { |
| 717 | 717 | $files[] = $row; |
| 718 | 718 | } |
| 719 | - return array_map(function (array $data) { |
|
| 719 | + return array_map(function(array $data) { |
|
| 720 | 720 | return new CacheEntry($data); |
| 721 | 721 | }, $files); |
| 722 | 722 | } |
@@ -752,8 +752,8 @@ discard block |
||
| 752 | 752 | } |
| 753 | 753 | if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') { |
| 754 | 754 | $id = $entry['fileid']; |
| 755 | - $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' . |
|
| 756 | - 'FROM `*PREFIX*filecache` ' . |
|
| 755 | + $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 '. |
|
| 756 | + 'FROM `*PREFIX*filecache` '. |
|
| 757 | 757 | 'WHERE `parent` = ? AND `storage` = ?'; |
| 758 | 758 | $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId())); |
| 759 | 759 | if ($row = $result->fetch()) { |
@@ -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 | } |
@@ -55,187 +55,187 @@ |
||
| 55 | 55 | |
| 56 | 56 | class Server { |
| 57 | 57 | |
| 58 | - /** @var IRequest */ |
|
| 59 | - private $request; |
|
| 60 | - |
|
| 61 | - /** @var string */ |
|
| 62 | - private $baseUri; |
|
| 63 | - |
|
| 64 | - /** @var Connector\Sabre\Server */ |
|
| 65 | - private $server; |
|
| 66 | - |
|
| 67 | - public function __construct(IRequest $request, $baseUri) { |
|
| 68 | - $this->request = $request; |
|
| 69 | - $this->baseUri = $baseUri; |
|
| 70 | - $logger = \OC::$server->getLogger(); |
|
| 71 | - $mailer = \OC::$server->getMailer(); |
|
| 72 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 73 | - |
|
| 74 | - $root = new RootCollection(); |
|
| 75 | - $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
| 76 | - |
|
| 77 | - // Backends |
|
| 78 | - $authBackend = new Auth( |
|
| 79 | - \OC::$server->getSession(), |
|
| 80 | - \OC::$server->getUserSession(), |
|
| 81 | - \OC::$server->getRequest(), |
|
| 82 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 83 | - \OC::$server->getBruteForceThrottler() |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - // Set URL explicitly due to reverse-proxy situations |
|
| 87 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 88 | - $this->server->setBaseUri($this->baseUri); |
|
| 89 | - |
|
| 90 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 91 | - $authPlugin = new Plugin(); |
|
| 92 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 93 | - $this->server->addPlugin($authPlugin); |
|
| 94 | - |
|
| 95 | - // allow setup of additional auth backends |
|
| 96 | - $event = new SabrePluginEvent($this->server); |
|
| 97 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 98 | - |
|
| 99 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 100 | - $authPlugin->addBackend($authBackend); |
|
| 101 | - |
|
| 102 | - // debugging |
|
| 103 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 104 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 105 | - } else { |
|
| 106 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 110 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 111 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 112 | - |
|
| 113 | - // acl |
|
| 114 | - $acl = new DavAclPlugin(); |
|
| 115 | - $acl->principalCollectionSet = [ |
|
| 116 | - 'principals/users', 'principals/groups' |
|
| 117 | - ]; |
|
| 118 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 119 | - $this->server->addPlugin($acl); |
|
| 120 | - |
|
| 121 | - // calendar plugins |
|
| 122 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 123 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 124 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 125 | - $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 126 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 127 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 128 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 129 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 130 | - \OC::$server->getConfig(), |
|
| 131 | - \OC::$server->getURLGenerator() |
|
| 132 | - )); |
|
| 133 | - |
|
| 134 | - // addressbook plugins |
|
| 135 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 136 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 137 | - $this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger())); |
|
| 138 | - |
|
| 139 | - // system tags plugins |
|
| 140 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 141 | - \OC::$server->getSystemTagManager(), |
|
| 142 | - \OC::$server->getGroupManager(), |
|
| 143 | - \OC::$server->getUserSession() |
|
| 144 | - )); |
|
| 145 | - |
|
| 146 | - // comments plugin |
|
| 147 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 148 | - \OC::$server->getCommentsManager(), |
|
| 149 | - \OC::$server->getUserSession() |
|
| 150 | - )); |
|
| 151 | - |
|
| 152 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 153 | - |
|
| 154 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 155 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 156 | - if($request->isUserAgent([ |
|
| 157 | - '/WebDAVFS/', |
|
| 158 | - '/Microsoft Office OneNote 2013/', |
|
| 159 | - ])) { |
|
| 160 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 164 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 168 | - $this->server->on('beforeMethod', function () { |
|
| 169 | - // custom properties plugin must be the last one |
|
| 170 | - $userSession = \OC::$server->getUserSession(); |
|
| 171 | - $user = $userSession->getUser(); |
|
| 172 | - if ($user !== null) { |
|
| 173 | - $view = \OC\Files\Filesystem::getView(); |
|
| 174 | - $this->server->addPlugin( |
|
| 175 | - new FilesPlugin( |
|
| 176 | - $this->server->tree, |
|
| 177 | - \OC::$server->getConfig(), |
|
| 178 | - $this->request, |
|
| 179 | - \OC::$server->getPreviewManager(), |
|
| 180 | - false, |
|
| 181 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 182 | - ) |
|
| 183 | - ); |
|
| 184 | - |
|
| 185 | - $this->server->addPlugin( |
|
| 186 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 187 | - new CustomPropertiesBackend( |
|
| 188 | - $this->server->tree, |
|
| 189 | - \OC::$server->getDatabaseConnection(), |
|
| 190 | - \OC::$server->getUserSession()->getUser() |
|
| 191 | - ) |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - if ($view !== null) { |
|
| 195 | - $this->server->addPlugin( |
|
| 196 | - new QuotaPlugin($view)); |
|
| 197 | - } |
|
| 198 | - $this->server->addPlugin( |
|
| 199 | - new TagsPlugin( |
|
| 200 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 201 | - ) |
|
| 202 | - ); |
|
| 203 | - // TODO: switch to LazyUserFolder |
|
| 204 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 205 | - $this->server->addPlugin(new SharesPlugin( |
|
| 206 | - $this->server->tree, |
|
| 207 | - $userSession, |
|
| 208 | - $userFolder, |
|
| 209 | - \OC::$server->getShareManager() |
|
| 210 | - )); |
|
| 211 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 212 | - \OC::$server->getCommentsManager(), |
|
| 213 | - $userSession |
|
| 214 | - )); |
|
| 215 | - if ($view !== null) { |
|
| 216 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 217 | - $this->server->tree, |
|
| 218 | - $view, |
|
| 219 | - \OC::$server->getSystemTagManager(), |
|
| 220 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 221 | - \OC::$server->getTagManager(), |
|
| 222 | - $userSession, |
|
| 223 | - \OC::$server->getGroupManager(), |
|
| 224 | - $userFolder |
|
| 225 | - )); |
|
| 226 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 227 | - $this->server->tree, |
|
| 228 | - $user, |
|
| 229 | - \OC::$server->getRootFolder(), |
|
| 230 | - \OC::$server->getShareManager(), |
|
| 231 | - $view |
|
| 232 | - ))); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - }); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - public function exec() { |
|
| 239 | - $this->server->exec(); |
|
| 240 | - } |
|
| 58 | + /** @var IRequest */ |
|
| 59 | + private $request; |
|
| 60 | + |
|
| 61 | + /** @var string */ |
|
| 62 | + private $baseUri; |
|
| 63 | + |
|
| 64 | + /** @var Connector\Sabre\Server */ |
|
| 65 | + private $server; |
|
| 66 | + |
|
| 67 | + public function __construct(IRequest $request, $baseUri) { |
|
| 68 | + $this->request = $request; |
|
| 69 | + $this->baseUri = $baseUri; |
|
| 70 | + $logger = \OC::$server->getLogger(); |
|
| 71 | + $mailer = \OC::$server->getMailer(); |
|
| 72 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 73 | + |
|
| 74 | + $root = new RootCollection(); |
|
| 75 | + $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
| 76 | + |
|
| 77 | + // Backends |
|
| 78 | + $authBackend = new Auth( |
|
| 79 | + \OC::$server->getSession(), |
|
| 80 | + \OC::$server->getUserSession(), |
|
| 81 | + \OC::$server->getRequest(), |
|
| 82 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 83 | + \OC::$server->getBruteForceThrottler() |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + // Set URL explicitly due to reverse-proxy situations |
|
| 87 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 88 | + $this->server->setBaseUri($this->baseUri); |
|
| 89 | + |
|
| 90 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 91 | + $authPlugin = new Plugin(); |
|
| 92 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 93 | + $this->server->addPlugin($authPlugin); |
|
| 94 | + |
|
| 95 | + // allow setup of additional auth backends |
|
| 96 | + $event = new SabrePluginEvent($this->server); |
|
| 97 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 98 | + |
|
| 99 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 100 | + $authPlugin->addBackend($authBackend); |
|
| 101 | + |
|
| 102 | + // debugging |
|
| 103 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 104 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 105 | + } else { |
|
| 106 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 110 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 111 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 112 | + |
|
| 113 | + // acl |
|
| 114 | + $acl = new DavAclPlugin(); |
|
| 115 | + $acl->principalCollectionSet = [ |
|
| 116 | + 'principals/users', 'principals/groups' |
|
| 117 | + ]; |
|
| 118 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 119 | + $this->server->addPlugin($acl); |
|
| 120 | + |
|
| 121 | + // calendar plugins |
|
| 122 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 123 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 124 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 125 | + $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 126 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 127 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 128 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 129 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 130 | + \OC::$server->getConfig(), |
|
| 131 | + \OC::$server->getURLGenerator() |
|
| 132 | + )); |
|
| 133 | + |
|
| 134 | + // addressbook plugins |
|
| 135 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 136 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 137 | + $this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger())); |
|
| 138 | + |
|
| 139 | + // system tags plugins |
|
| 140 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 141 | + \OC::$server->getSystemTagManager(), |
|
| 142 | + \OC::$server->getGroupManager(), |
|
| 143 | + \OC::$server->getUserSession() |
|
| 144 | + )); |
|
| 145 | + |
|
| 146 | + // comments plugin |
|
| 147 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 148 | + \OC::$server->getCommentsManager(), |
|
| 149 | + \OC::$server->getUserSession() |
|
| 150 | + )); |
|
| 151 | + |
|
| 152 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 153 | + |
|
| 154 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 155 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 156 | + if($request->isUserAgent([ |
|
| 157 | + '/WebDAVFS/', |
|
| 158 | + '/Microsoft Office OneNote 2013/', |
|
| 159 | + ])) { |
|
| 160 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 164 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 168 | + $this->server->on('beforeMethod', function () { |
|
| 169 | + // custom properties plugin must be the last one |
|
| 170 | + $userSession = \OC::$server->getUserSession(); |
|
| 171 | + $user = $userSession->getUser(); |
|
| 172 | + if ($user !== null) { |
|
| 173 | + $view = \OC\Files\Filesystem::getView(); |
|
| 174 | + $this->server->addPlugin( |
|
| 175 | + new FilesPlugin( |
|
| 176 | + $this->server->tree, |
|
| 177 | + \OC::$server->getConfig(), |
|
| 178 | + $this->request, |
|
| 179 | + \OC::$server->getPreviewManager(), |
|
| 180 | + false, |
|
| 181 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 182 | + ) |
|
| 183 | + ); |
|
| 184 | + |
|
| 185 | + $this->server->addPlugin( |
|
| 186 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 187 | + new CustomPropertiesBackend( |
|
| 188 | + $this->server->tree, |
|
| 189 | + \OC::$server->getDatabaseConnection(), |
|
| 190 | + \OC::$server->getUserSession()->getUser() |
|
| 191 | + ) |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + if ($view !== null) { |
|
| 195 | + $this->server->addPlugin( |
|
| 196 | + new QuotaPlugin($view)); |
|
| 197 | + } |
|
| 198 | + $this->server->addPlugin( |
|
| 199 | + new TagsPlugin( |
|
| 200 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 201 | + ) |
|
| 202 | + ); |
|
| 203 | + // TODO: switch to LazyUserFolder |
|
| 204 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 205 | + $this->server->addPlugin(new SharesPlugin( |
|
| 206 | + $this->server->tree, |
|
| 207 | + $userSession, |
|
| 208 | + $userFolder, |
|
| 209 | + \OC::$server->getShareManager() |
|
| 210 | + )); |
|
| 211 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 212 | + \OC::$server->getCommentsManager(), |
|
| 213 | + $userSession |
|
| 214 | + )); |
|
| 215 | + if ($view !== null) { |
|
| 216 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 217 | + $this->server->tree, |
|
| 218 | + $view, |
|
| 219 | + \OC::$server->getSystemTagManager(), |
|
| 220 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 221 | + \OC::$server->getTagManager(), |
|
| 222 | + $userSession, |
|
| 223 | + \OC::$server->getGroupManager(), |
|
| 224 | + $userFolder |
|
| 225 | + )); |
|
| 226 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 227 | + $this->server->tree, |
|
| 228 | + $user, |
|
| 229 | + \OC::$server->getRootFolder(), |
|
| 230 | + \OC::$server->getShareManager(), |
|
| 231 | + $view |
|
| 232 | + ))); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + }); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + public function exec() { |
|
| 239 | + $this->server->exec(); |
|
| 240 | + } |
|
| 241 | 241 | } |
@@ -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 | } |