@@ -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 | } |
@@ -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 | |
@@ -37,380 +37,380 @@ |
||
| 37 | 37 | use OCP\IUser; |
| 38 | 38 | |
| 39 | 39 | class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { |
| 40 | - /** |
|
| 41 | - * @var array $data |
|
| 42 | - */ |
|
| 43 | - private $data; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string $path |
|
| 47 | - */ |
|
| 48 | - private $path; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var \OC\Files\Storage\Storage $storage |
|
| 52 | - */ |
|
| 53 | - private $storage; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var string $internalPath |
|
| 57 | - */ |
|
| 58 | - private $internalPath; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var \OCP\Files\Mount\IMountPoint |
|
| 62 | - */ |
|
| 63 | - private $mount; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var IUser |
|
| 67 | - */ |
|
| 68 | - private $owner; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var string[] |
|
| 72 | - */ |
|
| 73 | - private $childEtags = []; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var IMountPoint[] |
|
| 77 | - */ |
|
| 78 | - private $subMounts = []; |
|
| 79 | - |
|
| 80 | - private $subMountsUsed = false; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The size of the file/folder without any sub mount |
|
| 84 | - * |
|
| 85 | - * @var int |
|
| 86 | - */ |
|
| 87 | - private $rawSize = 0; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param string|boolean $path |
|
| 91 | - * @param Storage\Storage $storage |
|
| 92 | - * @param string $internalPath |
|
| 93 | - * @param array|ICacheEntry $data |
|
| 94 | - * @param \OCP\Files\Mount\IMountPoint $mount |
|
| 95 | - * @param \OCP\IUser|null $owner |
|
| 96 | - */ |
|
| 97 | - public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
| 98 | - $this->path = $path; |
|
| 99 | - $this->storage = $storage; |
|
| 100 | - $this->internalPath = $internalPath; |
|
| 101 | - $this->data = $data; |
|
| 102 | - $this->mount = $mount; |
|
| 103 | - $this->owner = $owner; |
|
| 104 | - $this->rawSize = $this->data['size'] ?? 0; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function offsetSet($offset, $value) { |
|
| 108 | - $this->data[$offset] = $value; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function offsetExists($offset) { |
|
| 112 | - return isset($this->data[$offset]); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function offsetUnset($offset) { |
|
| 116 | - unset($this->data[$offset]); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function offsetGet($offset) { |
|
| 120 | - if ($offset === 'type') { |
|
| 121 | - return $this->getType(); |
|
| 122 | - } elseif ($offset === 'etag') { |
|
| 123 | - return $this->getEtag(); |
|
| 124 | - } elseif ($offset === 'size') { |
|
| 125 | - return $this->getSize(); |
|
| 126 | - } elseif ($offset === 'mtime') { |
|
| 127 | - return $this->getMTime(); |
|
| 128 | - } elseif ($offset === 'permissions') { |
|
| 129 | - return $this->getPermissions(); |
|
| 130 | - } elseif (isset($this->data[$offset])) { |
|
| 131 | - return $this->data[$offset]; |
|
| 132 | - } else { |
|
| 133 | - return null; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function getPath() { |
|
| 141 | - return $this->path; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return \OCP\Files\Storage |
|
| 146 | - */ |
|
| 147 | - public function getStorage() { |
|
| 148 | - return $this->storage; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return string |
|
| 153 | - */ |
|
| 154 | - public function getInternalPath() { |
|
| 155 | - return $this->internalPath; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Get FileInfo ID or null in case of part file |
|
| 160 | - * |
|
| 161 | - * @return int|null |
|
| 162 | - */ |
|
| 163 | - public function getId() { |
|
| 164 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function getMimetype() { |
|
| 171 | - return $this->data['mimetype']; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public function getMimePart() { |
|
| 178 | - return $this->data['mimepart']; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @return string |
|
| 183 | - */ |
|
| 184 | - public function getName() { |
|
| 185 | - return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - public function getEtag() { |
|
| 192 | - $this->updateEntryfromSubMounts(); |
|
| 193 | - if (count($this->childEtags) > 0) { |
|
| 194 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 195 | - return md5($combinedEtag); |
|
| 196 | - } else { |
|
| 197 | - return $this->data['etag']; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @return int |
|
| 203 | - */ |
|
| 204 | - public function getSize($includeMounts = true) { |
|
| 205 | - if ($includeMounts) { |
|
| 206 | - $this->updateEntryfromSubMounts(); |
|
| 207 | - return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
| 208 | - } else { |
|
| 209 | - return $this->rawSize; |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return int |
|
| 215 | - */ |
|
| 216 | - public function getMTime() { |
|
| 217 | - $this->updateEntryfromSubMounts(); |
|
| 218 | - return (int) $this->data['mtime']; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * @return bool |
|
| 223 | - */ |
|
| 224 | - public function isEncrypted() { |
|
| 225 | - return $this->data['encrypted']; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Return the currently version used for the HMAC in the encryption app |
|
| 230 | - * |
|
| 231 | - * @return int |
|
| 232 | - */ |
|
| 233 | - public function getEncryptedVersion() { |
|
| 234 | - return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @return int |
|
| 239 | - */ |
|
| 240 | - public function getPermissions() { |
|
| 241 | - $perms = (int) $this->data['permissions']; |
|
| 242 | - if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
| 243 | - $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
| 244 | - } |
|
| 245 | - return (int) $perms; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
| 250 | - */ |
|
| 251 | - public function getType() { |
|
| 252 | - if (!isset($this->data['type'])) { |
|
| 253 | - $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
| 254 | - } |
|
| 255 | - return $this->data['type']; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - public function getData() { |
|
| 259 | - return $this->data; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param int $permissions |
|
| 264 | - * @return bool |
|
| 265 | - */ |
|
| 266 | - protected function checkPermissions($permissions) { |
|
| 267 | - return ($this->getPermissions() & $permissions) === $permissions; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @return bool |
|
| 272 | - */ |
|
| 273 | - public function isReadable() { |
|
| 274 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @return bool |
|
| 279 | - */ |
|
| 280 | - public function isUpdateable() { |
|
| 281 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Check whether new files or folders can be created inside this folder |
|
| 286 | - * |
|
| 287 | - * @return bool |
|
| 288 | - */ |
|
| 289 | - public function isCreatable() { |
|
| 290 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @return bool |
|
| 295 | - */ |
|
| 296 | - public function isDeletable() { |
|
| 297 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @return bool |
|
| 302 | - */ |
|
| 303 | - public function isShareable() { |
|
| 304 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Check if a file or folder is shared |
|
| 309 | - * |
|
| 310 | - * @return bool |
|
| 311 | - */ |
|
| 312 | - public function isShared() { |
|
| 313 | - $sid = $this->getStorage()->getId(); |
|
| 314 | - if (!is_null($sid)) { |
|
| 315 | - $sid = explode(':', $sid); |
|
| 316 | - return ($sid[0] === 'shared'); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return false; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - public function isMounted() { |
|
| 323 | - $storage = $this->getStorage(); |
|
| 324 | - if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 325 | - return false; |
|
| 326 | - } |
|
| 327 | - $sid = $storage->getId(); |
|
| 328 | - if (!is_null($sid)) { |
|
| 329 | - $sid = explode(':', $sid); |
|
| 330 | - return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - return false; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Get the mountpoint the file belongs to |
|
| 338 | - * |
|
| 339 | - * @return \OCP\Files\Mount\IMountPoint |
|
| 340 | - */ |
|
| 341 | - public function getMountPoint() { |
|
| 342 | - return $this->mount; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Get the owner of the file |
|
| 347 | - * |
|
| 348 | - * @return \OCP\IUser |
|
| 349 | - */ |
|
| 350 | - public function getOwner() { |
|
| 351 | - return $this->owner; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @param IMountPoint[] $mounts |
|
| 356 | - */ |
|
| 357 | - public function setSubMounts(array $mounts) { |
|
| 358 | - $this->subMounts = $mounts; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - private function updateEntryfromSubMounts() { |
|
| 362 | - if ($this->subMountsUsed) { |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - $this->subMountsUsed = true; |
|
| 366 | - foreach ($this->subMounts as $mount) { |
|
| 367 | - $subStorage = $mount->getStorage(); |
|
| 368 | - if ($subStorage) { |
|
| 369 | - $subCache = $subStorage->getCache(''); |
|
| 370 | - $rootEntry = $subCache->get(''); |
|
| 371 | - $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Add a cache entry which is the child of this folder |
|
| 378 | - * |
|
| 379 | - * Sets the size, etag and size to for cross-storage childs |
|
| 380 | - * |
|
| 381 | - * @param array|ICacheEntry $data cache entry for the child |
|
| 382 | - * @param string $entryPath full path of the child entry |
|
| 383 | - */ |
|
| 384 | - public function addSubEntry($data, $entryPath) { |
|
| 385 | - $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
| 386 | - if (isset($data['mtime'])) { |
|
| 387 | - $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
| 388 | - } |
|
| 389 | - if (isset($data['etag'])) { |
|
| 390 | - // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
| 391 | - $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
| 392 | - // attach the permissions to propagate etag on permision changes of submounts |
|
| 393 | - $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
| 394 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * @inheritdoc |
|
| 400 | - */ |
|
| 401 | - public function getChecksum() { |
|
| 402 | - return $this->data['checksum']; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - public function getExtension(): string { |
|
| 406 | - return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - public function getCreationTime(): int { |
|
| 410 | - return (int) $this->data['creation_time']; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - public function getUploadTime(): int { |
|
| 414 | - return (int) $this->data['upload_time']; |
|
| 415 | - } |
|
| 40 | + /** |
|
| 41 | + * @var array $data |
|
| 42 | + */ |
|
| 43 | + private $data; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string $path |
|
| 47 | + */ |
|
| 48 | + private $path; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var \OC\Files\Storage\Storage $storage |
|
| 52 | + */ |
|
| 53 | + private $storage; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var string $internalPath |
|
| 57 | + */ |
|
| 58 | + private $internalPath; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var \OCP\Files\Mount\IMountPoint |
|
| 62 | + */ |
|
| 63 | + private $mount; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var IUser |
|
| 67 | + */ |
|
| 68 | + private $owner; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var string[] |
|
| 72 | + */ |
|
| 73 | + private $childEtags = []; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var IMountPoint[] |
|
| 77 | + */ |
|
| 78 | + private $subMounts = []; |
|
| 79 | + |
|
| 80 | + private $subMountsUsed = false; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The size of the file/folder without any sub mount |
|
| 84 | + * |
|
| 85 | + * @var int |
|
| 86 | + */ |
|
| 87 | + private $rawSize = 0; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param string|boolean $path |
|
| 91 | + * @param Storage\Storage $storage |
|
| 92 | + * @param string $internalPath |
|
| 93 | + * @param array|ICacheEntry $data |
|
| 94 | + * @param \OCP\Files\Mount\IMountPoint $mount |
|
| 95 | + * @param \OCP\IUser|null $owner |
|
| 96 | + */ |
|
| 97 | + public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) { |
|
| 98 | + $this->path = $path; |
|
| 99 | + $this->storage = $storage; |
|
| 100 | + $this->internalPath = $internalPath; |
|
| 101 | + $this->data = $data; |
|
| 102 | + $this->mount = $mount; |
|
| 103 | + $this->owner = $owner; |
|
| 104 | + $this->rawSize = $this->data['size'] ?? 0; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function offsetSet($offset, $value) { |
|
| 108 | + $this->data[$offset] = $value; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function offsetExists($offset) { |
|
| 112 | + return isset($this->data[$offset]); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function offsetUnset($offset) { |
|
| 116 | + unset($this->data[$offset]); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function offsetGet($offset) { |
|
| 120 | + if ($offset === 'type') { |
|
| 121 | + return $this->getType(); |
|
| 122 | + } elseif ($offset === 'etag') { |
|
| 123 | + return $this->getEtag(); |
|
| 124 | + } elseif ($offset === 'size') { |
|
| 125 | + return $this->getSize(); |
|
| 126 | + } elseif ($offset === 'mtime') { |
|
| 127 | + return $this->getMTime(); |
|
| 128 | + } elseif ($offset === 'permissions') { |
|
| 129 | + return $this->getPermissions(); |
|
| 130 | + } elseif (isset($this->data[$offset])) { |
|
| 131 | + return $this->data[$offset]; |
|
| 132 | + } else { |
|
| 133 | + return null; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function getPath() { |
|
| 141 | + return $this->path; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return \OCP\Files\Storage |
|
| 146 | + */ |
|
| 147 | + public function getStorage() { |
|
| 148 | + return $this->storage; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return string |
|
| 153 | + */ |
|
| 154 | + public function getInternalPath() { |
|
| 155 | + return $this->internalPath; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Get FileInfo ID or null in case of part file |
|
| 160 | + * |
|
| 161 | + * @return int|null |
|
| 162 | + */ |
|
| 163 | + public function getId() { |
|
| 164 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function getMimetype() { |
|
| 171 | + return $this->data['mimetype']; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public function getMimePart() { |
|
| 178 | + return $this->data['mimepart']; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @return string |
|
| 183 | + */ |
|
| 184 | + public function getName() { |
|
| 185 | + return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + public function getEtag() { |
|
| 192 | + $this->updateEntryfromSubMounts(); |
|
| 193 | + if (count($this->childEtags) > 0) { |
|
| 194 | + $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 195 | + return md5($combinedEtag); |
|
| 196 | + } else { |
|
| 197 | + return $this->data['etag']; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @return int |
|
| 203 | + */ |
|
| 204 | + public function getSize($includeMounts = true) { |
|
| 205 | + if ($includeMounts) { |
|
| 206 | + $this->updateEntryfromSubMounts(); |
|
| 207 | + return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
| 208 | + } else { |
|
| 209 | + return $this->rawSize; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return int |
|
| 215 | + */ |
|
| 216 | + public function getMTime() { |
|
| 217 | + $this->updateEntryfromSubMounts(); |
|
| 218 | + return (int) $this->data['mtime']; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * @return bool |
|
| 223 | + */ |
|
| 224 | + public function isEncrypted() { |
|
| 225 | + return $this->data['encrypted']; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Return the currently version used for the HMAC in the encryption app |
|
| 230 | + * |
|
| 231 | + * @return int |
|
| 232 | + */ |
|
| 233 | + public function getEncryptedVersion() { |
|
| 234 | + return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @return int |
|
| 239 | + */ |
|
| 240 | + public function getPermissions() { |
|
| 241 | + $perms = (int) $this->data['permissions']; |
|
| 242 | + if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
| 243 | + $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
| 244 | + } |
|
| 245 | + return (int) $perms; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
| 250 | + */ |
|
| 251 | + public function getType() { |
|
| 252 | + if (!isset($this->data['type'])) { |
|
| 253 | + $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
| 254 | + } |
|
| 255 | + return $this->data['type']; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + public function getData() { |
|
| 259 | + return $this->data; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param int $permissions |
|
| 264 | + * @return bool |
|
| 265 | + */ |
|
| 266 | + protected function checkPermissions($permissions) { |
|
| 267 | + return ($this->getPermissions() & $permissions) === $permissions; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @return bool |
|
| 272 | + */ |
|
| 273 | + public function isReadable() { |
|
| 274 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @return bool |
|
| 279 | + */ |
|
| 280 | + public function isUpdateable() { |
|
| 281 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Check whether new files or folders can be created inside this folder |
|
| 286 | + * |
|
| 287 | + * @return bool |
|
| 288 | + */ |
|
| 289 | + public function isCreatable() { |
|
| 290 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @return bool |
|
| 295 | + */ |
|
| 296 | + public function isDeletable() { |
|
| 297 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @return bool |
|
| 302 | + */ |
|
| 303 | + public function isShareable() { |
|
| 304 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Check if a file or folder is shared |
|
| 309 | + * |
|
| 310 | + * @return bool |
|
| 311 | + */ |
|
| 312 | + public function isShared() { |
|
| 313 | + $sid = $this->getStorage()->getId(); |
|
| 314 | + if (!is_null($sid)) { |
|
| 315 | + $sid = explode(':', $sid); |
|
| 316 | + return ($sid[0] === 'shared'); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + public function isMounted() { |
|
| 323 | + $storage = $this->getStorage(); |
|
| 324 | + if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 327 | + $sid = $storage->getId(); |
|
| 328 | + if (!is_null($sid)) { |
|
| 329 | + $sid = explode(':', $sid); |
|
| 330 | + return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Get the mountpoint the file belongs to |
|
| 338 | + * |
|
| 339 | + * @return \OCP\Files\Mount\IMountPoint |
|
| 340 | + */ |
|
| 341 | + public function getMountPoint() { |
|
| 342 | + return $this->mount; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Get the owner of the file |
|
| 347 | + * |
|
| 348 | + * @return \OCP\IUser |
|
| 349 | + */ |
|
| 350 | + public function getOwner() { |
|
| 351 | + return $this->owner; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @param IMountPoint[] $mounts |
|
| 356 | + */ |
|
| 357 | + public function setSubMounts(array $mounts) { |
|
| 358 | + $this->subMounts = $mounts; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + private function updateEntryfromSubMounts() { |
|
| 362 | + if ($this->subMountsUsed) { |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + $this->subMountsUsed = true; |
|
| 366 | + foreach ($this->subMounts as $mount) { |
|
| 367 | + $subStorage = $mount->getStorage(); |
|
| 368 | + if ($subStorage) { |
|
| 369 | + $subCache = $subStorage->getCache(''); |
|
| 370 | + $rootEntry = $subCache->get(''); |
|
| 371 | + $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Add a cache entry which is the child of this folder |
|
| 378 | + * |
|
| 379 | + * Sets the size, etag and size to for cross-storage childs |
|
| 380 | + * |
|
| 381 | + * @param array|ICacheEntry $data cache entry for the child |
|
| 382 | + * @param string $entryPath full path of the child entry |
|
| 383 | + */ |
|
| 384 | + public function addSubEntry($data, $entryPath) { |
|
| 385 | + $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
| 386 | + if (isset($data['mtime'])) { |
|
| 387 | + $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
| 388 | + } |
|
| 389 | + if (isset($data['etag'])) { |
|
| 390 | + // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
| 391 | + $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
| 392 | + // attach the permissions to propagate etag on permision changes of submounts |
|
| 393 | + $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
| 394 | + $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * @inheritdoc |
|
| 400 | + */ |
|
| 401 | + public function getChecksum() { |
|
| 402 | + return $this->data['checksum']; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + public function getExtension(): string { |
|
| 406 | + return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + public function getCreationTime(): int { |
|
| 410 | + return (int) $this->data['creation_time']; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + public function getUploadTime(): int { |
|
| 414 | + return (int) $this->data['upload_time']; |
|
| 415 | + } |
|
| 416 | 416 | } |
@@ -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 |
@@ -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; |
@@ -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 | - public 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 | + public 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 . '}prop-filter requires a valid name attribute'); |
|
| 42 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}prop-filter requires a valid name attribute'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | return $componentName; |
@@ -27,21 +27,21 @@ |
||
| 27 | 27 | |
| 28 | 28 | class PropFilter implements XmlDeserializable { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param Reader $reader |
|
| 32 | - * @throws BadRequest |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public 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 | + public 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 . '}prop-filter requires a valid name attribute'); |
|
| 43 | - } |
|
| 41 | + if (!is_string($componentName)) { |
|
| 42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return $componentName; |
|
| 46 | - } |
|
| 45 | + return $componentName; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | $reader->parseInnerTree(); |
| 41 | 41 | |
| 42 | 42 | if (!is_string($property)) { |
| 43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid property attribute'); |
|
| 43 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}param-filter requires a valid property attribute'); |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | 46 | if (!is_string($parameter)) { |
| 47 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid parameter attribute'); |
|
| 47 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}param-filter requires a valid parameter attribute'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | return [ |
@@ -27,28 +27,28 @@ |
||
| 27 | 27 | |
| 28 | 28 | class ParamFilter implements XmlDeserializable { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param Reader $reader |
|
| 32 | - * @throws BadRequest |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public static function xmlDeserialize(Reader $reader) { |
|
| 36 | - $att = $reader->parseAttributes(); |
|
| 37 | - $property = $att['property']; |
|
| 38 | - $parameter = $att['name']; |
|
| 30 | + /** |
|
| 31 | + * @param Reader $reader |
|
| 32 | + * @throws BadRequest |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public static function xmlDeserialize(Reader $reader) { |
|
| 36 | + $att = $reader->parseAttributes(); |
|
| 37 | + $property = $att['property']; |
|
| 38 | + $parameter = $att['name']; |
|
| 39 | 39 | |
| 40 | - $reader->parseInnerTree(); |
|
| 40 | + $reader->parseInnerTree(); |
|
| 41 | 41 | |
| 42 | - if (!is_string($property)) { |
|
| 43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid property attribute'); |
|
| 44 | - } |
|
| 45 | - if (!is_string($parameter)) { |
|
| 46 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid parameter attribute'); |
|
| 47 | - } |
|
| 42 | + if (!is_string($property)) { |
|
| 43 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid property attribute'); |
|
| 44 | + } |
|
| 45 | + if (!is_string($parameter)) { |
|
| 46 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid parameter attribute'); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return [ |
|
| 50 | - 'property' => $property, |
|
| 51 | - 'parameter' => $parameter, |
|
| 52 | - ]; |
|
| 53 | - } |
|
| 49 | + return [ |
|
| 50 | + 'property' => $property, |
|
| 51 | + 'parameter' => $parameter, |
|
| 52 | + ]; |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | <tr><td> |
| 28 | 28 | <table cellspacing="0" cellpadding="0" border="0" width="600px"> |
| 29 | 29 | <tr> |
| 30 | - <td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>"> |
|
| 30 | + <td colspan="2" bgcolor="<?php p($theme->getColorPrimary()); ?>"> |
|
| 31 | 31 | <img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/> |
| 32 | 32 | </td> |
| 33 | 33 | </tr> |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br> |
| 53 | 53 | <?php p($theme->getName()); ?> - |
| 54 | 54 | <?php p($theme->getSlogan()); ?> |
| 55 | - <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a> |
|
| 55 | + <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl()); ?></a> |
|
| 56 | 56 | </td> |
| 57 | 57 | </tr> |
| 58 | 58 | <tr> |
@@ -15,10 +15,10 @@ |
||
| 15 | 15 | <td width="20px"> </td> |
| 16 | 16 | <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;"> |
| 17 | 17 | <?php |
| 18 | - print_unescaped($l->t('Hey there,<br><br>the admin enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br>Please login to the web interface, go to the section "basic encryption module" of your personal settings and update your encryption password by entering this password into the "old log-in password" field and your current login-password.<br><br>', [$_['password']])); |
|
| 19 | - // TRANSLATORS term at the end of a mail |
|
| 20 | - p($l->t('Cheers!')); |
|
| 21 | - ?> |
|
| 18 | + print_unescaped($l->t('Hey there,<br><br>the admin enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br>Please login to the web interface, go to the section "basic encryption module" of your personal settings and update your encryption password by entering this password into the "old log-in password" field and your current login-password.<br><br>', [$_['password']])); |
|
| 19 | + // TRANSLATORS term at the end of a mail |
|
| 20 | + p($l->t('Cheers!')); |
|
| 21 | + ?> |
|
| 22 | 22 | </td> |
| 23 | 23 | </tr> |
| 24 | 24 | <tr><td colspan="2"> </td></tr> |
@@ -171,14 +171,14 @@ |
||
| 171 | 171 | protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
| 172 | 172 | $qb = $this->connection->getQueryBuilder(); |
| 173 | 173 | |
| 174 | - $qb->select('d.' . $deleteId) |
|
| 174 | + $qb->select('d.'.$deleteId) |
|
| 175 | 175 | ->from($deleteTable, 'd') |
| 176 | - ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
| 176 | + ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.'.$deleteId, 's.'.$sourceId)) |
|
| 177 | 177 | ->where( |
| 178 | 178 | $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
| 179 | 179 | ) |
| 180 | 180 | ->andWhere( |
| 181 | - $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
| 181 | + $qb->expr()->isNull('s.'.$sourceNullColumn) |
|
| 182 | 182 | ); |
| 183 | 183 | $result = $qb->execute(); |
| 184 | 184 | |
@@ -41,171 +41,171 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class CleanTags implements IRepairStep { |
| 43 | 43 | |
| 44 | - /** @var IDBConnection */ |
|
| 45 | - protected $connection; |
|
| 46 | - |
|
| 47 | - /** @var IUserManager */ |
|
| 48 | - protected $userManager; |
|
| 49 | - |
|
| 50 | - protected $deletedTags = 0; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param IDBConnection $connection |
|
| 54 | - * @param IUserManager $userManager |
|
| 55 | - */ |
|
| 56 | - public function __construct(IDBConnection $connection, IUserManager $userManager) { |
|
| 57 | - $this->connection = $connection; |
|
| 58 | - $this->userManager = $userManager; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function getName() { |
|
| 65 | - return 'Clean tags and favorites'; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Updates the configuration after running an update |
|
| 70 | - */ |
|
| 71 | - public function run(IOutput $output) { |
|
| 72 | - $this->deleteOrphanTags($output); |
|
| 73 | - $this->deleteOrphanFileEntries($output); |
|
| 74 | - $this->deleteOrphanTagEntries($output); |
|
| 75 | - $this->deleteOrphanCategoryEntries($output); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Delete tags for deleted users |
|
| 80 | - */ |
|
| 81 | - protected function deleteOrphanTags(IOutput $output) { |
|
| 82 | - $offset = 0; |
|
| 83 | - while ($this->checkTags($offset)) { |
|
| 84 | - $offset += 50; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags)); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - protected function checkTags($offset) { |
|
| 91 | - $query = $this->connection->getQueryBuilder(); |
|
| 92 | - $query->select('uid') |
|
| 93 | - ->from('vcategory') |
|
| 94 | - ->groupBy('uid') |
|
| 95 | - ->orderBy('uid') |
|
| 96 | - ->setMaxResults(50) |
|
| 97 | - ->setFirstResult($offset); |
|
| 98 | - $result = $query->execute(); |
|
| 99 | - |
|
| 100 | - $users = []; |
|
| 101 | - $hadResults = false; |
|
| 102 | - while ($row = $result->fetch()) { |
|
| 103 | - $hadResults = true; |
|
| 104 | - if (!$this->userManager->userExists($row['uid'])) { |
|
| 105 | - $users[] = $row['uid']; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - $result->closeCursor(); |
|
| 109 | - |
|
| 110 | - if (!$hadResults) { |
|
| 111 | - // No more tags, stop looping |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if (!empty($users)) { |
|
| 116 | - $query = $this->connection->getQueryBuilder(); |
|
| 117 | - $query->delete('vcategory') |
|
| 118 | - ->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 119 | - $this->deletedTags += $query->execute(); |
|
| 120 | - } |
|
| 121 | - return true; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Delete tag entries for deleted files |
|
| 126 | - */ |
|
| 127 | - protected function deleteOrphanFileEntries(IOutput $output) { |
|
| 128 | - $this->deleteOrphanEntries( |
|
| 129 | - $output, |
|
| 130 | - '%d tags for delete files have been removed.', |
|
| 131 | - 'vcategory_to_object', 'objid', |
|
| 132 | - 'filecache', 'fileid', 'path_hash' |
|
| 133 | - ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Delete tag entries for deleted tags |
|
| 138 | - */ |
|
| 139 | - protected function deleteOrphanTagEntries(IOutput $output) { |
|
| 140 | - $this->deleteOrphanEntries( |
|
| 141 | - $output, |
|
| 142 | - '%d tag entries for deleted tags have been removed.', |
|
| 143 | - 'vcategory_to_object', 'categoryid', |
|
| 144 | - 'vcategory', 'id', 'uid' |
|
| 145 | - ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Delete tags that have no entries |
|
| 150 | - */ |
|
| 151 | - protected function deleteOrphanCategoryEntries(IOutput $output) { |
|
| 152 | - $this->deleteOrphanEntries( |
|
| 153 | - $output, |
|
| 154 | - '%d tags with no entries have been removed.', |
|
| 155 | - 'vcategory', 'id', |
|
| 156 | - 'vcategory_to_object', 'categoryid', 'type' |
|
| 157 | - ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable |
|
| 162 | - * |
|
| 163 | - * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks |
|
| 164 | - * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable |
|
| 165 | - * is being deleted. |
|
| 166 | - * |
|
| 167 | - * @param string $repairInfo |
|
| 168 | - * @param string $deleteTable |
|
| 169 | - * @param string $deleteId |
|
| 170 | - * @param string $sourceTable |
|
| 171 | - * @param string $sourceId |
|
| 172 | - * @param string $sourceNullColumn If this column is null in the source table, |
|
| 173 | - * the entry is deleted in the $deleteTable |
|
| 174 | - */ |
|
| 175 | - protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
|
| 176 | - $qb = $this->connection->getQueryBuilder(); |
|
| 177 | - |
|
| 178 | - $qb->select('d.' . $deleteId) |
|
| 179 | - ->from($deleteTable, 'd') |
|
| 180 | - ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
| 181 | - ->where( |
|
| 182 | - $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
|
| 183 | - ) |
|
| 184 | - ->andWhere( |
|
| 185 | - $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
| 186 | - ); |
|
| 187 | - $result = $qb->execute(); |
|
| 188 | - |
|
| 189 | - $orphanItems = []; |
|
| 190 | - while ($row = $result->fetch()) { |
|
| 191 | - $orphanItems[] = (int) $row[$deleteId]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (!empty($orphanItems)) { |
|
| 195 | - $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
| 196 | - foreach ($orphanItemsBatch as $items) { |
|
| 197 | - $qb->delete($deleteTable) |
|
| 198 | - ->where( |
|
| 199 | - $qb->expr()->eq('type', $qb->expr()->literal('files')) |
|
| 200 | - ) |
|
| 201 | - ->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids'))); |
|
| 202 | - $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
| 203 | - $qb->execute(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if ($repairInfo) { |
|
| 208 | - $output->info(sprintf($repairInfo, count($orphanItems))); |
|
| 209 | - } |
|
| 210 | - } |
|
| 44 | + /** @var IDBConnection */ |
|
| 45 | + protected $connection; |
|
| 46 | + |
|
| 47 | + /** @var IUserManager */ |
|
| 48 | + protected $userManager; |
|
| 49 | + |
|
| 50 | + protected $deletedTags = 0; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param IDBConnection $connection |
|
| 54 | + * @param IUserManager $userManager |
|
| 55 | + */ |
|
| 56 | + public function __construct(IDBConnection $connection, IUserManager $userManager) { |
|
| 57 | + $this->connection = $connection; |
|
| 58 | + $this->userManager = $userManager; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function getName() { |
|
| 65 | + return 'Clean tags and favorites'; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Updates the configuration after running an update |
|
| 70 | + */ |
|
| 71 | + public function run(IOutput $output) { |
|
| 72 | + $this->deleteOrphanTags($output); |
|
| 73 | + $this->deleteOrphanFileEntries($output); |
|
| 74 | + $this->deleteOrphanTagEntries($output); |
|
| 75 | + $this->deleteOrphanCategoryEntries($output); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Delete tags for deleted users |
|
| 80 | + */ |
|
| 81 | + protected function deleteOrphanTags(IOutput $output) { |
|
| 82 | + $offset = 0; |
|
| 83 | + while ($this->checkTags($offset)) { |
|
| 84 | + $offset += 50; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags)); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + protected function checkTags($offset) { |
|
| 91 | + $query = $this->connection->getQueryBuilder(); |
|
| 92 | + $query->select('uid') |
|
| 93 | + ->from('vcategory') |
|
| 94 | + ->groupBy('uid') |
|
| 95 | + ->orderBy('uid') |
|
| 96 | + ->setMaxResults(50) |
|
| 97 | + ->setFirstResult($offset); |
|
| 98 | + $result = $query->execute(); |
|
| 99 | + |
|
| 100 | + $users = []; |
|
| 101 | + $hadResults = false; |
|
| 102 | + while ($row = $result->fetch()) { |
|
| 103 | + $hadResults = true; |
|
| 104 | + if (!$this->userManager->userExists($row['uid'])) { |
|
| 105 | + $users[] = $row['uid']; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + $result->closeCursor(); |
|
| 109 | + |
|
| 110 | + if (!$hadResults) { |
|
| 111 | + // No more tags, stop looping |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if (!empty($users)) { |
|
| 116 | + $query = $this->connection->getQueryBuilder(); |
|
| 117 | + $query->delete('vcategory') |
|
| 118 | + ->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 119 | + $this->deletedTags += $query->execute(); |
|
| 120 | + } |
|
| 121 | + return true; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Delete tag entries for deleted files |
|
| 126 | + */ |
|
| 127 | + protected function deleteOrphanFileEntries(IOutput $output) { |
|
| 128 | + $this->deleteOrphanEntries( |
|
| 129 | + $output, |
|
| 130 | + '%d tags for delete files have been removed.', |
|
| 131 | + 'vcategory_to_object', 'objid', |
|
| 132 | + 'filecache', 'fileid', 'path_hash' |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Delete tag entries for deleted tags |
|
| 138 | + */ |
|
| 139 | + protected function deleteOrphanTagEntries(IOutput $output) { |
|
| 140 | + $this->deleteOrphanEntries( |
|
| 141 | + $output, |
|
| 142 | + '%d tag entries for deleted tags have been removed.', |
|
| 143 | + 'vcategory_to_object', 'categoryid', |
|
| 144 | + 'vcategory', 'id', 'uid' |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Delete tags that have no entries |
|
| 150 | + */ |
|
| 151 | + protected function deleteOrphanCategoryEntries(IOutput $output) { |
|
| 152 | + $this->deleteOrphanEntries( |
|
| 153 | + $output, |
|
| 154 | + '%d tags with no entries have been removed.', |
|
| 155 | + 'vcategory', 'id', |
|
| 156 | + 'vcategory_to_object', 'categoryid', 'type' |
|
| 157 | + ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable |
|
| 162 | + * |
|
| 163 | + * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks |
|
| 164 | + * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable |
|
| 165 | + * is being deleted. |
|
| 166 | + * |
|
| 167 | + * @param string $repairInfo |
|
| 168 | + * @param string $deleteTable |
|
| 169 | + * @param string $deleteId |
|
| 170 | + * @param string $sourceTable |
|
| 171 | + * @param string $sourceId |
|
| 172 | + * @param string $sourceNullColumn If this column is null in the source table, |
|
| 173 | + * the entry is deleted in the $deleteTable |
|
| 174 | + */ |
|
| 175 | + protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
|
| 176 | + $qb = $this->connection->getQueryBuilder(); |
|
| 177 | + |
|
| 178 | + $qb->select('d.' . $deleteId) |
|
| 179 | + ->from($deleteTable, 'd') |
|
| 180 | + ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
| 181 | + ->where( |
|
| 182 | + $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
|
| 183 | + ) |
|
| 184 | + ->andWhere( |
|
| 185 | + $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
| 186 | + ); |
|
| 187 | + $result = $qb->execute(); |
|
| 188 | + |
|
| 189 | + $orphanItems = []; |
|
| 190 | + while ($row = $result->fetch()) { |
|
| 191 | + $orphanItems[] = (int) $row[$deleteId]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (!empty($orphanItems)) { |
|
| 195 | + $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
| 196 | + foreach ($orphanItemsBatch as $items) { |
|
| 197 | + $qb->delete($deleteTable) |
|
| 198 | + ->where( |
|
| 199 | + $qb->expr()->eq('type', $qb->expr()->literal('files')) |
|
| 200 | + ) |
|
| 201 | + ->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids'))); |
|
| 202 | + $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
| 203 | + $qb->execute(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if ($repairInfo) { |
|
| 208 | + $output->info(sprintf($repairInfo, count($orphanItems))); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | 211 | } |