@@ -31,36 +31,36 @@ |
||
31 | 31 | */ |
32 | 32 | interface IEntry extends JsonSerializable { |
33 | 33 | |
34 | - /** |
|
35 | - * @since 12.0 |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getFullName(); |
|
34 | + /** |
|
35 | + * @since 12.0 |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getFullName(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 12.0 |
|
42 | - * @return string[] |
|
43 | - */ |
|
44 | - public function getEMailAddresses(); |
|
40 | + /** |
|
41 | + * @since 12.0 |
|
42 | + * @return string[] |
|
43 | + */ |
|
44 | + public function getEMailAddresses(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 12.0 |
|
48 | - * @return string|null image URI |
|
49 | - */ |
|
50 | - public function getAvatar(); |
|
46 | + /** |
|
47 | + * @since 12.0 |
|
48 | + * @return string|null image URI |
|
49 | + */ |
|
50 | + public function getAvatar(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @since 12.0 |
|
54 | - * @param IAction $action an action to show in the contacts menu |
|
55 | - */ |
|
56 | - public function addAction(IAction $action); |
|
52 | + /** |
|
53 | + * @since 12.0 |
|
54 | + * @param IAction $action an action to show in the contacts menu |
|
55 | + */ |
|
56 | + public function addAction(IAction $action); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get an arbitrary property from the contact |
|
60 | - * |
|
61 | - * @since 12.0 |
|
62 | - * @param string $key |
|
63 | - * @return mixed the value of the property or null |
|
64 | - */ |
|
65 | - public function getProperty($key); |
|
58 | + /** |
|
59 | + * Get an arbitrary property from the contact |
|
60 | + * |
|
61 | + * @since 12.0 |
|
62 | + * @param string $key |
|
63 | + * @return mixed the value of the property or null |
|
64 | + */ |
|
65 | + public function getProperty($key); |
|
66 | 66 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $result = array(); |
45 | 45 | $timestamp = null; |
46 | 46 | |
47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
48 | 48 | |
49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
73 | 73 | } |
74 | 74 | $originalPath = ''; |
75 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
75 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
76 | 76 | if (isset($originalLocations[$originalName][$timestamp])) { |
77 | 77 | $originalPath = $originalLocations[$originalName][$timestamp]; |
78 | 78 | if (substr($originalPath, -1) === '/') { |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | ); |
93 | 93 | if ($originalPath) { |
94 | 94 | if ($originalPath !== '.') { |
95 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
95 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
96 | 96 | } else { |
97 | 97 | $i['extraData'] = $originalName; |
98 | 98 | } |
99 | 99 | } |
100 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
100 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | if ($sortAttribute !== '') { |
@@ -33,96 +33,96 @@ |
||
33 | 33 | use OCP\Files\Cache\ICacheEntry; |
34 | 34 | |
35 | 35 | class Helper { |
36 | - /** |
|
37 | - * Retrieves the contents of a trash bin directory. |
|
38 | - * |
|
39 | - * @param string $dir path to the directory inside the trashbin |
|
40 | - * or empty to retrieve the root of the trashbin |
|
41 | - * @param string $user |
|
42 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
43 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
44 | - * @return \OCP\Files\FileInfo[] |
|
45 | - */ |
|
46 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
47 | - $result = array(); |
|
48 | - $timestamp = null; |
|
36 | + /** |
|
37 | + * Retrieves the contents of a trash bin directory. |
|
38 | + * |
|
39 | + * @param string $dir path to the directory inside the trashbin |
|
40 | + * or empty to retrieve the root of the trashbin |
|
41 | + * @param string $user |
|
42 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
43 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
44 | + * @return \OCP\Files\FileInfo[] |
|
45 | + */ |
|
46 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
47 | + $result = array(); |
|
48 | + $timestamp = null; |
|
49 | 49 | |
50 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
50 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
51 | 51 | |
52 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
53 | - throw new \Exception('Directory does not exists'); |
|
54 | - } |
|
52 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
53 | + throw new \Exception('Directory does not exists'); |
|
54 | + } |
|
55 | 55 | |
56 | - $mount = $view->getMount($dir); |
|
57 | - $storage = $mount->getStorage(); |
|
58 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
59 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
56 | + $mount = $view->getMount($dir); |
|
57 | + $storage = $mount->getStorage(); |
|
58 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
59 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
60 | 60 | |
61 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
62 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
63 | - foreach ($dirContent as $entry) { |
|
64 | - $entryName = $entry->getName(); |
|
65 | - $name = $entryName; |
|
66 | - if ($dir === '' || $dir === '/') { |
|
67 | - $pathparts = pathinfo($entryName); |
|
68 | - $timestamp = substr($pathparts['extension'], 1); |
|
69 | - $name = $pathparts['filename']; |
|
61 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
62 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
63 | + foreach ($dirContent as $entry) { |
|
64 | + $entryName = $entry->getName(); |
|
65 | + $name = $entryName; |
|
66 | + if ($dir === '' || $dir === '/') { |
|
67 | + $pathparts = pathinfo($entryName); |
|
68 | + $timestamp = substr($pathparts['extension'], 1); |
|
69 | + $name = $pathparts['filename']; |
|
70 | 70 | |
71 | - } else if ($timestamp === null) { |
|
72 | - // for subfolders we need to calculate the timestamp only once |
|
73 | - $parts = explode('/', ltrim($dir, '/')); |
|
74 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
75 | - } |
|
76 | - $originalPath = ''; |
|
77 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
78 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
79 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
80 | - if (substr($originalPath, -1) === '/') { |
|
81 | - $originalPath = substr($originalPath, 0, -1); |
|
82 | - } |
|
83 | - } |
|
84 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
85 | - $i = array( |
|
86 | - 'name' => $name, |
|
87 | - 'mtime' => $timestamp, |
|
88 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
89 | - 'type' => $type, |
|
90 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
91 | - 'size' => $entry->getSize(), |
|
92 | - 'etag' => '', |
|
93 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
94 | - 'fileid' => $entry->getId(), |
|
95 | - ); |
|
96 | - if ($originalPath) { |
|
97 | - if ($originalPath !== '.') { |
|
98 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
99 | - } else { |
|
100 | - $i['extraData'] = $originalName; |
|
101 | - } |
|
102 | - } |
|
103 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
104 | - } |
|
71 | + } else if ($timestamp === null) { |
|
72 | + // for subfolders we need to calculate the timestamp only once |
|
73 | + $parts = explode('/', ltrim($dir, '/')); |
|
74 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
75 | + } |
|
76 | + $originalPath = ''; |
|
77 | + $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
78 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
79 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
80 | + if (substr($originalPath, -1) === '/') { |
|
81 | + $originalPath = substr($originalPath, 0, -1); |
|
82 | + } |
|
83 | + } |
|
84 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
85 | + $i = array( |
|
86 | + 'name' => $name, |
|
87 | + 'mtime' => $timestamp, |
|
88 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
89 | + 'type' => $type, |
|
90 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
91 | + 'size' => $entry->getSize(), |
|
92 | + 'etag' => '', |
|
93 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
94 | + 'fileid' => $entry->getId(), |
|
95 | + ); |
|
96 | + if ($originalPath) { |
|
97 | + if ($originalPath !== '.') { |
|
98 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
99 | + } else { |
|
100 | + $i['extraData'] = $originalName; |
|
101 | + } |
|
102 | + } |
|
103 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
104 | + } |
|
105 | 105 | |
106 | - if ($sortAttribute !== '') { |
|
107 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
108 | - } |
|
109 | - return $result; |
|
110 | - } |
|
106 | + if ($sortAttribute !== '') { |
|
107 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
108 | + } |
|
109 | + return $result; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Format file infos for JSON |
|
114 | - * |
|
115 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
116 | - */ |
|
117 | - public static function formatFileInfos($fileInfos) { |
|
118 | - $files = array(); |
|
119 | - foreach ($fileInfos as $i) { |
|
120 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
121 | - $entry['id'] = $i->getId(); |
|
122 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
123 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
124 | - $files[] = $entry; |
|
125 | - } |
|
126 | - return $files; |
|
127 | - } |
|
112 | + /** |
|
113 | + * Format file infos for JSON |
|
114 | + * |
|
115 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
116 | + */ |
|
117 | + public static function formatFileInfos($fileInfos) { |
|
118 | + $files = array(); |
|
119 | + foreach ($fileInfos as $i) { |
|
120 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
121 | + $entry['id'] = $i->getId(); |
|
122 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
123 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
124 | + $files[] = $entry; |
|
125 | + } |
|
126 | + return $files; |
|
127 | + } |
|
128 | 128 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
100 | 100 | // remote server revoked access to the address book, remove it |
101 | 101 | $this->backend->deleteAddressBook($addressBookId); |
102 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
102 | + $this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']); |
|
103 | 103 | throw $ex; |
104 | 104 | } |
105 | 105 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | protected function getClient($url, $userName, $sharedSecret) { |
151 | 151 | $settings = [ |
152 | - 'baseUri' => $url . '/', |
|
152 | + 'baseUri' => $url.'/', |
|
153 | 153 | 'userName' => $userName, |
154 | 154 | 'password' => $sharedSecret, |
155 | 155 | ]; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function deleteUser($userOrCardId) { |
271 | 271 | $systemAddressBook = $this->getLocalSystemAddressBook(); |
272 | - if ($userOrCardId instanceof IUser){ |
|
272 | + if ($userOrCardId instanceof IUser) { |
|
273 | 273 | $name = $userOrCardId->getBackendClassName(); |
274 | 274 | $userId = $userOrCardId->getUID(); |
275 | 275 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | if (is_null($this->localSystemAddressBook)) { |
286 | 286 | $systemPrincipal = "principals/system/system"; |
287 | 287 | $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
288 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
288 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
289 | 289 | ]); |
290 | 290 | } |
291 | 291 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | |
304 | 304 | // remove no longer existing |
305 | 305 | $allCards = $this->backend->getCards($systemAddressBook['id']); |
306 | - foreach($allCards as $card) { |
|
306 | + foreach ($allCards as $card) { |
|
307 | 307 | $vCard = Reader::read($card['carddata']); |
308 | 308 | $uid = $vCard->UID->getValue(); |
309 | 309 | // load backend and see if user exists |
@@ -39,304 +39,304 @@ |
||
39 | 39 | |
40 | 40 | class SyncService { |
41 | 41 | |
42 | - /** @var CardDavBackend */ |
|
43 | - private $backend; |
|
44 | - |
|
45 | - /** @var IUserManager */ |
|
46 | - private $userManager; |
|
47 | - |
|
48 | - /** @var ILogger */ |
|
49 | - private $logger; |
|
50 | - |
|
51 | - /** @var array */ |
|
52 | - private $localSystemAddressBook; |
|
53 | - |
|
54 | - /** @var AccountManager */ |
|
55 | - private $accountManager; |
|
56 | - |
|
57 | - /** @var string */ |
|
58 | - protected $certPath; |
|
59 | - |
|
60 | - /** |
|
61 | - * SyncService constructor. |
|
62 | - * |
|
63 | - * @param CardDavBackend $backend |
|
64 | - * @param IUserManager $userManager |
|
65 | - * @param ILogger $logger |
|
66 | - * @param AccountManager $accountManager |
|
67 | - */ |
|
68 | - public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
69 | - $this->backend = $backend; |
|
70 | - $this->userManager = $userManager; |
|
71 | - $this->logger = $logger; |
|
72 | - $this->accountManager = $accountManager; |
|
73 | - $this->certPath = ''; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $url |
|
78 | - * @param string $userName |
|
79 | - * @param string $addressBookUrl |
|
80 | - * @param string $sharedSecret |
|
81 | - * @param string $syncToken |
|
82 | - * @param int $targetBookId |
|
83 | - * @param string $targetPrincipal |
|
84 | - * @param array $targetProperties |
|
85 | - * @return string |
|
86 | - * @throws \Exception |
|
87 | - */ |
|
88 | - public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
89 | - // 1. create addressbook |
|
90 | - $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
91 | - $addressBookId = $book['id']; |
|
92 | - |
|
93 | - // 2. query changes |
|
94 | - try { |
|
95 | - $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
96 | - } catch (ClientHttpException $ex) { |
|
97 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
98 | - // remote server revoked access to the address book, remove it |
|
99 | - $this->backend->deleteAddressBook($addressBookId); |
|
100 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
101 | - throw $ex; |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - // 3. apply changes |
|
106 | - // TODO: use multi-get for download |
|
107 | - foreach ($response['response'] as $resource => $status) { |
|
108 | - $cardUri = basename($resource); |
|
109 | - if (isset($status[200])) { |
|
110 | - $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
111 | - $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
112 | - if ($existingCard === false) { |
|
113 | - $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
114 | - } else { |
|
115 | - $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
116 | - } |
|
117 | - } else { |
|
118 | - $this->backend->deleteCard($addressBookId, $cardUri); |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - return $response['token']; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $principal |
|
127 | - * @param string $id |
|
128 | - * @param array $properties |
|
129 | - * @return array|null |
|
130 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
131 | - */ |
|
132 | - public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
133 | - $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
134 | - if (!is_null($book)) { |
|
135 | - return $book; |
|
136 | - } |
|
137 | - $this->backend->createAddressBook($principal, $id, $properties); |
|
138 | - |
|
139 | - return $this->backend->getAddressBooksByUri($principal, $id); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Check if there is a valid certPath we should use |
|
144 | - * |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - protected function getCertPath() { |
|
148 | - |
|
149 | - // we already have a valid certPath |
|
150 | - if ($this->certPath !== '') { |
|
151 | - return $this->certPath; |
|
152 | - } |
|
153 | - |
|
154 | - /** @var ICertificateManager $certManager */ |
|
155 | - $certManager = \OC::$server->getCertificateManager(null); |
|
156 | - $certPath = $certManager->getAbsoluteBundlePath(); |
|
157 | - if (file_exists($certPath)) { |
|
158 | - $this->certPath = $certPath; |
|
159 | - } |
|
160 | - |
|
161 | - return $this->certPath; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param string $url |
|
166 | - * @param string $userName |
|
167 | - * @param string $addressBookUrl |
|
168 | - * @param string $sharedSecret |
|
169 | - * @return Client |
|
170 | - */ |
|
171 | - protected function getClient($url, $userName, $sharedSecret) { |
|
172 | - $settings = [ |
|
173 | - 'baseUri' => $url . '/', |
|
174 | - 'userName' => $userName, |
|
175 | - 'password' => $sharedSecret, |
|
176 | - ]; |
|
177 | - $client = new Client($settings); |
|
178 | - $certPath = $this->getCertPath(); |
|
179 | - $client->setThrowExceptions(true); |
|
180 | - |
|
181 | - if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
182 | - $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
183 | - } |
|
184 | - |
|
185 | - return $client; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @param string $url |
|
190 | - * @param string $userName |
|
191 | - * @param string $addressBookUrl |
|
192 | - * @param string $sharedSecret |
|
193 | - * @param string $syncToken |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
197 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
198 | - |
|
199 | - $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
200 | - |
|
201 | - $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
202 | - 'Content-Type' => 'application/xml' |
|
203 | - ]); |
|
204 | - |
|
205 | - return $this->parseMultiStatus($response['body']); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param string $url |
|
210 | - * @param string $userName |
|
211 | - * @param string $sharedSecret |
|
212 | - * @param string $resourcePath |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
216 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
217 | - return $client->request('GET', $resourcePath); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string|null $syncToken |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - private function buildSyncCollectionRequestBody($syncToken) { |
|
225 | - |
|
226 | - $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
227 | - $dom->formatOutput = true; |
|
228 | - $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
229 | - $sync = $dom->createElement('d:sync-token', $syncToken); |
|
230 | - $prop = $dom->createElement('d:prop'); |
|
231 | - $cont = $dom->createElement('d:getcontenttype'); |
|
232 | - $etag = $dom->createElement('d:getetag'); |
|
233 | - |
|
234 | - $prop->appendChild($cont); |
|
235 | - $prop->appendChild($etag); |
|
236 | - $root->appendChild($sync); |
|
237 | - $root->appendChild($prop); |
|
238 | - $dom->appendChild($root); |
|
239 | - return $dom->saveXML(); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $body |
|
244 | - * @return array |
|
245 | - * @throws \Sabre\Xml\ParseException |
|
246 | - */ |
|
247 | - private function parseMultiStatus($body) { |
|
248 | - $xml = new Service(); |
|
249 | - |
|
250 | - /** @var MultiStatus $multiStatus */ |
|
251 | - $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
252 | - |
|
253 | - $result = []; |
|
254 | - foreach ($multiStatus->getResponses() as $response) { |
|
255 | - $result[$response->getHref()] = $response->getResponseProperties(); |
|
256 | - } |
|
257 | - |
|
258 | - return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * @param IUser $user |
|
263 | - */ |
|
264 | - public function updateUser(IUser $user) { |
|
265 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
266 | - $addressBookId = $systemAddressBook['id']; |
|
267 | - $converter = new Converter($this->accountManager); |
|
268 | - $name = $user->getBackendClassName(); |
|
269 | - $userId = $user->getUID(); |
|
270 | - |
|
271 | - $cardId = "$name:$userId.vcf"; |
|
272 | - $card = $this->backend->getCard($addressBookId, $cardId); |
|
273 | - if ($user->isEnabled()) { |
|
274 | - if ($card === false) { |
|
275 | - $vCard = $converter->createCardFromUser($user); |
|
276 | - if ($vCard !== null) { |
|
277 | - $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
278 | - } |
|
279 | - } else { |
|
280 | - $vCard = $converter->createCardFromUser($user); |
|
281 | - if (is_null($vCard)) { |
|
282 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
283 | - } else { |
|
284 | - $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
285 | - } |
|
286 | - } |
|
287 | - } else { |
|
288 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * @param IUser|string $userOrCardId |
|
294 | - */ |
|
295 | - public function deleteUser($userOrCardId) { |
|
296 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
297 | - if ($userOrCardId instanceof IUser){ |
|
298 | - $name = $userOrCardId->getBackendClassName(); |
|
299 | - $userId = $userOrCardId->getUID(); |
|
300 | - |
|
301 | - $userOrCardId = "$name:$userId.vcf"; |
|
302 | - } |
|
303 | - $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * @return array|null |
|
308 | - */ |
|
309 | - public function getLocalSystemAddressBook() { |
|
310 | - if (is_null($this->localSystemAddressBook)) { |
|
311 | - $systemPrincipal = "principals/system/system"; |
|
312 | - $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
313 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
314 | - ]); |
|
315 | - } |
|
316 | - |
|
317 | - return $this->localSystemAddressBook; |
|
318 | - } |
|
319 | - |
|
320 | - public function syncInstance(\Closure $progressCallback = null) { |
|
321 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
322 | - $this->userManager->callForSeenUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
323 | - $this->updateUser($user); |
|
324 | - if (!is_null($progressCallback)) { |
|
325 | - $progressCallback(); |
|
326 | - } |
|
327 | - }); |
|
328 | - |
|
329 | - // remove no longer existing |
|
330 | - $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
331 | - foreach($allCards as $card) { |
|
332 | - $vCard = Reader::read($card['carddata']); |
|
333 | - $uid = $vCard->UID->getValue(); |
|
334 | - // load backend and see if user exists |
|
335 | - if (!$this->userManager->userExists($uid)) { |
|
336 | - $this->deleteUser($card['uri']); |
|
337 | - } |
|
338 | - } |
|
339 | - } |
|
42 | + /** @var CardDavBackend */ |
|
43 | + private $backend; |
|
44 | + |
|
45 | + /** @var IUserManager */ |
|
46 | + private $userManager; |
|
47 | + |
|
48 | + /** @var ILogger */ |
|
49 | + private $logger; |
|
50 | + |
|
51 | + /** @var array */ |
|
52 | + private $localSystemAddressBook; |
|
53 | + |
|
54 | + /** @var AccountManager */ |
|
55 | + private $accountManager; |
|
56 | + |
|
57 | + /** @var string */ |
|
58 | + protected $certPath; |
|
59 | + |
|
60 | + /** |
|
61 | + * SyncService constructor. |
|
62 | + * |
|
63 | + * @param CardDavBackend $backend |
|
64 | + * @param IUserManager $userManager |
|
65 | + * @param ILogger $logger |
|
66 | + * @param AccountManager $accountManager |
|
67 | + */ |
|
68 | + public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
69 | + $this->backend = $backend; |
|
70 | + $this->userManager = $userManager; |
|
71 | + $this->logger = $logger; |
|
72 | + $this->accountManager = $accountManager; |
|
73 | + $this->certPath = ''; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $url |
|
78 | + * @param string $userName |
|
79 | + * @param string $addressBookUrl |
|
80 | + * @param string $sharedSecret |
|
81 | + * @param string $syncToken |
|
82 | + * @param int $targetBookId |
|
83 | + * @param string $targetPrincipal |
|
84 | + * @param array $targetProperties |
|
85 | + * @return string |
|
86 | + * @throws \Exception |
|
87 | + */ |
|
88 | + public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
89 | + // 1. create addressbook |
|
90 | + $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
91 | + $addressBookId = $book['id']; |
|
92 | + |
|
93 | + // 2. query changes |
|
94 | + try { |
|
95 | + $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
96 | + } catch (ClientHttpException $ex) { |
|
97 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
98 | + // remote server revoked access to the address book, remove it |
|
99 | + $this->backend->deleteAddressBook($addressBookId); |
|
100 | + $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
101 | + throw $ex; |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + // 3. apply changes |
|
106 | + // TODO: use multi-get for download |
|
107 | + foreach ($response['response'] as $resource => $status) { |
|
108 | + $cardUri = basename($resource); |
|
109 | + if (isset($status[200])) { |
|
110 | + $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
111 | + $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
112 | + if ($existingCard === false) { |
|
113 | + $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
114 | + } else { |
|
115 | + $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
116 | + } |
|
117 | + } else { |
|
118 | + $this->backend->deleteCard($addressBookId, $cardUri); |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + return $response['token']; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $principal |
|
127 | + * @param string $id |
|
128 | + * @param array $properties |
|
129 | + * @return array|null |
|
130 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
131 | + */ |
|
132 | + public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
133 | + $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
134 | + if (!is_null($book)) { |
|
135 | + return $book; |
|
136 | + } |
|
137 | + $this->backend->createAddressBook($principal, $id, $properties); |
|
138 | + |
|
139 | + return $this->backend->getAddressBooksByUri($principal, $id); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Check if there is a valid certPath we should use |
|
144 | + * |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + protected function getCertPath() { |
|
148 | + |
|
149 | + // we already have a valid certPath |
|
150 | + if ($this->certPath !== '') { |
|
151 | + return $this->certPath; |
|
152 | + } |
|
153 | + |
|
154 | + /** @var ICertificateManager $certManager */ |
|
155 | + $certManager = \OC::$server->getCertificateManager(null); |
|
156 | + $certPath = $certManager->getAbsoluteBundlePath(); |
|
157 | + if (file_exists($certPath)) { |
|
158 | + $this->certPath = $certPath; |
|
159 | + } |
|
160 | + |
|
161 | + return $this->certPath; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param string $url |
|
166 | + * @param string $userName |
|
167 | + * @param string $addressBookUrl |
|
168 | + * @param string $sharedSecret |
|
169 | + * @return Client |
|
170 | + */ |
|
171 | + protected function getClient($url, $userName, $sharedSecret) { |
|
172 | + $settings = [ |
|
173 | + 'baseUri' => $url . '/', |
|
174 | + 'userName' => $userName, |
|
175 | + 'password' => $sharedSecret, |
|
176 | + ]; |
|
177 | + $client = new Client($settings); |
|
178 | + $certPath = $this->getCertPath(); |
|
179 | + $client->setThrowExceptions(true); |
|
180 | + |
|
181 | + if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
182 | + $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
183 | + } |
|
184 | + |
|
185 | + return $client; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @param string $url |
|
190 | + * @param string $userName |
|
191 | + * @param string $addressBookUrl |
|
192 | + * @param string $sharedSecret |
|
193 | + * @param string $syncToken |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
197 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
198 | + |
|
199 | + $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
200 | + |
|
201 | + $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
202 | + 'Content-Type' => 'application/xml' |
|
203 | + ]); |
|
204 | + |
|
205 | + return $this->parseMultiStatus($response['body']); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param string $url |
|
210 | + * @param string $userName |
|
211 | + * @param string $sharedSecret |
|
212 | + * @param string $resourcePath |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
216 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
217 | + return $client->request('GET', $resourcePath); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string|null $syncToken |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + private function buildSyncCollectionRequestBody($syncToken) { |
|
225 | + |
|
226 | + $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
227 | + $dom->formatOutput = true; |
|
228 | + $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
229 | + $sync = $dom->createElement('d:sync-token', $syncToken); |
|
230 | + $prop = $dom->createElement('d:prop'); |
|
231 | + $cont = $dom->createElement('d:getcontenttype'); |
|
232 | + $etag = $dom->createElement('d:getetag'); |
|
233 | + |
|
234 | + $prop->appendChild($cont); |
|
235 | + $prop->appendChild($etag); |
|
236 | + $root->appendChild($sync); |
|
237 | + $root->appendChild($prop); |
|
238 | + $dom->appendChild($root); |
|
239 | + return $dom->saveXML(); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $body |
|
244 | + * @return array |
|
245 | + * @throws \Sabre\Xml\ParseException |
|
246 | + */ |
|
247 | + private function parseMultiStatus($body) { |
|
248 | + $xml = new Service(); |
|
249 | + |
|
250 | + /** @var MultiStatus $multiStatus */ |
|
251 | + $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
252 | + |
|
253 | + $result = []; |
|
254 | + foreach ($multiStatus->getResponses() as $response) { |
|
255 | + $result[$response->getHref()] = $response->getResponseProperties(); |
|
256 | + } |
|
257 | + |
|
258 | + return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * @param IUser $user |
|
263 | + */ |
|
264 | + public function updateUser(IUser $user) { |
|
265 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
266 | + $addressBookId = $systemAddressBook['id']; |
|
267 | + $converter = new Converter($this->accountManager); |
|
268 | + $name = $user->getBackendClassName(); |
|
269 | + $userId = $user->getUID(); |
|
270 | + |
|
271 | + $cardId = "$name:$userId.vcf"; |
|
272 | + $card = $this->backend->getCard($addressBookId, $cardId); |
|
273 | + if ($user->isEnabled()) { |
|
274 | + if ($card === false) { |
|
275 | + $vCard = $converter->createCardFromUser($user); |
|
276 | + if ($vCard !== null) { |
|
277 | + $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
278 | + } |
|
279 | + } else { |
|
280 | + $vCard = $converter->createCardFromUser($user); |
|
281 | + if (is_null($vCard)) { |
|
282 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
283 | + } else { |
|
284 | + $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
285 | + } |
|
286 | + } |
|
287 | + } else { |
|
288 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * @param IUser|string $userOrCardId |
|
294 | + */ |
|
295 | + public function deleteUser($userOrCardId) { |
|
296 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
297 | + if ($userOrCardId instanceof IUser){ |
|
298 | + $name = $userOrCardId->getBackendClassName(); |
|
299 | + $userId = $userOrCardId->getUID(); |
|
300 | + |
|
301 | + $userOrCardId = "$name:$userId.vcf"; |
|
302 | + } |
|
303 | + $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * @return array|null |
|
308 | + */ |
|
309 | + public function getLocalSystemAddressBook() { |
|
310 | + if (is_null($this->localSystemAddressBook)) { |
|
311 | + $systemPrincipal = "principals/system/system"; |
|
312 | + $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
313 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
314 | + ]); |
|
315 | + } |
|
316 | + |
|
317 | + return $this->localSystemAddressBook; |
|
318 | + } |
|
319 | + |
|
320 | + public function syncInstance(\Closure $progressCallback = null) { |
|
321 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
322 | + $this->userManager->callForSeenUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
323 | + $this->updateUser($user); |
|
324 | + if (!is_null($progressCallback)) { |
|
325 | + $progressCallback(); |
|
326 | + } |
|
327 | + }); |
|
328 | + |
|
329 | + // remove no longer existing |
|
330 | + $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
331 | + foreach($allCards as $card) { |
|
332 | + $vCard = Reader::read($card['carddata']); |
|
333 | + $uid = $vCard->UID->getValue(); |
|
334 | + // load backend and see if user exists |
|
335 | + if (!$this->userManager->userExists($uid)) { |
|
336 | + $this->deleteUser($card['uri']); |
|
337 | + } |
|
338 | + } |
|
339 | + } |
|
340 | 340 | |
341 | 341 | |
342 | 342 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param \OCP\Files\Mount\IMountPoint $mount |
88 | 88 | * @param \OCP\IUser|null $owner |
89 | 89 | */ |
90 | - public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
90 | + public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) { |
|
91 | 91 | $this->path = $path; |
92 | 92 | $this->storage = $storage; |
93 | 93 | $this->internalPath = $internalPath; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return int|null |
154 | 154 | */ |
155 | 155 | public function getId() { |
156 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
156 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | public function getEtag() { |
184 | 184 | $this->updateEntryfromSubMounts(); |
185 | 185 | if (count($this->childEtags) > 0) { |
186 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
186 | + $combinedEtag = $this->data['etag'].'::'.implode('::', $this->childEtags); |
|
187 | 187 | return md5($combinedEtag); |
188 | 188 | } else { |
189 | 189 | return $this->data['etag']; |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
380 | 380 | // attach the permissions to propagate etag on permision changes of submounts |
381 | 381 | $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
382 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
382 | + $this->childEtags[] = $relativeEntryPath.'/'.$data['etag'].$permissions; |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 |
@@ -38,372 +38,372 @@ |
||
38 | 38 | use OCP\IUser; |
39 | 39 | |
40 | 40 | class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { |
41 | - /** |
|
42 | - * @var array $data |
|
43 | - */ |
|
44 | - private $data; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string $path |
|
48 | - */ |
|
49 | - private $path; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var \OC\Files\Storage\Storage $storage |
|
53 | - */ |
|
54 | - private $storage; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string $internalPath |
|
58 | - */ |
|
59 | - private $internalPath; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var \OCP\Files\Mount\IMountPoint |
|
63 | - */ |
|
64 | - private $mount; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var IUser |
|
68 | - */ |
|
69 | - private $owner; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string[] |
|
73 | - */ |
|
74 | - private $childEtags = []; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var IMountPoint[] |
|
78 | - */ |
|
79 | - private $subMounts = []; |
|
80 | - |
|
81 | - private $subMountsUsed = false; |
|
82 | - |
|
83 | - /** |
|
84 | - * The size of the file/folder without any sub mount |
|
85 | - * |
|
86 | - * @var int |
|
87 | - */ |
|
88 | - private $rawSize = 0; |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string|boolean $path |
|
92 | - * @param Storage\Storage $storage |
|
93 | - * @param string $internalPath |
|
94 | - * @param array|ICacheEntry $data |
|
95 | - * @param \OCP\Files\Mount\IMountPoint $mount |
|
96 | - * @param \OCP\IUser|null $owner |
|
97 | - */ |
|
98 | - public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
99 | - $this->path = $path; |
|
100 | - $this->storage = $storage; |
|
101 | - $this->internalPath = $internalPath; |
|
102 | - $this->data = $data; |
|
103 | - $this->mount = $mount; |
|
104 | - $this->owner = $owner; |
|
105 | - $this->rawSize = $this->data['size'] ?? 0; |
|
106 | - } |
|
107 | - |
|
108 | - public function offsetSet($offset, $value) { |
|
109 | - $this->data[$offset] = $value; |
|
110 | - } |
|
111 | - |
|
112 | - public function offsetExists($offset) { |
|
113 | - return isset($this->data[$offset]); |
|
114 | - } |
|
115 | - |
|
116 | - public function offsetUnset($offset) { |
|
117 | - unset($this->data[$offset]); |
|
118 | - } |
|
119 | - |
|
120 | - public function offsetGet($offset) { |
|
121 | - if ($offset === 'type') { |
|
122 | - return $this->getType(); |
|
123 | - } else if ($offset === 'etag') { |
|
124 | - return $this->getEtag(); |
|
125 | - } else if ($offset === 'size') { |
|
126 | - return $this->getSize(); |
|
127 | - } else if ($offset === 'mtime') { |
|
128 | - return $this->getMTime(); |
|
129 | - } elseif ($offset === 'permissions') { |
|
130 | - return $this->getPermissions(); |
|
131 | - } elseif (isset($this->data[$offset])) { |
|
132 | - return $this->data[$offset]; |
|
133 | - } else { |
|
134 | - return null; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function getPath() { |
|
142 | - return $this->path; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return \OCP\Files\Storage |
|
147 | - */ |
|
148 | - public function getStorage() { |
|
149 | - return $this->storage; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function getInternalPath() { |
|
156 | - return $this->internalPath; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Get FileInfo ID or null in case of part file |
|
161 | - * |
|
162 | - * @return int|null |
|
163 | - */ |
|
164 | - public function getId() { |
|
165 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function getMimetype() { |
|
172 | - return $this->data['mimetype']; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public function getMimePart() { |
|
179 | - return $this->data['mimepart']; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function getName() { |
|
186 | - return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - public function getEtag() { |
|
193 | - $this->updateEntryfromSubMounts(); |
|
194 | - if (count($this->childEtags) > 0) { |
|
195 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
196 | - return md5($combinedEtag); |
|
197 | - } else { |
|
198 | - return $this->data['etag']; |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @return int |
|
204 | - */ |
|
205 | - public function getSize($includeMounts = true) { |
|
206 | - if ($includeMounts) { |
|
207 | - $this->updateEntryfromSubMounts(); |
|
208 | - return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
209 | - } else { |
|
210 | - return $this->rawSize; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @return int |
|
216 | - */ |
|
217 | - public function getMTime() { |
|
218 | - $this->updateEntryfromSubMounts(); |
|
219 | - return (int) $this->data['mtime']; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @return bool |
|
224 | - */ |
|
225 | - public function isEncrypted() { |
|
226 | - return $this->data['encrypted']; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Return the currently version used for the HMAC in the encryption app |
|
231 | - * |
|
232 | - * @return int |
|
233 | - */ |
|
234 | - public function getEncryptedVersion() { |
|
235 | - return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @return int |
|
240 | - */ |
|
241 | - public function getPermissions() { |
|
242 | - $perms = (int) $this->data['permissions']; |
|
243 | - if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
244 | - $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
245 | - } |
|
246 | - return (int) $perms; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
251 | - */ |
|
252 | - public function getType() { |
|
253 | - if (!isset($this->data['type'])) { |
|
254 | - $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
255 | - } |
|
256 | - return $this->data['type']; |
|
257 | - } |
|
258 | - |
|
259 | - public function getData() { |
|
260 | - return $this->data; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @param int $permissions |
|
265 | - * @return bool |
|
266 | - */ |
|
267 | - protected function checkPermissions($permissions) { |
|
268 | - return ($this->getPermissions() & $permissions) === $permissions; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * @return bool |
|
273 | - */ |
|
274 | - public function isReadable() { |
|
275 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @return bool |
|
280 | - */ |
|
281 | - public function isUpdateable() { |
|
282 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Check whether new files or folders can be created inside this folder |
|
287 | - * |
|
288 | - * @return bool |
|
289 | - */ |
|
290 | - public function isCreatable() { |
|
291 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - public function isDeletable() { |
|
298 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @return bool |
|
303 | - */ |
|
304 | - public function isShareable() { |
|
305 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Check if a file or folder is shared |
|
310 | - * |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function isShared() { |
|
314 | - $sid = $this->getStorage()->getId(); |
|
315 | - if (!is_null($sid)) { |
|
316 | - $sid = explode(':', $sid); |
|
317 | - return ($sid[0] === 'shared'); |
|
318 | - } |
|
319 | - |
|
320 | - return false; |
|
321 | - } |
|
322 | - |
|
323 | - public function isMounted() { |
|
324 | - $storage = $this->getStorage(); |
|
325 | - if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
326 | - return false; |
|
327 | - } |
|
328 | - $sid = $storage->getId(); |
|
329 | - if (!is_null($sid)) { |
|
330 | - $sid = explode(':', $sid); |
|
331 | - return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
332 | - } |
|
333 | - |
|
334 | - return false; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Get the mountpoint the file belongs to |
|
339 | - * |
|
340 | - * @return \OCP\Files\Mount\IMountPoint |
|
341 | - */ |
|
342 | - public function getMountPoint() { |
|
343 | - return $this->mount; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get the owner of the file |
|
348 | - * |
|
349 | - * @return \OCP\IUser |
|
350 | - */ |
|
351 | - public function getOwner() { |
|
352 | - return $this->owner; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * @param IMountPoint[] $mounts |
|
357 | - */ |
|
358 | - public function setSubMounts(array $mounts) { |
|
359 | - $this->subMounts = $mounts; |
|
360 | - } |
|
361 | - |
|
362 | - private function updateEntryfromSubMounts() { |
|
363 | - if ($this->subMountsUsed) { |
|
364 | - return; |
|
365 | - } |
|
366 | - $this->subMountsUsed = true; |
|
367 | - foreach ($this->subMounts as $mount) { |
|
368 | - $subStorage = $mount->getStorage(); |
|
369 | - if ($subStorage) { |
|
370 | - $subCache = $subStorage->getCache(''); |
|
371 | - $rootEntry = $subCache->get(''); |
|
372 | - $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
373 | - } |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Add a cache entry which is the child of this folder |
|
379 | - * |
|
380 | - * Sets the size, etag and size to for cross-storage childs |
|
381 | - * |
|
382 | - * @param array|ICacheEntry $data cache entry for the child |
|
383 | - * @param string $entryPath full path of the child entry |
|
384 | - */ |
|
385 | - public function addSubEntry($data, $entryPath) { |
|
386 | - $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
387 | - if (isset($data['mtime'])) { |
|
388 | - $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
389 | - } |
|
390 | - if (isset($data['etag'])) { |
|
391 | - // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
392 | - $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
393 | - // attach the permissions to propagate etag on permision changes of submounts |
|
394 | - $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
395 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * @inheritdoc |
|
401 | - */ |
|
402 | - public function getChecksum() { |
|
403 | - return $this->data['checksum']; |
|
404 | - } |
|
405 | - |
|
406 | - public function getExtension(): string { |
|
407 | - return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
408 | - } |
|
41 | + /** |
|
42 | + * @var array $data |
|
43 | + */ |
|
44 | + private $data; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string $path |
|
48 | + */ |
|
49 | + private $path; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var \OC\Files\Storage\Storage $storage |
|
53 | + */ |
|
54 | + private $storage; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string $internalPath |
|
58 | + */ |
|
59 | + private $internalPath; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var \OCP\Files\Mount\IMountPoint |
|
63 | + */ |
|
64 | + private $mount; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var IUser |
|
68 | + */ |
|
69 | + private $owner; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string[] |
|
73 | + */ |
|
74 | + private $childEtags = []; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var IMountPoint[] |
|
78 | + */ |
|
79 | + private $subMounts = []; |
|
80 | + |
|
81 | + private $subMountsUsed = false; |
|
82 | + |
|
83 | + /** |
|
84 | + * The size of the file/folder without any sub mount |
|
85 | + * |
|
86 | + * @var int |
|
87 | + */ |
|
88 | + private $rawSize = 0; |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string|boolean $path |
|
92 | + * @param Storage\Storage $storage |
|
93 | + * @param string $internalPath |
|
94 | + * @param array|ICacheEntry $data |
|
95 | + * @param \OCP\Files\Mount\IMountPoint $mount |
|
96 | + * @param \OCP\IUser|null $owner |
|
97 | + */ |
|
98 | + public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
99 | + $this->path = $path; |
|
100 | + $this->storage = $storage; |
|
101 | + $this->internalPath = $internalPath; |
|
102 | + $this->data = $data; |
|
103 | + $this->mount = $mount; |
|
104 | + $this->owner = $owner; |
|
105 | + $this->rawSize = $this->data['size'] ?? 0; |
|
106 | + } |
|
107 | + |
|
108 | + public function offsetSet($offset, $value) { |
|
109 | + $this->data[$offset] = $value; |
|
110 | + } |
|
111 | + |
|
112 | + public function offsetExists($offset) { |
|
113 | + return isset($this->data[$offset]); |
|
114 | + } |
|
115 | + |
|
116 | + public function offsetUnset($offset) { |
|
117 | + unset($this->data[$offset]); |
|
118 | + } |
|
119 | + |
|
120 | + public function offsetGet($offset) { |
|
121 | + if ($offset === 'type') { |
|
122 | + return $this->getType(); |
|
123 | + } else if ($offset === 'etag') { |
|
124 | + return $this->getEtag(); |
|
125 | + } else if ($offset === 'size') { |
|
126 | + return $this->getSize(); |
|
127 | + } else if ($offset === 'mtime') { |
|
128 | + return $this->getMTime(); |
|
129 | + } elseif ($offset === 'permissions') { |
|
130 | + return $this->getPermissions(); |
|
131 | + } elseif (isset($this->data[$offset])) { |
|
132 | + return $this->data[$offset]; |
|
133 | + } else { |
|
134 | + return null; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function getPath() { |
|
142 | + return $this->path; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return \OCP\Files\Storage |
|
147 | + */ |
|
148 | + public function getStorage() { |
|
149 | + return $this->storage; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function getInternalPath() { |
|
156 | + return $this->internalPath; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Get FileInfo ID or null in case of part file |
|
161 | + * |
|
162 | + * @return int|null |
|
163 | + */ |
|
164 | + public function getId() { |
|
165 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function getMimetype() { |
|
172 | + return $this->data['mimetype']; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public function getMimePart() { |
|
179 | + return $this->data['mimepart']; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function getName() { |
|
186 | + return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + public function getEtag() { |
|
193 | + $this->updateEntryfromSubMounts(); |
|
194 | + if (count($this->childEtags) > 0) { |
|
195 | + $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
196 | + return md5($combinedEtag); |
|
197 | + } else { |
|
198 | + return $this->data['etag']; |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @return int |
|
204 | + */ |
|
205 | + public function getSize($includeMounts = true) { |
|
206 | + if ($includeMounts) { |
|
207 | + $this->updateEntryfromSubMounts(); |
|
208 | + return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
209 | + } else { |
|
210 | + return $this->rawSize; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @return int |
|
216 | + */ |
|
217 | + public function getMTime() { |
|
218 | + $this->updateEntryfromSubMounts(); |
|
219 | + return (int) $this->data['mtime']; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @return bool |
|
224 | + */ |
|
225 | + public function isEncrypted() { |
|
226 | + return $this->data['encrypted']; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Return the currently version used for the HMAC in the encryption app |
|
231 | + * |
|
232 | + * @return int |
|
233 | + */ |
|
234 | + public function getEncryptedVersion() { |
|
235 | + return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @return int |
|
240 | + */ |
|
241 | + public function getPermissions() { |
|
242 | + $perms = (int) $this->data['permissions']; |
|
243 | + if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
244 | + $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
245 | + } |
|
246 | + return (int) $perms; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
251 | + */ |
|
252 | + public function getType() { |
|
253 | + if (!isset($this->data['type'])) { |
|
254 | + $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
255 | + } |
|
256 | + return $this->data['type']; |
|
257 | + } |
|
258 | + |
|
259 | + public function getData() { |
|
260 | + return $this->data; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @param int $permissions |
|
265 | + * @return bool |
|
266 | + */ |
|
267 | + protected function checkPermissions($permissions) { |
|
268 | + return ($this->getPermissions() & $permissions) === $permissions; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * @return bool |
|
273 | + */ |
|
274 | + public function isReadable() { |
|
275 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @return bool |
|
280 | + */ |
|
281 | + public function isUpdateable() { |
|
282 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Check whether new files or folders can be created inside this folder |
|
287 | + * |
|
288 | + * @return bool |
|
289 | + */ |
|
290 | + public function isCreatable() { |
|
291 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + public function isDeletable() { |
|
298 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @return bool |
|
303 | + */ |
|
304 | + public function isShareable() { |
|
305 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Check if a file or folder is shared |
|
310 | + * |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function isShared() { |
|
314 | + $sid = $this->getStorage()->getId(); |
|
315 | + if (!is_null($sid)) { |
|
316 | + $sid = explode(':', $sid); |
|
317 | + return ($sid[0] === 'shared'); |
|
318 | + } |
|
319 | + |
|
320 | + return false; |
|
321 | + } |
|
322 | + |
|
323 | + public function isMounted() { |
|
324 | + $storage = $this->getStorage(); |
|
325 | + if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
326 | + return false; |
|
327 | + } |
|
328 | + $sid = $storage->getId(); |
|
329 | + if (!is_null($sid)) { |
|
330 | + $sid = explode(':', $sid); |
|
331 | + return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
332 | + } |
|
333 | + |
|
334 | + return false; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Get the mountpoint the file belongs to |
|
339 | + * |
|
340 | + * @return \OCP\Files\Mount\IMountPoint |
|
341 | + */ |
|
342 | + public function getMountPoint() { |
|
343 | + return $this->mount; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get the owner of the file |
|
348 | + * |
|
349 | + * @return \OCP\IUser |
|
350 | + */ |
|
351 | + public function getOwner() { |
|
352 | + return $this->owner; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * @param IMountPoint[] $mounts |
|
357 | + */ |
|
358 | + public function setSubMounts(array $mounts) { |
|
359 | + $this->subMounts = $mounts; |
|
360 | + } |
|
361 | + |
|
362 | + private function updateEntryfromSubMounts() { |
|
363 | + if ($this->subMountsUsed) { |
|
364 | + return; |
|
365 | + } |
|
366 | + $this->subMountsUsed = true; |
|
367 | + foreach ($this->subMounts as $mount) { |
|
368 | + $subStorage = $mount->getStorage(); |
|
369 | + if ($subStorage) { |
|
370 | + $subCache = $subStorage->getCache(''); |
|
371 | + $rootEntry = $subCache->get(''); |
|
372 | + $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
373 | + } |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Add a cache entry which is the child of this folder |
|
379 | + * |
|
380 | + * Sets the size, etag and size to for cross-storage childs |
|
381 | + * |
|
382 | + * @param array|ICacheEntry $data cache entry for the child |
|
383 | + * @param string $entryPath full path of the child entry |
|
384 | + */ |
|
385 | + public function addSubEntry($data, $entryPath) { |
|
386 | + $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
387 | + if (isset($data['mtime'])) { |
|
388 | + $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
389 | + } |
|
390 | + if (isset($data['etag'])) { |
|
391 | + // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
392 | + $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
393 | + // attach the permissions to propagate etag on permision changes of submounts |
|
394 | + $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
395 | + $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
396 | + } |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * @inheritdoc |
|
401 | + */ |
|
402 | + public function getChecksum() { |
|
403 | + return $this->data['checksum']; |
|
404 | + } |
|
405 | + |
|
406 | + public function getExtension(): string { |
|
407 | + return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
408 | + } |
|
409 | 409 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public function getChild($name) { |
60 | 60 | $elements = pathinfo($name); |
61 | 61 | $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
62 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
62 | + $size = (int) (isset($elements['filename']) ? $elements['filename'] : '64'); |
|
63 | 63 | if (!in_array($ext, ['jpeg', 'png'], true)) { |
64 | 64 | throw new MethodNotAllowed('File format not allowed'); |
65 | 65 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | return [ |
79 | 79 | $this->getChild('96.jpeg') |
80 | 80 | ]; |
81 | - } catch(NotFound $exception) { |
|
81 | + } catch (NotFound $exception) { |
|
82 | 82 | return []; |
83 | 83 | } |
84 | 84 | } |
@@ -35,89 +35,89 @@ |
||
35 | 35 | |
36 | 36 | class AvatarHome implements ICollection { |
37 | 37 | |
38 | - /** @var array */ |
|
39 | - private $principalInfo; |
|
40 | - /** @var IAvatarManager */ |
|
41 | - private $avatarManager; |
|
42 | - |
|
43 | - /** |
|
44 | - * AvatarHome constructor. |
|
45 | - * |
|
46 | - * @param array $principalInfo |
|
47 | - * @param IAvatarManager $avatarManager |
|
48 | - */ |
|
49 | - public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
50 | - $this->principalInfo = $principalInfo; |
|
51 | - $this->avatarManager = $avatarManager; |
|
52 | - } |
|
53 | - |
|
54 | - public function createFile($name, $data = null) { |
|
55 | - throw new Forbidden('Permission denied to create a file'); |
|
56 | - } |
|
57 | - |
|
58 | - public function createDirectory($name) { |
|
59 | - throw new Forbidden('Permission denied to create a folder'); |
|
60 | - } |
|
61 | - |
|
62 | - public function getChild($name) { |
|
63 | - $elements = pathinfo($name); |
|
64 | - $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
65 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
66 | - if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
67 | - throw new MethodNotAllowed('File format not allowed'); |
|
68 | - } |
|
69 | - if ($size <= 0 || $size > 1024) { |
|
70 | - throw new MethodNotAllowed('Invalid image size'); |
|
71 | - } |
|
72 | - $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
73 | - if (!$avatar->exists()) { |
|
74 | - throw new NotFound(); |
|
75 | - } |
|
76 | - return new AvatarNode($size, $ext, $avatar); |
|
77 | - } |
|
78 | - |
|
79 | - public function getChildren() { |
|
80 | - try { |
|
81 | - return [ |
|
82 | - $this->getChild('96.jpeg') |
|
83 | - ]; |
|
84 | - } catch(NotFound $exception) { |
|
85 | - return []; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - public function childExists($name) { |
|
90 | - try { |
|
91 | - $ret = $this->getChild($name); |
|
92 | - return $ret !== null; |
|
93 | - } catch (NotFound $ex) { |
|
94 | - return false; |
|
95 | - } catch (MethodNotAllowed $ex) { |
|
96 | - return false; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - public function delete() { |
|
101 | - throw new Forbidden('Permission denied to delete this folder'); |
|
102 | - } |
|
103 | - |
|
104 | - public function getName() { |
|
105 | - list(,$name) = Uri\split($this->principalInfo['uri']); |
|
106 | - return $name; |
|
107 | - } |
|
108 | - |
|
109 | - public function setName($name) { |
|
110 | - throw new Forbidden('Permission denied to rename this folder'); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Returns the last modification time, as a unix timestamp |
|
115 | - * |
|
116 | - * @return int|null |
|
117 | - */ |
|
118 | - public function getLastModified() { |
|
119 | - return null; |
|
120 | - } |
|
38 | + /** @var array */ |
|
39 | + private $principalInfo; |
|
40 | + /** @var IAvatarManager */ |
|
41 | + private $avatarManager; |
|
42 | + |
|
43 | + /** |
|
44 | + * AvatarHome constructor. |
|
45 | + * |
|
46 | + * @param array $principalInfo |
|
47 | + * @param IAvatarManager $avatarManager |
|
48 | + */ |
|
49 | + public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
50 | + $this->principalInfo = $principalInfo; |
|
51 | + $this->avatarManager = $avatarManager; |
|
52 | + } |
|
53 | + |
|
54 | + public function createFile($name, $data = null) { |
|
55 | + throw new Forbidden('Permission denied to create a file'); |
|
56 | + } |
|
57 | + |
|
58 | + public function createDirectory($name) { |
|
59 | + throw new Forbidden('Permission denied to create a folder'); |
|
60 | + } |
|
61 | + |
|
62 | + public function getChild($name) { |
|
63 | + $elements = pathinfo($name); |
|
64 | + $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
65 | + $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
66 | + if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
67 | + throw new MethodNotAllowed('File format not allowed'); |
|
68 | + } |
|
69 | + if ($size <= 0 || $size > 1024) { |
|
70 | + throw new MethodNotAllowed('Invalid image size'); |
|
71 | + } |
|
72 | + $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
73 | + if (!$avatar->exists()) { |
|
74 | + throw new NotFound(); |
|
75 | + } |
|
76 | + return new AvatarNode($size, $ext, $avatar); |
|
77 | + } |
|
78 | + |
|
79 | + public function getChildren() { |
|
80 | + try { |
|
81 | + return [ |
|
82 | + $this->getChild('96.jpeg') |
|
83 | + ]; |
|
84 | + } catch(NotFound $exception) { |
|
85 | + return []; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + public function childExists($name) { |
|
90 | + try { |
|
91 | + $ret = $this->getChild($name); |
|
92 | + return $ret !== null; |
|
93 | + } catch (NotFound $ex) { |
|
94 | + return false; |
|
95 | + } catch (MethodNotAllowed $ex) { |
|
96 | + return false; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + public function delete() { |
|
101 | + throw new Forbidden('Permission denied to delete this folder'); |
|
102 | + } |
|
103 | + |
|
104 | + public function getName() { |
|
105 | + list(,$name) = Uri\split($this->principalInfo['uri']); |
|
106 | + return $name; |
|
107 | + } |
|
108 | + |
|
109 | + public function setName($name) { |
|
110 | + throw new Forbidden('Permission denied to rename this folder'); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Returns the last modification time, as a unix timestamp |
|
115 | + * |
|
116 | + * @return int|null |
|
117 | + */ |
|
118 | + public function getLastModified() { |
|
119 | + return null; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | 123 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | public function getLastModified() { |
90 | 90 | $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
91 | 91 | if (!empty($timestamp)) { |
92 | - return (int)$timestamp; |
|
92 | + return (int) $timestamp; |
|
93 | 93 | } |
94 | 94 | return $timestamp; |
95 | 95 |
@@ -27,72 +27,72 @@ |
||
27 | 27 | use Sabre\DAV\File; |
28 | 28 | |
29 | 29 | class AvatarNode extends File { |
30 | - private $ext; |
|
31 | - private $size; |
|
32 | - private $avatar; |
|
30 | + private $ext; |
|
31 | + private $size; |
|
32 | + private $avatar; |
|
33 | 33 | |
34 | - /** |
|
35 | - * AvatarNode constructor. |
|
36 | - * |
|
37 | - * @param integer $size |
|
38 | - * @param string $ext |
|
39 | - * @param IAvatar $avatar |
|
40 | - */ |
|
41 | - public function __construct($size, $ext, $avatar) { |
|
42 | - $this->size = $size; |
|
43 | - $this->ext = $ext; |
|
44 | - $this->avatar = $avatar; |
|
45 | - } |
|
34 | + /** |
|
35 | + * AvatarNode constructor. |
|
36 | + * |
|
37 | + * @param integer $size |
|
38 | + * @param string $ext |
|
39 | + * @param IAvatar $avatar |
|
40 | + */ |
|
41 | + public function __construct($size, $ext, $avatar) { |
|
42 | + $this->size = $size; |
|
43 | + $this->ext = $ext; |
|
44 | + $this->avatar = $avatar; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Returns the name of the node. |
|
49 | - * |
|
50 | - * This is used to generate the url. |
|
51 | - * |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getName() { |
|
55 | - return "$this->size.$this->ext"; |
|
56 | - } |
|
47 | + /** |
|
48 | + * Returns the name of the node. |
|
49 | + * |
|
50 | + * This is used to generate the url. |
|
51 | + * |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getName() { |
|
55 | + return "$this->size.$this->ext"; |
|
56 | + } |
|
57 | 57 | |
58 | - public function get() { |
|
59 | - $image = $this->avatar->get($this->size); |
|
60 | - $res = $image->resource(); |
|
58 | + public function get() { |
|
59 | + $image = $this->avatar->get($this->size); |
|
60 | + $res = $image->resource(); |
|
61 | 61 | |
62 | - ob_start(); |
|
63 | - if ($this->ext === 'png') { |
|
64 | - imagepng($res); |
|
65 | - } else { |
|
66 | - imagejpeg($res); |
|
67 | - } |
|
62 | + ob_start(); |
|
63 | + if ($this->ext === 'png') { |
|
64 | + imagepng($res); |
|
65 | + } else { |
|
66 | + imagejpeg($res); |
|
67 | + } |
|
68 | 68 | |
69 | - return ob_get_clean(); |
|
70 | - } |
|
69 | + return ob_get_clean(); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Returns the mime-type for a file |
|
74 | - * |
|
75 | - * If null is returned, we'll assume application/octet-stream |
|
76 | - * |
|
77 | - * @return string|null |
|
78 | - */ |
|
79 | - public function getContentType() { |
|
80 | - if ($this->ext === 'png') { |
|
81 | - return 'image/png'; |
|
82 | - } |
|
83 | - return 'image/jpeg'; |
|
84 | - } |
|
72 | + /** |
|
73 | + * Returns the mime-type for a file |
|
74 | + * |
|
75 | + * If null is returned, we'll assume application/octet-stream |
|
76 | + * |
|
77 | + * @return string|null |
|
78 | + */ |
|
79 | + public function getContentType() { |
|
80 | + if ($this->ext === 'png') { |
|
81 | + return 'image/png'; |
|
82 | + } |
|
83 | + return 'image/jpeg'; |
|
84 | + } |
|
85 | 85 | |
86 | - public function getETag() { |
|
87 | - return $this->avatar->getFile($this->size)->getEtag(); |
|
88 | - } |
|
86 | + public function getETag() { |
|
87 | + return $this->avatar->getFile($this->size)->getEtag(); |
|
88 | + } |
|
89 | 89 | |
90 | - public function getLastModified() { |
|
91 | - $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
92 | - if (!empty($timestamp)) { |
|
93 | - return (int)$timestamp; |
|
94 | - } |
|
95 | - return $timestamp; |
|
90 | + public function getLastModified() { |
|
91 | + $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
92 | + if (!empty($timestamp)) { |
|
93 | + return (int)$timestamp; |
|
94 | + } |
|
95 | + return $timestamp; |
|
96 | 96 | |
97 | - } |
|
97 | + } |
|
98 | 98 | } |
@@ -7,23 +7,23 @@ |
||
7 | 7 | |
8 | 8 | class RootCollection extends AbstractPrincipalCollection { |
9 | 9 | |
10 | - /** |
|
11 | - * This method returns a node for a principal. |
|
12 | - * |
|
13 | - * The passed array contains principal information, and is guaranteed to |
|
14 | - * at least contain a uri item. Other properties may or may not be |
|
15 | - * supplied by the authentication backend. |
|
16 | - * |
|
17 | - * @param array $principalInfo |
|
18 | - * @return AvatarHome |
|
19 | - */ |
|
20 | - public function getChildForPrincipal(array $principalInfo) { |
|
21 | - $avatarManager = \OC::$server->getAvatarManager(); |
|
22 | - return new AvatarHome($principalInfo, $avatarManager); |
|
23 | - } |
|
10 | + /** |
|
11 | + * This method returns a node for a principal. |
|
12 | + * |
|
13 | + * The passed array contains principal information, and is guaranteed to |
|
14 | + * at least contain a uri item. Other properties may or may not be |
|
15 | + * supplied by the authentication backend. |
|
16 | + * |
|
17 | + * @param array $principalInfo |
|
18 | + * @return AvatarHome |
|
19 | + */ |
|
20 | + public function getChildForPrincipal(array $principalInfo) { |
|
21 | + $avatarManager = \OC::$server->getAvatarManager(); |
|
22 | + return new AvatarHome($principalInfo, $avatarManager); |
|
23 | + } |
|
24 | 24 | |
25 | - public function getName() { |
|
26 | - return 'avatars'; |
|
27 | - } |
|
25 | + public function getName() { |
|
26 | + return 'avatars'; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | } |
@@ -33,87 +33,87 @@ |
||
33 | 33 | |
34 | 34 | class CalDAVRemoveEmptyValue implements IRepairStep { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $db; |
|
38 | - |
|
39 | - /** @var CalDavBackend */ |
|
40 | - private $calDavBackend; |
|
41 | - |
|
42 | - /** @var ILogger */ |
|
43 | - private $logger; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param IDBConnection $db |
|
47 | - * @param CalDavBackend $calDavBackend |
|
48 | - * @param ILogger $logger |
|
49 | - */ |
|
50 | - public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) { |
|
51 | - $this->db = $db; |
|
52 | - $this->calDavBackend = $calDavBackend; |
|
53 | - $this->logger = $logger; |
|
54 | - } |
|
55 | - |
|
56 | - public function getName() { |
|
57 | - return 'Fix broken values of calendar objects'; |
|
58 | - } |
|
59 | - |
|
60 | - public function run(IOutput $output) { |
|
61 | - $pattern = ';VALUE=:'; |
|
62 | - $count = $warnings = 0; |
|
63 | - |
|
64 | - $objects = $this->getInvalidObjects($pattern); |
|
65 | - |
|
66 | - $output->startProgress(count($objects)); |
|
67 | - foreach ($objects as $row) { |
|
68 | - $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | - $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
70 | - |
|
71 | - if ($data !== $calObject['calendardata']) { |
|
72 | - $output->advance(); |
|
73 | - |
|
74 | - try { |
|
75 | - $this->calDavBackend->getDenormalizedData($data); |
|
76 | - } catch (InvalidDataException $e) { |
|
77 | - $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
78 | - 'app' => 'dav', |
|
79 | - 'cal' => (int)$row['calendarid'], |
|
80 | - 'uri' => $row['uri'], |
|
81 | - ]); |
|
82 | - $warnings++; |
|
83 | - continue; |
|
84 | - } |
|
85 | - |
|
86 | - $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
87 | - $count++; |
|
88 | - } |
|
89 | - } |
|
90 | - $output->finishProgress(); |
|
91 | - |
|
92 | - if ($warnings > 0) { |
|
93 | - $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings)); |
|
94 | - } |
|
95 | - if ($count > 0) { |
|
96 | - $output->info(sprintf('Updated %d events', $count)); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - protected function getInvalidObjects($pattern) { |
|
101 | - $query = $this->db->getQueryBuilder(); |
|
102 | - $query->select(['calendarid', 'uri']) |
|
103 | - ->from('calendarobjects') |
|
104 | - ->where($query->expr()->like( |
|
105 | - 'calendardata', |
|
106 | - $query->createNamedParameter( |
|
107 | - '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
108 | - IQueryBuilder::PARAM_STR |
|
109 | - ), |
|
110 | - IQueryBuilder::PARAM_STR |
|
111 | - )); |
|
112 | - |
|
113 | - $result = $query->execute(); |
|
114 | - $rows = $result->fetchAll(); |
|
115 | - $result->closeCursor(); |
|
116 | - |
|
117 | - return $rows; |
|
118 | - } |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $db; |
|
38 | + |
|
39 | + /** @var CalDavBackend */ |
|
40 | + private $calDavBackend; |
|
41 | + |
|
42 | + /** @var ILogger */ |
|
43 | + private $logger; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param IDBConnection $db |
|
47 | + * @param CalDavBackend $calDavBackend |
|
48 | + * @param ILogger $logger |
|
49 | + */ |
|
50 | + public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) { |
|
51 | + $this->db = $db; |
|
52 | + $this->calDavBackend = $calDavBackend; |
|
53 | + $this->logger = $logger; |
|
54 | + } |
|
55 | + |
|
56 | + public function getName() { |
|
57 | + return 'Fix broken values of calendar objects'; |
|
58 | + } |
|
59 | + |
|
60 | + public function run(IOutput $output) { |
|
61 | + $pattern = ';VALUE=:'; |
|
62 | + $count = $warnings = 0; |
|
63 | + |
|
64 | + $objects = $this->getInvalidObjects($pattern); |
|
65 | + |
|
66 | + $output->startProgress(count($objects)); |
|
67 | + foreach ($objects as $row) { |
|
68 | + $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | + $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
70 | + |
|
71 | + if ($data !== $calObject['calendardata']) { |
|
72 | + $output->advance(); |
|
73 | + |
|
74 | + try { |
|
75 | + $this->calDavBackend->getDenormalizedData($data); |
|
76 | + } catch (InvalidDataException $e) { |
|
77 | + $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
78 | + 'app' => 'dav', |
|
79 | + 'cal' => (int)$row['calendarid'], |
|
80 | + 'uri' => $row['uri'], |
|
81 | + ]); |
|
82 | + $warnings++; |
|
83 | + continue; |
|
84 | + } |
|
85 | + |
|
86 | + $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
87 | + $count++; |
|
88 | + } |
|
89 | + } |
|
90 | + $output->finishProgress(); |
|
91 | + |
|
92 | + if ($warnings > 0) { |
|
93 | + $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings)); |
|
94 | + } |
|
95 | + if ($count > 0) { |
|
96 | + $output->info(sprintf('Updated %d events', $count)); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + protected function getInvalidObjects($pattern) { |
|
101 | + $query = $this->db->getQueryBuilder(); |
|
102 | + $query->select(['calendarid', 'uri']) |
|
103 | + ->from('calendarobjects') |
|
104 | + ->where($query->expr()->like( |
|
105 | + 'calendardata', |
|
106 | + $query->createNamedParameter( |
|
107 | + '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
108 | + IQueryBuilder::PARAM_STR |
|
109 | + ), |
|
110 | + IQueryBuilder::PARAM_STR |
|
111 | + )); |
|
112 | + |
|
113 | + $result = $query->execute(); |
|
114 | + $rows = $result->fetchAll(); |
|
115 | + $result->closeCursor(); |
|
116 | + |
|
117 | + return $rows; |
|
118 | + } |
|
119 | 119 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | |
66 | 66 | $output->startProgress(count($objects)); |
67 | 67 | foreach ($objects as $row) { |
68 | - $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | - $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
68 | + $calObject = $this->calDavBackend->getCalendarObject((int) $row['calendarid'], $row['uri']); |
|
69 | + $data = preg_replace('/'.$pattern.'/', ':', $calObject['calendardata']); |
|
70 | 70 | |
71 | 71 | if ($data !== $calObject['calendardata']) { |
72 | 72 | $output->advance(); |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | } catch (InvalidDataException $e) { |
77 | 77 | $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
78 | 78 | 'app' => 'dav', |
79 | - 'cal' => (int)$row['calendarid'], |
|
79 | + 'cal' => (int) $row['calendarid'], |
|
80 | 80 | 'uri' => $row['uri'], |
81 | 81 | ]); |
82 | 82 | $warnings++; |
83 | 83 | continue; |
84 | 84 | } |
85 | 85 | |
86 | - $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
86 | + $this->calDavBackend->updateCalendarObject((int) $row['calendarid'], $row['uri'], $data); |
|
87 | 87 | $count++; |
88 | 88 | } |
89 | 89 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | ->where($query->expr()->like( |
105 | 105 | 'calendardata', |
106 | 106 | $query->createNamedParameter( |
107 | - '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
107 | + '%'.$this->db->escapeLikeParameter($pattern).'%', |
|
108 | 108 | IQueryBuilder::PARAM_STR |
109 | 109 | ), |
110 | 110 | IQueryBuilder::PARAM_STR |
@@ -27,21 +27,21 @@ |
||
27 | 27 | |
28 | 28 | class CompFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $componentName = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $componentName = $att['name']; |
|
38 | 38 | |
39 | - $reader->parseInnerTree(); |
|
39 | + $reader->parseInnerTree(); |
|
40 | 40 | |
41 | - if (!is_string($componentName)) { |
|
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | - } |
|
41 | + if (!is_string($componentName)) { |
|
42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | + } |
|
44 | 44 | |
45 | - return $componentName; |
|
46 | - } |
|
45 | + return $componentName; |
|
46 | + } |
|
47 | 47 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | $reader->parseInnerTree(); |
40 | 40 | |
41 | 41 | if (!is_string($componentName)) { |
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
42 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}comp-filter requires a valid name attribute'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return $componentName; |