@@ -26,55 +26,55 @@ |
||
| 26 | 26 | use OCP\Files\Search\ISearchQuery; |
| 27 | 27 | |
| 28 | 28 | class SearchQuery implements ISearchQuery { |
| 29 | - /** @var ISearchOperator */ |
|
| 30 | - private $searchOperation; |
|
| 31 | - /** @var integer */ |
|
| 32 | - private $limit; |
|
| 33 | - /** @var integer */ |
|
| 34 | - private $offset; |
|
| 35 | - /** @var ISearchOrder[] */ |
|
| 36 | - private $order; |
|
| 29 | + /** @var ISearchOperator */ |
|
| 30 | + private $searchOperation; |
|
| 31 | + /** @var integer */ |
|
| 32 | + private $limit; |
|
| 33 | + /** @var integer */ |
|
| 34 | + private $offset; |
|
| 35 | + /** @var ISearchOrder[] */ |
|
| 36 | + private $order; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * SearchQuery constructor. |
|
| 40 | - * |
|
| 41 | - * @param ISearchOperator $searchOperation |
|
| 42 | - * @param int $limit |
|
| 43 | - * @param int $offset |
|
| 44 | - * @param array $order |
|
| 45 | - */ |
|
| 46 | - public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order) { |
|
| 47 | - $this->searchOperation = $searchOperation; |
|
| 48 | - $this->limit = $limit; |
|
| 49 | - $this->offset = $offset; |
|
| 50 | - $this->order = $order; |
|
| 51 | - } |
|
| 38 | + /** |
|
| 39 | + * SearchQuery constructor. |
|
| 40 | + * |
|
| 41 | + * @param ISearchOperator $searchOperation |
|
| 42 | + * @param int $limit |
|
| 43 | + * @param int $offset |
|
| 44 | + * @param array $order |
|
| 45 | + */ |
|
| 46 | + public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order) { |
|
| 47 | + $this->searchOperation = $searchOperation; |
|
| 48 | + $this->limit = $limit; |
|
| 49 | + $this->offset = $offset; |
|
| 50 | + $this->order = $order; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return ISearchOperator |
|
| 55 | - */ |
|
| 56 | - public function getSearchOperation() { |
|
| 57 | - return $this->searchOperation; |
|
| 58 | - } |
|
| 53 | + /** |
|
| 54 | + * @return ISearchOperator |
|
| 55 | + */ |
|
| 56 | + public function getSearchOperation() { |
|
| 57 | + return $this->searchOperation; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return int |
|
| 62 | - */ |
|
| 63 | - public function getLimit() { |
|
| 64 | - return $this->limit; |
|
| 65 | - } |
|
| 60 | + /** |
|
| 61 | + * @return int |
|
| 62 | + */ |
|
| 63 | + public function getLimit() { |
|
| 64 | + return $this->limit; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 70 | - public function getOffset() { |
|
| 71 | - return $this->offset; |
|
| 72 | - } |
|
| 67 | + /** |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | + public function getOffset() { |
|
| 71 | + return $this->offset; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return ISearchOrder[] |
|
| 76 | - */ |
|
| 77 | - public function getOrder() { |
|
| 78 | - return $this->order; |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * @return ISearchOrder[] |
|
| 76 | + */ |
|
| 77 | + public function getOrder() { |
|
| 78 | + return $this->order; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -24,44 +24,44 @@ |
||
| 24 | 24 | use OCP\Files\Search\ISearchComparison; |
| 25 | 25 | |
| 26 | 26 | class SearchComparison implements ISearchComparison { |
| 27 | - /** @var string */ |
|
| 28 | - private $type; |
|
| 29 | - /** @var string */ |
|
| 30 | - private $field; |
|
| 31 | - /** @var string|integer|\DateTime */ |
|
| 32 | - private $value; |
|
| 27 | + /** @var string */ |
|
| 28 | + private $type; |
|
| 29 | + /** @var string */ |
|
| 30 | + private $field; |
|
| 31 | + /** @var string|integer|\DateTime */ |
|
| 32 | + private $value; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * SearchComparison constructor. |
|
| 36 | - * |
|
| 37 | - * @param string $type |
|
| 38 | - * @param string $field |
|
| 39 | - * @param \DateTime|int|string $value |
|
| 40 | - */ |
|
| 41 | - public function __construct($type, $field, $value) { |
|
| 42 | - $this->type = $type; |
|
| 43 | - $this->field = $field; |
|
| 44 | - $this->value = $value; |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * SearchComparison constructor. |
|
| 36 | + * |
|
| 37 | + * @param string $type |
|
| 38 | + * @param string $field |
|
| 39 | + * @param \DateTime|int|string $value |
|
| 40 | + */ |
|
| 41 | + public function __construct($type, $field, $value) { |
|
| 42 | + $this->type = $type; |
|
| 43 | + $this->field = $field; |
|
| 44 | + $this->value = $value; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function getType() { |
|
| 51 | - return $this->type; |
|
| 52 | - } |
|
| 47 | + /** |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function getType() { |
|
| 51 | + return $this->type; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function getField() { |
|
| 58 | - return $this->field; |
|
| 59 | - } |
|
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function getField() { |
|
| 58 | + return $this->field; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @return \DateTime|int|string |
|
| 63 | - */ |
|
| 64 | - public function getValue() { |
|
| 65 | - return $this->value; |
|
| 66 | - } |
|
| 61 | + /** |
|
| 62 | + * @return \DateTime|int|string |
|
| 63 | + */ |
|
| 64 | + public function getValue() { |
|
| 65 | + return $this->value; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -25,33 +25,33 @@ |
||
| 25 | 25 | use OCP\Files\Search\ISearchOrder; |
| 26 | 26 | |
| 27 | 27 | class SearchOrder implements ISearchOrder { |
| 28 | - /** @var string */ |
|
| 29 | - private $direction; |
|
| 30 | - /** @var string */ |
|
| 31 | - private $field; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $direction; |
|
| 30 | + /** @var string */ |
|
| 31 | + private $field; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * SearchOrder constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $direction |
|
| 37 | - * @param string $field |
|
| 38 | - */ |
|
| 39 | - public function __construct($direction, $field) { |
|
| 40 | - $this->direction = $direction; |
|
| 41 | - $this->field = $field; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * SearchOrder constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $direction |
|
| 37 | + * @param string $field |
|
| 38 | + */ |
|
| 39 | + public function __construct($direction, $field) { |
|
| 40 | + $this->direction = $direction; |
|
| 41 | + $this->field = $field; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getDirection() { |
|
| 48 | - return $this->direction; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getDirection() { |
|
| 48 | + return $this->direction; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getField() { |
|
| 55 | - return $this->field; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getField() { |
|
| 55 | + return $this->field; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -25,33 +25,33 @@ |
||
| 25 | 25 | use OCP\Files\Search\ISearchOperator; |
| 26 | 26 | |
| 27 | 27 | class SearchBinaryOperator implements ISearchBinaryOperator { |
| 28 | - /** @var string */ |
|
| 29 | - private $type; |
|
| 30 | - /** @var ISearchOperator[] */ |
|
| 31 | - private $arguments; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $type; |
|
| 30 | + /** @var ISearchOperator[] */ |
|
| 31 | + private $arguments; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * SearchBinaryOperator constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $type |
|
| 37 | - * @param ISearchOperator[] $arguments |
|
| 38 | - */ |
|
| 39 | - public function __construct($type, array $arguments) { |
|
| 40 | - $this->type = $type; |
|
| 41 | - $this->arguments = $arguments; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * SearchBinaryOperator constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $type |
|
| 37 | + * @param ISearchOperator[] $arguments |
|
| 38 | + */ |
|
| 39 | + public function __construct($type, array $arguments) { |
|
| 40 | + $this->type = $type; |
|
| 41 | + $this->arguments = $arguments; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getType() { |
|
| 48 | - return $this->type; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getType() { |
|
| 48 | + return $this->type; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return ISearchOperator[] |
|
| 53 | - */ |
|
| 54 | - public function getArguments() { |
|
| 55 | - return $this->arguments; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return ISearchOperator[] |
|
| 53 | + */ |
|
| 54 | + public function getArguments() { |
|
| 55 | + return $this->arguments; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -34,284 +34,284 @@ |
||
| 34 | 34 | * Jail to a subdirectory of the wrapped cache |
| 35 | 35 | */ |
| 36 | 36 | class CacheJail extends CacheWrapper { |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - protected $root; |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + protected $root; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | - * @param string $root |
|
| 45 | - */ |
|
| 46 | - public function __construct($cache, $root) { |
|
| 47 | - parent::__construct($cache); |
|
| 48 | - $this->root = $root; |
|
| 49 | - } |
|
| 42 | + /** |
|
| 43 | + * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | + * @param string $root |
|
| 45 | + */ |
|
| 46 | + public function __construct($cache, $root) { |
|
| 47 | + parent::__construct($cache); |
|
| 48 | + $this->root = $root; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - protected function getSourcePath($path) { |
|
| 52 | - if ($path === '') { |
|
| 53 | - return $this->root; |
|
| 54 | - } else { |
|
| 55 | - return $this->root . '/' . ltrim($path, '/'); |
|
| 56 | - } |
|
| 57 | - } |
|
| 51 | + protected function getSourcePath($path) { |
|
| 52 | + if ($path === '') { |
|
| 53 | + return $this->root; |
|
| 54 | + } else { |
|
| 55 | + return $this->root . '/' . ltrim($path, '/'); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param string $path |
|
| 61 | - * @return null|string the jailed path or null if the path is outside the jail |
|
| 62 | - */ |
|
| 63 | - protected function getJailedPath($path) { |
|
| 64 | - if ($this->root === '') { |
|
| 65 | - return $path; |
|
| 66 | - } |
|
| 67 | - $rootLength = strlen($this->root) + 1; |
|
| 68 | - if ($path === $this->root) { |
|
| 69 | - return ''; |
|
| 70 | - } else if (substr($path, 0, $rootLength) === $this->root . '/') { |
|
| 71 | - return substr($path, $rootLength); |
|
| 72 | - } else { |
|
| 73 | - return null; |
|
| 74 | - } |
|
| 75 | - } |
|
| 59 | + /** |
|
| 60 | + * @param string $path |
|
| 61 | + * @return null|string the jailed path or null if the path is outside the jail |
|
| 62 | + */ |
|
| 63 | + protected function getJailedPath($path) { |
|
| 64 | + if ($this->root === '') { |
|
| 65 | + return $path; |
|
| 66 | + } |
|
| 67 | + $rootLength = strlen($this->root) + 1; |
|
| 68 | + if ($path === $this->root) { |
|
| 69 | + return ''; |
|
| 70 | + } else if (substr($path, 0, $rootLength) === $this->root . '/') { |
|
| 71 | + return substr($path, $rootLength); |
|
| 72 | + } else { |
|
| 73 | + return null; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param ICacheEntry|array $entry |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - protected function formatCacheEntry($entry) { |
|
| 82 | - if (isset($entry['path'])) { |
|
| 83 | - $entry['path'] = $this->getJailedPath($entry['path']); |
|
| 84 | - } |
|
| 85 | - return $entry; |
|
| 86 | - } |
|
| 77 | + /** |
|
| 78 | + * @param ICacheEntry|array $entry |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + protected function formatCacheEntry($entry) { |
|
| 82 | + if (isset($entry['path'])) { |
|
| 83 | + $entry['path'] = $this->getJailedPath($entry['path']); |
|
| 84 | + } |
|
| 85 | + return $entry; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - protected function filterCacheEntry($entry) { |
|
| 89 | - $rootLength = strlen($this->root) + 1; |
|
| 90 | - return ($entry['path'] === $this->root) or (substr($entry['path'], 0, $rootLength) === $this->root . '/'); |
|
| 91 | - } |
|
| 88 | + protected function filterCacheEntry($entry) { |
|
| 89 | + $rootLength = strlen($this->root) + 1; |
|
| 90 | + return ($entry['path'] === $this->root) or (substr($entry['path'], 0, $rootLength) === $this->root . '/'); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * get the stored metadata of a file or folder |
|
| 95 | - * |
|
| 96 | - * @param string /int $file |
|
| 97 | - * @return array|false |
|
| 98 | - */ |
|
| 99 | - public function get($file) { |
|
| 100 | - if (is_string($file) or $file == '') { |
|
| 101 | - $file = $this->getSourcePath($file); |
|
| 102 | - } |
|
| 103 | - return parent::get($file); |
|
| 104 | - } |
|
| 93 | + /** |
|
| 94 | + * get the stored metadata of a file or folder |
|
| 95 | + * |
|
| 96 | + * @param string /int $file |
|
| 97 | + * @return array|false |
|
| 98 | + */ |
|
| 99 | + public function get($file) { |
|
| 100 | + if (is_string($file) or $file == '') { |
|
| 101 | + $file = $this->getSourcePath($file); |
|
| 102 | + } |
|
| 103 | + return parent::get($file); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * insert meta data for a new file or folder |
|
| 108 | - * |
|
| 109 | - * @param string $file |
|
| 110 | - * @param array $data |
|
| 111 | - * |
|
| 112 | - * @return int file id |
|
| 113 | - * @throws \RuntimeException |
|
| 114 | - */ |
|
| 115 | - public function insert($file, array $data) { |
|
| 116 | - return $this->getCache()->insert($this->getSourcePath($file), $data); |
|
| 117 | - } |
|
| 106 | + /** |
|
| 107 | + * insert meta data for a new file or folder |
|
| 108 | + * |
|
| 109 | + * @param string $file |
|
| 110 | + * @param array $data |
|
| 111 | + * |
|
| 112 | + * @return int file id |
|
| 113 | + * @throws \RuntimeException |
|
| 114 | + */ |
|
| 115 | + public function insert($file, array $data) { |
|
| 116 | + return $this->getCache()->insert($this->getSourcePath($file), $data); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * update the metadata in the cache |
|
| 121 | - * |
|
| 122 | - * @param int $id |
|
| 123 | - * @param array $data |
|
| 124 | - */ |
|
| 125 | - public function update($id, array $data) { |
|
| 126 | - $this->getCache()->update($id, $data); |
|
| 127 | - } |
|
| 119 | + /** |
|
| 120 | + * update the metadata in the cache |
|
| 121 | + * |
|
| 122 | + * @param int $id |
|
| 123 | + * @param array $data |
|
| 124 | + */ |
|
| 125 | + public function update($id, array $data) { |
|
| 126 | + $this->getCache()->update($id, $data); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * get the file id for a file |
|
| 131 | - * |
|
| 132 | - * @param string $file |
|
| 133 | - * @return int |
|
| 134 | - */ |
|
| 135 | - public function getId($file) { |
|
| 136 | - return $this->getCache()->getId($this->getSourcePath($file)); |
|
| 137 | - } |
|
| 129 | + /** |
|
| 130 | + * get the file id for a file |
|
| 131 | + * |
|
| 132 | + * @param string $file |
|
| 133 | + * @return int |
|
| 134 | + */ |
|
| 135 | + public function getId($file) { |
|
| 136 | + return $this->getCache()->getId($this->getSourcePath($file)); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * get the id of the parent folder of a file |
|
| 141 | - * |
|
| 142 | - * @param string $file |
|
| 143 | - * @return int |
|
| 144 | - */ |
|
| 145 | - public function getParentId($file) { |
|
| 146 | - return $this->getCache()->getParentId($this->getSourcePath($file)); |
|
| 147 | - } |
|
| 139 | + /** |
|
| 140 | + * get the id of the parent folder of a file |
|
| 141 | + * |
|
| 142 | + * @param string $file |
|
| 143 | + * @return int |
|
| 144 | + */ |
|
| 145 | + public function getParentId($file) { |
|
| 146 | + return $this->getCache()->getParentId($this->getSourcePath($file)); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * check if a file is available in the cache |
|
| 151 | - * |
|
| 152 | - * @param string $file |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - public function inCache($file) { |
|
| 156 | - return $this->getCache()->inCache($this->getSourcePath($file)); |
|
| 157 | - } |
|
| 149 | + /** |
|
| 150 | + * check if a file is available in the cache |
|
| 151 | + * |
|
| 152 | + * @param string $file |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + public function inCache($file) { |
|
| 156 | + return $this->getCache()->inCache($this->getSourcePath($file)); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * remove a file or folder from the cache |
|
| 161 | - * |
|
| 162 | - * @param string $file |
|
| 163 | - */ |
|
| 164 | - public function remove($file) { |
|
| 165 | - $this->getCache()->remove($this->getSourcePath($file)); |
|
| 166 | - } |
|
| 159 | + /** |
|
| 160 | + * remove a file or folder from the cache |
|
| 161 | + * |
|
| 162 | + * @param string $file |
|
| 163 | + */ |
|
| 164 | + public function remove($file) { |
|
| 165 | + $this->getCache()->remove($this->getSourcePath($file)); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Move a file or folder in the cache |
|
| 170 | - * |
|
| 171 | - * @param string $source |
|
| 172 | - * @param string $target |
|
| 173 | - */ |
|
| 174 | - public function move($source, $target) { |
|
| 175 | - $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target)); |
|
| 176 | - } |
|
| 168 | + /** |
|
| 169 | + * Move a file or folder in the cache |
|
| 170 | + * |
|
| 171 | + * @param string $source |
|
| 172 | + * @param string $target |
|
| 173 | + */ |
|
| 174 | + public function move($source, $target) { |
|
| 175 | + $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target)); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * remove all entries for files that are stored on the storage from the cache |
|
| 180 | - */ |
|
| 181 | - public function clear() { |
|
| 182 | - $this->getCache()->remove($this->root); |
|
| 183 | - } |
|
| 178 | + /** |
|
| 179 | + * remove all entries for files that are stored on the storage from the cache |
|
| 180 | + */ |
|
| 181 | + public function clear() { |
|
| 182 | + $this->getCache()->remove($this->root); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * @param string $file |
|
| 187 | - * |
|
| 188 | - * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 189 | - */ |
|
| 190 | - public function getStatus($file) { |
|
| 191 | - return $this->getCache()->getStatus($this->getSourcePath($file)); |
|
| 192 | - } |
|
| 185 | + /** |
|
| 186 | + * @param string $file |
|
| 187 | + * |
|
| 188 | + * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 189 | + */ |
|
| 190 | + public function getStatus($file) { |
|
| 191 | + return $this->getCache()->getStatus($this->getSourcePath($file)); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - private function formatSearchResults($results) { |
|
| 195 | - $results = array_filter($results, array($this, 'filterCacheEntry')); |
|
| 196 | - $results = array_values($results); |
|
| 197 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 198 | - } |
|
| 194 | + private function formatSearchResults($results) { |
|
| 195 | + $results = array_filter($results, array($this, 'filterCacheEntry')); |
|
| 196 | + $results = array_values($results); |
|
| 197 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * search for files matching $pattern |
|
| 202 | - * |
|
| 203 | - * @param string $pattern |
|
| 204 | - * @return array an array of file data |
|
| 205 | - */ |
|
| 206 | - public function search($pattern) { |
|
| 207 | - $results = $this->getCache()->search($pattern); |
|
| 208 | - return $this->formatSearchResults($results); |
|
| 209 | - } |
|
| 200 | + /** |
|
| 201 | + * search for files matching $pattern |
|
| 202 | + * |
|
| 203 | + * @param string $pattern |
|
| 204 | + * @return array an array of file data |
|
| 205 | + */ |
|
| 206 | + public function search($pattern) { |
|
| 207 | + $results = $this->getCache()->search($pattern); |
|
| 208 | + return $this->formatSearchResults($results); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * search for files by mimetype |
|
| 213 | - * |
|
| 214 | - * @param string $mimetype |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function searchByMime($mimetype) { |
|
| 218 | - $results = $this->getCache()->searchByMime($mimetype); |
|
| 219 | - return $this->formatSearchResults($results); |
|
| 220 | - } |
|
| 211 | + /** |
|
| 212 | + * search for files by mimetype |
|
| 213 | + * |
|
| 214 | + * @param string $mimetype |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function searchByMime($mimetype) { |
|
| 218 | + $results = $this->getCache()->searchByMime($mimetype); |
|
| 219 | + return $this->formatSearchResults($results); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - public function searchQuery(ISearchQuery $query) { |
|
| 223 | - $results = $this->getCache()->searchQuery($query); |
|
| 224 | - return $this->formatSearchResults($results); |
|
| 225 | - } |
|
| 222 | + public function searchQuery(ISearchQuery $query) { |
|
| 223 | + $results = $this->getCache()->searchQuery($query); |
|
| 224 | + return $this->formatSearchResults($results); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * search for files by mimetype |
|
| 229 | - * |
|
| 230 | - * @param string|int $tag name or tag id |
|
| 231 | - * @param string $userId owner of the tags |
|
| 232 | - * @return array |
|
| 233 | - */ |
|
| 234 | - public function searchByTag($tag, $userId) { |
|
| 235 | - $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 236 | - return $this->formatSearchResults($results); |
|
| 237 | - } |
|
| 227 | + /** |
|
| 228 | + * search for files by mimetype |
|
| 229 | + * |
|
| 230 | + * @param string|int $tag name or tag id |
|
| 231 | + * @param string $userId owner of the tags |
|
| 232 | + * @return array |
|
| 233 | + */ |
|
| 234 | + public function searchByTag($tag, $userId) { |
|
| 235 | + $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 236 | + return $this->formatSearchResults($results); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * update the folder size and the size of all parent folders |
|
| 241 | - * |
|
| 242 | - * @param string|boolean $path |
|
| 243 | - * @param array $data (optional) meta data of the folder |
|
| 244 | - */ |
|
| 245 | - public function correctFolderSize($path, $data = null) { |
|
| 246 | - if ($this->getCache() instanceof Cache) { |
|
| 247 | - $this->getCache()->correctFolderSize($this->getSourcePath($path), $data); |
|
| 248 | - } |
|
| 249 | - } |
|
| 239 | + /** |
|
| 240 | + * update the folder size and the size of all parent folders |
|
| 241 | + * |
|
| 242 | + * @param string|boolean $path |
|
| 243 | + * @param array $data (optional) meta data of the folder |
|
| 244 | + */ |
|
| 245 | + public function correctFolderSize($path, $data = null) { |
|
| 246 | + if ($this->getCache() instanceof Cache) { |
|
| 247 | + $this->getCache()->correctFolderSize($this->getSourcePath($path), $data); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * get the size of a folder and set it in the cache |
|
| 253 | - * |
|
| 254 | - * @param string $path |
|
| 255 | - * @param array $entry (optional) meta data of the folder |
|
| 256 | - * @return int |
|
| 257 | - */ |
|
| 258 | - public function calculateFolderSize($path, $entry = null) { |
|
| 259 | - if ($this->getCache() instanceof Cache) { |
|
| 260 | - return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry); |
|
| 261 | - } else { |
|
| 262 | - return 0; |
|
| 263 | - } |
|
| 251 | + /** |
|
| 252 | + * get the size of a folder and set it in the cache |
|
| 253 | + * |
|
| 254 | + * @param string $path |
|
| 255 | + * @param array $entry (optional) meta data of the folder |
|
| 256 | + * @return int |
|
| 257 | + */ |
|
| 258 | + public function calculateFolderSize($path, $entry = null) { |
|
| 259 | + if ($this->getCache() instanceof Cache) { |
|
| 260 | + return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry); |
|
| 261 | + } else { |
|
| 262 | + return 0; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * get all file ids on the files on the storage |
|
| 269 | - * |
|
| 270 | - * @return int[] |
|
| 271 | - */ |
|
| 272 | - public function getAll() { |
|
| 273 | - // not supported |
|
| 274 | - return array(); |
|
| 275 | - } |
|
| 267 | + /** |
|
| 268 | + * get all file ids on the files on the storage |
|
| 269 | + * |
|
| 270 | + * @return int[] |
|
| 271 | + */ |
|
| 272 | + public function getAll() { |
|
| 273 | + // not supported |
|
| 274 | + return array(); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * find a folder in the cache which has not been fully scanned |
|
| 279 | - * |
|
| 280 | - * If multiply incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 281 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 282 | - * likely the folder where we stopped scanning previously |
|
| 283 | - * |
|
| 284 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 285 | - */ |
|
| 286 | - public function getIncomplete() { |
|
| 287 | - // not supported |
|
| 288 | - return false; |
|
| 289 | - } |
|
| 277 | + /** |
|
| 278 | + * find a folder in the cache which has not been fully scanned |
|
| 279 | + * |
|
| 280 | + * If multiply incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 281 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 282 | + * likely the folder where we stopped scanning previously |
|
| 283 | + * |
|
| 284 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 285 | + */ |
|
| 286 | + public function getIncomplete() { |
|
| 287 | + // not supported |
|
| 288 | + return false; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * get the path of a file on this storage by it's id |
|
| 293 | - * |
|
| 294 | - * @param int $id |
|
| 295 | - * @return string|null |
|
| 296 | - */ |
|
| 297 | - public function getPathById($id) { |
|
| 298 | - $path = $this->getCache()->getPathById($id); |
|
| 299 | - return $this->getJailedPath($path); |
|
| 300 | - } |
|
| 291 | + /** |
|
| 292 | + * get the path of a file on this storage by it's id |
|
| 293 | + * |
|
| 294 | + * @param int $id |
|
| 295 | + * @return string|null |
|
| 296 | + */ |
|
| 297 | + public function getPathById($id) { |
|
| 298 | + $path = $this->getCache()->getPathById($id); |
|
| 299 | + return $this->getJailedPath($path); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Move a file or folder in the cache |
|
| 304 | - * |
|
| 305 | - * Note that this should make sure the entries are removed from the source cache |
|
| 306 | - * |
|
| 307 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 308 | - * @param string $sourcePath |
|
| 309 | - * @param string $targetPath |
|
| 310 | - */ |
|
| 311 | - public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 312 | - if ($sourceCache === $this) { |
|
| 313 | - return $this->move($sourcePath, $targetPath); |
|
| 314 | - } |
|
| 315 | - return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath)); |
|
| 316 | - } |
|
| 302 | + /** |
|
| 303 | + * Move a file or folder in the cache |
|
| 304 | + * |
|
| 305 | + * Note that this should make sure the entries are removed from the source cache |
|
| 306 | + * |
|
| 307 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 308 | + * @param string $sourcePath |
|
| 309 | + * @param string $targetPath |
|
| 310 | + */ |
|
| 311 | + public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 312 | + if ($sourceCache === $this) { |
|
| 313 | + return $this->move($sourcePath, $targetPath); |
|
| 314 | + } |
|
| 315 | + return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath)); |
|
| 316 | + } |
|
| 317 | 317 | } |
@@ -34,296 +34,296 @@ |
||
| 34 | 34 | use OCP\Files\Search\ISearchQuery; |
| 35 | 35 | |
| 36 | 36 | class CacheWrapper extends Cache { |
| 37 | - /** |
|
| 38 | - * @var \OCP\Files\Cache\ICache |
|
| 39 | - */ |
|
| 40 | - protected $cache; |
|
| 37 | + /** |
|
| 38 | + * @var \OCP\Files\Cache\ICache |
|
| 39 | + */ |
|
| 40 | + protected $cache; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | - */ |
|
| 45 | - public function __construct($cache) { |
|
| 46 | - $this->cache = $cache; |
|
| 47 | - } |
|
| 42 | + /** |
|
| 43 | + * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | + */ |
|
| 45 | + public function __construct($cache) { |
|
| 46 | + $this->cache = $cache; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - protected function getCache() { |
|
| 50 | - return $this->cache; |
|
| 51 | - } |
|
| 49 | + protected function getCache() { |
|
| 50 | + return $this->cache; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Make it easy for wrappers to modify every returned cache entry |
|
| 55 | - * |
|
| 56 | - * @param ICacheEntry $entry |
|
| 57 | - * @return ICacheEntry |
|
| 58 | - */ |
|
| 59 | - protected function formatCacheEntry($entry) { |
|
| 60 | - return $entry; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Make it easy for wrappers to modify every returned cache entry |
|
| 55 | + * |
|
| 56 | + * @param ICacheEntry $entry |
|
| 57 | + * @return ICacheEntry |
|
| 58 | + */ |
|
| 59 | + protected function formatCacheEntry($entry) { |
|
| 60 | + return $entry; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * get the stored metadata of a file or folder |
|
| 65 | - * |
|
| 66 | - * @param string|int $file |
|
| 67 | - * @return ICacheEntry|false |
|
| 68 | - */ |
|
| 69 | - public function get($file) { |
|
| 70 | - $result = $this->getCache()->get($file); |
|
| 71 | - if ($result) { |
|
| 72 | - $result = $this->formatCacheEntry($result); |
|
| 73 | - } |
|
| 74 | - return $result; |
|
| 75 | - } |
|
| 63 | + /** |
|
| 64 | + * get the stored metadata of a file or folder |
|
| 65 | + * |
|
| 66 | + * @param string|int $file |
|
| 67 | + * @return ICacheEntry|false |
|
| 68 | + */ |
|
| 69 | + public function get($file) { |
|
| 70 | + $result = $this->getCache()->get($file); |
|
| 71 | + if ($result) { |
|
| 72 | + $result = $this->formatCacheEntry($result); |
|
| 73 | + } |
|
| 74 | + return $result; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * get the metadata of all files stored in $folder |
|
| 79 | - * |
|
| 80 | - * @param string $folder |
|
| 81 | - * @return ICacheEntry[] |
|
| 82 | - */ |
|
| 83 | - public function getFolderContents($folder) { |
|
| 84 | - // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this |
|
| 85 | - // and not the wrapped cache |
|
| 86 | - $fileId = $this->getId($folder); |
|
| 87 | - return $this->getFolderContentsById($fileId); |
|
| 88 | - } |
|
| 77 | + /** |
|
| 78 | + * get the metadata of all files stored in $folder |
|
| 79 | + * |
|
| 80 | + * @param string $folder |
|
| 81 | + * @return ICacheEntry[] |
|
| 82 | + */ |
|
| 83 | + public function getFolderContents($folder) { |
|
| 84 | + // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this |
|
| 85 | + // and not the wrapped cache |
|
| 86 | + $fileId = $this->getId($folder); |
|
| 87 | + return $this->getFolderContentsById($fileId); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * get the metadata of all files stored in $folder |
|
| 92 | - * |
|
| 93 | - * @param int $fileId the file id of the folder |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public function getFolderContentsById($fileId) { |
|
| 97 | - $results = $this->getCache()->getFolderContentsById($fileId); |
|
| 98 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 99 | - } |
|
| 90 | + /** |
|
| 91 | + * get the metadata of all files stored in $folder |
|
| 92 | + * |
|
| 93 | + * @param int $fileId the file id of the folder |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public function getFolderContentsById($fileId) { |
|
| 97 | + $results = $this->getCache()->getFolderContentsById($fileId); |
|
| 98 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * insert or update meta data for a file or folder |
|
| 103 | - * |
|
| 104 | - * @param string $file |
|
| 105 | - * @param array $data |
|
| 106 | - * |
|
| 107 | - * @return int file id |
|
| 108 | - * @throws \RuntimeException |
|
| 109 | - */ |
|
| 110 | - public function put($file, array $data) { |
|
| 111 | - if (($id = $this->getId($file)) > -1) { |
|
| 112 | - $this->update($id, $data); |
|
| 113 | - return $id; |
|
| 114 | - } else { |
|
| 115 | - return $this->insert($file, $data); |
|
| 116 | - } |
|
| 117 | - } |
|
| 101 | + /** |
|
| 102 | + * insert or update meta data for a file or folder |
|
| 103 | + * |
|
| 104 | + * @param string $file |
|
| 105 | + * @param array $data |
|
| 106 | + * |
|
| 107 | + * @return int file id |
|
| 108 | + * @throws \RuntimeException |
|
| 109 | + */ |
|
| 110 | + public function put($file, array $data) { |
|
| 111 | + if (($id = $this->getId($file)) > -1) { |
|
| 112 | + $this->update($id, $data); |
|
| 113 | + return $id; |
|
| 114 | + } else { |
|
| 115 | + return $this->insert($file, $data); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * insert meta data for a new file or folder |
|
| 121 | - * |
|
| 122 | - * @param string $file |
|
| 123 | - * @param array $data |
|
| 124 | - * |
|
| 125 | - * @return int file id |
|
| 126 | - * @throws \RuntimeException |
|
| 127 | - */ |
|
| 128 | - public function insert($file, array $data) { |
|
| 129 | - return $this->getCache()->insert($file, $data); |
|
| 130 | - } |
|
| 119 | + /** |
|
| 120 | + * insert meta data for a new file or folder |
|
| 121 | + * |
|
| 122 | + * @param string $file |
|
| 123 | + * @param array $data |
|
| 124 | + * |
|
| 125 | + * @return int file id |
|
| 126 | + * @throws \RuntimeException |
|
| 127 | + */ |
|
| 128 | + public function insert($file, array $data) { |
|
| 129 | + return $this->getCache()->insert($file, $data); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * update the metadata in the cache |
|
| 134 | - * |
|
| 135 | - * @param int $id |
|
| 136 | - * @param array $data |
|
| 137 | - */ |
|
| 138 | - public function update($id, array $data) { |
|
| 139 | - $this->getCache()->update($id, $data); |
|
| 140 | - } |
|
| 132 | + /** |
|
| 133 | + * update the metadata in the cache |
|
| 134 | + * |
|
| 135 | + * @param int $id |
|
| 136 | + * @param array $data |
|
| 137 | + */ |
|
| 138 | + public function update($id, array $data) { |
|
| 139 | + $this->getCache()->update($id, $data); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * get the file id for a file |
|
| 144 | - * |
|
| 145 | - * @param string $file |
|
| 146 | - * @return int |
|
| 147 | - */ |
|
| 148 | - public function getId($file) { |
|
| 149 | - return $this->getCache()->getId($file); |
|
| 150 | - } |
|
| 142 | + /** |
|
| 143 | + * get the file id for a file |
|
| 144 | + * |
|
| 145 | + * @param string $file |
|
| 146 | + * @return int |
|
| 147 | + */ |
|
| 148 | + public function getId($file) { |
|
| 149 | + return $this->getCache()->getId($file); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * get the id of the parent folder of a file |
|
| 154 | - * |
|
| 155 | - * @param string $file |
|
| 156 | - * @return int |
|
| 157 | - */ |
|
| 158 | - public function getParentId($file) { |
|
| 159 | - return $this->getCache()->getParentId($file); |
|
| 160 | - } |
|
| 152 | + /** |
|
| 153 | + * get the id of the parent folder of a file |
|
| 154 | + * |
|
| 155 | + * @param string $file |
|
| 156 | + * @return int |
|
| 157 | + */ |
|
| 158 | + public function getParentId($file) { |
|
| 159 | + return $this->getCache()->getParentId($file); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * check if a file is available in the cache |
|
| 164 | - * |
|
| 165 | - * @param string $file |
|
| 166 | - * @return bool |
|
| 167 | - */ |
|
| 168 | - public function inCache($file) { |
|
| 169 | - return $this->getCache()->inCache($file); |
|
| 170 | - } |
|
| 162 | + /** |
|
| 163 | + * check if a file is available in the cache |
|
| 164 | + * |
|
| 165 | + * @param string $file |
|
| 166 | + * @return bool |
|
| 167 | + */ |
|
| 168 | + public function inCache($file) { |
|
| 169 | + return $this->getCache()->inCache($file); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * remove a file or folder from the cache |
|
| 174 | - * |
|
| 175 | - * @param string $file |
|
| 176 | - */ |
|
| 177 | - public function remove($file) { |
|
| 178 | - $this->getCache()->remove($file); |
|
| 179 | - } |
|
| 172 | + /** |
|
| 173 | + * remove a file or folder from the cache |
|
| 174 | + * |
|
| 175 | + * @param string $file |
|
| 176 | + */ |
|
| 177 | + public function remove($file) { |
|
| 178 | + $this->getCache()->remove($file); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Move a file or folder in the cache |
|
| 183 | - * |
|
| 184 | - * @param string $source |
|
| 185 | - * @param string $target |
|
| 186 | - */ |
|
| 187 | - public function move($source, $target) { |
|
| 188 | - $this->getCache()->move($source, $target); |
|
| 189 | - } |
|
| 181 | + /** |
|
| 182 | + * Move a file or folder in the cache |
|
| 183 | + * |
|
| 184 | + * @param string $source |
|
| 185 | + * @param string $target |
|
| 186 | + */ |
|
| 187 | + public function move($source, $target) { |
|
| 188 | + $this->getCache()->move($source, $target); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 192 | - $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
| 193 | - } |
|
| 191 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 192 | + $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * remove all entries for files that are stored on the storage from the cache |
|
| 197 | - */ |
|
| 198 | - public function clear() { |
|
| 199 | - $this->getCache()->clear(); |
|
| 200 | - } |
|
| 195 | + /** |
|
| 196 | + * remove all entries for files that are stored on the storage from the cache |
|
| 197 | + */ |
|
| 198 | + public function clear() { |
|
| 199 | + $this->getCache()->clear(); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * @param string $file |
|
| 204 | - * |
|
| 205 | - * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 206 | - */ |
|
| 207 | - public function getStatus($file) { |
|
| 208 | - return $this->getCache()->getStatus($file); |
|
| 209 | - } |
|
| 202 | + /** |
|
| 203 | + * @param string $file |
|
| 204 | + * |
|
| 205 | + * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 206 | + */ |
|
| 207 | + public function getStatus($file) { |
|
| 208 | + return $this->getCache()->getStatus($file); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * search for files matching $pattern |
|
| 213 | - * |
|
| 214 | - * @param string $pattern |
|
| 215 | - * @return ICacheEntry[] an array of file data |
|
| 216 | - */ |
|
| 217 | - public function search($pattern) { |
|
| 218 | - $results = $this->getCache()->search($pattern); |
|
| 219 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 220 | - } |
|
| 211 | + /** |
|
| 212 | + * search for files matching $pattern |
|
| 213 | + * |
|
| 214 | + * @param string $pattern |
|
| 215 | + * @return ICacheEntry[] an array of file data |
|
| 216 | + */ |
|
| 217 | + public function search($pattern) { |
|
| 218 | + $results = $this->getCache()->search($pattern); |
|
| 219 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * search for files by mimetype |
|
| 224 | - * |
|
| 225 | - * @param string $mimetype |
|
| 226 | - * @return ICacheEntry[] |
|
| 227 | - */ |
|
| 228 | - public function searchByMime($mimetype) { |
|
| 229 | - $results = $this->getCache()->searchByMime($mimetype); |
|
| 230 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 231 | - } |
|
| 222 | + /** |
|
| 223 | + * search for files by mimetype |
|
| 224 | + * |
|
| 225 | + * @param string $mimetype |
|
| 226 | + * @return ICacheEntry[] |
|
| 227 | + */ |
|
| 228 | + public function searchByMime($mimetype) { |
|
| 229 | + $results = $this->getCache()->searchByMime($mimetype); |
|
| 230 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - public function searchQuery(ISearchQuery $query) { |
|
| 234 | - $results = $this->getCache()->searchQuery($query); |
|
| 235 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 236 | - } |
|
| 233 | + public function searchQuery(ISearchQuery $query) { |
|
| 234 | + $results = $this->getCache()->searchQuery($query); |
|
| 235 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * search for files by tag |
|
| 240 | - * |
|
| 241 | - * @param string|int $tag name or tag id |
|
| 242 | - * @param string $userId owner of the tags |
|
| 243 | - * @return ICacheEntry[] file data |
|
| 244 | - */ |
|
| 245 | - public function searchByTag($tag, $userId) { |
|
| 246 | - $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 247 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 248 | - } |
|
| 238 | + /** |
|
| 239 | + * search for files by tag |
|
| 240 | + * |
|
| 241 | + * @param string|int $tag name or tag id |
|
| 242 | + * @param string $userId owner of the tags |
|
| 243 | + * @return ICacheEntry[] file data |
|
| 244 | + */ |
|
| 245 | + public function searchByTag($tag, $userId) { |
|
| 246 | + $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 247 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * update the folder size and the size of all parent folders |
|
| 252 | - * |
|
| 253 | - * @param string|boolean $path |
|
| 254 | - * @param array $data (optional) meta data of the folder |
|
| 255 | - */ |
|
| 256 | - public function correctFolderSize($path, $data = null) { |
|
| 257 | - if ($this->getCache() instanceof Cache) { |
|
| 258 | - $this->getCache()->correctFolderSize($path, $data); |
|
| 259 | - } |
|
| 260 | - } |
|
| 250 | + /** |
|
| 251 | + * update the folder size and the size of all parent folders |
|
| 252 | + * |
|
| 253 | + * @param string|boolean $path |
|
| 254 | + * @param array $data (optional) meta data of the folder |
|
| 255 | + */ |
|
| 256 | + public function correctFolderSize($path, $data = null) { |
|
| 257 | + if ($this->getCache() instanceof Cache) { |
|
| 258 | + $this->getCache()->correctFolderSize($path, $data); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * get the size of a folder and set it in the cache |
|
| 264 | - * |
|
| 265 | - * @param string $path |
|
| 266 | - * @param array $entry (optional) meta data of the folder |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function calculateFolderSize($path, $entry = null) { |
|
| 270 | - if ($this->getCache() instanceof Cache) { |
|
| 271 | - return $this->getCache()->calculateFolderSize($path, $entry); |
|
| 272 | - } else { |
|
| 273 | - return 0; |
|
| 274 | - } |
|
| 275 | - } |
|
| 262 | + /** |
|
| 263 | + * get the size of a folder and set it in the cache |
|
| 264 | + * |
|
| 265 | + * @param string $path |
|
| 266 | + * @param array $entry (optional) meta data of the folder |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function calculateFolderSize($path, $entry = null) { |
|
| 270 | + if ($this->getCache() instanceof Cache) { |
|
| 271 | + return $this->getCache()->calculateFolderSize($path, $entry); |
|
| 272 | + } else { |
|
| 273 | + return 0; |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * get all file ids on the files on the storage |
|
| 279 | - * |
|
| 280 | - * @return int[] |
|
| 281 | - */ |
|
| 282 | - public function getAll() { |
|
| 283 | - return $this->getCache()->getAll(); |
|
| 284 | - } |
|
| 277 | + /** |
|
| 278 | + * get all file ids on the files on the storage |
|
| 279 | + * |
|
| 280 | + * @return int[] |
|
| 281 | + */ |
|
| 282 | + public function getAll() { |
|
| 283 | + return $this->getCache()->getAll(); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * find a folder in the cache which has not been fully scanned |
|
| 288 | - * |
|
| 289 | - * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 290 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 291 | - * likely the folder where we stopped scanning previously |
|
| 292 | - * |
|
| 293 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 294 | - */ |
|
| 295 | - public function getIncomplete() { |
|
| 296 | - return $this->getCache()->getIncomplete(); |
|
| 297 | - } |
|
| 286 | + /** |
|
| 287 | + * find a folder in the cache which has not been fully scanned |
|
| 288 | + * |
|
| 289 | + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 290 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 291 | + * likely the folder where we stopped scanning previously |
|
| 292 | + * |
|
| 293 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 294 | + */ |
|
| 295 | + public function getIncomplete() { |
|
| 296 | + return $this->getCache()->getIncomplete(); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * get the path of a file on this storage by it's id |
|
| 301 | - * |
|
| 302 | - * @param int $id |
|
| 303 | - * @return string|null |
|
| 304 | - */ |
|
| 305 | - public function getPathById($id) { |
|
| 306 | - return $this->getCache()->getPathById($id); |
|
| 307 | - } |
|
| 299 | + /** |
|
| 300 | + * get the path of a file on this storage by it's id |
|
| 301 | + * |
|
| 302 | + * @param int $id |
|
| 303 | + * @return string|null |
|
| 304 | + */ |
|
| 305 | + public function getPathById($id) { |
|
| 306 | + return $this->getCache()->getPathById($id); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Returns the numeric storage id |
|
| 311 | - * |
|
| 312 | - * @return int |
|
| 313 | - */ |
|
| 314 | - public function getNumericStorageId() { |
|
| 315 | - return $this->getCache()->getNumericStorageId(); |
|
| 316 | - } |
|
| 309 | + /** |
|
| 310 | + * Returns the numeric storage id |
|
| 311 | + * |
|
| 312 | + * @return int |
|
| 313 | + */ |
|
| 314 | + public function getNumericStorageId() { |
|
| 315 | + return $this->getCache()->getNumericStorageId(); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * get the storage id of the storage for a file and the internal path of the file |
|
| 320 | - * unlike getPathById this does not limit the search to files on this storage and |
|
| 321 | - * instead does a global search in the cache table |
|
| 322 | - * |
|
| 323 | - * @param int $id |
|
| 324 | - * @return array first element holding the storage id, second the path |
|
| 325 | - */ |
|
| 326 | - static public function getById($id) { |
|
| 327 | - return parent::getById($id); |
|
| 328 | - } |
|
| 318 | + /** |
|
| 319 | + * get the storage id of the storage for a file and the internal path of the file |
|
| 320 | + * unlike getPathById this does not limit the search to files on this storage and |
|
| 321 | + * instead does a global search in the cache table |
|
| 322 | + * |
|
| 323 | + * @param int $id |
|
| 324 | + * @return array first element holding the storage id, second the path |
|
| 325 | + */ |
|
| 326 | + static public function getById($id) { |
|
| 327 | + return parent::getById($id); |
|
| 328 | + } |
|
| 329 | 329 | } |
@@ -31,130 +31,130 @@ |
||
| 31 | 31 | * Tools for transforming search queries into database queries |
| 32 | 32 | */ |
| 33 | 33 | class QuerySearchHelper { |
| 34 | - static protected $searchOperatorMap = [ |
|
| 35 | - ISearchComparison::COMPARE_LIKE => 'iLike', |
|
| 36 | - ISearchComparison::COMPARE_EQUAL => 'eq', |
|
| 37 | - ISearchComparison::COMPARE_GREATER_THAN => 'gt', |
|
| 38 | - ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'gte', |
|
| 39 | - ISearchComparison::COMPARE_LESS_THAN => 'lt', |
|
| 40 | - ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lte' |
|
| 41 | - ]; |
|
| 34 | + static protected $searchOperatorMap = [ |
|
| 35 | + ISearchComparison::COMPARE_LIKE => 'iLike', |
|
| 36 | + ISearchComparison::COMPARE_EQUAL => 'eq', |
|
| 37 | + ISearchComparison::COMPARE_GREATER_THAN => 'gt', |
|
| 38 | + ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'gte', |
|
| 39 | + ISearchComparison::COMPARE_LESS_THAN => 'lt', |
|
| 40 | + ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lte' |
|
| 41 | + ]; |
|
| 42 | 42 | |
| 43 | - static protected $searchOperatorNegativeMap = [ |
|
| 44 | - ISearchComparison::COMPARE_LIKE => 'notLike', |
|
| 45 | - ISearchComparison::COMPARE_EQUAL => 'neq', |
|
| 46 | - ISearchComparison::COMPARE_GREATER_THAN => 'lte', |
|
| 47 | - ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'lt', |
|
| 48 | - ISearchComparison::COMPARE_LESS_THAN => 'gte', |
|
| 49 | - ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lt' |
|
| 50 | - ]; |
|
| 43 | + static protected $searchOperatorNegativeMap = [ |
|
| 44 | + ISearchComparison::COMPARE_LIKE => 'notLike', |
|
| 45 | + ISearchComparison::COMPARE_EQUAL => 'neq', |
|
| 46 | + ISearchComparison::COMPARE_GREATER_THAN => 'lte', |
|
| 47 | + ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'lt', |
|
| 48 | + ISearchComparison::COMPARE_LESS_THAN => 'gte', |
|
| 49 | + ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lt' |
|
| 50 | + ]; |
|
| 51 | 51 | |
| 52 | - /** @var IMimeTypeLoader */ |
|
| 53 | - private $mimetypeLoader; |
|
| 52 | + /** @var IMimeTypeLoader */ |
|
| 53 | + private $mimetypeLoader; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * QuerySearchUtil constructor. |
|
| 57 | - * |
|
| 58 | - * @param IMimeTypeLoader $mimetypeLoader |
|
| 59 | - */ |
|
| 60 | - public function __construct(IMimeTypeLoader $mimetypeLoader) { |
|
| 61 | - $this->mimetypeLoader = $mimetypeLoader; |
|
| 62 | - } |
|
| 55 | + /** |
|
| 56 | + * QuerySearchUtil constructor. |
|
| 57 | + * |
|
| 58 | + * @param IMimeTypeLoader $mimetypeLoader |
|
| 59 | + */ |
|
| 60 | + public function __construct(IMimeTypeLoader $mimetypeLoader) { |
|
| 61 | + $this->mimetypeLoader = $mimetypeLoader; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function searchOperatorToDBExpr(IQueryBuilder $builder, ISearchOperator $operator) { |
|
| 65 | - $expr = $builder->expr(); |
|
| 66 | - if ($operator instanceof ISearchBinaryOperator) { |
|
| 67 | - switch ($operator->getType()) { |
|
| 68 | - case ISearchBinaryOperator::OPERATOR_NOT: |
|
| 69 | - $negativeOperator = $operator->getArguments()[0]; |
|
| 70 | - if ($negativeOperator instanceof ISearchComparison) { |
|
| 71 | - return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::$searchOperatorNegativeMap); |
|
| 72 | - } else { |
|
| 73 | - throw new \InvalidArgumentException('Binary operators inside "not" is not supported'); |
|
| 74 | - } |
|
| 75 | - case ISearchBinaryOperator::OPERATOR_AND: |
|
| 76 | - return $expr->andX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 77 | - case ISearchBinaryOperator::OPERATOR_OR: |
|
| 78 | - return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 79 | - default: |
|
| 80 | - throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
| 81 | - } |
|
| 82 | - } else if ($operator instanceof ISearchComparison) { |
|
| 83 | - return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
|
| 84 | - } else { |
|
| 85 | - throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
| 86 | - } |
|
| 87 | - } |
|
| 64 | + public function searchOperatorToDBExpr(IQueryBuilder $builder, ISearchOperator $operator) { |
|
| 65 | + $expr = $builder->expr(); |
|
| 66 | + if ($operator instanceof ISearchBinaryOperator) { |
|
| 67 | + switch ($operator->getType()) { |
|
| 68 | + case ISearchBinaryOperator::OPERATOR_NOT: |
|
| 69 | + $negativeOperator = $operator->getArguments()[0]; |
|
| 70 | + if ($negativeOperator instanceof ISearchComparison) { |
|
| 71 | + return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::$searchOperatorNegativeMap); |
|
| 72 | + } else { |
|
| 73 | + throw new \InvalidArgumentException('Binary operators inside "not" is not supported'); |
|
| 74 | + } |
|
| 75 | + case ISearchBinaryOperator::OPERATOR_AND: |
|
| 76 | + return $expr->andX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 77 | + case ISearchBinaryOperator::OPERATOR_OR: |
|
| 78 | + return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 79 | + default: |
|
| 80 | + throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
| 81 | + } |
|
| 82 | + } else if ($operator instanceof ISearchComparison) { |
|
| 83 | + return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
|
| 84 | + } else { |
|
| 85 | + throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - private function searchComparisonToDBExpr(IQueryBuilder $builder, ISearchComparison $comparison, array $operatorMap) { |
|
| 90 | - $this->validateComparison($comparison); |
|
| 89 | + private function searchComparisonToDBExpr(IQueryBuilder $builder, ISearchComparison $comparison, array $operatorMap) { |
|
| 90 | + $this->validateComparison($comparison); |
|
| 91 | 91 | |
| 92 | - list($field, $value, $type) = $this->getOperatorFieldAndValue($comparison); |
|
| 93 | - if (isset($operatorMap[$type])) { |
|
| 94 | - $queryOperator = $operatorMap[$type]; |
|
| 95 | - return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
|
| 96 | - } else { |
|
| 97 | - throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
| 98 | - } |
|
| 99 | - } |
|
| 92 | + list($field, $value, $type) = $this->getOperatorFieldAndValue($comparison); |
|
| 93 | + if (isset($operatorMap[$type])) { |
|
| 94 | + $queryOperator = $operatorMap[$type]; |
|
| 95 | + return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
|
| 96 | + } else { |
|
| 97 | + throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - private function getOperatorFieldAndValue(ISearchComparison $operator) { |
|
| 102 | - $field = $operator->getField(); |
|
| 103 | - $value = $operator->getValue(); |
|
| 104 | - $type = $operator->getType(); |
|
| 105 | - if ($field === 'mimetype') { |
|
| 106 | - if ($operator->getType() === ISearchComparison::COMPARE_EQUAL) { |
|
| 107 | - $value = $this->mimetypeLoader->getId($value); |
|
| 108 | - } else if ($operator->getType() === ISearchComparison::COMPARE_LIKE) { |
|
| 109 | - // transform "mimetype='foo/%'" to "mimepart='foo'" |
|
| 110 | - if (preg_match('|(.+)/%|', $value, $matches)) { |
|
| 111 | - $field = 'mimepart'; |
|
| 112 | - $value = $this->mimetypeLoader->getId($matches[1]); |
|
| 113 | - $type = ISearchComparison::COMPARE_EQUAL; |
|
| 114 | - } |
|
| 115 | - if (strpos($value, '%') !== false) { |
|
| 116 | - throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - return [$field, $value, $type]; |
|
| 121 | - } |
|
| 101 | + private function getOperatorFieldAndValue(ISearchComparison $operator) { |
|
| 102 | + $field = $operator->getField(); |
|
| 103 | + $value = $operator->getValue(); |
|
| 104 | + $type = $operator->getType(); |
|
| 105 | + if ($field === 'mimetype') { |
|
| 106 | + if ($operator->getType() === ISearchComparison::COMPARE_EQUAL) { |
|
| 107 | + $value = $this->mimetypeLoader->getId($value); |
|
| 108 | + } else if ($operator->getType() === ISearchComparison::COMPARE_LIKE) { |
|
| 109 | + // transform "mimetype='foo/%'" to "mimepart='foo'" |
|
| 110 | + if (preg_match('|(.+)/%|', $value, $matches)) { |
|
| 111 | + $field = 'mimepart'; |
|
| 112 | + $value = $this->mimetypeLoader->getId($matches[1]); |
|
| 113 | + $type = ISearchComparison::COMPARE_EQUAL; |
|
| 114 | + } |
|
| 115 | + if (strpos($value, '%') !== false) { |
|
| 116 | + throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + return [$field, $value, $type]; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - private function validateComparison(ISearchComparison $operator) { |
|
| 124 | - $types = [ |
|
| 125 | - 'mimetype' => 'string', |
|
| 126 | - 'mtime' => 'integer', |
|
| 127 | - 'name' => 'string', |
|
| 128 | - 'size' => 'integer' |
|
| 129 | - ]; |
|
| 130 | - $comparisons = [ |
|
| 131 | - 'mimetype' => ['eq', 'like'], |
|
| 132 | - 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
| 133 | - 'name' => ['eq', 'like'], |
|
| 134 | - 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'] |
|
| 135 | - ]; |
|
| 123 | + private function validateComparison(ISearchComparison $operator) { |
|
| 124 | + $types = [ |
|
| 125 | + 'mimetype' => 'string', |
|
| 126 | + 'mtime' => 'integer', |
|
| 127 | + 'name' => 'string', |
|
| 128 | + 'size' => 'integer' |
|
| 129 | + ]; |
|
| 130 | + $comparisons = [ |
|
| 131 | + 'mimetype' => ['eq', 'like'], |
|
| 132 | + 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
| 133 | + 'name' => ['eq', 'like'], |
|
| 134 | + 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'] |
|
| 135 | + ]; |
|
| 136 | 136 | |
| 137 | - if (!isset($types[$operator->getField()])) { |
|
| 138 | - throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
| 139 | - } |
|
| 140 | - $type = $types[$operator->getField()]; |
|
| 141 | - if (gettype($operator->getValue()) !== $type) { |
|
| 142 | - throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
| 143 | - } |
|
| 144 | - if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
|
| 145 | - throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
| 146 | - } |
|
| 147 | - } |
|
| 137 | + if (!isset($types[$operator->getField()])) { |
|
| 138 | + throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
| 139 | + } |
|
| 140 | + $type = $types[$operator->getField()]; |
|
| 141 | + if (gettype($operator->getValue()) !== $type) { |
|
| 142 | + throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
| 143 | + } |
|
| 144 | + if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
|
| 145 | + throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - private function getParameterForValue(IQueryBuilder $builder, $value) { |
|
| 150 | - if ($value instanceof \DateTime) { |
|
| 151 | - $value = $value->getTimestamp(); |
|
| 152 | - } |
|
| 153 | - if (is_numeric($value)) { |
|
| 154 | - $type = IQueryBuilder::PARAM_INT; |
|
| 155 | - } else { |
|
| 156 | - $type = IQueryBuilder::PARAM_STR; |
|
| 157 | - } |
|
| 158 | - return $builder->createNamedParameter($value, $type); |
|
| 159 | - } |
|
| 149 | + private function getParameterForValue(IQueryBuilder $builder, $value) { |
|
| 150 | + if ($value instanceof \DateTime) { |
|
| 151 | + $value = $value->getTimestamp(); |
|
| 152 | + } |
|
| 153 | + if (is_numeric($value)) { |
|
| 154 | + $type = IQueryBuilder::PARAM_INT; |
|
| 155 | + } else { |
|
| 156 | + $type = IQueryBuilder::PARAM_STR; |
|
| 157 | + } |
|
| 158 | + return $builder->createNamedParameter($value, $type); |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | case ISearchBinaryOperator::OPERATOR_OR: |
| 78 | 78 | return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
| 79 | 79 | default: |
| 80 | - throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
| 80 | + throw new \InvalidArgumentException('Invalid operator type: '.$operator->getType()); |
|
| 81 | 81 | } |
| 82 | 82 | } else if ($operator instanceof ISearchComparison) { |
| 83 | 83 | return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
| 84 | 84 | } else { |
| 85 | - throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
| 85 | + throw new \InvalidArgumentException('Invalid operator type: '.get_class($operator)); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $queryOperator = $operatorMap[$type]; |
| 95 | 95 | return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
| 96 | 96 | } else { |
| 97 | - throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
| 97 | + throw new \InvalidArgumentException('Invalid operator type: '.$comparison->getType()); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $type = ISearchComparison::COMPARE_EQUAL; |
| 114 | 114 | } |
| 115 | 115 | if (strpos($value, '%') !== false) { |
| 116 | - throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 116 | + throw new \InvalidArgumentException('Unsupported query value for mimetype: '.$value.', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -135,14 +135,14 @@ discard block |
||
| 135 | 135 | ]; |
| 136 | 136 | |
| 137 | 137 | if (!isset($types[$operator->getField()])) { |
| 138 | - throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
| 138 | + throw new \InvalidArgumentException('Unsupported comparison field '.$operator->getField()); |
|
| 139 | 139 | } |
| 140 | 140 | $type = $types[$operator->getField()]; |
| 141 | 141 | if (gettype($operator->getValue()) !== $type) { |
| 142 | - throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
| 142 | + throw new \InvalidArgumentException('Invalid type for field '.$operator->getField()); |
|
| 143 | 143 | } |
| 144 | 144 | if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
| 145 | - throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
| 145 | + throw new \InvalidArgumentException('Unsupported comparison for field '.$operator->getField().': '.$operator->getType()); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -30,119 +30,119 @@ |
||
| 30 | 30 | * Storage placeholder to represent a missing precondition, storage unavailable |
| 31 | 31 | */ |
| 32 | 32 | class FailedCache implements ICache { |
| 33 | - /** @var bool whether to show the failed storage in the ui */ |
|
| 34 | - private $visible; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * FailedCache constructor. |
|
| 38 | - * |
|
| 39 | - * @param bool $visible |
|
| 40 | - */ |
|
| 41 | - public function __construct($visible = true) { |
|
| 42 | - $this->visible = $visible; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - public function getNumericStorageId() { |
|
| 47 | - return -1; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function get($file) { |
|
| 51 | - if ($file === '') { |
|
| 52 | - return new CacheEntry([ |
|
| 53 | - 'fileid' => -1, |
|
| 54 | - 'size' => 0, |
|
| 55 | - 'mimetype' => 'httpd/unix-directory', |
|
| 56 | - 'mimepart' => 'httpd', |
|
| 57 | - 'permissions' => $this->visible ? Constants::PERMISSION_READ : 0, |
|
| 58 | - 'mtime' => time() |
|
| 59 | - ]); |
|
| 60 | - } else { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getFolderContents($folder) { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function getFolderContentsById($fileId) { |
|
| 70 | - return []; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function put($file, array $data) { |
|
| 74 | - return; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function insert($file, array $data) { |
|
| 78 | - return; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function update($id, array $data) { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function getId($file) { |
|
| 86 | - return -1; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function getParentId($file) { |
|
| 90 | - return -1; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function inCache($file) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function remove($file) { |
|
| 98 | - return; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function move($source, $target) { |
|
| 102 | - return; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function clear() { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function getStatus($file) { |
|
| 114 | - return ICache::NOT_FOUND; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function search($pattern) { |
|
| 118 | - return []; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function searchByMime($mimetype) { |
|
| 122 | - return []; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function searchByTag($tag, $userId) { |
|
| 126 | - return []; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function searchQuery(ISearchQuery $query) { |
|
| 130 | - return []; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function getAll() { |
|
| 134 | - return []; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function getIncomplete() { |
|
| 138 | - return []; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function getPathById($id) { |
|
| 142 | - return null; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function normalize($path) { |
|
| 146 | - return $path; |
|
| 147 | - } |
|
| 33 | + /** @var bool whether to show the failed storage in the ui */ |
|
| 34 | + private $visible; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * FailedCache constructor. |
|
| 38 | + * |
|
| 39 | + * @param bool $visible |
|
| 40 | + */ |
|
| 41 | + public function __construct($visible = true) { |
|
| 42 | + $this->visible = $visible; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + public function getNumericStorageId() { |
|
| 47 | + return -1; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function get($file) { |
|
| 51 | + if ($file === '') { |
|
| 52 | + return new CacheEntry([ |
|
| 53 | + 'fileid' => -1, |
|
| 54 | + 'size' => 0, |
|
| 55 | + 'mimetype' => 'httpd/unix-directory', |
|
| 56 | + 'mimepart' => 'httpd', |
|
| 57 | + 'permissions' => $this->visible ? Constants::PERMISSION_READ : 0, |
|
| 58 | + 'mtime' => time() |
|
| 59 | + ]); |
|
| 60 | + } else { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getFolderContents($folder) { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function getFolderContentsById($fileId) { |
|
| 70 | + return []; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function put($file, array $data) { |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function insert($file, array $data) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function update($id, array $data) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function getId($file) { |
|
| 86 | + return -1; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function getParentId($file) { |
|
| 90 | + return -1; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function inCache($file) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function remove($file) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function move($source, $target) { |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function clear() { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function getStatus($file) { |
|
| 114 | + return ICache::NOT_FOUND; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function search($pattern) { |
|
| 118 | + return []; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function searchByMime($mimetype) { |
|
| 122 | + return []; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function searchByTag($tag, $userId) { |
|
| 126 | + return []; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function searchQuery(ISearchQuery $query) { |
|
| 130 | + return []; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function getAll() { |
|
| 134 | + return []; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function getIncomplete() { |
|
| 138 | + return []; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function getPathById($id) { |
|
| 142 | + return null; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function normalize($path) { |
|
| 146 | + return $path; |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -55,188 +55,188 @@ |
||
| 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 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 160 | - ])) { |
|
| 161 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 165 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 169 | - $this->server->on('beforeMethod', function () { |
|
| 170 | - // custom properties plugin must be the last one |
|
| 171 | - $userSession = \OC::$server->getUserSession(); |
|
| 172 | - $user = $userSession->getUser(); |
|
| 173 | - if ($user !== null) { |
|
| 174 | - $view = \OC\Files\Filesystem::getView(); |
|
| 175 | - $this->server->addPlugin( |
|
| 176 | - new FilesPlugin( |
|
| 177 | - $this->server->tree, |
|
| 178 | - \OC::$server->getConfig(), |
|
| 179 | - $this->request, |
|
| 180 | - \OC::$server->getPreviewManager(), |
|
| 181 | - false, |
|
| 182 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 183 | - ) |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - $this->server->addPlugin( |
|
| 187 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 188 | - new CustomPropertiesBackend( |
|
| 189 | - $this->server->tree, |
|
| 190 | - \OC::$server->getDatabaseConnection(), |
|
| 191 | - \OC::$server->getUserSession()->getUser() |
|
| 192 | - ) |
|
| 193 | - ) |
|
| 194 | - ); |
|
| 195 | - if ($view !== null) { |
|
| 196 | - $this->server->addPlugin( |
|
| 197 | - new QuotaPlugin($view)); |
|
| 198 | - } |
|
| 199 | - $this->server->addPlugin( |
|
| 200 | - new TagsPlugin( |
|
| 201 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 202 | - ) |
|
| 203 | - ); |
|
| 204 | - // TODO: switch to LazyUserFolder |
|
| 205 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 206 | - $this->server->addPlugin(new SharesPlugin( |
|
| 207 | - $this->server->tree, |
|
| 208 | - $userSession, |
|
| 209 | - $userFolder, |
|
| 210 | - \OC::$server->getShareManager() |
|
| 211 | - )); |
|
| 212 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 213 | - \OC::$server->getCommentsManager(), |
|
| 214 | - $userSession |
|
| 215 | - )); |
|
| 216 | - if ($view !== null) { |
|
| 217 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 218 | - $this->server->tree, |
|
| 219 | - $view, |
|
| 220 | - \OC::$server->getSystemTagManager(), |
|
| 221 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 222 | - \OC::$server->getTagManager(), |
|
| 223 | - $userSession, |
|
| 224 | - \OC::$server->getGroupManager(), |
|
| 225 | - $userFolder |
|
| 226 | - )); |
|
| 227 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 228 | - $this->server->tree, |
|
| 229 | - $user, |
|
| 230 | - \OC::$server->getRootFolder(), |
|
| 231 | - \OC::$server->getShareManager(), |
|
| 232 | - $view |
|
| 233 | - ))); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - }); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - public function exec() { |
|
| 240 | - $this->server->exec(); |
|
| 241 | - } |
|
| 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 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 160 | + ])) { |
|
| 161 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 165 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 169 | + $this->server->on('beforeMethod', function () { |
|
| 170 | + // custom properties plugin must be the last one |
|
| 171 | + $userSession = \OC::$server->getUserSession(); |
|
| 172 | + $user = $userSession->getUser(); |
|
| 173 | + if ($user !== null) { |
|
| 174 | + $view = \OC\Files\Filesystem::getView(); |
|
| 175 | + $this->server->addPlugin( |
|
| 176 | + new FilesPlugin( |
|
| 177 | + $this->server->tree, |
|
| 178 | + \OC::$server->getConfig(), |
|
| 179 | + $this->request, |
|
| 180 | + \OC::$server->getPreviewManager(), |
|
| 181 | + false, |
|
| 182 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 183 | + ) |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + $this->server->addPlugin( |
|
| 187 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 188 | + new CustomPropertiesBackend( |
|
| 189 | + $this->server->tree, |
|
| 190 | + \OC::$server->getDatabaseConnection(), |
|
| 191 | + \OC::$server->getUserSession()->getUser() |
|
| 192 | + ) |
|
| 193 | + ) |
|
| 194 | + ); |
|
| 195 | + if ($view !== null) { |
|
| 196 | + $this->server->addPlugin( |
|
| 197 | + new QuotaPlugin($view)); |
|
| 198 | + } |
|
| 199 | + $this->server->addPlugin( |
|
| 200 | + new TagsPlugin( |
|
| 201 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 202 | + ) |
|
| 203 | + ); |
|
| 204 | + // TODO: switch to LazyUserFolder |
|
| 205 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 206 | + $this->server->addPlugin(new SharesPlugin( |
|
| 207 | + $this->server->tree, |
|
| 208 | + $userSession, |
|
| 209 | + $userFolder, |
|
| 210 | + \OC::$server->getShareManager() |
|
| 211 | + )); |
|
| 212 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 213 | + \OC::$server->getCommentsManager(), |
|
| 214 | + $userSession |
|
| 215 | + )); |
|
| 216 | + if ($view !== null) { |
|
| 217 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 218 | + $this->server->tree, |
|
| 219 | + $view, |
|
| 220 | + \OC::$server->getSystemTagManager(), |
|
| 221 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 222 | + \OC::$server->getTagManager(), |
|
| 223 | + $userSession, |
|
| 224 | + \OC::$server->getGroupManager(), |
|
| 225 | + $userFolder |
|
| 226 | + )); |
|
| 227 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 228 | + $this->server->tree, |
|
| 229 | + $user, |
|
| 230 | + \OC::$server->getRootFolder(), |
|
| 231 | + \OC::$server->getShareManager(), |
|
| 232 | + $view |
|
| 233 | + ))); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + }); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + public function exec() { |
|
| 240 | + $this->server->exec(); |
|
| 241 | + } |
|
| 242 | 242 | } |