@@ -46,448 +46,448 @@ |
||
| 46 | 46 | * Cache mounts points per user in the cache so we can easily look them up |
| 47 | 47 | */ |
| 48 | 48 | class UserMountCache implements IUserMountCache { |
| 49 | - private IDBConnection $connection; |
|
| 50 | - private IUserManager $userManager; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Cached mount info. |
|
| 54 | - * @var CappedMemoryCache<ICachedMountInfo[]> |
|
| 55 | - **/ |
|
| 56 | - private CappedMemoryCache $mountsForUsers; |
|
| 57 | - private LoggerInterface $logger; |
|
| 58 | - /** @var CappedMemoryCache<array> */ |
|
| 59 | - private CappedMemoryCache $cacheInfoCache; |
|
| 60 | - private IEventLogger $eventLogger; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * UserMountCache constructor. |
|
| 64 | - */ |
|
| 65 | - public function __construct( |
|
| 66 | - IDBConnection $connection, |
|
| 67 | - IUserManager $userManager, |
|
| 68 | - LoggerInterface $logger, |
|
| 69 | - IEventLogger $eventLogger |
|
| 70 | - ) { |
|
| 71 | - $this->connection = $connection; |
|
| 72 | - $this->userManager = $userManager; |
|
| 73 | - $this->logger = $logger; |
|
| 74 | - $this->eventLogger = $eventLogger; |
|
| 75 | - $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 76 | - $this->mountsForUsers = new CappedMemoryCache(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function registerMounts(IUser $user, array $mounts, array $mountProviderClasses = null) { |
|
| 80 | - $this->eventLogger->start('fs:setup:user:register', 'Registering mounts for user'); |
|
| 81 | - // filter out non-proper storages coming from unit tests |
|
| 82 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 83 | - return $mount instanceof SharedMount || ($mount->getStorage() && $mount->getStorage()->getCache()); |
|
| 84 | - }); |
|
| 85 | - /** @var ICachedMountInfo[] $newMounts */ |
|
| 86 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 87 | - // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
| 88 | - if ($mount->getStorageRootId() === -1) { |
|
| 89 | - return null; |
|
| 90 | - } else { |
|
| 91 | - return new LazyStorageMountInfo($user, $mount); |
|
| 92 | - } |
|
| 93 | - }, $mounts); |
|
| 94 | - $newMounts = array_values(array_filter($newMounts)); |
|
| 95 | - $newMountKeys = array_map(function (ICachedMountInfo $mount) { |
|
| 96 | - return $mount->getRootId() . '::' . $mount->getMountPoint(); |
|
| 97 | - }, $newMounts); |
|
| 98 | - $newMounts = array_combine($newMountKeys, $newMounts); |
|
| 99 | - |
|
| 100 | - $cachedMounts = $this->getMountsForUser($user); |
|
| 101 | - if (is_array($mountProviderClasses)) { |
|
| 102 | - $cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) { |
|
| 103 | - // for existing mounts that didn't have a mount provider set |
|
| 104 | - // we still want the ones that map to new mounts |
|
| 105 | - $mountKey = $mountInfo->getRootId() . '::' . $mountInfo->getMountPoint(); |
|
| 106 | - if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountKey])) { |
|
| 107 | - return true; |
|
| 108 | - } |
|
| 109 | - return in_array($mountInfo->getMountProvider(), $mountProviderClasses); |
|
| 110 | - }); |
|
| 111 | - } |
|
| 112 | - $cachedRootKeys = array_map(function (ICachedMountInfo $mount) { |
|
| 113 | - return $mount->getRootId() . '::' . $mount->getMountPoint(); |
|
| 114 | - }, $cachedMounts); |
|
| 115 | - $cachedMounts = array_combine($cachedRootKeys, $cachedMounts); |
|
| 116 | - |
|
| 117 | - $addedMounts = []; |
|
| 118 | - $removedMounts = []; |
|
| 119 | - |
|
| 120 | - foreach ($newMounts as $mountKey => $newMount) { |
|
| 121 | - if (!isset($cachedMounts[$mountKey])) { |
|
| 122 | - $addedMounts[] = $newMount; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - foreach ($cachedMounts as $mountKey => $cachedMount) { |
|
| 127 | - if (!isset($newMounts[$mountKey])) { |
|
| 128 | - $removedMounts[] = $cachedMount; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
| 133 | - |
|
| 134 | - $this->connection->beginTransaction(); |
|
| 135 | - try { |
|
| 136 | - foreach ($addedMounts as $mount) { |
|
| 137 | - $this->addToCache($mount); |
|
| 138 | - /** @psalm-suppress InvalidArgument */ |
|
| 139 | - $this->mountsForUsers[$user->getUID()][] = $mount; |
|
| 140 | - } |
|
| 141 | - foreach ($removedMounts as $mount) { |
|
| 142 | - $this->removeFromCache($mount); |
|
| 143 | - $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
| 144 | - unset($this->mountsForUsers[$user->getUID()][$index]); |
|
| 145 | - } |
|
| 146 | - foreach ($changedMounts as $mount) { |
|
| 147 | - $this->updateCachedMount($mount); |
|
| 148 | - } |
|
| 149 | - $this->connection->commit(); |
|
| 150 | - } catch (\Throwable $e) { |
|
| 151 | - $this->connection->rollBack(); |
|
| 152 | - throw $e; |
|
| 153 | - } |
|
| 154 | - $this->eventLogger->end('fs:setup:user:register'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param ICachedMountInfo[] $newMounts |
|
| 159 | - * @param ICachedMountInfo[] $cachedMounts |
|
| 160 | - * @return ICachedMountInfo[] |
|
| 161 | - */ |
|
| 162 | - private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
| 163 | - $new = []; |
|
| 164 | - foreach ($newMounts as $mount) { |
|
| 165 | - $new[$mount->getRootId() . '::' . $mount->getMountPoint()] = $mount; |
|
| 166 | - } |
|
| 167 | - $changed = []; |
|
| 168 | - foreach ($cachedMounts as $cachedMount) { |
|
| 169 | - $key = $cachedMount->getRootId() . '::' . $cachedMount->getMountPoint(); |
|
| 170 | - if (isset($new[$key])) { |
|
| 171 | - $newMount = $new[$key]; |
|
| 172 | - if ( |
|
| 173 | - $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
| 174 | - $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
| 175 | - $newMount->getMountId() !== $cachedMount->getMountId() || |
|
| 176 | - $newMount->getMountProvider() !== $cachedMount->getMountProvider() |
|
| 177 | - ) { |
|
| 178 | - $changed[] = $newMount; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - return $changed; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - private function addToCache(ICachedMountInfo $mount) { |
|
| 186 | - if ($mount->getStorageId() !== -1) { |
|
| 187 | - $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
| 188 | - 'storage_id' => $mount->getStorageId(), |
|
| 189 | - 'root_id' => $mount->getRootId(), |
|
| 190 | - 'user_id' => $mount->getUser()->getUID(), |
|
| 191 | - 'mount_point' => $mount->getMountPoint(), |
|
| 192 | - 'mount_id' => $mount->getMountId(), |
|
| 193 | - 'mount_provider_class' => $mount->getMountProvider(), |
|
| 194 | - ], ['root_id', 'user_id', 'mount_point']); |
|
| 195 | - } else { |
|
| 196 | - // in some cases this is legitimate, like orphaned shares |
|
| 197 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - private function updateCachedMount(ICachedMountInfo $mount) { |
|
| 202 | - $builder = $this->connection->getQueryBuilder(); |
|
| 203 | - |
|
| 204 | - $query = $builder->update('mounts') |
|
| 205 | - ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
| 206 | - ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
| 207 | - ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
| 208 | - ->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider())) |
|
| 209 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 210 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 211 | - |
|
| 212 | - $query->execute(); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - private function removeFromCache(ICachedMountInfo $mount) { |
|
| 216 | - $builder = $this->connection->getQueryBuilder(); |
|
| 217 | - |
|
| 218 | - $query = $builder->delete('mounts') |
|
| 219 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 220 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))) |
|
| 221 | - ->andWhere($builder->expr()->eq('mount_point', $builder->createNamedParameter($mount->getMountPoint()))); |
|
| 222 | - $query->execute(); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - private function dbRowToMountInfo(array $row) { |
|
| 226 | - $user = $this->userManager->get($row['user_id']); |
|
| 227 | - if (is_null($user)) { |
|
| 228 | - return null; |
|
| 229 | - } |
|
| 230 | - $mount_id = $row['mount_id']; |
|
| 231 | - if (!is_null($mount_id)) { |
|
| 232 | - $mount_id = (int)$mount_id; |
|
| 233 | - } |
|
| 234 | - return new CachedMountInfo( |
|
| 235 | - $user, |
|
| 236 | - (int)$row['storage_id'], |
|
| 237 | - (int)$row['root_id'], |
|
| 238 | - $row['mount_point'], |
|
| 239 | - $row['mount_provider_class'] ?? '', |
|
| 240 | - $mount_id, |
|
| 241 | - isset($row['path']) ? $row['path'] : '', |
|
| 242 | - ); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param IUser $user |
|
| 247 | - * @return ICachedMountInfo[] |
|
| 248 | - */ |
|
| 249 | - public function getMountsForUser(IUser $user) { |
|
| 250 | - if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
| 251 | - $builder = $this->connection->getQueryBuilder(); |
|
| 252 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 253 | - ->from('mounts', 'm') |
|
| 254 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 255 | - ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
| 256 | - |
|
| 257 | - $result = $query->execute(); |
|
| 258 | - $rows = $result->fetchAll(); |
|
| 259 | - $result->closeCursor(); |
|
| 260 | - |
|
| 261 | - $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 262 | - } |
|
| 263 | - return $this->mountsForUsers[$user->getUID()]; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param int $numericStorageId |
|
| 268 | - * @param string|null $user limit the results to a single user |
|
| 269 | - * @return CachedMountInfo[] |
|
| 270 | - */ |
|
| 271 | - public function getMountsForStorageId($numericStorageId, $user = null) { |
|
| 272 | - $builder = $this->connection->getQueryBuilder(); |
|
| 273 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 274 | - ->from('mounts', 'm') |
|
| 275 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 276 | - ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
| 277 | - |
|
| 278 | - if ($user) { |
|
| 279 | - $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - $result = $query->execute(); |
|
| 283 | - $rows = $result->fetchAll(); |
|
| 284 | - $result->closeCursor(); |
|
| 285 | - |
|
| 286 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param int $rootFileId |
|
| 291 | - * @return CachedMountInfo[] |
|
| 292 | - */ |
|
| 293 | - public function getMountsForRootId($rootFileId) { |
|
| 294 | - $builder = $this->connection->getQueryBuilder(); |
|
| 295 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 296 | - ->from('mounts', 'm') |
|
| 297 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 298 | - ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
| 299 | - |
|
| 300 | - $result = $query->execute(); |
|
| 301 | - $rows = $result->fetchAll(); |
|
| 302 | - $result->closeCursor(); |
|
| 303 | - |
|
| 304 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @param $fileId |
|
| 309 | - * @return array{int, string, int} |
|
| 310 | - * @throws \OCP\Files\NotFoundException |
|
| 311 | - */ |
|
| 312 | - private function getCacheInfoFromFileId($fileId): array { |
|
| 313 | - if (!isset($this->cacheInfoCache[$fileId])) { |
|
| 314 | - $builder = $this->connection->getQueryBuilder(); |
|
| 315 | - $query = $builder->select('storage', 'path', 'mimetype') |
|
| 316 | - ->from('filecache') |
|
| 317 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
| 318 | - |
|
| 319 | - $result = $query->execute(); |
|
| 320 | - $row = $result->fetch(); |
|
| 321 | - $result->closeCursor(); |
|
| 322 | - |
|
| 323 | - if (is_array($row)) { |
|
| 324 | - $this->cacheInfoCache[$fileId] = [ |
|
| 325 | - (int)$row['storage'], |
|
| 326 | - (string)$row['path'], |
|
| 327 | - (int)$row['mimetype'] |
|
| 328 | - ]; |
|
| 329 | - } else { |
|
| 330 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - return $this->cacheInfoCache[$fileId]; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param int $fileId |
|
| 338 | - * @param string|null $user optionally restrict the results to a single user |
|
| 339 | - * @return ICachedMountFileInfo[] |
|
| 340 | - * @since 9.0.0 |
|
| 341 | - */ |
|
| 342 | - public function getMountsForFileId($fileId, $user = null) { |
|
| 343 | - try { |
|
| 344 | - [$storageId, $internalPath] = $this->getCacheInfoFromFileId($fileId); |
|
| 345 | - } catch (NotFoundException $e) { |
|
| 346 | - return []; |
|
| 347 | - } |
|
| 348 | - $builder = $this->connection->getQueryBuilder(); |
|
| 349 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 350 | - ->from('mounts', 'm') |
|
| 351 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 352 | - ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 353 | - |
|
| 354 | - if ($user) { |
|
| 355 | - $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $result = $query->execute(); |
|
| 359 | - $rows = $result->fetchAll(); |
|
| 360 | - $result->closeCursor(); |
|
| 361 | - // filter mounts that are from the same storage but a different directory |
|
| 362 | - $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) { |
|
| 363 | - if ($fileId === (int)$row['root_id']) { |
|
| 364 | - return true; |
|
| 365 | - } |
|
| 366 | - $internalMountPath = $row['path'] ?? ''; |
|
| 367 | - |
|
| 368 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 369 | - }); |
|
| 370 | - |
|
| 371 | - $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts)); |
|
| 372 | - return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
| 373 | - return new CachedMountFileInfo( |
|
| 374 | - $mount->getUser(), |
|
| 375 | - $mount->getStorageId(), |
|
| 376 | - $mount->getRootId(), |
|
| 377 | - $mount->getMountPoint(), |
|
| 378 | - $mount->getMountId(), |
|
| 379 | - $mount->getMountProvider(), |
|
| 380 | - $mount->getRootInternalPath(), |
|
| 381 | - $internalPath |
|
| 382 | - ); |
|
| 383 | - }, $filteredMounts); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Remove all cached mounts for a user |
|
| 388 | - * |
|
| 389 | - * @param IUser $user |
|
| 390 | - */ |
|
| 391 | - public function removeUserMounts(IUser $user) { |
|
| 392 | - $builder = $this->connection->getQueryBuilder(); |
|
| 393 | - |
|
| 394 | - $query = $builder->delete('mounts') |
|
| 395 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
| 396 | - $query->execute(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - public function removeUserStorageMount($storageId, $userId) { |
|
| 400 | - $builder = $this->connection->getQueryBuilder(); |
|
| 401 | - |
|
| 402 | - $query = $builder->delete('mounts') |
|
| 403 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
| 404 | - ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 405 | - $query->execute(); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - public function remoteStorageMounts($storageId) { |
|
| 409 | - $builder = $this->connection->getQueryBuilder(); |
|
| 410 | - |
|
| 411 | - $query = $builder->delete('mounts') |
|
| 412 | - ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 413 | - $query->execute(); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * @param array $users |
|
| 418 | - * @return array |
|
| 419 | - */ |
|
| 420 | - public function getUsedSpaceForUsers(array $users) { |
|
| 421 | - $builder = $this->connection->getQueryBuilder(); |
|
| 422 | - |
|
| 423 | - $slash = $builder->createNamedParameter('/'); |
|
| 424 | - |
|
| 425 | - $mountPoint = $builder->func()->concat( |
|
| 426 | - $builder->func()->concat($slash, 'user_id'), |
|
| 427 | - $slash |
|
| 428 | - ); |
|
| 429 | - |
|
| 430 | - $userIds = array_map(function (IUser $user) { |
|
| 431 | - return $user->getUID(); |
|
| 432 | - }, $users); |
|
| 433 | - |
|
| 434 | - $query = $builder->select('m.user_id', 'f.size') |
|
| 435 | - ->from('mounts', 'm') |
|
| 436 | - ->innerJoin('m', 'filecache', 'f', |
|
| 437 | - $builder->expr()->andX( |
|
| 438 | - $builder->expr()->eq('m.storage_id', 'f.storage'), |
|
| 439 | - $builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files'))) |
|
| 440 | - )) |
|
| 441 | - ->where($builder->expr()->eq('m.mount_point', $mountPoint)) |
|
| 442 | - ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 443 | - |
|
| 444 | - $result = $query->execute(); |
|
| 445 | - |
|
| 446 | - $results = []; |
|
| 447 | - while ($row = $result->fetch()) { |
|
| 448 | - $results[$row['user_id']] = $row['size']; |
|
| 449 | - } |
|
| 450 | - $result->closeCursor(); |
|
| 451 | - return $results; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - public function clear(): void { |
|
| 455 | - $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 456 | - $this->mountsForUsers = new CappedMemoryCache(); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - public function getMountForPath(IUser $user, string $path): ICachedMountInfo { |
|
| 460 | - $mounts = $this->getMountsForUser($user); |
|
| 461 | - $mountPoints = array_map(function (ICachedMountInfo $mount) { |
|
| 462 | - return $mount->getMountPoint(); |
|
| 463 | - }, $mounts); |
|
| 464 | - $mounts = array_combine($mountPoints, $mounts); |
|
| 465 | - |
|
| 466 | - $current = $path; |
|
| 467 | - // walk up the directory tree until we find a path that has a mountpoint set |
|
| 468 | - // the loop will return if a mountpoint is found or break if none are found |
|
| 469 | - while (true) { |
|
| 470 | - $mountPoint = $current . '/'; |
|
| 471 | - if (isset($mounts[$mountPoint])) { |
|
| 472 | - return $mounts[$mountPoint]; |
|
| 473 | - } elseif ($current === '') { |
|
| 474 | - break; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $current = dirname($current); |
|
| 478 | - if ($current === '.' || $current === '/') { |
|
| 479 | - $current = ''; |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - throw new NotFoundException("No cached mount for path " . $path); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - public function getMountsInPath(IUser $user, string $path): array { |
|
| 487 | - $path = rtrim($path, '/') . '/'; |
|
| 488 | - $mounts = $this->getMountsForUser($user); |
|
| 489 | - return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) { |
|
| 490 | - return $mount->getMountPoint() !== $path && strpos($mount->getMountPoint(), $path) === 0; |
|
| 491 | - }); |
|
| 492 | - } |
|
| 49 | + private IDBConnection $connection; |
|
| 50 | + private IUserManager $userManager; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Cached mount info. |
|
| 54 | + * @var CappedMemoryCache<ICachedMountInfo[]> |
|
| 55 | + **/ |
|
| 56 | + private CappedMemoryCache $mountsForUsers; |
|
| 57 | + private LoggerInterface $logger; |
|
| 58 | + /** @var CappedMemoryCache<array> */ |
|
| 59 | + private CappedMemoryCache $cacheInfoCache; |
|
| 60 | + private IEventLogger $eventLogger; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * UserMountCache constructor. |
|
| 64 | + */ |
|
| 65 | + public function __construct( |
|
| 66 | + IDBConnection $connection, |
|
| 67 | + IUserManager $userManager, |
|
| 68 | + LoggerInterface $logger, |
|
| 69 | + IEventLogger $eventLogger |
|
| 70 | + ) { |
|
| 71 | + $this->connection = $connection; |
|
| 72 | + $this->userManager = $userManager; |
|
| 73 | + $this->logger = $logger; |
|
| 74 | + $this->eventLogger = $eventLogger; |
|
| 75 | + $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 76 | + $this->mountsForUsers = new CappedMemoryCache(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function registerMounts(IUser $user, array $mounts, array $mountProviderClasses = null) { |
|
| 80 | + $this->eventLogger->start('fs:setup:user:register', 'Registering mounts for user'); |
|
| 81 | + // filter out non-proper storages coming from unit tests |
|
| 82 | + $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 83 | + return $mount instanceof SharedMount || ($mount->getStorage() && $mount->getStorage()->getCache()); |
|
| 84 | + }); |
|
| 85 | + /** @var ICachedMountInfo[] $newMounts */ |
|
| 86 | + $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 87 | + // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
| 88 | + if ($mount->getStorageRootId() === -1) { |
|
| 89 | + return null; |
|
| 90 | + } else { |
|
| 91 | + return new LazyStorageMountInfo($user, $mount); |
|
| 92 | + } |
|
| 93 | + }, $mounts); |
|
| 94 | + $newMounts = array_values(array_filter($newMounts)); |
|
| 95 | + $newMountKeys = array_map(function (ICachedMountInfo $mount) { |
|
| 96 | + return $mount->getRootId() . '::' . $mount->getMountPoint(); |
|
| 97 | + }, $newMounts); |
|
| 98 | + $newMounts = array_combine($newMountKeys, $newMounts); |
|
| 99 | + |
|
| 100 | + $cachedMounts = $this->getMountsForUser($user); |
|
| 101 | + if (is_array($mountProviderClasses)) { |
|
| 102 | + $cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) { |
|
| 103 | + // for existing mounts that didn't have a mount provider set |
|
| 104 | + // we still want the ones that map to new mounts |
|
| 105 | + $mountKey = $mountInfo->getRootId() . '::' . $mountInfo->getMountPoint(); |
|
| 106 | + if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountKey])) { |
|
| 107 | + return true; |
|
| 108 | + } |
|
| 109 | + return in_array($mountInfo->getMountProvider(), $mountProviderClasses); |
|
| 110 | + }); |
|
| 111 | + } |
|
| 112 | + $cachedRootKeys = array_map(function (ICachedMountInfo $mount) { |
|
| 113 | + return $mount->getRootId() . '::' . $mount->getMountPoint(); |
|
| 114 | + }, $cachedMounts); |
|
| 115 | + $cachedMounts = array_combine($cachedRootKeys, $cachedMounts); |
|
| 116 | + |
|
| 117 | + $addedMounts = []; |
|
| 118 | + $removedMounts = []; |
|
| 119 | + |
|
| 120 | + foreach ($newMounts as $mountKey => $newMount) { |
|
| 121 | + if (!isset($cachedMounts[$mountKey])) { |
|
| 122 | + $addedMounts[] = $newMount; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + foreach ($cachedMounts as $mountKey => $cachedMount) { |
|
| 127 | + if (!isset($newMounts[$mountKey])) { |
|
| 128 | + $removedMounts[] = $cachedMount; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
| 133 | + |
|
| 134 | + $this->connection->beginTransaction(); |
|
| 135 | + try { |
|
| 136 | + foreach ($addedMounts as $mount) { |
|
| 137 | + $this->addToCache($mount); |
|
| 138 | + /** @psalm-suppress InvalidArgument */ |
|
| 139 | + $this->mountsForUsers[$user->getUID()][] = $mount; |
|
| 140 | + } |
|
| 141 | + foreach ($removedMounts as $mount) { |
|
| 142 | + $this->removeFromCache($mount); |
|
| 143 | + $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
| 144 | + unset($this->mountsForUsers[$user->getUID()][$index]); |
|
| 145 | + } |
|
| 146 | + foreach ($changedMounts as $mount) { |
|
| 147 | + $this->updateCachedMount($mount); |
|
| 148 | + } |
|
| 149 | + $this->connection->commit(); |
|
| 150 | + } catch (\Throwable $e) { |
|
| 151 | + $this->connection->rollBack(); |
|
| 152 | + throw $e; |
|
| 153 | + } |
|
| 154 | + $this->eventLogger->end('fs:setup:user:register'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param ICachedMountInfo[] $newMounts |
|
| 159 | + * @param ICachedMountInfo[] $cachedMounts |
|
| 160 | + * @return ICachedMountInfo[] |
|
| 161 | + */ |
|
| 162 | + private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
| 163 | + $new = []; |
|
| 164 | + foreach ($newMounts as $mount) { |
|
| 165 | + $new[$mount->getRootId() . '::' . $mount->getMountPoint()] = $mount; |
|
| 166 | + } |
|
| 167 | + $changed = []; |
|
| 168 | + foreach ($cachedMounts as $cachedMount) { |
|
| 169 | + $key = $cachedMount->getRootId() . '::' . $cachedMount->getMountPoint(); |
|
| 170 | + if (isset($new[$key])) { |
|
| 171 | + $newMount = $new[$key]; |
|
| 172 | + if ( |
|
| 173 | + $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
| 174 | + $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
| 175 | + $newMount->getMountId() !== $cachedMount->getMountId() || |
|
| 176 | + $newMount->getMountProvider() !== $cachedMount->getMountProvider() |
|
| 177 | + ) { |
|
| 178 | + $changed[] = $newMount; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + return $changed; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + private function addToCache(ICachedMountInfo $mount) { |
|
| 186 | + if ($mount->getStorageId() !== -1) { |
|
| 187 | + $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
| 188 | + 'storage_id' => $mount->getStorageId(), |
|
| 189 | + 'root_id' => $mount->getRootId(), |
|
| 190 | + 'user_id' => $mount->getUser()->getUID(), |
|
| 191 | + 'mount_point' => $mount->getMountPoint(), |
|
| 192 | + 'mount_id' => $mount->getMountId(), |
|
| 193 | + 'mount_provider_class' => $mount->getMountProvider(), |
|
| 194 | + ], ['root_id', 'user_id', 'mount_point']); |
|
| 195 | + } else { |
|
| 196 | + // in some cases this is legitimate, like orphaned shares |
|
| 197 | + $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + private function updateCachedMount(ICachedMountInfo $mount) { |
|
| 202 | + $builder = $this->connection->getQueryBuilder(); |
|
| 203 | + |
|
| 204 | + $query = $builder->update('mounts') |
|
| 205 | + ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
| 206 | + ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
| 207 | + ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
| 208 | + ->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider())) |
|
| 209 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 210 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 211 | + |
|
| 212 | + $query->execute(); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + private function removeFromCache(ICachedMountInfo $mount) { |
|
| 216 | + $builder = $this->connection->getQueryBuilder(); |
|
| 217 | + |
|
| 218 | + $query = $builder->delete('mounts') |
|
| 219 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 220 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))) |
|
| 221 | + ->andWhere($builder->expr()->eq('mount_point', $builder->createNamedParameter($mount->getMountPoint()))); |
|
| 222 | + $query->execute(); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + private function dbRowToMountInfo(array $row) { |
|
| 226 | + $user = $this->userManager->get($row['user_id']); |
|
| 227 | + if (is_null($user)) { |
|
| 228 | + return null; |
|
| 229 | + } |
|
| 230 | + $mount_id = $row['mount_id']; |
|
| 231 | + if (!is_null($mount_id)) { |
|
| 232 | + $mount_id = (int)$mount_id; |
|
| 233 | + } |
|
| 234 | + return new CachedMountInfo( |
|
| 235 | + $user, |
|
| 236 | + (int)$row['storage_id'], |
|
| 237 | + (int)$row['root_id'], |
|
| 238 | + $row['mount_point'], |
|
| 239 | + $row['mount_provider_class'] ?? '', |
|
| 240 | + $mount_id, |
|
| 241 | + isset($row['path']) ? $row['path'] : '', |
|
| 242 | + ); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param IUser $user |
|
| 247 | + * @return ICachedMountInfo[] |
|
| 248 | + */ |
|
| 249 | + public function getMountsForUser(IUser $user) { |
|
| 250 | + if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
| 251 | + $builder = $this->connection->getQueryBuilder(); |
|
| 252 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 253 | + ->from('mounts', 'm') |
|
| 254 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 255 | + ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
| 256 | + |
|
| 257 | + $result = $query->execute(); |
|
| 258 | + $rows = $result->fetchAll(); |
|
| 259 | + $result->closeCursor(); |
|
| 260 | + |
|
| 261 | + $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 262 | + } |
|
| 263 | + return $this->mountsForUsers[$user->getUID()]; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param int $numericStorageId |
|
| 268 | + * @param string|null $user limit the results to a single user |
|
| 269 | + * @return CachedMountInfo[] |
|
| 270 | + */ |
|
| 271 | + public function getMountsForStorageId($numericStorageId, $user = null) { |
|
| 272 | + $builder = $this->connection->getQueryBuilder(); |
|
| 273 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 274 | + ->from('mounts', 'm') |
|
| 275 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 276 | + ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
| 277 | + |
|
| 278 | + if ($user) { |
|
| 279 | + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + $result = $query->execute(); |
|
| 283 | + $rows = $result->fetchAll(); |
|
| 284 | + $result->closeCursor(); |
|
| 285 | + |
|
| 286 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param int $rootFileId |
|
| 291 | + * @return CachedMountInfo[] |
|
| 292 | + */ |
|
| 293 | + public function getMountsForRootId($rootFileId) { |
|
| 294 | + $builder = $this->connection->getQueryBuilder(); |
|
| 295 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 296 | + ->from('mounts', 'm') |
|
| 297 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 298 | + ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
| 299 | + |
|
| 300 | + $result = $query->execute(); |
|
| 301 | + $rows = $result->fetchAll(); |
|
| 302 | + $result->closeCursor(); |
|
| 303 | + |
|
| 304 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @param $fileId |
|
| 309 | + * @return array{int, string, int} |
|
| 310 | + * @throws \OCP\Files\NotFoundException |
|
| 311 | + */ |
|
| 312 | + private function getCacheInfoFromFileId($fileId): array { |
|
| 313 | + if (!isset($this->cacheInfoCache[$fileId])) { |
|
| 314 | + $builder = $this->connection->getQueryBuilder(); |
|
| 315 | + $query = $builder->select('storage', 'path', 'mimetype') |
|
| 316 | + ->from('filecache') |
|
| 317 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
| 318 | + |
|
| 319 | + $result = $query->execute(); |
|
| 320 | + $row = $result->fetch(); |
|
| 321 | + $result->closeCursor(); |
|
| 322 | + |
|
| 323 | + if (is_array($row)) { |
|
| 324 | + $this->cacheInfoCache[$fileId] = [ |
|
| 325 | + (int)$row['storage'], |
|
| 326 | + (string)$row['path'], |
|
| 327 | + (int)$row['mimetype'] |
|
| 328 | + ]; |
|
| 329 | + } else { |
|
| 330 | + throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + return $this->cacheInfoCache[$fileId]; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param int $fileId |
|
| 338 | + * @param string|null $user optionally restrict the results to a single user |
|
| 339 | + * @return ICachedMountFileInfo[] |
|
| 340 | + * @since 9.0.0 |
|
| 341 | + */ |
|
| 342 | + public function getMountsForFileId($fileId, $user = null) { |
|
| 343 | + try { |
|
| 344 | + [$storageId, $internalPath] = $this->getCacheInfoFromFileId($fileId); |
|
| 345 | + } catch (NotFoundException $e) { |
|
| 346 | + return []; |
|
| 347 | + } |
|
| 348 | + $builder = $this->connection->getQueryBuilder(); |
|
| 349 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 350 | + ->from('mounts', 'm') |
|
| 351 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 352 | + ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 353 | + |
|
| 354 | + if ($user) { |
|
| 355 | + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $result = $query->execute(); |
|
| 359 | + $rows = $result->fetchAll(); |
|
| 360 | + $result->closeCursor(); |
|
| 361 | + // filter mounts that are from the same storage but a different directory |
|
| 362 | + $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) { |
|
| 363 | + if ($fileId === (int)$row['root_id']) { |
|
| 364 | + return true; |
|
| 365 | + } |
|
| 366 | + $internalMountPath = $row['path'] ?? ''; |
|
| 367 | + |
|
| 368 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 369 | + }); |
|
| 370 | + |
|
| 371 | + $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts)); |
|
| 372 | + return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
| 373 | + return new CachedMountFileInfo( |
|
| 374 | + $mount->getUser(), |
|
| 375 | + $mount->getStorageId(), |
|
| 376 | + $mount->getRootId(), |
|
| 377 | + $mount->getMountPoint(), |
|
| 378 | + $mount->getMountId(), |
|
| 379 | + $mount->getMountProvider(), |
|
| 380 | + $mount->getRootInternalPath(), |
|
| 381 | + $internalPath |
|
| 382 | + ); |
|
| 383 | + }, $filteredMounts); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Remove all cached mounts for a user |
|
| 388 | + * |
|
| 389 | + * @param IUser $user |
|
| 390 | + */ |
|
| 391 | + public function removeUserMounts(IUser $user) { |
|
| 392 | + $builder = $this->connection->getQueryBuilder(); |
|
| 393 | + |
|
| 394 | + $query = $builder->delete('mounts') |
|
| 395 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
| 396 | + $query->execute(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + public function removeUserStorageMount($storageId, $userId) { |
|
| 400 | + $builder = $this->connection->getQueryBuilder(); |
|
| 401 | + |
|
| 402 | + $query = $builder->delete('mounts') |
|
| 403 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
| 404 | + ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 405 | + $query->execute(); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + public function remoteStorageMounts($storageId) { |
|
| 409 | + $builder = $this->connection->getQueryBuilder(); |
|
| 410 | + |
|
| 411 | + $query = $builder->delete('mounts') |
|
| 412 | + ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 413 | + $query->execute(); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @param array $users |
|
| 418 | + * @return array |
|
| 419 | + */ |
|
| 420 | + public function getUsedSpaceForUsers(array $users) { |
|
| 421 | + $builder = $this->connection->getQueryBuilder(); |
|
| 422 | + |
|
| 423 | + $slash = $builder->createNamedParameter('/'); |
|
| 424 | + |
|
| 425 | + $mountPoint = $builder->func()->concat( |
|
| 426 | + $builder->func()->concat($slash, 'user_id'), |
|
| 427 | + $slash |
|
| 428 | + ); |
|
| 429 | + |
|
| 430 | + $userIds = array_map(function (IUser $user) { |
|
| 431 | + return $user->getUID(); |
|
| 432 | + }, $users); |
|
| 433 | + |
|
| 434 | + $query = $builder->select('m.user_id', 'f.size') |
|
| 435 | + ->from('mounts', 'm') |
|
| 436 | + ->innerJoin('m', 'filecache', 'f', |
|
| 437 | + $builder->expr()->andX( |
|
| 438 | + $builder->expr()->eq('m.storage_id', 'f.storage'), |
|
| 439 | + $builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files'))) |
|
| 440 | + )) |
|
| 441 | + ->where($builder->expr()->eq('m.mount_point', $mountPoint)) |
|
| 442 | + ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 443 | + |
|
| 444 | + $result = $query->execute(); |
|
| 445 | + |
|
| 446 | + $results = []; |
|
| 447 | + while ($row = $result->fetch()) { |
|
| 448 | + $results[$row['user_id']] = $row['size']; |
|
| 449 | + } |
|
| 450 | + $result->closeCursor(); |
|
| 451 | + return $results; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + public function clear(): void { |
|
| 455 | + $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 456 | + $this->mountsForUsers = new CappedMemoryCache(); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + public function getMountForPath(IUser $user, string $path): ICachedMountInfo { |
|
| 460 | + $mounts = $this->getMountsForUser($user); |
|
| 461 | + $mountPoints = array_map(function (ICachedMountInfo $mount) { |
|
| 462 | + return $mount->getMountPoint(); |
|
| 463 | + }, $mounts); |
|
| 464 | + $mounts = array_combine($mountPoints, $mounts); |
|
| 465 | + |
|
| 466 | + $current = $path; |
|
| 467 | + // walk up the directory tree until we find a path that has a mountpoint set |
|
| 468 | + // the loop will return if a mountpoint is found or break if none are found |
|
| 469 | + while (true) { |
|
| 470 | + $mountPoint = $current . '/'; |
|
| 471 | + if (isset($mounts[$mountPoint])) { |
|
| 472 | + return $mounts[$mountPoint]; |
|
| 473 | + } elseif ($current === '') { |
|
| 474 | + break; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $current = dirname($current); |
|
| 478 | + if ($current === '.' || $current === '/') { |
|
| 479 | + $current = ''; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + throw new NotFoundException("No cached mount for path " . $path); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + public function getMountsInPath(IUser $user, string $path): array { |
|
| 487 | + $path = rtrim($path, '/') . '/'; |
|
| 488 | + $mounts = $this->getMountsForUser($user); |
|
| 489 | + return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) { |
|
| 490 | + return $mount->getMountPoint() !== $path && strpos($mount->getMountPoint(), $path) === 0; |
|
| 491 | + }); |
|
| 492 | + } |
|
| 493 | 493 | } |
@@ -79,11 +79,11 @@ discard block |
||
| 79 | 79 | public function registerMounts(IUser $user, array $mounts, array $mountProviderClasses = null) { |
| 80 | 80 | $this->eventLogger->start('fs:setup:user:register', 'Registering mounts for user'); |
| 81 | 81 | // filter out non-proper storages coming from unit tests |
| 82 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 82 | + $mounts = array_filter($mounts, function(IMountPoint $mount) { |
|
| 83 | 83 | return $mount instanceof SharedMount || ($mount->getStorage() && $mount->getStorage()->getCache()); |
| 84 | 84 | }); |
| 85 | 85 | /** @var ICachedMountInfo[] $newMounts */ |
| 86 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 86 | + $newMounts = array_map(function(IMountPoint $mount) use ($user) { |
|
| 87 | 87 | // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
| 88 | 88 | if ($mount->getStorageRootId() === -1) { |
| 89 | 89 | return null; |
@@ -92,25 +92,25 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | }, $mounts); |
| 94 | 94 | $newMounts = array_values(array_filter($newMounts)); |
| 95 | - $newMountKeys = array_map(function (ICachedMountInfo $mount) { |
|
| 96 | - return $mount->getRootId() . '::' . $mount->getMountPoint(); |
|
| 95 | + $newMountKeys = array_map(function(ICachedMountInfo $mount) { |
|
| 96 | + return $mount->getRootId().'::'.$mount->getMountPoint(); |
|
| 97 | 97 | }, $newMounts); |
| 98 | 98 | $newMounts = array_combine($newMountKeys, $newMounts); |
| 99 | 99 | |
| 100 | 100 | $cachedMounts = $this->getMountsForUser($user); |
| 101 | 101 | if (is_array($mountProviderClasses)) { |
| 102 | - $cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) { |
|
| 102 | + $cachedMounts = array_filter($cachedMounts, function(ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) { |
|
| 103 | 103 | // for existing mounts that didn't have a mount provider set |
| 104 | 104 | // we still want the ones that map to new mounts |
| 105 | - $mountKey = $mountInfo->getRootId() . '::' . $mountInfo->getMountPoint(); |
|
| 105 | + $mountKey = $mountInfo->getRootId().'::'.$mountInfo->getMountPoint(); |
|
| 106 | 106 | if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountKey])) { |
| 107 | 107 | return true; |
| 108 | 108 | } |
| 109 | 109 | return in_array($mountInfo->getMountProvider(), $mountProviderClasses); |
| 110 | 110 | }); |
| 111 | 111 | } |
| 112 | - $cachedRootKeys = array_map(function (ICachedMountInfo $mount) { |
|
| 113 | - return $mount->getRootId() . '::' . $mount->getMountPoint(); |
|
| 112 | + $cachedRootKeys = array_map(function(ICachedMountInfo $mount) { |
|
| 113 | + return $mount->getRootId().'::'.$mount->getMountPoint(); |
|
| 114 | 114 | }, $cachedMounts); |
| 115 | 115 | $cachedMounts = array_combine($cachedRootKeys, $cachedMounts); |
| 116 | 116 | |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | private function findChangedMounts(array $newMounts, array $cachedMounts) { |
| 163 | 163 | $new = []; |
| 164 | 164 | foreach ($newMounts as $mount) { |
| 165 | - $new[$mount->getRootId() . '::' . $mount->getMountPoint()] = $mount; |
|
| 165 | + $new[$mount->getRootId().'::'.$mount->getMountPoint()] = $mount; |
|
| 166 | 166 | } |
| 167 | 167 | $changed = []; |
| 168 | 168 | foreach ($cachedMounts as $cachedMount) { |
| 169 | - $key = $cachedMount->getRootId() . '::' . $cachedMount->getMountPoint(); |
|
| 169 | + $key = $cachedMount->getRootId().'::'.$cachedMount->getMountPoint(); |
|
| 170 | 170 | if (isset($new[$key])) { |
| 171 | 171 | $newMount = $new[$key]; |
| 172 | 172 | if ( |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | ], ['root_id', 'user_id', 'mount_point']); |
| 195 | 195 | } else { |
| 196 | 196 | // in some cases this is legitimate, like orphaned shares |
| 197 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 197 | + $this->logger->debug('Could not get storage info for mount at '.$mount->getMountPoint()); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
@@ -229,12 +229,12 @@ discard block |
||
| 229 | 229 | } |
| 230 | 230 | $mount_id = $row['mount_id']; |
| 231 | 231 | if (!is_null($mount_id)) { |
| 232 | - $mount_id = (int)$mount_id; |
|
| 232 | + $mount_id = (int) $mount_id; |
|
| 233 | 233 | } |
| 234 | 234 | return new CachedMountInfo( |
| 235 | 235 | $user, |
| 236 | - (int)$row['storage_id'], |
|
| 237 | - (int)$row['root_id'], |
|
| 236 | + (int) $row['storage_id'], |
|
| 237 | + (int) $row['root_id'], |
|
| 238 | 238 | $row['mount_point'], |
| 239 | 239 | $row['mount_provider_class'] ?? '', |
| 240 | 240 | $mount_id, |
@@ -322,12 +322,12 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | if (is_array($row)) { |
| 324 | 324 | $this->cacheInfoCache[$fileId] = [ |
| 325 | - (int)$row['storage'], |
|
| 326 | - (string)$row['path'], |
|
| 327 | - (int)$row['mimetype'] |
|
| 325 | + (int) $row['storage'], |
|
| 326 | + (string) $row['path'], |
|
| 327 | + (int) $row['mimetype'] |
|
| 328 | 328 | ]; |
| 329 | 329 | } else { |
| 330 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 330 | + throw new NotFoundException('File with id "'.$fileId.'" not found'); |
|
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | return $this->cacheInfoCache[$fileId]; |
@@ -359,17 +359,17 @@ discard block |
||
| 359 | 359 | $rows = $result->fetchAll(); |
| 360 | 360 | $result->closeCursor(); |
| 361 | 361 | // filter mounts that are from the same storage but a different directory |
| 362 | - $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) { |
|
| 363 | - if ($fileId === (int)$row['root_id']) { |
|
| 362 | + $filteredMounts = array_filter($rows, function(array $row) use ($internalPath, $fileId) { |
|
| 363 | + if ($fileId === (int) $row['root_id']) { |
|
| 364 | 364 | return true; |
| 365 | 365 | } |
| 366 | 366 | $internalMountPath = $row['path'] ?? ''; |
| 367 | 367 | |
| 368 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 368 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath.'/'; |
|
| 369 | 369 | }); |
| 370 | 370 | |
| 371 | 371 | $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts)); |
| 372 | - return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
| 372 | + return array_map(function(ICachedMountInfo $mount) use ($internalPath) { |
|
| 373 | 373 | return new CachedMountFileInfo( |
| 374 | 374 | $mount->getUser(), |
| 375 | 375 | $mount->getStorageId(), |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | $slash |
| 428 | 428 | ); |
| 429 | 429 | |
| 430 | - $userIds = array_map(function (IUser $user) { |
|
| 430 | + $userIds = array_map(function(IUser $user) { |
|
| 431 | 431 | return $user->getUID(); |
| 432 | 432 | }, $users); |
| 433 | 433 | |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | public function getMountForPath(IUser $user, string $path): ICachedMountInfo { |
| 460 | 460 | $mounts = $this->getMountsForUser($user); |
| 461 | - $mountPoints = array_map(function (ICachedMountInfo $mount) { |
|
| 461 | + $mountPoints = array_map(function(ICachedMountInfo $mount) { |
|
| 462 | 462 | return $mount->getMountPoint(); |
| 463 | 463 | }, $mounts); |
| 464 | 464 | $mounts = array_combine($mountPoints, $mounts); |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | // walk up the directory tree until we find a path that has a mountpoint set |
| 468 | 468 | // the loop will return if a mountpoint is found or break if none are found |
| 469 | 469 | while (true) { |
| 470 | - $mountPoint = $current . '/'; |
|
| 470 | + $mountPoint = $current.'/'; |
|
| 471 | 471 | if (isset($mounts[$mountPoint])) { |
| 472 | 472 | return $mounts[$mountPoint]; |
| 473 | 473 | } elseif ($current === '') { |
@@ -480,13 +480,13 @@ discard block |
||
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - throw new NotFoundException("No cached mount for path " . $path); |
|
| 483 | + throw new NotFoundException("No cached mount for path ".$path); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | public function getMountsInPath(IUser $user, string $path): array { |
| 487 | - $path = rtrim($path, '/') . '/'; |
|
| 487 | + $path = rtrim($path, '/').'/'; |
|
| 488 | 488 | $mounts = $this->getMountsForUser($user); |
| 489 | - return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) { |
|
| 489 | + return array_filter($mounts, function(ICachedMountInfo $mount) use ($path) { |
|
| 490 | 490 | return $mount->getMountPoint() !== $path && strpos($mount->getMountPoint(), $path) === 0; |
| 491 | 491 | }); |
| 492 | 492 | } |
@@ -53,430 +53,430 @@ |
||
| 53 | 53 | * @package OC\Core\Command\Db |
| 54 | 54 | */ |
| 55 | 55 | class AddMissingIndices extends Command { |
| 56 | - private Connection $connection; |
|
| 57 | - private EventDispatcherInterface $dispatcher; |
|
| 58 | - |
|
| 59 | - public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) { |
|
| 60 | - parent::__construct(); |
|
| 61 | - |
|
| 62 | - $this->connection = $connection; |
|
| 63 | - $this->dispatcher = $dispatcher; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - protected function configure() { |
|
| 67 | - $this |
|
| 68 | - ->setName('db:add-missing-indices') |
|
| 69 | - ->setDescription('Add missing indices to the database tables') |
|
| 70 | - ->addOption('dry-run', null, InputOption::VALUE_NONE, "Output the SQL queries instead of running them."); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 74 | - $this->addCoreIndexes($output, $input->getOption('dry-run')); |
|
| 75 | - |
|
| 76 | - // Dispatch event so apps can also update indexes if needed |
|
| 77 | - $event = new GenericEvent($output); |
|
| 78 | - $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event); |
|
| 79 | - return 0; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * add missing indices to the share table |
|
| 84 | - * |
|
| 85 | - * @param OutputInterface $output |
|
| 86 | - * @param bool $dryRun If true, will return the sql queries instead of running them. |
|
| 87 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
| 88 | - */ |
|
| 89 | - private function addCoreIndexes(OutputInterface $output, bool $dryRun): void { |
|
| 90 | - $output->writeln('<info>Check indices of the share table.</info>'); |
|
| 91 | - |
|
| 92 | - $schema = new SchemaWrapper($this->connection); |
|
| 93 | - $updated = false; |
|
| 94 | - |
|
| 95 | - if ($schema->hasTable('share')) { |
|
| 96 | - $table = $schema->getTable('share'); |
|
| 97 | - if (!$table->hasIndex('share_with_index')) { |
|
| 98 | - $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>'); |
|
| 99 | - $table->addIndex(['share_with'], 'share_with_index'); |
|
| 100 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 101 | - if ($dryRun && $sqlQueries !== null) { |
|
| 102 | - $output->writeln($sqlQueries); |
|
| 103 | - } |
|
| 104 | - $updated = true; |
|
| 105 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (!$table->hasIndex('parent_index')) { |
|
| 109 | - $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>'); |
|
| 110 | - $table->addIndex(['parent'], 'parent_index'); |
|
| 111 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 112 | - if ($dryRun && $sqlQueries !== null) { |
|
| 113 | - $output->writeln($sqlQueries); |
|
| 114 | - } |
|
| 115 | - $updated = true; |
|
| 116 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if (!$table->hasIndex('owner_index')) { |
|
| 120 | - $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>'); |
|
| 121 | - $table->addIndex(['uid_owner'], 'owner_index'); |
|
| 122 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 123 | - if ($dryRun && $sqlQueries !== null) { |
|
| 124 | - $output->writeln($sqlQueries); |
|
| 125 | - } |
|
| 126 | - $updated = true; |
|
| 127 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if (!$table->hasIndex('initiator_index')) { |
|
| 131 | - $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>'); |
|
| 132 | - $table->addIndex(['uid_initiator'], 'initiator_index'); |
|
| 133 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 134 | - if ($dryRun && $sqlQueries !== null) { |
|
| 135 | - $output->writeln($sqlQueries); |
|
| 136 | - } |
|
| 137 | - $updated = true; |
|
| 138 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $output->writeln('<info>Check indices of the filecache table.</info>'); |
|
| 143 | - if ($schema->hasTable('filecache')) { |
|
| 144 | - $table = $schema->getTable('filecache'); |
|
| 145 | - if (!$table->hasIndex('fs_mtime')) { |
|
| 146 | - $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>'); |
|
| 147 | - $table->addIndex(['mtime'], 'fs_mtime'); |
|
| 148 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 149 | - if ($dryRun && $sqlQueries !== null) { |
|
| 150 | - $output->writeln($sqlQueries); |
|
| 151 | - } |
|
| 152 | - $updated = true; |
|
| 153 | - $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 154 | - } |
|
| 155 | - if (!$table->hasIndex('fs_size')) { |
|
| 156 | - $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>'); |
|
| 157 | - $table->addIndex(['size'], 'fs_size'); |
|
| 158 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 159 | - if ($dryRun && $sqlQueries !== null) { |
|
| 160 | - $output->writeln($sqlQueries); |
|
| 161 | - } |
|
| 162 | - $updated = true; |
|
| 163 | - $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 164 | - } |
|
| 165 | - if (!$table->hasIndex('fs_id_storage_size')) { |
|
| 166 | - $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>'); |
|
| 167 | - $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size'); |
|
| 168 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 169 | - if ($dryRun && $sqlQueries !== null) { |
|
| 170 | - $output->writeln($sqlQueries); |
|
| 171 | - } |
|
| 172 | - $updated = true; |
|
| 173 | - $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 174 | - } |
|
| 175 | - if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
| 176 | - $output->writeln('<info>Adding additional path index to the filecache table, this can take some time...</info>'); |
|
| 177 | - $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]); |
|
| 178 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 179 | - if ($dryRun && $sqlQueries !== null) { |
|
| 180 | - $output->writeln($sqlQueries); |
|
| 181 | - } |
|
| 182 | - $updated = true; |
|
| 183 | - $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 184 | - } |
|
| 185 | - if (!$table->hasIndex('fs_parent')) { |
|
| 186 | - $output->writeln('<info>Adding additional parent index to the filecache table, this can take some time...</info>'); |
|
| 187 | - $table->addIndex(['parent'], 'fs_parent'); |
|
| 188 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 189 | - if ($dryRun && $sqlQueries !== null) { |
|
| 190 | - $output->writeln($sqlQueries); |
|
| 191 | - } |
|
| 192 | - $updated = true; |
|
| 193 | - $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $output->writeln('<info>Check indices of the twofactor_providers table.</info>'); |
|
| 198 | - if ($schema->hasTable('twofactor_providers')) { |
|
| 199 | - $table = $schema->getTable('twofactor_providers'); |
|
| 200 | - if (!$table->hasIndex('twofactor_providers_uid')) { |
|
| 201 | - $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>'); |
|
| 202 | - $table->addIndex(['uid'], 'twofactor_providers_uid'); |
|
| 203 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 204 | - if ($dryRun && $sqlQueries !== null) { |
|
| 205 | - $output->writeln($sqlQueries); |
|
| 206 | - } |
|
| 207 | - $updated = true; |
|
| 208 | - $output->writeln('<info>Twofactor_providers table updated successfully.</info>'); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $output->writeln('<info>Check indices of the login_flow_v2 table.</info>'); |
|
| 213 | - if ($schema->hasTable('login_flow_v2')) { |
|
| 214 | - $table = $schema->getTable('login_flow_v2'); |
|
| 215 | - if (!$table->hasIndex('poll_token')) { |
|
| 216 | - $output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>'); |
|
| 217 | - |
|
| 218 | - foreach ($table->getIndexes() as $index) { |
|
| 219 | - $columns = $index->getColumns(); |
|
| 220 | - if ($columns === ['poll_token'] || |
|
| 221 | - $columns === ['login_token'] || |
|
| 222 | - $columns === ['timestamp']) { |
|
| 223 | - $table->dropIndex($index->getName()); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $table->addUniqueIndex(['poll_token'], 'poll_token'); |
|
| 228 | - $table->addUniqueIndex(['login_token'], 'login_token'); |
|
| 229 | - $table->addIndex(['timestamp'], 'timestamp'); |
|
| 230 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 231 | - if ($dryRun && $sqlQueries !== null) { |
|
| 232 | - $output->writeln($sqlQueries); |
|
| 233 | - } |
|
| 234 | - $updated = true; |
|
| 235 | - $output->writeln('<info>login_flow_v2 table updated successfully.</info>'); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $output->writeln('<info>Check indices of the whats_new table.</info>'); |
|
| 240 | - if ($schema->hasTable('whats_new')) { |
|
| 241 | - $table = $schema->getTable('whats_new'); |
|
| 242 | - if (!$table->hasIndex('version')) { |
|
| 243 | - $output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>'); |
|
| 244 | - |
|
| 245 | - foreach ($table->getIndexes() as $index) { |
|
| 246 | - if ($index->getColumns() === ['version']) { |
|
| 247 | - $table->dropIndex($index->getName()); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $table->addUniqueIndex(['version'], 'version'); |
|
| 252 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 253 | - if ($dryRun && $sqlQueries !== null) { |
|
| 254 | - $output->writeln($sqlQueries); |
|
| 255 | - } |
|
| 256 | - $updated = true; |
|
| 257 | - $output->writeln('<info>whats_new table updated successfully.</info>'); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $output->writeln('<info>Check indices of the cards table.</info>'); |
|
| 262 | - $cardsUpdated = false; |
|
| 263 | - if ($schema->hasTable('cards')) { |
|
| 264 | - $table = $schema->getTable('cards'); |
|
| 265 | - |
|
| 266 | - if ($table->hasIndex('addressbookid_uri_index')) { |
|
| 267 | - if ($table->hasIndex('cards_abiduri')) { |
|
| 268 | - $table->dropIndex('addressbookid_uri_index'); |
|
| 269 | - } else { |
|
| 270 | - $output->writeln('<info>Renaming addressbookid_uri_index index to cards_abiduri in the cards table, this can take some time...</info>'); |
|
| 271 | - |
|
| 272 | - foreach ($table->getIndexes() as $index) { |
|
| 273 | - if ($index->getColumns() === ['addressbookid', 'uri']) { |
|
| 274 | - $table->renameIndex('addressbookid_uri_index', 'cards_abiduri'); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 280 | - if ($dryRun && $sqlQueries !== null) { |
|
| 281 | - $output->writeln($sqlQueries); |
|
| 282 | - } |
|
| 283 | - $cardsUpdated = true; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - if (!$table->hasIndex('cards_abid')) { |
|
| 287 | - $output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>'); |
|
| 288 | - |
|
| 289 | - foreach ($table->getIndexes() as $index) { |
|
| 290 | - if ($index->getColumns() === ['addressbookid']) { |
|
| 291 | - $table->dropIndex($index->getName()); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $table->addIndex(['addressbookid'], 'cards_abid'); |
|
| 296 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 297 | - if ($dryRun && $sqlQueries !== null) { |
|
| 298 | - $output->writeln($sqlQueries); |
|
| 299 | - } |
|
| 300 | - $cardsUpdated = true; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - if (!$table->hasIndex('cards_abiduri')) { |
|
| 304 | - $output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>'); |
|
| 305 | - |
|
| 306 | - foreach ($table->getIndexes() as $index) { |
|
| 307 | - if ($index->getColumns() === ['addressbookid', 'uri']) { |
|
| 308 | - $table->dropIndex($index->getName()); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $table->addIndex(['addressbookid', 'uri'], 'cards_abiduri'); |
|
| 313 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 314 | - if ($dryRun && $sqlQueries !== null) { |
|
| 315 | - $output->writeln($sqlQueries); |
|
| 316 | - } |
|
| 317 | - $cardsUpdated = true; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - if ($cardsUpdated) { |
|
| 321 | - $updated = true; |
|
| 322 | - $output->writeln('<info>cards table updated successfully.</info>'); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - $output->writeln('<info>Check indices of the cards_properties table.</info>'); |
|
| 327 | - if ($schema->hasTable('cards_properties')) { |
|
| 328 | - $table = $schema->getTable('cards_properties'); |
|
| 329 | - if (!$table->hasIndex('cards_prop_abid')) { |
|
| 330 | - $output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>'); |
|
| 331 | - |
|
| 332 | - foreach ($table->getIndexes() as $index) { |
|
| 333 | - if ($index->getColumns() === ['addressbookid']) { |
|
| 334 | - $table->dropIndex($index->getName()); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $table->addIndex(['addressbookid'], 'cards_prop_abid'); |
|
| 339 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 340 | - if ($dryRun && $sqlQueries !== null) { |
|
| 341 | - $output->writeln($sqlQueries); |
|
| 342 | - } |
|
| 343 | - $updated = true; |
|
| 344 | - $output->writeln('<info>cards_properties table updated successfully.</info>'); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $output->writeln('<info>Check indices of the calendarobjects_props table.</info>'); |
|
| 349 | - if ($schema->hasTable('calendarobjects_props')) { |
|
| 350 | - $table = $schema->getTable('calendarobjects_props'); |
|
| 351 | - if (!$table->hasIndex('calendarobject_calid_index')) { |
|
| 352 | - $output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>'); |
|
| 353 | - |
|
| 354 | - $table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index'); |
|
| 355 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 356 | - if ($dryRun && $sqlQueries !== null) { |
|
| 357 | - $output->writeln($sqlQueries); |
|
| 358 | - } |
|
| 359 | - $updated = true; |
|
| 360 | - $output->writeln('<info>calendarobjects_props table updated successfully.</info>'); |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $output->writeln('<info>Check indices of the schedulingobjects table.</info>'); |
|
| 365 | - if ($schema->hasTable('schedulingobjects')) { |
|
| 366 | - $table = $schema->getTable('schedulingobjects'); |
|
| 367 | - if (!$table->hasIndex('schedulobj_principuri_index')) { |
|
| 368 | - $output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>'); |
|
| 369 | - |
|
| 370 | - $table->addIndex(['principaluri'], 'schedulobj_principuri_index'); |
|
| 371 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 372 | - if ($dryRun && $sqlQueries !== null) { |
|
| 373 | - $output->writeln($sqlQueries); |
|
| 374 | - } |
|
| 375 | - $updated = true; |
|
| 376 | - $output->writeln('<info>schedulingobjects table updated successfully.</info>'); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - $output->writeln('<info>Check indices of the oc_properties table.</info>'); |
|
| 381 | - if ($schema->hasTable('properties')) { |
|
| 382 | - $table = $schema->getTable('properties'); |
|
| 383 | - $propertiesUpdated = false; |
|
| 384 | - |
|
| 385 | - if (!$table->hasIndex('properties_path_index')) { |
|
| 386 | - $output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>'); |
|
| 387 | - |
|
| 388 | - $table->addIndex(['userid', 'propertypath'], 'properties_path_index'); |
|
| 389 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 390 | - if ($dryRun && $sqlQueries !== null) { |
|
| 391 | - $output->writeln($sqlQueries); |
|
| 392 | - } |
|
| 393 | - $propertiesUpdated = true; |
|
| 394 | - } |
|
| 395 | - if (!$table->hasIndex('properties_pathonly_index')) { |
|
| 396 | - $output->writeln('<info>Adding properties_pathonly_index index to the oc_properties table, this can take some time...</info>'); |
|
| 397 | - |
|
| 398 | - $table->addIndex(['propertypath'], 'properties_pathonly_index'); |
|
| 399 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 400 | - if ($dryRun && $sqlQueries !== null) { |
|
| 401 | - $output->writeln($sqlQueries); |
|
| 402 | - } |
|
| 403 | - $propertiesUpdated = true; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - if ($propertiesUpdated) { |
|
| 407 | - $updated = true; |
|
| 408 | - $output->writeln('<info>oc_properties table updated successfully.</info>'); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $output->writeln('<info>Check indices of the oc_jobs table.</info>'); |
|
| 413 | - if ($schema->hasTable('jobs')) { |
|
| 414 | - $table = $schema->getTable('jobs'); |
|
| 415 | - if (!$table->hasIndex('job_lastcheck_reserved')) { |
|
| 416 | - $output->writeln('<info>Adding job_lastcheck_reserved index to the oc_jobs table, this can take some time...</info>'); |
|
| 417 | - |
|
| 418 | - $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved'); |
|
| 419 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 420 | - if ($dryRun && $sqlQueries !== null) { |
|
| 421 | - $output->writeln($sqlQueries); |
|
| 422 | - } |
|
| 423 | - $updated = true; |
|
| 424 | - $output->writeln('<info>oc_properties table updated successfully.</info>'); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - $output->writeln('<info>Check indices of the oc_direct_edit table.</info>'); |
|
| 429 | - if ($schema->hasTable('direct_edit')) { |
|
| 430 | - $table = $schema->getTable('direct_edit'); |
|
| 431 | - if (!$table->hasIndex('direct_edit_timestamp')) { |
|
| 432 | - $output->writeln('<info>Adding direct_edit_timestamp index to the oc_direct_edit table, this can take some time...</info>'); |
|
| 433 | - |
|
| 434 | - $table->addIndex(['timestamp'], 'direct_edit_timestamp'); |
|
| 435 | - $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 436 | - if ($dryRun && $sqlQueries !== null) { |
|
| 437 | - $output->writeln($sqlQueries); |
|
| 438 | - } |
|
| 439 | - $updated = true; |
|
| 440 | - $output->writeln('<info>oc_direct_edit table updated successfully.</info>'); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - $output->writeln('<info>Check indices of the oc_preferences table.</info>'); |
|
| 445 | - if ($schema->hasTable('preferences')) { |
|
| 446 | - $table = $schema->getTable('preferences'); |
|
| 447 | - if (!$table->hasIndex('preferences_app_key')) { |
|
| 448 | - $output->writeln('<info>Adding preferences_app_key index to the oc_preferences table, this can take some time...</info>'); |
|
| 449 | - |
|
| 450 | - $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); |
|
| 451 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
| 452 | - $updated = true; |
|
| 453 | - $output->writeln('<info>oc_properties table updated successfully.</info>'); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $output->writeln('<info>Check indices of the oc_mounts table.</info>'); |
|
| 458 | - if ($schema->hasTable('mounts')) { |
|
| 459 | - $table = $schema->getTable('mounts'); |
|
| 460 | - if (!$table->hasIndex('mounts_class_index')) { |
|
| 461 | - $output->writeln('<info>Adding mounts_class_index index to the oc_mounts table, this can take some time...</info>'); |
|
| 462 | - |
|
| 463 | - $table->addIndex(['mount_provider_class'], 'mounts_class_index'); |
|
| 464 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
| 465 | - $updated = true; |
|
| 466 | - $output->writeln('<info>oc_mounts table updated successfully.</info>'); |
|
| 467 | - } |
|
| 468 | - if (!$table->hasIndex('mounts_user_root_path_index')) { |
|
| 469 | - $output->writeln('<info>Adding mounts_user_root_path_index index to the oc_mounts table, this can take some time...</info>'); |
|
| 470 | - |
|
| 471 | - $table->addIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', [], ['lengths' => [null, null, 128]]); |
|
| 472 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
| 473 | - $updated = true; |
|
| 474 | - $output->writeln('<info>oc_mounts table updated successfully.</info>'); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if (!$updated) { |
|
| 479 | - $output->writeln('<info>Done.</info>'); |
|
| 480 | - } |
|
| 481 | - } |
|
| 56 | + private Connection $connection; |
|
| 57 | + private EventDispatcherInterface $dispatcher; |
|
| 58 | + |
|
| 59 | + public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) { |
|
| 60 | + parent::__construct(); |
|
| 61 | + |
|
| 62 | + $this->connection = $connection; |
|
| 63 | + $this->dispatcher = $dispatcher; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + protected function configure() { |
|
| 67 | + $this |
|
| 68 | + ->setName('db:add-missing-indices') |
|
| 69 | + ->setDescription('Add missing indices to the database tables') |
|
| 70 | + ->addOption('dry-run', null, InputOption::VALUE_NONE, "Output the SQL queries instead of running them."); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 74 | + $this->addCoreIndexes($output, $input->getOption('dry-run')); |
|
| 75 | + |
|
| 76 | + // Dispatch event so apps can also update indexes if needed |
|
| 77 | + $event = new GenericEvent($output); |
|
| 78 | + $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event); |
|
| 79 | + return 0; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * add missing indices to the share table |
|
| 84 | + * |
|
| 85 | + * @param OutputInterface $output |
|
| 86 | + * @param bool $dryRun If true, will return the sql queries instead of running them. |
|
| 87 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
| 88 | + */ |
|
| 89 | + private function addCoreIndexes(OutputInterface $output, bool $dryRun): void { |
|
| 90 | + $output->writeln('<info>Check indices of the share table.</info>'); |
|
| 91 | + |
|
| 92 | + $schema = new SchemaWrapper($this->connection); |
|
| 93 | + $updated = false; |
|
| 94 | + |
|
| 95 | + if ($schema->hasTable('share')) { |
|
| 96 | + $table = $schema->getTable('share'); |
|
| 97 | + if (!$table->hasIndex('share_with_index')) { |
|
| 98 | + $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>'); |
|
| 99 | + $table->addIndex(['share_with'], 'share_with_index'); |
|
| 100 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 101 | + if ($dryRun && $sqlQueries !== null) { |
|
| 102 | + $output->writeln($sqlQueries); |
|
| 103 | + } |
|
| 104 | + $updated = true; |
|
| 105 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if (!$table->hasIndex('parent_index')) { |
|
| 109 | + $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>'); |
|
| 110 | + $table->addIndex(['parent'], 'parent_index'); |
|
| 111 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 112 | + if ($dryRun && $sqlQueries !== null) { |
|
| 113 | + $output->writeln($sqlQueries); |
|
| 114 | + } |
|
| 115 | + $updated = true; |
|
| 116 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if (!$table->hasIndex('owner_index')) { |
|
| 120 | + $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>'); |
|
| 121 | + $table->addIndex(['uid_owner'], 'owner_index'); |
|
| 122 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 123 | + if ($dryRun && $sqlQueries !== null) { |
|
| 124 | + $output->writeln($sqlQueries); |
|
| 125 | + } |
|
| 126 | + $updated = true; |
|
| 127 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if (!$table->hasIndex('initiator_index')) { |
|
| 131 | + $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>'); |
|
| 132 | + $table->addIndex(['uid_initiator'], 'initiator_index'); |
|
| 133 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 134 | + if ($dryRun && $sqlQueries !== null) { |
|
| 135 | + $output->writeln($sqlQueries); |
|
| 136 | + } |
|
| 137 | + $updated = true; |
|
| 138 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $output->writeln('<info>Check indices of the filecache table.</info>'); |
|
| 143 | + if ($schema->hasTable('filecache')) { |
|
| 144 | + $table = $schema->getTable('filecache'); |
|
| 145 | + if (!$table->hasIndex('fs_mtime')) { |
|
| 146 | + $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>'); |
|
| 147 | + $table->addIndex(['mtime'], 'fs_mtime'); |
|
| 148 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 149 | + if ($dryRun && $sqlQueries !== null) { |
|
| 150 | + $output->writeln($sqlQueries); |
|
| 151 | + } |
|
| 152 | + $updated = true; |
|
| 153 | + $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 154 | + } |
|
| 155 | + if (!$table->hasIndex('fs_size')) { |
|
| 156 | + $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>'); |
|
| 157 | + $table->addIndex(['size'], 'fs_size'); |
|
| 158 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 159 | + if ($dryRun && $sqlQueries !== null) { |
|
| 160 | + $output->writeln($sqlQueries); |
|
| 161 | + } |
|
| 162 | + $updated = true; |
|
| 163 | + $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 164 | + } |
|
| 165 | + if (!$table->hasIndex('fs_id_storage_size')) { |
|
| 166 | + $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>'); |
|
| 167 | + $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size'); |
|
| 168 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 169 | + if ($dryRun && $sqlQueries !== null) { |
|
| 170 | + $output->writeln($sqlQueries); |
|
| 171 | + } |
|
| 172 | + $updated = true; |
|
| 173 | + $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 174 | + } |
|
| 175 | + if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
| 176 | + $output->writeln('<info>Adding additional path index to the filecache table, this can take some time...</info>'); |
|
| 177 | + $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]); |
|
| 178 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 179 | + if ($dryRun && $sqlQueries !== null) { |
|
| 180 | + $output->writeln($sqlQueries); |
|
| 181 | + } |
|
| 182 | + $updated = true; |
|
| 183 | + $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 184 | + } |
|
| 185 | + if (!$table->hasIndex('fs_parent')) { |
|
| 186 | + $output->writeln('<info>Adding additional parent index to the filecache table, this can take some time...</info>'); |
|
| 187 | + $table->addIndex(['parent'], 'fs_parent'); |
|
| 188 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 189 | + if ($dryRun && $sqlQueries !== null) { |
|
| 190 | + $output->writeln($sqlQueries); |
|
| 191 | + } |
|
| 192 | + $updated = true; |
|
| 193 | + $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $output->writeln('<info>Check indices of the twofactor_providers table.</info>'); |
|
| 198 | + if ($schema->hasTable('twofactor_providers')) { |
|
| 199 | + $table = $schema->getTable('twofactor_providers'); |
|
| 200 | + if (!$table->hasIndex('twofactor_providers_uid')) { |
|
| 201 | + $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>'); |
|
| 202 | + $table->addIndex(['uid'], 'twofactor_providers_uid'); |
|
| 203 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 204 | + if ($dryRun && $sqlQueries !== null) { |
|
| 205 | + $output->writeln($sqlQueries); |
|
| 206 | + } |
|
| 207 | + $updated = true; |
|
| 208 | + $output->writeln('<info>Twofactor_providers table updated successfully.</info>'); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $output->writeln('<info>Check indices of the login_flow_v2 table.</info>'); |
|
| 213 | + if ($schema->hasTable('login_flow_v2')) { |
|
| 214 | + $table = $schema->getTable('login_flow_v2'); |
|
| 215 | + if (!$table->hasIndex('poll_token')) { |
|
| 216 | + $output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>'); |
|
| 217 | + |
|
| 218 | + foreach ($table->getIndexes() as $index) { |
|
| 219 | + $columns = $index->getColumns(); |
|
| 220 | + if ($columns === ['poll_token'] || |
|
| 221 | + $columns === ['login_token'] || |
|
| 222 | + $columns === ['timestamp']) { |
|
| 223 | + $table->dropIndex($index->getName()); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $table->addUniqueIndex(['poll_token'], 'poll_token'); |
|
| 228 | + $table->addUniqueIndex(['login_token'], 'login_token'); |
|
| 229 | + $table->addIndex(['timestamp'], 'timestamp'); |
|
| 230 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 231 | + if ($dryRun && $sqlQueries !== null) { |
|
| 232 | + $output->writeln($sqlQueries); |
|
| 233 | + } |
|
| 234 | + $updated = true; |
|
| 235 | + $output->writeln('<info>login_flow_v2 table updated successfully.</info>'); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $output->writeln('<info>Check indices of the whats_new table.</info>'); |
|
| 240 | + if ($schema->hasTable('whats_new')) { |
|
| 241 | + $table = $schema->getTable('whats_new'); |
|
| 242 | + if (!$table->hasIndex('version')) { |
|
| 243 | + $output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>'); |
|
| 244 | + |
|
| 245 | + foreach ($table->getIndexes() as $index) { |
|
| 246 | + if ($index->getColumns() === ['version']) { |
|
| 247 | + $table->dropIndex($index->getName()); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $table->addUniqueIndex(['version'], 'version'); |
|
| 252 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 253 | + if ($dryRun && $sqlQueries !== null) { |
|
| 254 | + $output->writeln($sqlQueries); |
|
| 255 | + } |
|
| 256 | + $updated = true; |
|
| 257 | + $output->writeln('<info>whats_new table updated successfully.</info>'); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $output->writeln('<info>Check indices of the cards table.</info>'); |
|
| 262 | + $cardsUpdated = false; |
|
| 263 | + if ($schema->hasTable('cards')) { |
|
| 264 | + $table = $schema->getTable('cards'); |
|
| 265 | + |
|
| 266 | + if ($table->hasIndex('addressbookid_uri_index')) { |
|
| 267 | + if ($table->hasIndex('cards_abiduri')) { |
|
| 268 | + $table->dropIndex('addressbookid_uri_index'); |
|
| 269 | + } else { |
|
| 270 | + $output->writeln('<info>Renaming addressbookid_uri_index index to cards_abiduri in the cards table, this can take some time...</info>'); |
|
| 271 | + |
|
| 272 | + foreach ($table->getIndexes() as $index) { |
|
| 273 | + if ($index->getColumns() === ['addressbookid', 'uri']) { |
|
| 274 | + $table->renameIndex('addressbookid_uri_index', 'cards_abiduri'); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 280 | + if ($dryRun && $sqlQueries !== null) { |
|
| 281 | + $output->writeln($sqlQueries); |
|
| 282 | + } |
|
| 283 | + $cardsUpdated = true; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + if (!$table->hasIndex('cards_abid')) { |
|
| 287 | + $output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>'); |
|
| 288 | + |
|
| 289 | + foreach ($table->getIndexes() as $index) { |
|
| 290 | + if ($index->getColumns() === ['addressbookid']) { |
|
| 291 | + $table->dropIndex($index->getName()); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $table->addIndex(['addressbookid'], 'cards_abid'); |
|
| 296 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 297 | + if ($dryRun && $sqlQueries !== null) { |
|
| 298 | + $output->writeln($sqlQueries); |
|
| 299 | + } |
|
| 300 | + $cardsUpdated = true; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + if (!$table->hasIndex('cards_abiduri')) { |
|
| 304 | + $output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>'); |
|
| 305 | + |
|
| 306 | + foreach ($table->getIndexes() as $index) { |
|
| 307 | + if ($index->getColumns() === ['addressbookid', 'uri']) { |
|
| 308 | + $table->dropIndex($index->getName()); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $table->addIndex(['addressbookid', 'uri'], 'cards_abiduri'); |
|
| 313 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 314 | + if ($dryRun && $sqlQueries !== null) { |
|
| 315 | + $output->writeln($sqlQueries); |
|
| 316 | + } |
|
| 317 | + $cardsUpdated = true; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + if ($cardsUpdated) { |
|
| 321 | + $updated = true; |
|
| 322 | + $output->writeln('<info>cards table updated successfully.</info>'); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + $output->writeln('<info>Check indices of the cards_properties table.</info>'); |
|
| 327 | + if ($schema->hasTable('cards_properties')) { |
|
| 328 | + $table = $schema->getTable('cards_properties'); |
|
| 329 | + if (!$table->hasIndex('cards_prop_abid')) { |
|
| 330 | + $output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>'); |
|
| 331 | + |
|
| 332 | + foreach ($table->getIndexes() as $index) { |
|
| 333 | + if ($index->getColumns() === ['addressbookid']) { |
|
| 334 | + $table->dropIndex($index->getName()); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $table->addIndex(['addressbookid'], 'cards_prop_abid'); |
|
| 339 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 340 | + if ($dryRun && $sqlQueries !== null) { |
|
| 341 | + $output->writeln($sqlQueries); |
|
| 342 | + } |
|
| 343 | + $updated = true; |
|
| 344 | + $output->writeln('<info>cards_properties table updated successfully.</info>'); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $output->writeln('<info>Check indices of the calendarobjects_props table.</info>'); |
|
| 349 | + if ($schema->hasTable('calendarobjects_props')) { |
|
| 350 | + $table = $schema->getTable('calendarobjects_props'); |
|
| 351 | + if (!$table->hasIndex('calendarobject_calid_index')) { |
|
| 352 | + $output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>'); |
|
| 353 | + |
|
| 354 | + $table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index'); |
|
| 355 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 356 | + if ($dryRun && $sqlQueries !== null) { |
|
| 357 | + $output->writeln($sqlQueries); |
|
| 358 | + } |
|
| 359 | + $updated = true; |
|
| 360 | + $output->writeln('<info>calendarobjects_props table updated successfully.</info>'); |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $output->writeln('<info>Check indices of the schedulingobjects table.</info>'); |
|
| 365 | + if ($schema->hasTable('schedulingobjects')) { |
|
| 366 | + $table = $schema->getTable('schedulingobjects'); |
|
| 367 | + if (!$table->hasIndex('schedulobj_principuri_index')) { |
|
| 368 | + $output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>'); |
|
| 369 | + |
|
| 370 | + $table->addIndex(['principaluri'], 'schedulobj_principuri_index'); |
|
| 371 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 372 | + if ($dryRun && $sqlQueries !== null) { |
|
| 373 | + $output->writeln($sqlQueries); |
|
| 374 | + } |
|
| 375 | + $updated = true; |
|
| 376 | + $output->writeln('<info>schedulingobjects table updated successfully.</info>'); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + $output->writeln('<info>Check indices of the oc_properties table.</info>'); |
|
| 381 | + if ($schema->hasTable('properties')) { |
|
| 382 | + $table = $schema->getTable('properties'); |
|
| 383 | + $propertiesUpdated = false; |
|
| 384 | + |
|
| 385 | + if (!$table->hasIndex('properties_path_index')) { |
|
| 386 | + $output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>'); |
|
| 387 | + |
|
| 388 | + $table->addIndex(['userid', 'propertypath'], 'properties_path_index'); |
|
| 389 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 390 | + if ($dryRun && $sqlQueries !== null) { |
|
| 391 | + $output->writeln($sqlQueries); |
|
| 392 | + } |
|
| 393 | + $propertiesUpdated = true; |
|
| 394 | + } |
|
| 395 | + if (!$table->hasIndex('properties_pathonly_index')) { |
|
| 396 | + $output->writeln('<info>Adding properties_pathonly_index index to the oc_properties table, this can take some time...</info>'); |
|
| 397 | + |
|
| 398 | + $table->addIndex(['propertypath'], 'properties_pathonly_index'); |
|
| 399 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 400 | + if ($dryRun && $sqlQueries !== null) { |
|
| 401 | + $output->writeln($sqlQueries); |
|
| 402 | + } |
|
| 403 | + $propertiesUpdated = true; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + if ($propertiesUpdated) { |
|
| 407 | + $updated = true; |
|
| 408 | + $output->writeln('<info>oc_properties table updated successfully.</info>'); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $output->writeln('<info>Check indices of the oc_jobs table.</info>'); |
|
| 413 | + if ($schema->hasTable('jobs')) { |
|
| 414 | + $table = $schema->getTable('jobs'); |
|
| 415 | + if (!$table->hasIndex('job_lastcheck_reserved')) { |
|
| 416 | + $output->writeln('<info>Adding job_lastcheck_reserved index to the oc_jobs table, this can take some time...</info>'); |
|
| 417 | + |
|
| 418 | + $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved'); |
|
| 419 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 420 | + if ($dryRun && $sqlQueries !== null) { |
|
| 421 | + $output->writeln($sqlQueries); |
|
| 422 | + } |
|
| 423 | + $updated = true; |
|
| 424 | + $output->writeln('<info>oc_properties table updated successfully.</info>'); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + $output->writeln('<info>Check indices of the oc_direct_edit table.</info>'); |
|
| 429 | + if ($schema->hasTable('direct_edit')) { |
|
| 430 | + $table = $schema->getTable('direct_edit'); |
|
| 431 | + if (!$table->hasIndex('direct_edit_timestamp')) { |
|
| 432 | + $output->writeln('<info>Adding direct_edit_timestamp index to the oc_direct_edit table, this can take some time...</info>'); |
|
| 433 | + |
|
| 434 | + $table->addIndex(['timestamp'], 'direct_edit_timestamp'); |
|
| 435 | + $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun); |
|
| 436 | + if ($dryRun && $sqlQueries !== null) { |
|
| 437 | + $output->writeln($sqlQueries); |
|
| 438 | + } |
|
| 439 | + $updated = true; |
|
| 440 | + $output->writeln('<info>oc_direct_edit table updated successfully.</info>'); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + $output->writeln('<info>Check indices of the oc_preferences table.</info>'); |
|
| 445 | + if ($schema->hasTable('preferences')) { |
|
| 446 | + $table = $schema->getTable('preferences'); |
|
| 447 | + if (!$table->hasIndex('preferences_app_key')) { |
|
| 448 | + $output->writeln('<info>Adding preferences_app_key index to the oc_preferences table, this can take some time...</info>'); |
|
| 449 | + |
|
| 450 | + $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); |
|
| 451 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
| 452 | + $updated = true; |
|
| 453 | + $output->writeln('<info>oc_properties table updated successfully.</info>'); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $output->writeln('<info>Check indices of the oc_mounts table.</info>'); |
|
| 458 | + if ($schema->hasTable('mounts')) { |
|
| 459 | + $table = $schema->getTable('mounts'); |
|
| 460 | + if (!$table->hasIndex('mounts_class_index')) { |
|
| 461 | + $output->writeln('<info>Adding mounts_class_index index to the oc_mounts table, this can take some time...</info>'); |
|
| 462 | + |
|
| 463 | + $table->addIndex(['mount_provider_class'], 'mounts_class_index'); |
|
| 464 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
| 465 | + $updated = true; |
|
| 466 | + $output->writeln('<info>oc_mounts table updated successfully.</info>'); |
|
| 467 | + } |
|
| 468 | + if (!$table->hasIndex('mounts_user_root_path_index')) { |
|
| 469 | + $output->writeln('<info>Adding mounts_user_root_path_index index to the oc_mounts table, this can take some time...</info>'); |
|
| 470 | + |
|
| 471 | + $table->addIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', [], ['lengths' => [null, null, 128]]); |
|
| 472 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
| 473 | + $updated = true; |
|
| 474 | + $output->writeln('<info>oc_mounts table updated successfully.</info>'); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if (!$updated) { |
|
| 479 | + $output->writeln('<info>Done.</info>'); |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | 482 | } |
@@ -39,858 +39,858 @@ discard block |
||
| 39 | 39 | use OCP\Migration\SimpleMigrationStep; |
| 40 | 40 | |
| 41 | 41 | class Version13000Date20170718121200 extends SimpleMigrationStep { |
| 42 | - /** @var IDBConnection */ |
|
| 43 | - private $connection; |
|
| 42 | + /** @var IDBConnection */ |
|
| 43 | + private $connection; |
|
| 44 | 44 | |
| 45 | - public function __construct(IDBConnection $connection) { |
|
| 46 | - $this->connection = $connection; |
|
| 47 | - } |
|
| 45 | + public function __construct(IDBConnection $connection) { |
|
| 46 | + $this->connection = $connection; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 50 | - /** @var ISchemaWrapper $schema */ |
|
| 51 | - $schema = $schemaClosure(); |
|
| 49 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 50 | + /** @var ISchemaWrapper $schema */ |
|
| 51 | + $schema = $schemaClosure(); |
|
| 52 | 52 | |
| 53 | - if (!$schema->hasTable('properties')) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - // in case we have a properties table from oc we drop it since we will only migrate |
|
| 57 | - // the dav_properties values in the postSchemaChange step |
|
| 58 | - $table = $schema->getTable('properties'); |
|
| 59 | - if ($table->hasColumn('fileid')) { |
|
| 60 | - $qb = $this->connection->getQueryBuilder(); |
|
| 61 | - $qb->delete('properties'); |
|
| 62 | - $qb->execute(); |
|
| 63 | - } |
|
| 64 | - } |
|
| 53 | + if (!$schema->hasTable('properties')) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + // in case we have a properties table from oc we drop it since we will only migrate |
|
| 57 | + // the dav_properties values in the postSchemaChange step |
|
| 58 | + $table = $schema->getTable('properties'); |
|
| 59 | + if ($table->hasColumn('fileid')) { |
|
| 60 | + $qb = $this->connection->getQueryBuilder(); |
|
| 61 | + $qb->delete('properties'); |
|
| 62 | + $qb->execute(); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param IOutput $output |
|
| 69 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 70 | - * @param array $options |
|
| 71 | - * @return null|ISchemaWrapper |
|
| 72 | - * @since 13.0.0 |
|
| 73 | - */ |
|
| 74 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 75 | - /** @var ISchemaWrapper $schema */ |
|
| 76 | - $schema = $schemaClosure(); |
|
| 67 | + /** |
|
| 68 | + * @param IOutput $output |
|
| 69 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 70 | + * @param array $options |
|
| 71 | + * @return null|ISchemaWrapper |
|
| 72 | + * @since 13.0.0 |
|
| 73 | + */ |
|
| 74 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 75 | + /** @var ISchemaWrapper $schema */ |
|
| 76 | + $schema = $schemaClosure(); |
|
| 77 | 77 | |
| 78 | - if (!$schema->hasTable('appconfig')) { |
|
| 79 | - $table = $schema->createTable('appconfig'); |
|
| 80 | - $table->addColumn('appid', 'string', [ |
|
| 81 | - 'notnull' => true, |
|
| 82 | - 'length' => 32, |
|
| 83 | - 'default' => '', |
|
| 84 | - ]); |
|
| 85 | - $table->addColumn('configkey', 'string', [ |
|
| 86 | - 'notnull' => true, |
|
| 87 | - 'length' => 64, |
|
| 88 | - 'default' => '', |
|
| 89 | - ]); |
|
| 90 | - $table->addColumn('configvalue', 'text', [ |
|
| 91 | - 'notnull' => false, |
|
| 92 | - ]); |
|
| 93 | - $table->setPrimaryKey(['appid', 'configkey']); |
|
| 94 | - $table->addIndex(['configkey'], 'appconfig_config_key_index'); |
|
| 95 | - $table->addIndex(['appid'], 'appconfig_appid_key'); |
|
| 96 | - } |
|
| 78 | + if (!$schema->hasTable('appconfig')) { |
|
| 79 | + $table = $schema->createTable('appconfig'); |
|
| 80 | + $table->addColumn('appid', 'string', [ |
|
| 81 | + 'notnull' => true, |
|
| 82 | + 'length' => 32, |
|
| 83 | + 'default' => '', |
|
| 84 | + ]); |
|
| 85 | + $table->addColumn('configkey', 'string', [ |
|
| 86 | + 'notnull' => true, |
|
| 87 | + 'length' => 64, |
|
| 88 | + 'default' => '', |
|
| 89 | + ]); |
|
| 90 | + $table->addColumn('configvalue', 'text', [ |
|
| 91 | + 'notnull' => false, |
|
| 92 | + ]); |
|
| 93 | + $table->setPrimaryKey(['appid', 'configkey']); |
|
| 94 | + $table->addIndex(['configkey'], 'appconfig_config_key_index'); |
|
| 95 | + $table->addIndex(['appid'], 'appconfig_appid_key'); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - if (!$schema->hasTable('storages')) { |
|
| 99 | - $table = $schema->createTable('storages'); |
|
| 100 | - $table->addColumn('id', 'string', [ |
|
| 101 | - 'notnull' => false, |
|
| 102 | - 'length' => 64, |
|
| 103 | - ]); |
|
| 104 | - $table->addColumn('numeric_id', Types::BIGINT, [ |
|
| 105 | - 'autoincrement' => true, |
|
| 106 | - 'notnull' => true, |
|
| 107 | - 'length' => 20, |
|
| 108 | - ]); |
|
| 109 | - $table->addColumn('available', 'integer', [ |
|
| 110 | - 'notnull' => true, |
|
| 111 | - 'default' => 1, |
|
| 112 | - ]); |
|
| 113 | - $table->addColumn('last_checked', 'integer', [ |
|
| 114 | - 'notnull' => false, |
|
| 115 | - ]); |
|
| 116 | - $table->setPrimaryKey(['numeric_id']); |
|
| 117 | - $table->addUniqueIndex(['id'], 'storages_id_index'); |
|
| 118 | - } |
|
| 98 | + if (!$schema->hasTable('storages')) { |
|
| 99 | + $table = $schema->createTable('storages'); |
|
| 100 | + $table->addColumn('id', 'string', [ |
|
| 101 | + 'notnull' => false, |
|
| 102 | + 'length' => 64, |
|
| 103 | + ]); |
|
| 104 | + $table->addColumn('numeric_id', Types::BIGINT, [ |
|
| 105 | + 'autoincrement' => true, |
|
| 106 | + 'notnull' => true, |
|
| 107 | + 'length' => 20, |
|
| 108 | + ]); |
|
| 109 | + $table->addColumn('available', 'integer', [ |
|
| 110 | + 'notnull' => true, |
|
| 111 | + 'default' => 1, |
|
| 112 | + ]); |
|
| 113 | + $table->addColumn('last_checked', 'integer', [ |
|
| 114 | + 'notnull' => false, |
|
| 115 | + ]); |
|
| 116 | + $table->setPrimaryKey(['numeric_id']); |
|
| 117 | + $table->addUniqueIndex(['id'], 'storages_id_index'); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - if (!$schema->hasTable('mounts')) { |
|
| 121 | - $table = $schema->createTable('mounts'); |
|
| 122 | - $table->addColumn('id', 'integer', [ |
|
| 123 | - 'autoincrement' => true, |
|
| 124 | - 'notnull' => true, |
|
| 125 | - 'length' => 4, |
|
| 126 | - ]); |
|
| 127 | - $table->addColumn('storage_id', Types::BIGINT, [ |
|
| 128 | - 'notnull' => true, |
|
| 129 | - 'length' => 20, |
|
| 130 | - ]); |
|
| 131 | - $table->addColumn('root_id', Types::BIGINT, [ |
|
| 132 | - 'notnull' => true, |
|
| 133 | - 'length' => 20, |
|
| 134 | - ]); |
|
| 135 | - $table->addColumn('user_id', 'string', [ |
|
| 136 | - 'notnull' => true, |
|
| 137 | - 'length' => 64, |
|
| 138 | - ]); |
|
| 139 | - $table->addColumn('mount_point', 'string', [ |
|
| 140 | - 'notnull' => true, |
|
| 141 | - 'length' => 4000, |
|
| 142 | - ]); |
|
| 143 | - $table->addColumn('mount_id', Types::BIGINT, [ |
|
| 144 | - 'notnull' => false, |
|
| 145 | - 'length' => 20, |
|
| 146 | - ]); |
|
| 147 | - $table->setPrimaryKey(['id']); |
|
| 148 | - $table->addIndex(['user_id'], 'mounts_user_index'); |
|
| 149 | - $table->addIndex(['storage_id'], 'mounts_storage_index'); |
|
| 150 | - $table->addIndex(['root_id'], 'mounts_root_index'); |
|
| 151 | - $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
|
| 152 | - $table->addIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', [], ['lengths' => [null, null, 128]]); |
|
| 153 | - } else { |
|
| 154 | - $table = $schema->getTable('mounts'); |
|
| 155 | - $table->addColumn('mount_id', Types::BIGINT, [ |
|
| 156 | - 'notnull' => false, |
|
| 157 | - 'length' => 20, |
|
| 158 | - ]); |
|
| 159 | - if (!$table->hasIndex('mounts_mount_id_index')) { |
|
| 160 | - $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
|
| 161 | - } |
|
| 162 | - } |
|
| 120 | + if (!$schema->hasTable('mounts')) { |
|
| 121 | + $table = $schema->createTable('mounts'); |
|
| 122 | + $table->addColumn('id', 'integer', [ |
|
| 123 | + 'autoincrement' => true, |
|
| 124 | + 'notnull' => true, |
|
| 125 | + 'length' => 4, |
|
| 126 | + ]); |
|
| 127 | + $table->addColumn('storage_id', Types::BIGINT, [ |
|
| 128 | + 'notnull' => true, |
|
| 129 | + 'length' => 20, |
|
| 130 | + ]); |
|
| 131 | + $table->addColumn('root_id', Types::BIGINT, [ |
|
| 132 | + 'notnull' => true, |
|
| 133 | + 'length' => 20, |
|
| 134 | + ]); |
|
| 135 | + $table->addColumn('user_id', 'string', [ |
|
| 136 | + 'notnull' => true, |
|
| 137 | + 'length' => 64, |
|
| 138 | + ]); |
|
| 139 | + $table->addColumn('mount_point', 'string', [ |
|
| 140 | + 'notnull' => true, |
|
| 141 | + 'length' => 4000, |
|
| 142 | + ]); |
|
| 143 | + $table->addColumn('mount_id', Types::BIGINT, [ |
|
| 144 | + 'notnull' => false, |
|
| 145 | + 'length' => 20, |
|
| 146 | + ]); |
|
| 147 | + $table->setPrimaryKey(['id']); |
|
| 148 | + $table->addIndex(['user_id'], 'mounts_user_index'); |
|
| 149 | + $table->addIndex(['storage_id'], 'mounts_storage_index'); |
|
| 150 | + $table->addIndex(['root_id'], 'mounts_root_index'); |
|
| 151 | + $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
|
| 152 | + $table->addIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', [], ['lengths' => [null, null, 128]]); |
|
| 153 | + } else { |
|
| 154 | + $table = $schema->getTable('mounts'); |
|
| 155 | + $table->addColumn('mount_id', Types::BIGINT, [ |
|
| 156 | + 'notnull' => false, |
|
| 157 | + 'length' => 20, |
|
| 158 | + ]); |
|
| 159 | + if (!$table->hasIndex('mounts_mount_id_index')) { |
|
| 160 | + $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - if (!$schema->hasTable('mimetypes')) { |
|
| 165 | - $table = $schema->createTable('mimetypes'); |
|
| 166 | - $table->addColumn('id', Types::BIGINT, [ |
|
| 167 | - 'autoincrement' => true, |
|
| 168 | - 'notnull' => true, |
|
| 169 | - 'length' => 20, |
|
| 170 | - ]); |
|
| 171 | - $table->addColumn('mimetype', 'string', [ |
|
| 172 | - 'notnull' => true, |
|
| 173 | - 'length' => 255, |
|
| 174 | - 'default' => '', |
|
| 175 | - ]); |
|
| 176 | - $table->setPrimaryKey(['id']); |
|
| 177 | - $table->addUniqueIndex(['mimetype'], 'mimetype_id_index'); |
|
| 178 | - } |
|
| 164 | + if (!$schema->hasTable('mimetypes')) { |
|
| 165 | + $table = $schema->createTable('mimetypes'); |
|
| 166 | + $table->addColumn('id', Types::BIGINT, [ |
|
| 167 | + 'autoincrement' => true, |
|
| 168 | + 'notnull' => true, |
|
| 169 | + 'length' => 20, |
|
| 170 | + ]); |
|
| 171 | + $table->addColumn('mimetype', 'string', [ |
|
| 172 | + 'notnull' => true, |
|
| 173 | + 'length' => 255, |
|
| 174 | + 'default' => '', |
|
| 175 | + ]); |
|
| 176 | + $table->setPrimaryKey(['id']); |
|
| 177 | + $table->addUniqueIndex(['mimetype'], 'mimetype_id_index'); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - if (!$schema->hasTable('filecache')) { |
|
| 181 | - $table = $schema->createTable('filecache'); |
|
| 182 | - $table->addColumn('fileid', Types::BIGINT, [ |
|
| 183 | - 'autoincrement' => true, |
|
| 184 | - 'notnull' => true, |
|
| 185 | - 'length' => 20, |
|
| 186 | - ]); |
|
| 187 | - $table->addColumn('storage', Types::BIGINT, [ |
|
| 188 | - 'notnull' => true, |
|
| 189 | - 'length' => 20, |
|
| 190 | - 'default' => 0, |
|
| 191 | - ]); |
|
| 192 | - $table->addColumn('path', 'string', [ |
|
| 193 | - 'notnull' => false, |
|
| 194 | - 'length' => 4000, |
|
| 195 | - ]); |
|
| 196 | - $table->addColumn('path_hash', 'string', [ |
|
| 197 | - 'notnull' => true, |
|
| 198 | - 'length' => 32, |
|
| 199 | - 'default' => '', |
|
| 200 | - ]); |
|
| 201 | - $table->addColumn('parent', Types::BIGINT, [ |
|
| 202 | - 'notnull' => true, |
|
| 203 | - 'length' => 20, |
|
| 204 | - 'default' => 0, |
|
| 205 | - ]); |
|
| 206 | - $table->addColumn('name', 'string', [ |
|
| 207 | - 'notnull' => false, |
|
| 208 | - 'length' => 250, |
|
| 209 | - ]); |
|
| 210 | - $table->addColumn('mimetype', Types::BIGINT, [ |
|
| 211 | - 'notnull' => true, |
|
| 212 | - 'length' => 20, |
|
| 213 | - 'default' => 0, |
|
| 214 | - ]); |
|
| 215 | - $table->addColumn('mimepart', Types::BIGINT, [ |
|
| 216 | - 'notnull' => true, |
|
| 217 | - 'length' => 20, |
|
| 218 | - 'default' => 0, |
|
| 219 | - ]); |
|
| 220 | - $table->addColumn('size', 'bigint', [ |
|
| 221 | - 'notnull' => true, |
|
| 222 | - 'length' => 8, |
|
| 223 | - 'default' => 0, |
|
| 224 | - ]); |
|
| 225 | - $table->addColumn('mtime', Types::BIGINT, [ |
|
| 226 | - 'notnull' => true, |
|
| 227 | - 'length' => 20, |
|
| 228 | - 'default' => 0, |
|
| 229 | - ]); |
|
| 230 | - $table->addColumn('storage_mtime', Types::BIGINT, [ |
|
| 231 | - 'notnull' => true, |
|
| 232 | - 'length' => 20, |
|
| 233 | - 'default' => 0, |
|
| 234 | - ]); |
|
| 235 | - $table->addColumn('encrypted', 'integer', [ |
|
| 236 | - 'notnull' => true, |
|
| 237 | - 'length' => 4, |
|
| 238 | - 'default' => 0, |
|
| 239 | - ]); |
|
| 240 | - $table->addColumn('unencrypted_size', 'bigint', [ |
|
| 241 | - 'notnull' => true, |
|
| 242 | - 'length' => 8, |
|
| 243 | - 'default' => 0, |
|
| 244 | - ]); |
|
| 245 | - $table->addColumn('etag', 'string', [ |
|
| 246 | - 'notnull' => false, |
|
| 247 | - 'length' => 40, |
|
| 248 | - ]); |
|
| 249 | - $table->addColumn('permissions', 'integer', [ |
|
| 250 | - 'notnull' => false, |
|
| 251 | - 'length' => 4, |
|
| 252 | - 'default' => 0, |
|
| 253 | - ]); |
|
| 254 | - $table->addColumn('checksum', 'string', [ |
|
| 255 | - 'notnull' => false, |
|
| 256 | - 'length' => 255, |
|
| 257 | - ]); |
|
| 258 | - $table->setPrimaryKey(['fileid']); |
|
| 259 | - $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash'); |
|
| 260 | - $table->addIndex(['parent', 'name'], 'fs_parent_name_hash'); |
|
| 261 | - $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype'); |
|
| 262 | - $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart'); |
|
| 263 | - $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size'); |
|
| 264 | - $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size'); |
|
| 265 | - $table->addIndex(['parent'], 'fs_parent'); |
|
| 266 | - $table->addIndex(['mtime'], 'fs_mtime'); |
|
| 267 | - $table->addIndex(['size'], 'fs_size'); |
|
| 268 | - if (!$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
| 269 | - $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]); |
|
| 270 | - } |
|
| 271 | - } |
|
| 180 | + if (!$schema->hasTable('filecache')) { |
|
| 181 | + $table = $schema->createTable('filecache'); |
|
| 182 | + $table->addColumn('fileid', Types::BIGINT, [ |
|
| 183 | + 'autoincrement' => true, |
|
| 184 | + 'notnull' => true, |
|
| 185 | + 'length' => 20, |
|
| 186 | + ]); |
|
| 187 | + $table->addColumn('storage', Types::BIGINT, [ |
|
| 188 | + 'notnull' => true, |
|
| 189 | + 'length' => 20, |
|
| 190 | + 'default' => 0, |
|
| 191 | + ]); |
|
| 192 | + $table->addColumn('path', 'string', [ |
|
| 193 | + 'notnull' => false, |
|
| 194 | + 'length' => 4000, |
|
| 195 | + ]); |
|
| 196 | + $table->addColumn('path_hash', 'string', [ |
|
| 197 | + 'notnull' => true, |
|
| 198 | + 'length' => 32, |
|
| 199 | + 'default' => '', |
|
| 200 | + ]); |
|
| 201 | + $table->addColumn('parent', Types::BIGINT, [ |
|
| 202 | + 'notnull' => true, |
|
| 203 | + 'length' => 20, |
|
| 204 | + 'default' => 0, |
|
| 205 | + ]); |
|
| 206 | + $table->addColumn('name', 'string', [ |
|
| 207 | + 'notnull' => false, |
|
| 208 | + 'length' => 250, |
|
| 209 | + ]); |
|
| 210 | + $table->addColumn('mimetype', Types::BIGINT, [ |
|
| 211 | + 'notnull' => true, |
|
| 212 | + 'length' => 20, |
|
| 213 | + 'default' => 0, |
|
| 214 | + ]); |
|
| 215 | + $table->addColumn('mimepart', Types::BIGINT, [ |
|
| 216 | + 'notnull' => true, |
|
| 217 | + 'length' => 20, |
|
| 218 | + 'default' => 0, |
|
| 219 | + ]); |
|
| 220 | + $table->addColumn('size', 'bigint', [ |
|
| 221 | + 'notnull' => true, |
|
| 222 | + 'length' => 8, |
|
| 223 | + 'default' => 0, |
|
| 224 | + ]); |
|
| 225 | + $table->addColumn('mtime', Types::BIGINT, [ |
|
| 226 | + 'notnull' => true, |
|
| 227 | + 'length' => 20, |
|
| 228 | + 'default' => 0, |
|
| 229 | + ]); |
|
| 230 | + $table->addColumn('storage_mtime', Types::BIGINT, [ |
|
| 231 | + 'notnull' => true, |
|
| 232 | + 'length' => 20, |
|
| 233 | + 'default' => 0, |
|
| 234 | + ]); |
|
| 235 | + $table->addColumn('encrypted', 'integer', [ |
|
| 236 | + 'notnull' => true, |
|
| 237 | + 'length' => 4, |
|
| 238 | + 'default' => 0, |
|
| 239 | + ]); |
|
| 240 | + $table->addColumn('unencrypted_size', 'bigint', [ |
|
| 241 | + 'notnull' => true, |
|
| 242 | + 'length' => 8, |
|
| 243 | + 'default' => 0, |
|
| 244 | + ]); |
|
| 245 | + $table->addColumn('etag', 'string', [ |
|
| 246 | + 'notnull' => false, |
|
| 247 | + 'length' => 40, |
|
| 248 | + ]); |
|
| 249 | + $table->addColumn('permissions', 'integer', [ |
|
| 250 | + 'notnull' => false, |
|
| 251 | + 'length' => 4, |
|
| 252 | + 'default' => 0, |
|
| 253 | + ]); |
|
| 254 | + $table->addColumn('checksum', 'string', [ |
|
| 255 | + 'notnull' => false, |
|
| 256 | + 'length' => 255, |
|
| 257 | + ]); |
|
| 258 | + $table->setPrimaryKey(['fileid']); |
|
| 259 | + $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash'); |
|
| 260 | + $table->addIndex(['parent', 'name'], 'fs_parent_name_hash'); |
|
| 261 | + $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype'); |
|
| 262 | + $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart'); |
|
| 263 | + $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size'); |
|
| 264 | + $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size'); |
|
| 265 | + $table->addIndex(['parent'], 'fs_parent'); |
|
| 266 | + $table->addIndex(['mtime'], 'fs_mtime'); |
|
| 267 | + $table->addIndex(['size'], 'fs_size'); |
|
| 268 | + if (!$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
| 269 | + $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - if (!$schema->hasTable('group_user')) { |
|
| 274 | - $table = $schema->createTable('group_user'); |
|
| 275 | - $table->addColumn('gid', 'string', [ |
|
| 276 | - 'notnull' => true, |
|
| 277 | - 'length' => 64, |
|
| 278 | - 'default' => '', |
|
| 279 | - ]); |
|
| 280 | - $table->addColumn('uid', 'string', [ |
|
| 281 | - 'notnull' => true, |
|
| 282 | - 'length' => 64, |
|
| 283 | - 'default' => '', |
|
| 284 | - ]); |
|
| 285 | - $table->setPrimaryKey(['gid', 'uid']); |
|
| 286 | - $table->addIndex(['uid'], 'gu_uid_index'); |
|
| 287 | - } |
|
| 273 | + if (!$schema->hasTable('group_user')) { |
|
| 274 | + $table = $schema->createTable('group_user'); |
|
| 275 | + $table->addColumn('gid', 'string', [ |
|
| 276 | + 'notnull' => true, |
|
| 277 | + 'length' => 64, |
|
| 278 | + 'default' => '', |
|
| 279 | + ]); |
|
| 280 | + $table->addColumn('uid', 'string', [ |
|
| 281 | + 'notnull' => true, |
|
| 282 | + 'length' => 64, |
|
| 283 | + 'default' => '', |
|
| 284 | + ]); |
|
| 285 | + $table->setPrimaryKey(['gid', 'uid']); |
|
| 286 | + $table->addIndex(['uid'], 'gu_uid_index'); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - if (!$schema->hasTable('group_admin')) { |
|
| 290 | - $table = $schema->createTable('group_admin'); |
|
| 291 | - $table->addColumn('gid', 'string', [ |
|
| 292 | - 'notnull' => true, |
|
| 293 | - 'length' => 64, |
|
| 294 | - 'default' => '', |
|
| 295 | - ]); |
|
| 296 | - $table->addColumn('uid', 'string', [ |
|
| 297 | - 'notnull' => true, |
|
| 298 | - 'length' => 64, |
|
| 299 | - 'default' => '', |
|
| 300 | - ]); |
|
| 301 | - $table->setPrimaryKey(['gid', 'uid']); |
|
| 302 | - $table->addIndex(['uid'], 'group_admin_uid'); |
|
| 303 | - } |
|
| 289 | + if (!$schema->hasTable('group_admin')) { |
|
| 290 | + $table = $schema->createTable('group_admin'); |
|
| 291 | + $table->addColumn('gid', 'string', [ |
|
| 292 | + 'notnull' => true, |
|
| 293 | + 'length' => 64, |
|
| 294 | + 'default' => '', |
|
| 295 | + ]); |
|
| 296 | + $table->addColumn('uid', 'string', [ |
|
| 297 | + 'notnull' => true, |
|
| 298 | + 'length' => 64, |
|
| 299 | + 'default' => '', |
|
| 300 | + ]); |
|
| 301 | + $table->setPrimaryKey(['gid', 'uid']); |
|
| 302 | + $table->addIndex(['uid'], 'group_admin_uid'); |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - if (!$schema->hasTable('groups')) { |
|
| 306 | - $table = $schema->createTable('groups'); |
|
| 307 | - $table->addColumn('gid', 'string', [ |
|
| 308 | - 'notnull' => true, |
|
| 309 | - 'length' => 64, |
|
| 310 | - 'default' => '', |
|
| 311 | - ]); |
|
| 312 | - $table->setPrimaryKey(['gid']); |
|
| 313 | - } |
|
| 305 | + if (!$schema->hasTable('groups')) { |
|
| 306 | + $table = $schema->createTable('groups'); |
|
| 307 | + $table->addColumn('gid', 'string', [ |
|
| 308 | + 'notnull' => true, |
|
| 309 | + 'length' => 64, |
|
| 310 | + 'default' => '', |
|
| 311 | + ]); |
|
| 312 | + $table->setPrimaryKey(['gid']); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - if (!$schema->hasTable('preferences')) { |
|
| 316 | - $table = $schema->createTable('preferences'); |
|
| 317 | - $table->addColumn('userid', 'string', [ |
|
| 318 | - 'notnull' => true, |
|
| 319 | - 'length' => 64, |
|
| 320 | - 'default' => '', |
|
| 321 | - ]); |
|
| 322 | - $table->addColumn('appid', 'string', [ |
|
| 323 | - 'notnull' => true, |
|
| 324 | - 'length' => 32, |
|
| 325 | - 'default' => '', |
|
| 326 | - ]); |
|
| 327 | - $table->addColumn('configkey', 'string', [ |
|
| 328 | - 'notnull' => true, |
|
| 329 | - 'length' => 64, |
|
| 330 | - 'default' => '', |
|
| 331 | - ]); |
|
| 332 | - $table->addColumn('configvalue', 'text', [ |
|
| 333 | - 'notnull' => false, |
|
| 334 | - ]); |
|
| 335 | - $table->setPrimaryKey(['userid', 'appid', 'configkey']); |
|
| 336 | - $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); |
|
| 337 | - } |
|
| 315 | + if (!$schema->hasTable('preferences')) { |
|
| 316 | + $table = $schema->createTable('preferences'); |
|
| 317 | + $table->addColumn('userid', 'string', [ |
|
| 318 | + 'notnull' => true, |
|
| 319 | + 'length' => 64, |
|
| 320 | + 'default' => '', |
|
| 321 | + ]); |
|
| 322 | + $table->addColumn('appid', 'string', [ |
|
| 323 | + 'notnull' => true, |
|
| 324 | + 'length' => 32, |
|
| 325 | + 'default' => '', |
|
| 326 | + ]); |
|
| 327 | + $table->addColumn('configkey', 'string', [ |
|
| 328 | + 'notnull' => true, |
|
| 329 | + 'length' => 64, |
|
| 330 | + 'default' => '', |
|
| 331 | + ]); |
|
| 332 | + $table->addColumn('configvalue', 'text', [ |
|
| 333 | + 'notnull' => false, |
|
| 334 | + ]); |
|
| 335 | + $table->setPrimaryKey(['userid', 'appid', 'configkey']); |
|
| 336 | + $table->addIndex(['appid', 'configkey'], 'preferences_app_key'); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (!$schema->hasTable('properties')) { |
|
| 340 | - $table = $schema->createTable('properties'); |
|
| 341 | - $table->addColumn('id', 'integer', [ |
|
| 342 | - 'autoincrement' => true, |
|
| 343 | - 'notnull' => true, |
|
| 344 | - 'length' => 4, |
|
| 345 | - ]); |
|
| 346 | - $table->addColumn('userid', 'string', [ |
|
| 347 | - 'notnull' => true, |
|
| 348 | - 'length' => 64, |
|
| 349 | - 'default' => '', |
|
| 350 | - ]); |
|
| 351 | - $table->addColumn('propertypath', 'string', [ |
|
| 352 | - 'notnull' => true, |
|
| 353 | - 'length' => 255, |
|
| 354 | - 'default' => '', |
|
| 355 | - ]); |
|
| 356 | - $table->addColumn('propertyname', 'string', [ |
|
| 357 | - 'notnull' => true, |
|
| 358 | - 'length' => 255, |
|
| 359 | - 'default' => '', |
|
| 360 | - ]); |
|
| 361 | - $table->addColumn('propertyvalue', 'text', [ |
|
| 362 | - 'notnull' => true, |
|
| 363 | - ]); |
|
| 364 | - $table->setPrimaryKey(['id']); |
|
| 365 | - $table->addIndex(['userid'], 'property_index'); |
|
| 366 | - $table->addIndex(['userid', 'propertypath'], 'properties_path_index'); |
|
| 367 | - $table->addIndex(['propertypath'], 'properties_pathonly_index'); |
|
| 368 | - } else { |
|
| 369 | - $table = $schema->getTable('properties'); |
|
| 370 | - if ($table->hasColumn('propertytype')) { |
|
| 371 | - $table->dropColumn('propertytype'); |
|
| 372 | - } |
|
| 373 | - if ($table->hasColumn('fileid')) { |
|
| 374 | - $table->dropColumn('fileid'); |
|
| 375 | - } |
|
| 376 | - if (!$table->hasColumn('propertypath')) { |
|
| 377 | - $table->addColumn('propertypath', 'string', [ |
|
| 378 | - 'notnull' => true, |
|
| 379 | - 'length' => 255, |
|
| 380 | - ]); |
|
| 381 | - } |
|
| 382 | - if (!$table->hasColumn('userid')) { |
|
| 383 | - $table->addColumn('userid', 'string', [ |
|
| 384 | - 'notnull' => false, |
|
| 385 | - 'length' => 64, |
|
| 386 | - 'default' => '', |
|
| 387 | - ]); |
|
| 388 | - } |
|
| 389 | - } |
|
| 339 | + if (!$schema->hasTable('properties')) { |
|
| 340 | + $table = $schema->createTable('properties'); |
|
| 341 | + $table->addColumn('id', 'integer', [ |
|
| 342 | + 'autoincrement' => true, |
|
| 343 | + 'notnull' => true, |
|
| 344 | + 'length' => 4, |
|
| 345 | + ]); |
|
| 346 | + $table->addColumn('userid', 'string', [ |
|
| 347 | + 'notnull' => true, |
|
| 348 | + 'length' => 64, |
|
| 349 | + 'default' => '', |
|
| 350 | + ]); |
|
| 351 | + $table->addColumn('propertypath', 'string', [ |
|
| 352 | + 'notnull' => true, |
|
| 353 | + 'length' => 255, |
|
| 354 | + 'default' => '', |
|
| 355 | + ]); |
|
| 356 | + $table->addColumn('propertyname', 'string', [ |
|
| 357 | + 'notnull' => true, |
|
| 358 | + 'length' => 255, |
|
| 359 | + 'default' => '', |
|
| 360 | + ]); |
|
| 361 | + $table->addColumn('propertyvalue', 'text', [ |
|
| 362 | + 'notnull' => true, |
|
| 363 | + ]); |
|
| 364 | + $table->setPrimaryKey(['id']); |
|
| 365 | + $table->addIndex(['userid'], 'property_index'); |
|
| 366 | + $table->addIndex(['userid', 'propertypath'], 'properties_path_index'); |
|
| 367 | + $table->addIndex(['propertypath'], 'properties_pathonly_index'); |
|
| 368 | + } else { |
|
| 369 | + $table = $schema->getTable('properties'); |
|
| 370 | + if ($table->hasColumn('propertytype')) { |
|
| 371 | + $table->dropColumn('propertytype'); |
|
| 372 | + } |
|
| 373 | + if ($table->hasColumn('fileid')) { |
|
| 374 | + $table->dropColumn('fileid'); |
|
| 375 | + } |
|
| 376 | + if (!$table->hasColumn('propertypath')) { |
|
| 377 | + $table->addColumn('propertypath', 'string', [ |
|
| 378 | + 'notnull' => true, |
|
| 379 | + 'length' => 255, |
|
| 380 | + ]); |
|
| 381 | + } |
|
| 382 | + if (!$table->hasColumn('userid')) { |
|
| 383 | + $table->addColumn('userid', 'string', [ |
|
| 384 | + 'notnull' => false, |
|
| 385 | + 'length' => 64, |
|
| 386 | + 'default' => '', |
|
| 387 | + ]); |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - if (!$schema->hasTable('share')) { |
|
| 392 | - $table = $schema->createTable('share'); |
|
| 393 | - $table->addColumn('id', 'integer', [ |
|
| 394 | - 'autoincrement' => true, |
|
| 395 | - 'notnull' => true, |
|
| 396 | - 'length' => 4, |
|
| 397 | - ]); |
|
| 398 | - $table->addColumn('share_type', 'smallint', [ |
|
| 399 | - 'notnull' => true, |
|
| 400 | - 'length' => 1, |
|
| 401 | - 'default' => 0, |
|
| 402 | - ]); |
|
| 403 | - $table->addColumn('share_with', 'string', [ |
|
| 404 | - 'notnull' => false, |
|
| 405 | - 'length' => 255, |
|
| 406 | - ]); |
|
| 407 | - $table->addColumn('password', 'string', [ |
|
| 408 | - 'notnull' => false, |
|
| 409 | - 'length' => 255, |
|
| 410 | - ]); |
|
| 411 | - $table->addColumn('uid_owner', 'string', [ |
|
| 412 | - 'notnull' => true, |
|
| 413 | - 'length' => 64, |
|
| 414 | - 'default' => '', |
|
| 415 | - ]); |
|
| 416 | - $table->addColumn('uid_initiator', 'string', [ |
|
| 417 | - 'notnull' => false, |
|
| 418 | - 'length' => 64, |
|
| 419 | - ]); |
|
| 420 | - $table->addColumn('parent', 'integer', [ |
|
| 421 | - 'notnull' => false, |
|
| 422 | - 'length' => 4, |
|
| 423 | - ]); |
|
| 424 | - $table->addColumn('item_type', 'string', [ |
|
| 425 | - 'notnull' => true, |
|
| 426 | - 'length' => 64, |
|
| 427 | - 'default' => '', |
|
| 428 | - ]); |
|
| 429 | - $table->addColumn('item_source', 'string', [ |
|
| 430 | - 'notnull' => false, |
|
| 431 | - 'length' => 255, |
|
| 432 | - ]); |
|
| 433 | - $table->addColumn('item_target', 'string', [ |
|
| 434 | - 'notnull' => false, |
|
| 435 | - 'length' => 255, |
|
| 436 | - ]); |
|
| 437 | - $table->addColumn('file_source', 'integer', [ |
|
| 438 | - 'notnull' => false, |
|
| 439 | - 'length' => 4, |
|
| 440 | - ]); |
|
| 441 | - $table->addColumn('file_target', 'string', [ |
|
| 442 | - 'notnull' => false, |
|
| 443 | - 'length' => 512, |
|
| 444 | - ]); |
|
| 445 | - $table->addColumn('permissions', 'smallint', [ |
|
| 446 | - 'notnull' => true, |
|
| 447 | - 'length' => 1, |
|
| 448 | - 'default' => 0, |
|
| 449 | - ]); |
|
| 450 | - $table->addColumn('stime', 'bigint', [ |
|
| 451 | - 'notnull' => true, |
|
| 452 | - 'length' => 8, |
|
| 453 | - 'default' => 0, |
|
| 454 | - ]); |
|
| 455 | - $table->addColumn('accepted', 'smallint', [ |
|
| 456 | - 'notnull' => true, |
|
| 457 | - 'length' => 1, |
|
| 458 | - 'default' => 0, |
|
| 459 | - ]); |
|
| 460 | - $table->addColumn('expiration', 'datetime', [ |
|
| 461 | - 'notnull' => false, |
|
| 462 | - ]); |
|
| 463 | - $table->addColumn('token', 'string', [ |
|
| 464 | - 'notnull' => false, |
|
| 465 | - 'length' => 32, |
|
| 466 | - ]); |
|
| 467 | - $table->addColumn('mail_send', 'smallint', [ |
|
| 468 | - 'notnull' => true, |
|
| 469 | - 'length' => 1, |
|
| 470 | - 'default' => 0, |
|
| 471 | - ]); |
|
| 472 | - $table->addColumn('share_name', 'string', [ |
|
| 473 | - 'notnull' => false, |
|
| 474 | - 'length' => 64, |
|
| 475 | - ]); |
|
| 476 | - $table->setPrimaryKey(['id']); |
|
| 477 | - $table->addIndex(['item_type', 'share_type'], 'item_share_type_index'); |
|
| 478 | - $table->addIndex(['file_source'], 'file_source_index'); |
|
| 479 | - $table->addIndex(['token'], 'token_index'); |
|
| 480 | - $table->addIndex(['share_with'], 'share_with_index'); |
|
| 481 | - $table->addIndex(['parent'], 'parent_index'); |
|
| 482 | - $table->addIndex(['uid_owner'], 'owner_index'); |
|
| 483 | - $table->addIndex(['uid_initiator'], 'initiator_index'); |
|
| 484 | - } else { |
|
| 485 | - $table = $schema->getTable('share'); |
|
| 486 | - if (!$table->hasColumn('password')) { |
|
| 487 | - $table->addColumn('password', 'string', [ |
|
| 488 | - 'notnull' => false, |
|
| 489 | - 'length' => 255, |
|
| 490 | - ]); |
|
| 491 | - } |
|
| 492 | - } |
|
| 391 | + if (!$schema->hasTable('share')) { |
|
| 392 | + $table = $schema->createTable('share'); |
|
| 393 | + $table->addColumn('id', 'integer', [ |
|
| 394 | + 'autoincrement' => true, |
|
| 395 | + 'notnull' => true, |
|
| 396 | + 'length' => 4, |
|
| 397 | + ]); |
|
| 398 | + $table->addColumn('share_type', 'smallint', [ |
|
| 399 | + 'notnull' => true, |
|
| 400 | + 'length' => 1, |
|
| 401 | + 'default' => 0, |
|
| 402 | + ]); |
|
| 403 | + $table->addColumn('share_with', 'string', [ |
|
| 404 | + 'notnull' => false, |
|
| 405 | + 'length' => 255, |
|
| 406 | + ]); |
|
| 407 | + $table->addColumn('password', 'string', [ |
|
| 408 | + 'notnull' => false, |
|
| 409 | + 'length' => 255, |
|
| 410 | + ]); |
|
| 411 | + $table->addColumn('uid_owner', 'string', [ |
|
| 412 | + 'notnull' => true, |
|
| 413 | + 'length' => 64, |
|
| 414 | + 'default' => '', |
|
| 415 | + ]); |
|
| 416 | + $table->addColumn('uid_initiator', 'string', [ |
|
| 417 | + 'notnull' => false, |
|
| 418 | + 'length' => 64, |
|
| 419 | + ]); |
|
| 420 | + $table->addColumn('parent', 'integer', [ |
|
| 421 | + 'notnull' => false, |
|
| 422 | + 'length' => 4, |
|
| 423 | + ]); |
|
| 424 | + $table->addColumn('item_type', 'string', [ |
|
| 425 | + 'notnull' => true, |
|
| 426 | + 'length' => 64, |
|
| 427 | + 'default' => '', |
|
| 428 | + ]); |
|
| 429 | + $table->addColumn('item_source', 'string', [ |
|
| 430 | + 'notnull' => false, |
|
| 431 | + 'length' => 255, |
|
| 432 | + ]); |
|
| 433 | + $table->addColumn('item_target', 'string', [ |
|
| 434 | + 'notnull' => false, |
|
| 435 | + 'length' => 255, |
|
| 436 | + ]); |
|
| 437 | + $table->addColumn('file_source', 'integer', [ |
|
| 438 | + 'notnull' => false, |
|
| 439 | + 'length' => 4, |
|
| 440 | + ]); |
|
| 441 | + $table->addColumn('file_target', 'string', [ |
|
| 442 | + 'notnull' => false, |
|
| 443 | + 'length' => 512, |
|
| 444 | + ]); |
|
| 445 | + $table->addColumn('permissions', 'smallint', [ |
|
| 446 | + 'notnull' => true, |
|
| 447 | + 'length' => 1, |
|
| 448 | + 'default' => 0, |
|
| 449 | + ]); |
|
| 450 | + $table->addColumn('stime', 'bigint', [ |
|
| 451 | + 'notnull' => true, |
|
| 452 | + 'length' => 8, |
|
| 453 | + 'default' => 0, |
|
| 454 | + ]); |
|
| 455 | + $table->addColumn('accepted', 'smallint', [ |
|
| 456 | + 'notnull' => true, |
|
| 457 | + 'length' => 1, |
|
| 458 | + 'default' => 0, |
|
| 459 | + ]); |
|
| 460 | + $table->addColumn('expiration', 'datetime', [ |
|
| 461 | + 'notnull' => false, |
|
| 462 | + ]); |
|
| 463 | + $table->addColumn('token', 'string', [ |
|
| 464 | + 'notnull' => false, |
|
| 465 | + 'length' => 32, |
|
| 466 | + ]); |
|
| 467 | + $table->addColumn('mail_send', 'smallint', [ |
|
| 468 | + 'notnull' => true, |
|
| 469 | + 'length' => 1, |
|
| 470 | + 'default' => 0, |
|
| 471 | + ]); |
|
| 472 | + $table->addColumn('share_name', 'string', [ |
|
| 473 | + 'notnull' => false, |
|
| 474 | + 'length' => 64, |
|
| 475 | + ]); |
|
| 476 | + $table->setPrimaryKey(['id']); |
|
| 477 | + $table->addIndex(['item_type', 'share_type'], 'item_share_type_index'); |
|
| 478 | + $table->addIndex(['file_source'], 'file_source_index'); |
|
| 479 | + $table->addIndex(['token'], 'token_index'); |
|
| 480 | + $table->addIndex(['share_with'], 'share_with_index'); |
|
| 481 | + $table->addIndex(['parent'], 'parent_index'); |
|
| 482 | + $table->addIndex(['uid_owner'], 'owner_index'); |
|
| 483 | + $table->addIndex(['uid_initiator'], 'initiator_index'); |
|
| 484 | + } else { |
|
| 485 | + $table = $schema->getTable('share'); |
|
| 486 | + if (!$table->hasColumn('password')) { |
|
| 487 | + $table->addColumn('password', 'string', [ |
|
| 488 | + 'notnull' => false, |
|
| 489 | + 'length' => 255, |
|
| 490 | + ]); |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - if (!$schema->hasTable('jobs')) { |
|
| 495 | - $table = $schema->createTable('jobs'); |
|
| 496 | - $table->addColumn('id', 'integer', [ |
|
| 497 | - 'autoincrement' => true, |
|
| 498 | - 'notnull' => true, |
|
| 499 | - 'length' => 4, |
|
| 500 | - 'unsigned' => true, |
|
| 501 | - ]); |
|
| 502 | - $table->addColumn('class', 'string', [ |
|
| 503 | - 'notnull' => true, |
|
| 504 | - 'length' => 255, |
|
| 505 | - 'default' => '', |
|
| 506 | - ]); |
|
| 507 | - $table->addColumn('argument', 'string', [ |
|
| 508 | - 'notnull' => true, |
|
| 509 | - 'length' => 4000, |
|
| 510 | - 'default' => '', |
|
| 511 | - ]); |
|
| 512 | - $table->addColumn('last_run', 'integer', [ |
|
| 513 | - 'notnull' => false, |
|
| 514 | - 'default' => 0, |
|
| 515 | - ]); |
|
| 516 | - $table->addColumn('last_checked', 'integer', [ |
|
| 517 | - 'notnull' => false, |
|
| 518 | - 'default' => 0, |
|
| 519 | - ]); |
|
| 520 | - $table->addColumn('reserved_at', 'integer', [ |
|
| 521 | - 'notnull' => false, |
|
| 522 | - 'default' => 0, |
|
| 523 | - ]); |
|
| 524 | - $table->addColumn('execution_duration', 'integer', [ |
|
| 525 | - 'notnull' => true, |
|
| 526 | - 'default' => 0, |
|
| 527 | - ]); |
|
| 528 | - $table->setPrimaryKey(['id']); |
|
| 529 | - $table->addIndex(['class'], 'job_class_index'); |
|
| 530 | - $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved'); |
|
| 531 | - } |
|
| 494 | + if (!$schema->hasTable('jobs')) { |
|
| 495 | + $table = $schema->createTable('jobs'); |
|
| 496 | + $table->addColumn('id', 'integer', [ |
|
| 497 | + 'autoincrement' => true, |
|
| 498 | + 'notnull' => true, |
|
| 499 | + 'length' => 4, |
|
| 500 | + 'unsigned' => true, |
|
| 501 | + ]); |
|
| 502 | + $table->addColumn('class', 'string', [ |
|
| 503 | + 'notnull' => true, |
|
| 504 | + 'length' => 255, |
|
| 505 | + 'default' => '', |
|
| 506 | + ]); |
|
| 507 | + $table->addColumn('argument', 'string', [ |
|
| 508 | + 'notnull' => true, |
|
| 509 | + 'length' => 4000, |
|
| 510 | + 'default' => '', |
|
| 511 | + ]); |
|
| 512 | + $table->addColumn('last_run', 'integer', [ |
|
| 513 | + 'notnull' => false, |
|
| 514 | + 'default' => 0, |
|
| 515 | + ]); |
|
| 516 | + $table->addColumn('last_checked', 'integer', [ |
|
| 517 | + 'notnull' => false, |
|
| 518 | + 'default' => 0, |
|
| 519 | + ]); |
|
| 520 | + $table->addColumn('reserved_at', 'integer', [ |
|
| 521 | + 'notnull' => false, |
|
| 522 | + 'default' => 0, |
|
| 523 | + ]); |
|
| 524 | + $table->addColumn('execution_duration', 'integer', [ |
|
| 525 | + 'notnull' => true, |
|
| 526 | + 'default' => 0, |
|
| 527 | + ]); |
|
| 528 | + $table->setPrimaryKey(['id']); |
|
| 529 | + $table->addIndex(['class'], 'job_class_index'); |
|
| 530 | + $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved'); |
|
| 531 | + } |
|
| 532 | 532 | |
| 533 | - if (!$schema->hasTable('users')) { |
|
| 534 | - $table = $schema->createTable('users'); |
|
| 535 | - $table->addColumn('uid', 'string', [ |
|
| 536 | - 'notnull' => true, |
|
| 537 | - 'length' => 64, |
|
| 538 | - 'default' => '', |
|
| 539 | - ]); |
|
| 540 | - $table->addColumn('displayname', 'string', [ |
|
| 541 | - 'notnull' => false, |
|
| 542 | - 'length' => 64, |
|
| 543 | - ]); |
|
| 544 | - $table->addColumn('password', 'string', [ |
|
| 545 | - 'notnull' => true, |
|
| 546 | - 'length' => 255, |
|
| 547 | - 'default' => '', |
|
| 548 | - ]); |
|
| 549 | - $table->setPrimaryKey(['uid']); |
|
| 550 | - } |
|
| 533 | + if (!$schema->hasTable('users')) { |
|
| 534 | + $table = $schema->createTable('users'); |
|
| 535 | + $table->addColumn('uid', 'string', [ |
|
| 536 | + 'notnull' => true, |
|
| 537 | + 'length' => 64, |
|
| 538 | + 'default' => '', |
|
| 539 | + ]); |
|
| 540 | + $table->addColumn('displayname', 'string', [ |
|
| 541 | + 'notnull' => false, |
|
| 542 | + 'length' => 64, |
|
| 543 | + ]); |
|
| 544 | + $table->addColumn('password', 'string', [ |
|
| 545 | + 'notnull' => true, |
|
| 546 | + 'length' => 255, |
|
| 547 | + 'default' => '', |
|
| 548 | + ]); |
|
| 549 | + $table->setPrimaryKey(['uid']); |
|
| 550 | + } |
|
| 551 | 551 | |
| 552 | - if (!$schema->hasTable('authtoken')) { |
|
| 553 | - $table = $schema->createTable('authtoken'); |
|
| 554 | - $table->addColumn('id', 'integer', [ |
|
| 555 | - 'autoincrement' => true, |
|
| 556 | - 'notnull' => true, |
|
| 557 | - 'length' => 4, |
|
| 558 | - 'unsigned' => true, |
|
| 559 | - ]); |
|
| 560 | - $table->addColumn('uid', 'string', [ |
|
| 561 | - 'notnull' => true, |
|
| 562 | - 'length' => 64, |
|
| 563 | - 'default' => '', |
|
| 564 | - ]); |
|
| 565 | - $table->addColumn('login_name', 'string', [ |
|
| 566 | - 'notnull' => true, |
|
| 567 | - 'length' => 64, |
|
| 568 | - 'default' => '', |
|
| 569 | - ]); |
|
| 570 | - $table->addColumn('password', 'text', [ |
|
| 571 | - 'notnull' => false, |
|
| 572 | - ]); |
|
| 573 | - $table->addColumn('name', 'text', [ |
|
| 574 | - 'notnull' => true, |
|
| 575 | - 'default' => '', |
|
| 576 | - ]); |
|
| 577 | - $table->addColumn('token', 'string', [ |
|
| 578 | - 'notnull' => true, |
|
| 579 | - 'length' => 200, |
|
| 580 | - 'default' => '', |
|
| 581 | - ]); |
|
| 582 | - $table->addColumn('type', 'smallint', [ |
|
| 583 | - 'notnull' => false, |
|
| 584 | - 'length' => 2, |
|
| 585 | - 'default' => 0, |
|
| 586 | - 'unsigned' => true, |
|
| 587 | - ]); |
|
| 588 | - $table->addColumn('remember', 'smallint', [ |
|
| 589 | - 'notnull' => false, |
|
| 590 | - 'length' => 1, |
|
| 591 | - 'default' => 0, |
|
| 592 | - 'unsigned' => true, |
|
| 593 | - ]); |
|
| 594 | - $table->addColumn('last_activity', 'integer', [ |
|
| 595 | - 'notnull' => false, |
|
| 596 | - 'length' => 4, |
|
| 597 | - 'default' => 0, |
|
| 598 | - 'unsigned' => true, |
|
| 599 | - ]); |
|
| 600 | - $table->addColumn('last_check', 'integer', [ |
|
| 601 | - 'notnull' => false, |
|
| 602 | - 'length' => 4, |
|
| 603 | - 'default' => 0, |
|
| 604 | - 'unsigned' => true, |
|
| 605 | - ]); |
|
| 606 | - $table->addColumn('scope', 'text', [ |
|
| 607 | - 'notnull' => false, |
|
| 608 | - ]); |
|
| 609 | - $table->setPrimaryKey(['id']); |
|
| 610 | - $table->addUniqueIndex(['token'], 'authtoken_token_index'); |
|
| 611 | - $table->addIndex(['last_activity'], 'authtoken_last_activity_idx'); |
|
| 612 | - } else { |
|
| 613 | - $table = $schema->getTable('authtoken'); |
|
| 614 | - $table->addColumn('scope', 'text', [ |
|
| 615 | - 'notnull' => false, |
|
| 616 | - ]); |
|
| 617 | - } |
|
| 552 | + if (!$schema->hasTable('authtoken')) { |
|
| 553 | + $table = $schema->createTable('authtoken'); |
|
| 554 | + $table->addColumn('id', 'integer', [ |
|
| 555 | + 'autoincrement' => true, |
|
| 556 | + 'notnull' => true, |
|
| 557 | + 'length' => 4, |
|
| 558 | + 'unsigned' => true, |
|
| 559 | + ]); |
|
| 560 | + $table->addColumn('uid', 'string', [ |
|
| 561 | + 'notnull' => true, |
|
| 562 | + 'length' => 64, |
|
| 563 | + 'default' => '', |
|
| 564 | + ]); |
|
| 565 | + $table->addColumn('login_name', 'string', [ |
|
| 566 | + 'notnull' => true, |
|
| 567 | + 'length' => 64, |
|
| 568 | + 'default' => '', |
|
| 569 | + ]); |
|
| 570 | + $table->addColumn('password', 'text', [ |
|
| 571 | + 'notnull' => false, |
|
| 572 | + ]); |
|
| 573 | + $table->addColumn('name', 'text', [ |
|
| 574 | + 'notnull' => true, |
|
| 575 | + 'default' => '', |
|
| 576 | + ]); |
|
| 577 | + $table->addColumn('token', 'string', [ |
|
| 578 | + 'notnull' => true, |
|
| 579 | + 'length' => 200, |
|
| 580 | + 'default' => '', |
|
| 581 | + ]); |
|
| 582 | + $table->addColumn('type', 'smallint', [ |
|
| 583 | + 'notnull' => false, |
|
| 584 | + 'length' => 2, |
|
| 585 | + 'default' => 0, |
|
| 586 | + 'unsigned' => true, |
|
| 587 | + ]); |
|
| 588 | + $table->addColumn('remember', 'smallint', [ |
|
| 589 | + 'notnull' => false, |
|
| 590 | + 'length' => 1, |
|
| 591 | + 'default' => 0, |
|
| 592 | + 'unsigned' => true, |
|
| 593 | + ]); |
|
| 594 | + $table->addColumn('last_activity', 'integer', [ |
|
| 595 | + 'notnull' => false, |
|
| 596 | + 'length' => 4, |
|
| 597 | + 'default' => 0, |
|
| 598 | + 'unsigned' => true, |
|
| 599 | + ]); |
|
| 600 | + $table->addColumn('last_check', 'integer', [ |
|
| 601 | + 'notnull' => false, |
|
| 602 | + 'length' => 4, |
|
| 603 | + 'default' => 0, |
|
| 604 | + 'unsigned' => true, |
|
| 605 | + ]); |
|
| 606 | + $table->addColumn('scope', 'text', [ |
|
| 607 | + 'notnull' => false, |
|
| 608 | + ]); |
|
| 609 | + $table->setPrimaryKey(['id']); |
|
| 610 | + $table->addUniqueIndex(['token'], 'authtoken_token_index'); |
|
| 611 | + $table->addIndex(['last_activity'], 'authtoken_last_activity_idx'); |
|
| 612 | + } else { |
|
| 613 | + $table = $schema->getTable('authtoken'); |
|
| 614 | + $table->addColumn('scope', 'text', [ |
|
| 615 | + 'notnull' => false, |
|
| 616 | + ]); |
|
| 617 | + } |
|
| 618 | 618 | |
| 619 | - if (!$schema->hasTable('bruteforce_attempts')) { |
|
| 620 | - $table = $schema->createTable('bruteforce_attempts'); |
|
| 621 | - $table->addColumn('id', 'integer', [ |
|
| 622 | - 'autoincrement' => true, |
|
| 623 | - 'notnull' => true, |
|
| 624 | - 'length' => 4, |
|
| 625 | - 'unsigned' => true, |
|
| 626 | - ]); |
|
| 627 | - $table->addColumn('action', 'string', [ |
|
| 628 | - 'notnull' => true, |
|
| 629 | - 'length' => 64, |
|
| 630 | - 'default' => '', |
|
| 631 | - ]); |
|
| 632 | - $table->addColumn('occurred', 'integer', [ |
|
| 633 | - 'notnull' => true, |
|
| 634 | - 'length' => 4, |
|
| 635 | - 'default' => 0, |
|
| 636 | - 'unsigned' => true, |
|
| 637 | - ]); |
|
| 638 | - $table->addColumn('ip', 'string', [ |
|
| 639 | - 'notnull' => true, |
|
| 640 | - 'length' => 255, |
|
| 641 | - 'default' => '', |
|
| 642 | - ]); |
|
| 643 | - $table->addColumn('subnet', 'string', [ |
|
| 644 | - 'notnull' => true, |
|
| 645 | - 'length' => 255, |
|
| 646 | - 'default' => '', |
|
| 647 | - ]); |
|
| 648 | - $table->addColumn('metadata', 'string', [ |
|
| 649 | - 'notnull' => true, |
|
| 650 | - 'length' => 255, |
|
| 651 | - 'default' => '', |
|
| 652 | - ]); |
|
| 653 | - $table->setPrimaryKey(['id']); |
|
| 654 | - $table->addIndex(['ip'], 'bruteforce_attempts_ip'); |
|
| 655 | - $table->addIndex(['subnet'], 'bruteforce_attempts_subnet'); |
|
| 656 | - } |
|
| 619 | + if (!$schema->hasTable('bruteforce_attempts')) { |
|
| 620 | + $table = $schema->createTable('bruteforce_attempts'); |
|
| 621 | + $table->addColumn('id', 'integer', [ |
|
| 622 | + 'autoincrement' => true, |
|
| 623 | + 'notnull' => true, |
|
| 624 | + 'length' => 4, |
|
| 625 | + 'unsigned' => true, |
|
| 626 | + ]); |
|
| 627 | + $table->addColumn('action', 'string', [ |
|
| 628 | + 'notnull' => true, |
|
| 629 | + 'length' => 64, |
|
| 630 | + 'default' => '', |
|
| 631 | + ]); |
|
| 632 | + $table->addColumn('occurred', 'integer', [ |
|
| 633 | + 'notnull' => true, |
|
| 634 | + 'length' => 4, |
|
| 635 | + 'default' => 0, |
|
| 636 | + 'unsigned' => true, |
|
| 637 | + ]); |
|
| 638 | + $table->addColumn('ip', 'string', [ |
|
| 639 | + 'notnull' => true, |
|
| 640 | + 'length' => 255, |
|
| 641 | + 'default' => '', |
|
| 642 | + ]); |
|
| 643 | + $table->addColumn('subnet', 'string', [ |
|
| 644 | + 'notnull' => true, |
|
| 645 | + 'length' => 255, |
|
| 646 | + 'default' => '', |
|
| 647 | + ]); |
|
| 648 | + $table->addColumn('metadata', 'string', [ |
|
| 649 | + 'notnull' => true, |
|
| 650 | + 'length' => 255, |
|
| 651 | + 'default' => '', |
|
| 652 | + ]); |
|
| 653 | + $table->setPrimaryKey(['id']); |
|
| 654 | + $table->addIndex(['ip'], 'bruteforce_attempts_ip'); |
|
| 655 | + $table->addIndex(['subnet'], 'bruteforce_attempts_subnet'); |
|
| 656 | + } |
|
| 657 | 657 | |
| 658 | - if (!$schema->hasTable('vcategory')) { |
|
| 659 | - $table = $schema->createTable('vcategory'); |
|
| 660 | - $table->addColumn('id', 'integer', [ |
|
| 661 | - 'autoincrement' => true, |
|
| 662 | - 'notnull' => true, |
|
| 663 | - 'length' => 4, |
|
| 664 | - 'unsigned' => true, |
|
| 665 | - ]); |
|
| 666 | - $table->addColumn('uid', 'string', [ |
|
| 667 | - 'notnull' => true, |
|
| 668 | - 'length' => 64, |
|
| 669 | - 'default' => '', |
|
| 670 | - ]); |
|
| 671 | - $table->addColumn('type', 'string', [ |
|
| 672 | - 'notnull' => true, |
|
| 673 | - 'length' => 64, |
|
| 674 | - 'default' => '', |
|
| 675 | - ]); |
|
| 676 | - $table->addColumn('category', 'string', [ |
|
| 677 | - 'notnull' => true, |
|
| 678 | - 'length' => 255, |
|
| 679 | - 'default' => '', |
|
| 680 | - ]); |
|
| 681 | - $table->setPrimaryKey(['id']); |
|
| 682 | - $table->addIndex(['uid'], 'uid_index'); |
|
| 683 | - $table->addIndex(['type'], 'type_index'); |
|
| 684 | - $table->addIndex(['category'], 'category_index'); |
|
| 685 | - } |
|
| 658 | + if (!$schema->hasTable('vcategory')) { |
|
| 659 | + $table = $schema->createTable('vcategory'); |
|
| 660 | + $table->addColumn('id', 'integer', [ |
|
| 661 | + 'autoincrement' => true, |
|
| 662 | + 'notnull' => true, |
|
| 663 | + 'length' => 4, |
|
| 664 | + 'unsigned' => true, |
|
| 665 | + ]); |
|
| 666 | + $table->addColumn('uid', 'string', [ |
|
| 667 | + 'notnull' => true, |
|
| 668 | + 'length' => 64, |
|
| 669 | + 'default' => '', |
|
| 670 | + ]); |
|
| 671 | + $table->addColumn('type', 'string', [ |
|
| 672 | + 'notnull' => true, |
|
| 673 | + 'length' => 64, |
|
| 674 | + 'default' => '', |
|
| 675 | + ]); |
|
| 676 | + $table->addColumn('category', 'string', [ |
|
| 677 | + 'notnull' => true, |
|
| 678 | + 'length' => 255, |
|
| 679 | + 'default' => '', |
|
| 680 | + ]); |
|
| 681 | + $table->setPrimaryKey(['id']); |
|
| 682 | + $table->addIndex(['uid'], 'uid_index'); |
|
| 683 | + $table->addIndex(['type'], 'type_index'); |
|
| 684 | + $table->addIndex(['category'], 'category_index'); |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | - if (!$schema->hasTable('vcategory_to_object')) { |
|
| 688 | - $table = $schema->createTable('vcategory_to_object'); |
|
| 689 | - $table->addColumn('objid', 'integer', [ |
|
| 690 | - 'notnull' => true, |
|
| 691 | - 'length' => 4, |
|
| 692 | - 'default' => 0, |
|
| 693 | - 'unsigned' => true, |
|
| 694 | - ]); |
|
| 695 | - $table->addColumn('categoryid', 'integer', [ |
|
| 696 | - 'notnull' => true, |
|
| 697 | - 'length' => 4, |
|
| 698 | - 'default' => 0, |
|
| 699 | - 'unsigned' => true, |
|
| 700 | - ]); |
|
| 701 | - $table->addColumn('type', 'string', [ |
|
| 702 | - 'notnull' => true, |
|
| 703 | - 'length' => 64, |
|
| 704 | - 'default' => '', |
|
| 705 | - ]); |
|
| 706 | - $table->setPrimaryKey(['categoryid', 'objid', 'type']); |
|
| 707 | - $table->addIndex(['objid', 'type'], 'vcategory_objectd_index'); |
|
| 708 | - } |
|
| 687 | + if (!$schema->hasTable('vcategory_to_object')) { |
|
| 688 | + $table = $schema->createTable('vcategory_to_object'); |
|
| 689 | + $table->addColumn('objid', 'integer', [ |
|
| 690 | + 'notnull' => true, |
|
| 691 | + 'length' => 4, |
|
| 692 | + 'default' => 0, |
|
| 693 | + 'unsigned' => true, |
|
| 694 | + ]); |
|
| 695 | + $table->addColumn('categoryid', 'integer', [ |
|
| 696 | + 'notnull' => true, |
|
| 697 | + 'length' => 4, |
|
| 698 | + 'default' => 0, |
|
| 699 | + 'unsigned' => true, |
|
| 700 | + ]); |
|
| 701 | + $table->addColumn('type', 'string', [ |
|
| 702 | + 'notnull' => true, |
|
| 703 | + 'length' => 64, |
|
| 704 | + 'default' => '', |
|
| 705 | + ]); |
|
| 706 | + $table->setPrimaryKey(['categoryid', 'objid', 'type']); |
|
| 707 | + $table->addIndex(['objid', 'type'], 'vcategory_objectd_index'); |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | - if (!$schema->hasTable('systemtag')) { |
|
| 711 | - $table = $schema->createTable('systemtag'); |
|
| 712 | - $table->addColumn('id', 'integer', [ |
|
| 713 | - 'autoincrement' => true, |
|
| 714 | - 'notnull' => true, |
|
| 715 | - 'length' => 4, |
|
| 716 | - 'unsigned' => true, |
|
| 717 | - ]); |
|
| 718 | - $table->addColumn('name', 'string', [ |
|
| 719 | - 'notnull' => true, |
|
| 720 | - 'length' => 64, |
|
| 721 | - 'default' => '', |
|
| 722 | - ]); |
|
| 723 | - $table->addColumn('visibility', 'smallint', [ |
|
| 724 | - 'notnull' => true, |
|
| 725 | - 'length' => 1, |
|
| 726 | - 'default' => 1, |
|
| 727 | - ]); |
|
| 728 | - $table->addColumn('editable', 'smallint', [ |
|
| 729 | - 'notnull' => true, |
|
| 730 | - 'length' => 1, |
|
| 731 | - 'default' => 1, |
|
| 732 | - ]); |
|
| 733 | - $table->setPrimaryKey(['id']); |
|
| 734 | - $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident'); |
|
| 735 | - } |
|
| 710 | + if (!$schema->hasTable('systemtag')) { |
|
| 711 | + $table = $schema->createTable('systemtag'); |
|
| 712 | + $table->addColumn('id', 'integer', [ |
|
| 713 | + 'autoincrement' => true, |
|
| 714 | + 'notnull' => true, |
|
| 715 | + 'length' => 4, |
|
| 716 | + 'unsigned' => true, |
|
| 717 | + ]); |
|
| 718 | + $table->addColumn('name', 'string', [ |
|
| 719 | + 'notnull' => true, |
|
| 720 | + 'length' => 64, |
|
| 721 | + 'default' => '', |
|
| 722 | + ]); |
|
| 723 | + $table->addColumn('visibility', 'smallint', [ |
|
| 724 | + 'notnull' => true, |
|
| 725 | + 'length' => 1, |
|
| 726 | + 'default' => 1, |
|
| 727 | + ]); |
|
| 728 | + $table->addColumn('editable', 'smallint', [ |
|
| 729 | + 'notnull' => true, |
|
| 730 | + 'length' => 1, |
|
| 731 | + 'default' => 1, |
|
| 732 | + ]); |
|
| 733 | + $table->setPrimaryKey(['id']); |
|
| 734 | + $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident'); |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - if (!$schema->hasTable('systemtag_object_mapping')) { |
|
| 738 | - $table = $schema->createTable('systemtag_object_mapping'); |
|
| 739 | - $table->addColumn('objectid', 'string', [ |
|
| 740 | - 'notnull' => true, |
|
| 741 | - 'length' => 64, |
|
| 742 | - 'default' => '', |
|
| 743 | - ]); |
|
| 744 | - $table->addColumn('objecttype', 'string', [ |
|
| 745 | - 'notnull' => true, |
|
| 746 | - 'length' => 64, |
|
| 747 | - 'default' => '', |
|
| 748 | - ]); |
|
| 749 | - $table->addColumn('systemtagid', 'integer', [ |
|
| 750 | - 'notnull' => true, |
|
| 751 | - 'length' => 4, |
|
| 752 | - 'default' => 0, |
|
| 753 | - 'unsigned' => true, |
|
| 754 | - ]); |
|
| 755 | - $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk'); |
|
| 737 | + if (!$schema->hasTable('systemtag_object_mapping')) { |
|
| 738 | + $table = $schema->createTable('systemtag_object_mapping'); |
|
| 739 | + $table->addColumn('objectid', 'string', [ |
|
| 740 | + 'notnull' => true, |
|
| 741 | + 'length' => 64, |
|
| 742 | + 'default' => '', |
|
| 743 | + ]); |
|
| 744 | + $table->addColumn('objecttype', 'string', [ |
|
| 745 | + 'notnull' => true, |
|
| 746 | + 'length' => 64, |
|
| 747 | + 'default' => '', |
|
| 748 | + ]); |
|
| 749 | + $table->addColumn('systemtagid', 'integer', [ |
|
| 750 | + 'notnull' => true, |
|
| 751 | + 'length' => 4, |
|
| 752 | + 'default' => 0, |
|
| 753 | + 'unsigned' => true, |
|
| 754 | + ]); |
|
| 755 | + $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk'); |
|
| 756 | 756 | // $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping'); |
| 757 | - } |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - if (!$schema->hasTable('systemtag_group')) { |
|
| 760 | - $table = $schema->createTable('systemtag_group'); |
|
| 761 | - $table->addColumn('systemtagid', 'integer', [ |
|
| 762 | - 'notnull' => true, |
|
| 763 | - 'length' => 4, |
|
| 764 | - 'default' => 0, |
|
| 765 | - 'unsigned' => true, |
|
| 766 | - ]); |
|
| 767 | - $table->addColumn('gid', 'string', [ |
|
| 768 | - 'notnull' => true, |
|
| 769 | - ]); |
|
| 770 | - $table->setPrimaryKey(['gid', 'systemtagid']); |
|
| 771 | - } |
|
| 759 | + if (!$schema->hasTable('systemtag_group')) { |
|
| 760 | + $table = $schema->createTable('systemtag_group'); |
|
| 761 | + $table->addColumn('systemtagid', 'integer', [ |
|
| 762 | + 'notnull' => true, |
|
| 763 | + 'length' => 4, |
|
| 764 | + 'default' => 0, |
|
| 765 | + 'unsigned' => true, |
|
| 766 | + ]); |
|
| 767 | + $table->addColumn('gid', 'string', [ |
|
| 768 | + 'notnull' => true, |
|
| 769 | + ]); |
|
| 770 | + $table->setPrimaryKey(['gid', 'systemtagid']); |
|
| 771 | + } |
|
| 772 | 772 | |
| 773 | - if (!$schema->hasTable('file_locks')) { |
|
| 774 | - $table = $schema->createTable('file_locks'); |
|
| 775 | - $table->addColumn('id', 'integer', [ |
|
| 776 | - 'autoincrement' => true, |
|
| 777 | - 'notnull' => true, |
|
| 778 | - 'length' => 4, |
|
| 779 | - 'unsigned' => true, |
|
| 780 | - ]); |
|
| 781 | - $table->addColumn('lock', 'integer', [ |
|
| 782 | - 'notnull' => true, |
|
| 783 | - 'length' => 4, |
|
| 784 | - 'default' => 0, |
|
| 785 | - ]); |
|
| 786 | - $table->addColumn('key', 'string', [ |
|
| 787 | - 'notnull' => true, |
|
| 788 | - 'length' => 64, |
|
| 789 | - ]); |
|
| 790 | - $table->addColumn('ttl', 'integer', [ |
|
| 791 | - 'notnull' => true, |
|
| 792 | - 'length' => 4, |
|
| 793 | - 'default' => -1, |
|
| 794 | - ]); |
|
| 795 | - $table->setPrimaryKey(['id']); |
|
| 796 | - $table->addUniqueIndex(['key'], 'lock_key_index'); |
|
| 797 | - $table->addIndex(['ttl'], 'lock_ttl_index'); |
|
| 798 | - } |
|
| 773 | + if (!$schema->hasTable('file_locks')) { |
|
| 774 | + $table = $schema->createTable('file_locks'); |
|
| 775 | + $table->addColumn('id', 'integer', [ |
|
| 776 | + 'autoincrement' => true, |
|
| 777 | + 'notnull' => true, |
|
| 778 | + 'length' => 4, |
|
| 779 | + 'unsigned' => true, |
|
| 780 | + ]); |
|
| 781 | + $table->addColumn('lock', 'integer', [ |
|
| 782 | + 'notnull' => true, |
|
| 783 | + 'length' => 4, |
|
| 784 | + 'default' => 0, |
|
| 785 | + ]); |
|
| 786 | + $table->addColumn('key', 'string', [ |
|
| 787 | + 'notnull' => true, |
|
| 788 | + 'length' => 64, |
|
| 789 | + ]); |
|
| 790 | + $table->addColumn('ttl', 'integer', [ |
|
| 791 | + 'notnull' => true, |
|
| 792 | + 'length' => 4, |
|
| 793 | + 'default' => -1, |
|
| 794 | + ]); |
|
| 795 | + $table->setPrimaryKey(['id']); |
|
| 796 | + $table->addUniqueIndex(['key'], 'lock_key_index'); |
|
| 797 | + $table->addIndex(['ttl'], 'lock_ttl_index'); |
|
| 798 | + } |
|
| 799 | 799 | |
| 800 | - if (!$schema->hasTable('comments')) { |
|
| 801 | - $table = $schema->createTable('comments'); |
|
| 802 | - $table->addColumn('id', 'integer', [ |
|
| 803 | - 'autoincrement' => true, |
|
| 804 | - 'notnull' => true, |
|
| 805 | - 'length' => 4, |
|
| 806 | - 'unsigned' => true, |
|
| 807 | - ]); |
|
| 808 | - $table->addColumn('parent_id', 'integer', [ |
|
| 809 | - 'notnull' => true, |
|
| 810 | - 'length' => 4, |
|
| 811 | - 'default' => 0, |
|
| 812 | - 'unsigned' => true, |
|
| 813 | - ]); |
|
| 814 | - $table->addColumn('topmost_parent_id', 'integer', [ |
|
| 815 | - 'notnull' => true, |
|
| 816 | - 'length' => 4, |
|
| 817 | - 'default' => 0, |
|
| 818 | - 'unsigned' => true, |
|
| 819 | - ]); |
|
| 820 | - $table->addColumn('children_count', 'integer', [ |
|
| 821 | - 'notnull' => true, |
|
| 822 | - 'length' => 4, |
|
| 823 | - 'default' => 0, |
|
| 824 | - 'unsigned' => true, |
|
| 825 | - ]); |
|
| 826 | - $table->addColumn('actor_type', 'string', [ |
|
| 827 | - 'notnull' => true, |
|
| 828 | - 'length' => 64, |
|
| 829 | - 'default' => '', |
|
| 830 | - ]); |
|
| 831 | - $table->addColumn('actor_id', 'string', [ |
|
| 832 | - 'notnull' => true, |
|
| 833 | - 'length' => 64, |
|
| 834 | - 'default' => '', |
|
| 835 | - ]); |
|
| 836 | - $table->addColumn('message', 'text', [ |
|
| 837 | - 'notnull' => false, |
|
| 838 | - ]); |
|
| 839 | - $table->addColumn('verb', 'string', [ |
|
| 840 | - 'notnull' => false, |
|
| 841 | - 'length' => 64, |
|
| 842 | - ]); |
|
| 843 | - $table->addColumn('creation_timestamp', 'datetime', [ |
|
| 844 | - 'notnull' => false, |
|
| 845 | - ]); |
|
| 846 | - $table->addColumn('latest_child_timestamp', 'datetime', [ |
|
| 847 | - 'notnull' => false, |
|
| 848 | - ]); |
|
| 849 | - $table->addColumn('object_type', 'string', [ |
|
| 850 | - 'notnull' => true, |
|
| 851 | - 'length' => 64, |
|
| 852 | - 'default' => '', |
|
| 853 | - ]); |
|
| 854 | - $table->addColumn('object_id', 'string', [ |
|
| 855 | - 'notnull' => true, |
|
| 856 | - 'length' => 64, |
|
| 857 | - 'default' => '', |
|
| 858 | - ]); |
|
| 859 | - $table->addColumn('reference_id', 'string', [ |
|
| 860 | - 'notnull' => false, |
|
| 861 | - 'length' => 64, |
|
| 862 | - ]); |
|
| 863 | - $table->setPrimaryKey(['id']); |
|
| 864 | - $table->addIndex(['parent_id'], 'comments_parent_id_index'); |
|
| 865 | - $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx'); |
|
| 866 | - $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index'); |
|
| 867 | - $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index'); |
|
| 868 | - } |
|
| 800 | + if (!$schema->hasTable('comments')) { |
|
| 801 | + $table = $schema->createTable('comments'); |
|
| 802 | + $table->addColumn('id', 'integer', [ |
|
| 803 | + 'autoincrement' => true, |
|
| 804 | + 'notnull' => true, |
|
| 805 | + 'length' => 4, |
|
| 806 | + 'unsigned' => true, |
|
| 807 | + ]); |
|
| 808 | + $table->addColumn('parent_id', 'integer', [ |
|
| 809 | + 'notnull' => true, |
|
| 810 | + 'length' => 4, |
|
| 811 | + 'default' => 0, |
|
| 812 | + 'unsigned' => true, |
|
| 813 | + ]); |
|
| 814 | + $table->addColumn('topmost_parent_id', 'integer', [ |
|
| 815 | + 'notnull' => true, |
|
| 816 | + 'length' => 4, |
|
| 817 | + 'default' => 0, |
|
| 818 | + 'unsigned' => true, |
|
| 819 | + ]); |
|
| 820 | + $table->addColumn('children_count', 'integer', [ |
|
| 821 | + 'notnull' => true, |
|
| 822 | + 'length' => 4, |
|
| 823 | + 'default' => 0, |
|
| 824 | + 'unsigned' => true, |
|
| 825 | + ]); |
|
| 826 | + $table->addColumn('actor_type', 'string', [ |
|
| 827 | + 'notnull' => true, |
|
| 828 | + 'length' => 64, |
|
| 829 | + 'default' => '', |
|
| 830 | + ]); |
|
| 831 | + $table->addColumn('actor_id', 'string', [ |
|
| 832 | + 'notnull' => true, |
|
| 833 | + 'length' => 64, |
|
| 834 | + 'default' => '', |
|
| 835 | + ]); |
|
| 836 | + $table->addColumn('message', 'text', [ |
|
| 837 | + 'notnull' => false, |
|
| 838 | + ]); |
|
| 839 | + $table->addColumn('verb', 'string', [ |
|
| 840 | + 'notnull' => false, |
|
| 841 | + 'length' => 64, |
|
| 842 | + ]); |
|
| 843 | + $table->addColumn('creation_timestamp', 'datetime', [ |
|
| 844 | + 'notnull' => false, |
|
| 845 | + ]); |
|
| 846 | + $table->addColumn('latest_child_timestamp', 'datetime', [ |
|
| 847 | + 'notnull' => false, |
|
| 848 | + ]); |
|
| 849 | + $table->addColumn('object_type', 'string', [ |
|
| 850 | + 'notnull' => true, |
|
| 851 | + 'length' => 64, |
|
| 852 | + 'default' => '', |
|
| 853 | + ]); |
|
| 854 | + $table->addColumn('object_id', 'string', [ |
|
| 855 | + 'notnull' => true, |
|
| 856 | + 'length' => 64, |
|
| 857 | + 'default' => '', |
|
| 858 | + ]); |
|
| 859 | + $table->addColumn('reference_id', 'string', [ |
|
| 860 | + 'notnull' => false, |
|
| 861 | + 'length' => 64, |
|
| 862 | + ]); |
|
| 863 | + $table->setPrimaryKey(['id']); |
|
| 864 | + $table->addIndex(['parent_id'], 'comments_parent_id_index'); |
|
| 865 | + $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx'); |
|
| 866 | + $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index'); |
|
| 867 | + $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index'); |
|
| 868 | + } |
|
| 869 | 869 | |
| 870 | - if (!$schema->hasTable('comments_read_markers')) { |
|
| 871 | - $table = $schema->createTable('comments_read_markers'); |
|
| 872 | - $table->addColumn('user_id', 'string', [ |
|
| 873 | - 'notnull' => true, |
|
| 874 | - 'length' => 64, |
|
| 875 | - 'default' => '', |
|
| 876 | - ]); |
|
| 877 | - $table->addColumn('marker_datetime', 'datetime', [ |
|
| 878 | - 'notnull' => false, |
|
| 879 | - ]); |
|
| 880 | - $table->addColumn('object_type', 'string', [ |
|
| 881 | - 'notnull' => true, |
|
| 882 | - 'length' => 64, |
|
| 883 | - 'default' => '', |
|
| 884 | - ]); |
|
| 885 | - $table->addColumn('object_id', 'string', [ |
|
| 886 | - 'notnull' => true, |
|
| 887 | - 'length' => 64, |
|
| 888 | - 'default' => '', |
|
| 889 | - ]); |
|
| 890 | - $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index'); |
|
| 891 | - $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk'); |
|
| 870 | + if (!$schema->hasTable('comments_read_markers')) { |
|
| 871 | + $table = $schema->createTable('comments_read_markers'); |
|
| 872 | + $table->addColumn('user_id', 'string', [ |
|
| 873 | + 'notnull' => true, |
|
| 874 | + 'length' => 64, |
|
| 875 | + 'default' => '', |
|
| 876 | + ]); |
|
| 877 | + $table->addColumn('marker_datetime', 'datetime', [ |
|
| 878 | + 'notnull' => false, |
|
| 879 | + ]); |
|
| 880 | + $table->addColumn('object_type', 'string', [ |
|
| 881 | + 'notnull' => true, |
|
| 882 | + 'length' => 64, |
|
| 883 | + 'default' => '', |
|
| 884 | + ]); |
|
| 885 | + $table->addColumn('object_id', 'string', [ |
|
| 886 | + 'notnull' => true, |
|
| 887 | + 'length' => 64, |
|
| 888 | + 'default' => '', |
|
| 889 | + ]); |
|
| 890 | + $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index'); |
|
| 891 | + $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk'); |
|
| 892 | 892 | // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index'); |
| 893 | - } |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | 895 | // if (!$schema->hasTable('credentials')) { |
| 896 | 896 | // $table = $schema->createTable('credentials'); |
@@ -909,139 +909,139 @@ discard block |
||
| 909 | 909 | // $table->addIndex(['user'], 'credentials_user'); |
| 910 | 910 | // } |
| 911 | 911 | |
| 912 | - if (!$schema->hasTable('admin_sections')) { |
|
| 913 | - $table = $schema->createTable('admin_sections'); |
|
| 914 | - $table->addColumn('id', 'string', [ |
|
| 915 | - 'notnull' => true, |
|
| 916 | - 'length' => 64, |
|
| 917 | - ]); |
|
| 918 | - $table->addColumn('class', 'string', [ |
|
| 919 | - 'notnull' => true, |
|
| 920 | - 'length' => 255, |
|
| 921 | - 'default' => '', |
|
| 922 | - ]); |
|
| 923 | - $table->addColumn('priority', 'smallint', [ |
|
| 924 | - 'notnull' => true, |
|
| 925 | - 'length' => 1, |
|
| 926 | - 'default' => 0, |
|
| 927 | - ]); |
|
| 928 | - $table->setPrimaryKey(['id']); |
|
| 929 | - $table->addUniqueIndex(['class'], 'admin_sections_class'); |
|
| 930 | - } |
|
| 912 | + if (!$schema->hasTable('admin_sections')) { |
|
| 913 | + $table = $schema->createTable('admin_sections'); |
|
| 914 | + $table->addColumn('id', 'string', [ |
|
| 915 | + 'notnull' => true, |
|
| 916 | + 'length' => 64, |
|
| 917 | + ]); |
|
| 918 | + $table->addColumn('class', 'string', [ |
|
| 919 | + 'notnull' => true, |
|
| 920 | + 'length' => 255, |
|
| 921 | + 'default' => '', |
|
| 922 | + ]); |
|
| 923 | + $table->addColumn('priority', 'smallint', [ |
|
| 924 | + 'notnull' => true, |
|
| 925 | + 'length' => 1, |
|
| 926 | + 'default' => 0, |
|
| 927 | + ]); |
|
| 928 | + $table->setPrimaryKey(['id']); |
|
| 929 | + $table->addUniqueIndex(['class'], 'admin_sections_class'); |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | - if (!$schema->hasTable('admin_settings')) { |
|
| 933 | - $table = $schema->createTable('admin_settings'); |
|
| 934 | - $table->addColumn('id', 'integer', [ |
|
| 935 | - 'autoincrement' => true, |
|
| 936 | - 'notnull' => true, |
|
| 937 | - 'length' => 4, |
|
| 938 | - ]); |
|
| 939 | - $table->addColumn('class', 'string', [ |
|
| 940 | - 'notnull' => true, |
|
| 941 | - 'length' => 255, |
|
| 942 | - 'default' => '', |
|
| 943 | - ]); |
|
| 944 | - $table->addColumn('section', 'string', [ |
|
| 945 | - 'notnull' => false, |
|
| 946 | - 'length' => 64, |
|
| 947 | - ]); |
|
| 948 | - $table->addColumn('priority', 'smallint', [ |
|
| 949 | - 'notnull' => true, |
|
| 950 | - 'length' => 1, |
|
| 951 | - 'default' => 0, |
|
| 952 | - ]); |
|
| 953 | - $table->setPrimaryKey(['id']); |
|
| 954 | - $table->addUniqueIndex(['class'], 'admin_settings_class'); |
|
| 955 | - $table->addIndex(['section'], 'admin_settings_section'); |
|
| 956 | - } |
|
| 932 | + if (!$schema->hasTable('admin_settings')) { |
|
| 933 | + $table = $schema->createTable('admin_settings'); |
|
| 934 | + $table->addColumn('id', 'integer', [ |
|
| 935 | + 'autoincrement' => true, |
|
| 936 | + 'notnull' => true, |
|
| 937 | + 'length' => 4, |
|
| 938 | + ]); |
|
| 939 | + $table->addColumn('class', 'string', [ |
|
| 940 | + 'notnull' => true, |
|
| 941 | + 'length' => 255, |
|
| 942 | + 'default' => '', |
|
| 943 | + ]); |
|
| 944 | + $table->addColumn('section', 'string', [ |
|
| 945 | + 'notnull' => false, |
|
| 946 | + 'length' => 64, |
|
| 947 | + ]); |
|
| 948 | + $table->addColumn('priority', 'smallint', [ |
|
| 949 | + 'notnull' => true, |
|
| 950 | + 'length' => 1, |
|
| 951 | + 'default' => 0, |
|
| 952 | + ]); |
|
| 953 | + $table->setPrimaryKey(['id']); |
|
| 954 | + $table->addUniqueIndex(['class'], 'admin_settings_class'); |
|
| 955 | + $table->addIndex(['section'], 'admin_settings_section'); |
|
| 956 | + } |
|
| 957 | 957 | |
| 958 | - if (!$schema->hasTable('personal_sections')) { |
|
| 959 | - $table = $schema->createTable('personal_sections'); |
|
| 960 | - $table->addColumn('id', 'string', [ |
|
| 961 | - 'notnull' => true, |
|
| 962 | - 'length' => 64, |
|
| 963 | - ]); |
|
| 964 | - $table->addColumn('class', 'string', [ |
|
| 965 | - 'notnull' => true, |
|
| 966 | - 'length' => 255, |
|
| 967 | - 'default' => '', |
|
| 968 | - ]); |
|
| 969 | - $table->addColumn('priority', 'smallint', [ |
|
| 970 | - 'notnull' => true, |
|
| 971 | - 'length' => 1, |
|
| 972 | - 'default' => 0, |
|
| 973 | - ]); |
|
| 974 | - $table->setPrimaryKey(['id']); |
|
| 975 | - $table->addUniqueIndex(['class'], 'personal_sections_class'); |
|
| 976 | - } |
|
| 958 | + if (!$schema->hasTable('personal_sections')) { |
|
| 959 | + $table = $schema->createTable('personal_sections'); |
|
| 960 | + $table->addColumn('id', 'string', [ |
|
| 961 | + 'notnull' => true, |
|
| 962 | + 'length' => 64, |
|
| 963 | + ]); |
|
| 964 | + $table->addColumn('class', 'string', [ |
|
| 965 | + 'notnull' => true, |
|
| 966 | + 'length' => 255, |
|
| 967 | + 'default' => '', |
|
| 968 | + ]); |
|
| 969 | + $table->addColumn('priority', 'smallint', [ |
|
| 970 | + 'notnull' => true, |
|
| 971 | + 'length' => 1, |
|
| 972 | + 'default' => 0, |
|
| 973 | + ]); |
|
| 974 | + $table->setPrimaryKey(['id']); |
|
| 975 | + $table->addUniqueIndex(['class'], 'personal_sections_class'); |
|
| 976 | + } |
|
| 977 | 977 | |
| 978 | - if (!$schema->hasTable('personal_settings')) { |
|
| 979 | - $table = $schema->createTable('personal_settings'); |
|
| 980 | - $table->addColumn('id', 'integer', [ |
|
| 981 | - 'autoincrement' => true, |
|
| 982 | - 'notnull' => true, |
|
| 983 | - 'length' => 4, |
|
| 984 | - ]); |
|
| 985 | - $table->addColumn('class', 'string', [ |
|
| 986 | - 'notnull' => true, |
|
| 987 | - 'length' => 255, |
|
| 988 | - 'default' => '', |
|
| 989 | - ]); |
|
| 990 | - $table->addColumn('section', 'string', [ |
|
| 991 | - 'notnull' => false, |
|
| 992 | - 'length' => 64, |
|
| 993 | - ]); |
|
| 994 | - $table->addColumn('priority', 'smallint', [ |
|
| 995 | - 'notnull' => true, |
|
| 996 | - 'length' => 1, |
|
| 997 | - 'default' => 0, |
|
| 998 | - ]); |
|
| 999 | - $table->setPrimaryKey(['id']); |
|
| 1000 | - $table->addUniqueIndex(['class'], 'personal_settings_class'); |
|
| 1001 | - $table->addIndex(['section'], 'personal_settings_section'); |
|
| 1002 | - } |
|
| 978 | + if (!$schema->hasTable('personal_settings')) { |
|
| 979 | + $table = $schema->createTable('personal_settings'); |
|
| 980 | + $table->addColumn('id', 'integer', [ |
|
| 981 | + 'autoincrement' => true, |
|
| 982 | + 'notnull' => true, |
|
| 983 | + 'length' => 4, |
|
| 984 | + ]); |
|
| 985 | + $table->addColumn('class', 'string', [ |
|
| 986 | + 'notnull' => true, |
|
| 987 | + 'length' => 255, |
|
| 988 | + 'default' => '', |
|
| 989 | + ]); |
|
| 990 | + $table->addColumn('section', 'string', [ |
|
| 991 | + 'notnull' => false, |
|
| 992 | + 'length' => 64, |
|
| 993 | + ]); |
|
| 994 | + $table->addColumn('priority', 'smallint', [ |
|
| 995 | + 'notnull' => true, |
|
| 996 | + 'length' => 1, |
|
| 997 | + 'default' => 0, |
|
| 998 | + ]); |
|
| 999 | + $table->setPrimaryKey(['id']); |
|
| 1000 | + $table->addUniqueIndex(['class'], 'personal_settings_class'); |
|
| 1001 | + $table->addIndex(['section'], 'personal_settings_section'); |
|
| 1002 | + } |
|
| 1003 | 1003 | |
| 1004 | - if (!$schema->hasTable('accounts')) { |
|
| 1005 | - $table = $schema->createTable('accounts'); |
|
| 1006 | - $table->addColumn('uid', 'string', [ |
|
| 1007 | - 'notnull' => true, |
|
| 1008 | - 'length' => 64, |
|
| 1009 | - 'default' => '', |
|
| 1010 | - ]); |
|
| 1011 | - $table->addColumn('data', 'text', [ |
|
| 1012 | - 'notnull' => true, |
|
| 1013 | - 'default' => '', |
|
| 1014 | - ]); |
|
| 1015 | - $table->setPrimaryKey(['uid']); |
|
| 1016 | - } |
|
| 1017 | - return $schema; |
|
| 1018 | - } |
|
| 1004 | + if (!$schema->hasTable('accounts')) { |
|
| 1005 | + $table = $schema->createTable('accounts'); |
|
| 1006 | + $table->addColumn('uid', 'string', [ |
|
| 1007 | + 'notnull' => true, |
|
| 1008 | + 'length' => 64, |
|
| 1009 | + 'default' => '', |
|
| 1010 | + ]); |
|
| 1011 | + $table->addColumn('data', 'text', [ |
|
| 1012 | + 'notnull' => true, |
|
| 1013 | + 'default' => '', |
|
| 1014 | + ]); |
|
| 1015 | + $table->setPrimaryKey(['uid']); |
|
| 1016 | + } |
|
| 1017 | + return $schema; |
|
| 1018 | + } |
|
| 1019 | 1019 | |
| 1020 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 1021 | - /** @var ISchemaWrapper $schema */ |
|
| 1022 | - $schema = $schemaClosure(); |
|
| 1023 | - if (!$schema->hasTable('dav_properties')) { |
|
| 1024 | - return; |
|
| 1025 | - } |
|
| 1026 | - $query = $this->connection->getQueryBuilder(); |
|
| 1027 | - $query->select('*') |
|
| 1028 | - ->from('dav_properties'); |
|
| 1020 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 1021 | + /** @var ISchemaWrapper $schema */ |
|
| 1022 | + $schema = $schemaClosure(); |
|
| 1023 | + if (!$schema->hasTable('dav_properties')) { |
|
| 1024 | + return; |
|
| 1025 | + } |
|
| 1026 | + $query = $this->connection->getQueryBuilder(); |
|
| 1027 | + $query->select('*') |
|
| 1028 | + ->from('dav_properties'); |
|
| 1029 | 1029 | |
| 1030 | - $insert = $this->connection->getQueryBuilder(); |
|
| 1031 | - $insert->insert('properties') |
|
| 1032 | - ->setValue('propertypath', $insert->createParameter('propertypath')) |
|
| 1033 | - ->setValue('propertyname', $insert->createParameter('propertyname')) |
|
| 1034 | - ->setValue('propertyvalue', $insert->createParameter('propertyvalue')) |
|
| 1035 | - ->setValue('userid', $insert->createParameter('userid')); |
|
| 1030 | + $insert = $this->connection->getQueryBuilder(); |
|
| 1031 | + $insert->insert('properties') |
|
| 1032 | + ->setValue('propertypath', $insert->createParameter('propertypath')) |
|
| 1033 | + ->setValue('propertyname', $insert->createParameter('propertyname')) |
|
| 1034 | + ->setValue('propertyvalue', $insert->createParameter('propertyvalue')) |
|
| 1035 | + ->setValue('userid', $insert->createParameter('userid')); |
|
| 1036 | 1036 | |
| 1037 | - $result = $query->execute(); |
|
| 1038 | - while ($row = $result->fetch()) { |
|
| 1039 | - preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match); |
|
| 1040 | - $insert->setParameter('propertypath', (string) $row['propertypath']) |
|
| 1041 | - ->setParameter('propertyname', (string) $row['propertyname']) |
|
| 1042 | - ->setParameter('propertyvalue', (string) $row['propertyvalue']) |
|
| 1043 | - ->setParameter('userid', ($match[2] ?? '')); |
|
| 1044 | - $insert->execute(); |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1037 | + $result = $query->execute(); |
|
| 1038 | + while ($row = $result->fetch()) { |
|
| 1039 | + preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match); |
|
| 1040 | + $insert->setParameter('propertypath', (string) $row['propertypath']) |
|
| 1041 | + ->setParameter('propertyname', (string) $row['propertyname']) |
|
| 1042 | + ->setParameter('propertyvalue', (string) $row['propertyvalue']) |
|
| 1043 | + ->setParameter('userid', ($match[2] ?? '')); |
|
| 1044 | + $insert->execute(); |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | 1047 | } |
@@ -32,20 +32,20 @@ |
||
| 32 | 32 | use OCP\Migration\SimpleMigrationStep; |
| 33 | 33 | |
| 34 | 34 | class Version27000Date20220613163520 extends SimpleMigrationStep { |
| 35 | - public function name(): string { |
|
| 36 | - return "Add mountpoint path to mounts table unique index"; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 40 | - /** @var ISchemaWrapper $schema */ |
|
| 41 | - $schema = $schemaClosure(); |
|
| 42 | - |
|
| 43 | - $table = $schema->getTable('mounts'); |
|
| 44 | - if ($table->hasIndex('mounts_user_root_index')) { |
|
| 45 | - $table->dropIndex('mounts_user_root_index'); |
|
| 46 | - // new index gets added with "add missing indexes" |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - return $schema; |
|
| 50 | - } |
|
| 35 | + public function name(): string { |
|
| 36 | + return "Add mountpoint path to mounts table unique index"; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 40 | + /** @var ISchemaWrapper $schema */ |
|
| 41 | + $schema = $schemaClosure(); |
|
| 42 | + |
|
| 43 | + $table = $schema->getTable('mounts'); |
|
| 44 | + if ($table->hasIndex('mounts_user_root_index')) { |
|
| 45 | + $table->dropIndex('mounts_user_root_index'); |
|
| 46 | + // new index gets added with "add missing indexes" |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + return $schema; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -71,281 +71,281 @@ |
||
| 71 | 71 | * @package OC\Core |
| 72 | 72 | */ |
| 73 | 73 | class Application extends App { |
| 74 | - public function __construct() { |
|
| 75 | - parent::__construct('core'); |
|
| 76 | - |
|
| 77 | - $container = $this->getContainer(); |
|
| 78 | - |
|
| 79 | - $container->registerService('defaultMailAddress', function () { |
|
| 80 | - return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
| 81 | - }); |
|
| 82 | - |
|
| 83 | - $server = $container->getServer(); |
|
| 84 | - /** @var IEventDispatcher $eventDispatcher */ |
|
| 85 | - $eventDispatcher = $server->get(IEventDispatcher::class); |
|
| 86 | - |
|
| 87 | - $notificationManager = $server->getNotificationManager(); |
|
| 88 | - $notificationManager->registerNotifierService(CoreNotifier::class); |
|
| 89 | - $notificationManager->registerNotifierService(AuthenticationNotifier::class); |
|
| 90 | - |
|
| 91 | - $oldEventDispatcher = $server->getEventDispatcher(); |
|
| 92 | - |
|
| 93 | - $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT, |
|
| 94 | - function (GenericEvent $event) use ($container) { |
|
| 95 | - /** @var MissingIndexInformation $subject */ |
|
| 96 | - $subject = $event->getSubject(); |
|
| 97 | - |
|
| 98 | - $schema = new SchemaWrapper($container->query(Connection::class)); |
|
| 99 | - |
|
| 100 | - if ($schema->hasTable('share')) { |
|
| 101 | - $table = $schema->getTable('share'); |
|
| 102 | - |
|
| 103 | - if (!$table->hasIndex('share_with_index')) { |
|
| 104 | - $subject->addHintForMissingSubject($table->getName(), 'share_with_index'); |
|
| 105 | - } |
|
| 106 | - if (!$table->hasIndex('parent_index')) { |
|
| 107 | - $subject->addHintForMissingSubject($table->getName(), 'parent_index'); |
|
| 108 | - } |
|
| 109 | - if (!$table->hasIndex('owner_index')) { |
|
| 110 | - $subject->addHintForMissingSubject($table->getName(), 'owner_index'); |
|
| 111 | - } |
|
| 112 | - if (!$table->hasIndex('initiator_index')) { |
|
| 113 | - $subject->addHintForMissingSubject($table->getName(), 'initiator_index'); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if ($schema->hasTable('filecache')) { |
|
| 118 | - $table = $schema->getTable('filecache'); |
|
| 119 | - |
|
| 120 | - if (!$table->hasIndex('fs_mtime')) { |
|
| 121 | - $subject->addHintForMissingSubject($table->getName(), 'fs_mtime'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (!$table->hasIndex('fs_size')) { |
|
| 125 | - $subject->addHintForMissingSubject($table->getName(), 'fs_size'); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if (!$table->hasIndex('fs_id_storage_size')) { |
|
| 129 | - $subject->addHintForMissingSubject($table->getName(), 'fs_id_storage_size'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
| 133 | - $subject->addHintForMissingSubject($table->getName(), 'fs_storage_path_prefix'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if (!$table->hasIndex('fs_parent')) { |
|
| 137 | - $subject->addHintForMissingSubject($table->getName(), 'fs_parent'); |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if ($schema->hasTable('twofactor_providers')) { |
|
| 142 | - $table = $schema->getTable('twofactor_providers'); |
|
| 143 | - |
|
| 144 | - if (!$table->hasIndex('twofactor_providers_uid')) { |
|
| 145 | - $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid'); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if ($schema->hasTable('login_flow_v2')) { |
|
| 150 | - $table = $schema->getTable('login_flow_v2'); |
|
| 151 | - |
|
| 152 | - if (!$table->hasIndex('poll_token')) { |
|
| 153 | - $subject->addHintForMissingSubject($table->getName(), 'poll_token'); |
|
| 154 | - } |
|
| 155 | - if (!$table->hasIndex('login_token')) { |
|
| 156 | - $subject->addHintForMissingSubject($table->getName(), 'login_token'); |
|
| 157 | - } |
|
| 158 | - if (!$table->hasIndex('timestamp')) { |
|
| 159 | - $subject->addHintForMissingSubject($table->getName(), 'timestamp'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if ($schema->hasTable('whats_new')) { |
|
| 164 | - $table = $schema->getTable('whats_new'); |
|
| 165 | - |
|
| 166 | - if (!$table->hasIndex('version')) { |
|
| 167 | - $subject->addHintForMissingSubject($table->getName(), 'version'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - if ($schema->hasTable('cards')) { |
|
| 172 | - $table = $schema->getTable('cards'); |
|
| 173 | - |
|
| 174 | - if (!$table->hasIndex('cards_abid')) { |
|
| 175 | - $subject->addHintForMissingSubject($table->getName(), 'cards_abid'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if (!$table->hasIndex('cards_abiduri')) { |
|
| 179 | - $subject->addHintForMissingSubject($table->getName(), 'cards_abiduri'); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if ($schema->hasTable('cards_properties')) { |
|
| 184 | - $table = $schema->getTable('cards_properties'); |
|
| 185 | - |
|
| 186 | - if (!$table->hasIndex('cards_prop_abid')) { |
|
| 187 | - $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid'); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if ($schema->hasTable('calendarobjects_props')) { |
|
| 192 | - $table = $schema->getTable('calendarobjects_props'); |
|
| 193 | - |
|
| 194 | - if (!$table->hasIndex('calendarobject_calid_index')) { |
|
| 195 | - $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index'); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if ($schema->hasTable('schedulingobjects')) { |
|
| 200 | - $table = $schema->getTable('schedulingobjects'); |
|
| 201 | - if (!$table->hasIndex('schedulobj_principuri_index')) { |
|
| 202 | - $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index'); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($schema->hasTable('properties')) { |
|
| 207 | - $table = $schema->getTable('properties'); |
|
| 208 | - if (!$table->hasIndex('properties_path_index')) { |
|
| 209 | - $subject->addHintForMissingSubject($table->getName(), 'properties_path_index'); |
|
| 210 | - } |
|
| 211 | - if (!$table->hasIndex('properties_pathonly_index')) { |
|
| 212 | - $subject->addHintForMissingSubject($table->getName(), 'properties_pathonly_index'); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if ($schema->hasTable('jobs')) { |
|
| 217 | - $table = $schema->getTable('jobs'); |
|
| 218 | - if (!$table->hasIndex('job_lastcheck_reserved')) { |
|
| 219 | - $subject->addHintForMissingSubject($table->getName(), 'job_lastcheck_reserved'); |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - if ($schema->hasTable('direct_edit')) { |
|
| 224 | - $table = $schema->getTable('direct_edit'); |
|
| 225 | - if (!$table->hasIndex('direct_edit_timestamp')) { |
|
| 226 | - $subject->addHintForMissingSubject($table->getName(), 'direct_edit_timestamp'); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ($schema->hasTable('preferences')) { |
|
| 231 | - $table = $schema->getTable('preferences'); |
|
| 232 | - if (!$table->hasIndex('preferences_app_key')) { |
|
| 233 | - $subject->addHintForMissingSubject($table->getName(), 'preferences_app_key'); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - if ($schema->hasTable('mounts')) { |
|
| 238 | - $table = $schema->getTable('mounts'); |
|
| 239 | - if (!$table->hasIndex('mounts_class_index')) { |
|
| 240 | - $subject->addHintForMissingSubject($table->getName(), 'mounts_class_index'); |
|
| 241 | - } |
|
| 242 | - if (!$table->hasIndex('mounts_user_root_path_index')) { |
|
| 243 | - $subject->addHintForMissingSubject($table->getName(), 'mounts_user_root_path_index'); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - ); |
|
| 248 | - |
|
| 249 | - $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, |
|
| 250 | - function (GenericEvent $event) use ($container) { |
|
| 251 | - /** @var MissingPrimaryKeyInformation $subject */ |
|
| 252 | - $subject = $event->getSubject(); |
|
| 253 | - |
|
| 254 | - $schema = new SchemaWrapper($container->query(Connection::class)); |
|
| 255 | - |
|
| 256 | - if ($schema->hasTable('federated_reshares')) { |
|
| 257 | - $table = $schema->getTable('federated_reshares'); |
|
| 258 | - |
|
| 259 | - if (!$table->hasPrimaryKey()) { |
|
| 260 | - $subject->addHintForMissingSubject($table->getName()); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if ($schema->hasTable('systemtag_object_mapping')) { |
|
| 265 | - $table = $schema->getTable('systemtag_object_mapping'); |
|
| 266 | - |
|
| 267 | - if (!$table->hasPrimaryKey()) { |
|
| 268 | - $subject->addHintForMissingSubject($table->getName()); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - if ($schema->hasTable('comments_read_markers')) { |
|
| 273 | - $table = $schema->getTable('comments_read_markers'); |
|
| 274 | - |
|
| 275 | - if (!$table->hasPrimaryKey()) { |
|
| 276 | - $subject->addHintForMissingSubject($table->getName()); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - if ($schema->hasTable('collres_resources')) { |
|
| 281 | - $table = $schema->getTable('collres_resources'); |
|
| 282 | - |
|
| 283 | - if (!$table->hasPrimaryKey()) { |
|
| 284 | - $subject->addHintForMissingSubject($table->getName()); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if ($schema->hasTable('collres_accesscache')) { |
|
| 289 | - $table = $schema->getTable('collres_accesscache'); |
|
| 290 | - |
|
| 291 | - if (!$table->hasPrimaryKey()) { |
|
| 292 | - $subject->addHintForMissingSubject($table->getName()); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - if ($schema->hasTable('filecache_extended')) { |
|
| 297 | - $table = $schema->getTable('filecache_extended'); |
|
| 298 | - |
|
| 299 | - if (!$table->hasPrimaryKey()) { |
|
| 300 | - $subject->addHintForMissingSubject($table->getName()); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - ); |
|
| 305 | - |
|
| 306 | - $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, |
|
| 307 | - function (GenericEvent $event) use ($container) { |
|
| 308 | - /** @var MissingColumnInformation $subject */ |
|
| 309 | - $subject = $event->getSubject(); |
|
| 310 | - |
|
| 311 | - $schema = new SchemaWrapper($container->query(Connection::class)); |
|
| 312 | - |
|
| 313 | - if ($schema->hasTable('comments')) { |
|
| 314 | - $table = $schema->getTable('comments'); |
|
| 315 | - |
|
| 316 | - if (!$table->hasColumn('reference_id')) { |
|
| 317 | - $subject->addHintForMissingColumn($table->getName(), 'reference_id'); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - ); |
|
| 322 | - |
|
| 323 | - $eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); |
|
| 324 | - $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class); |
|
| 325 | - $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class); |
|
| 326 | - $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class); |
|
| 327 | - $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class); |
|
| 328 | - $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class); |
|
| 329 | - $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class); |
|
| 330 | - $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class); |
|
| 331 | - $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class); |
|
| 332 | - $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class); |
|
| 333 | - $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class); |
|
| 334 | - $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class); |
|
| 335 | - |
|
| 336 | - // Metadata |
|
| 337 | - /** @var IConfig $config */ |
|
| 338 | - $config = $container->get(IConfig::class); |
|
| 339 | - if ($config->getSystemValueBool('enable_file_metadata', true)) { |
|
| 340 | - /** @psalm-suppress InvalidArgument */ |
|
| 341 | - $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class); |
|
| 342 | - /** @psalm-suppress InvalidArgument */ |
|
| 343 | - $eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class); |
|
| 344 | - /** @psalm-suppress InvalidArgument */ |
|
| 345 | - $eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - // Tags |
|
| 349 | - $eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class); |
|
| 350 | - } |
|
| 74 | + public function __construct() { |
|
| 75 | + parent::__construct('core'); |
|
| 76 | + |
|
| 77 | + $container = $this->getContainer(); |
|
| 78 | + |
|
| 79 | + $container->registerService('defaultMailAddress', function () { |
|
| 80 | + return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
| 81 | + }); |
|
| 82 | + |
|
| 83 | + $server = $container->getServer(); |
|
| 84 | + /** @var IEventDispatcher $eventDispatcher */ |
|
| 85 | + $eventDispatcher = $server->get(IEventDispatcher::class); |
|
| 86 | + |
|
| 87 | + $notificationManager = $server->getNotificationManager(); |
|
| 88 | + $notificationManager->registerNotifierService(CoreNotifier::class); |
|
| 89 | + $notificationManager->registerNotifierService(AuthenticationNotifier::class); |
|
| 90 | + |
|
| 91 | + $oldEventDispatcher = $server->getEventDispatcher(); |
|
| 92 | + |
|
| 93 | + $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT, |
|
| 94 | + function (GenericEvent $event) use ($container) { |
|
| 95 | + /** @var MissingIndexInformation $subject */ |
|
| 96 | + $subject = $event->getSubject(); |
|
| 97 | + |
|
| 98 | + $schema = new SchemaWrapper($container->query(Connection::class)); |
|
| 99 | + |
|
| 100 | + if ($schema->hasTable('share')) { |
|
| 101 | + $table = $schema->getTable('share'); |
|
| 102 | + |
|
| 103 | + if (!$table->hasIndex('share_with_index')) { |
|
| 104 | + $subject->addHintForMissingSubject($table->getName(), 'share_with_index'); |
|
| 105 | + } |
|
| 106 | + if (!$table->hasIndex('parent_index')) { |
|
| 107 | + $subject->addHintForMissingSubject($table->getName(), 'parent_index'); |
|
| 108 | + } |
|
| 109 | + if (!$table->hasIndex('owner_index')) { |
|
| 110 | + $subject->addHintForMissingSubject($table->getName(), 'owner_index'); |
|
| 111 | + } |
|
| 112 | + if (!$table->hasIndex('initiator_index')) { |
|
| 113 | + $subject->addHintForMissingSubject($table->getName(), 'initiator_index'); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if ($schema->hasTable('filecache')) { |
|
| 118 | + $table = $schema->getTable('filecache'); |
|
| 119 | + |
|
| 120 | + if (!$table->hasIndex('fs_mtime')) { |
|
| 121 | + $subject->addHintForMissingSubject($table->getName(), 'fs_mtime'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (!$table->hasIndex('fs_size')) { |
|
| 125 | + $subject->addHintForMissingSubject($table->getName(), 'fs_size'); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if (!$table->hasIndex('fs_id_storage_size')) { |
|
| 129 | + $subject->addHintForMissingSubject($table->getName(), 'fs_id_storage_size'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) { |
|
| 133 | + $subject->addHintForMissingSubject($table->getName(), 'fs_storage_path_prefix'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if (!$table->hasIndex('fs_parent')) { |
|
| 137 | + $subject->addHintForMissingSubject($table->getName(), 'fs_parent'); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ($schema->hasTable('twofactor_providers')) { |
|
| 142 | + $table = $schema->getTable('twofactor_providers'); |
|
| 143 | + |
|
| 144 | + if (!$table->hasIndex('twofactor_providers_uid')) { |
|
| 145 | + $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid'); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if ($schema->hasTable('login_flow_v2')) { |
|
| 150 | + $table = $schema->getTable('login_flow_v2'); |
|
| 151 | + |
|
| 152 | + if (!$table->hasIndex('poll_token')) { |
|
| 153 | + $subject->addHintForMissingSubject($table->getName(), 'poll_token'); |
|
| 154 | + } |
|
| 155 | + if (!$table->hasIndex('login_token')) { |
|
| 156 | + $subject->addHintForMissingSubject($table->getName(), 'login_token'); |
|
| 157 | + } |
|
| 158 | + if (!$table->hasIndex('timestamp')) { |
|
| 159 | + $subject->addHintForMissingSubject($table->getName(), 'timestamp'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if ($schema->hasTable('whats_new')) { |
|
| 164 | + $table = $schema->getTable('whats_new'); |
|
| 165 | + |
|
| 166 | + if (!$table->hasIndex('version')) { |
|
| 167 | + $subject->addHintForMissingSubject($table->getName(), 'version'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + if ($schema->hasTable('cards')) { |
|
| 172 | + $table = $schema->getTable('cards'); |
|
| 173 | + |
|
| 174 | + if (!$table->hasIndex('cards_abid')) { |
|
| 175 | + $subject->addHintForMissingSubject($table->getName(), 'cards_abid'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if (!$table->hasIndex('cards_abiduri')) { |
|
| 179 | + $subject->addHintForMissingSubject($table->getName(), 'cards_abiduri'); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if ($schema->hasTable('cards_properties')) { |
|
| 184 | + $table = $schema->getTable('cards_properties'); |
|
| 185 | + |
|
| 186 | + if (!$table->hasIndex('cards_prop_abid')) { |
|
| 187 | + $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid'); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if ($schema->hasTable('calendarobjects_props')) { |
|
| 192 | + $table = $schema->getTable('calendarobjects_props'); |
|
| 193 | + |
|
| 194 | + if (!$table->hasIndex('calendarobject_calid_index')) { |
|
| 195 | + $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index'); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if ($schema->hasTable('schedulingobjects')) { |
|
| 200 | + $table = $schema->getTable('schedulingobjects'); |
|
| 201 | + if (!$table->hasIndex('schedulobj_principuri_index')) { |
|
| 202 | + $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index'); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($schema->hasTable('properties')) { |
|
| 207 | + $table = $schema->getTable('properties'); |
|
| 208 | + if (!$table->hasIndex('properties_path_index')) { |
|
| 209 | + $subject->addHintForMissingSubject($table->getName(), 'properties_path_index'); |
|
| 210 | + } |
|
| 211 | + if (!$table->hasIndex('properties_pathonly_index')) { |
|
| 212 | + $subject->addHintForMissingSubject($table->getName(), 'properties_pathonly_index'); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if ($schema->hasTable('jobs')) { |
|
| 217 | + $table = $schema->getTable('jobs'); |
|
| 218 | + if (!$table->hasIndex('job_lastcheck_reserved')) { |
|
| 219 | + $subject->addHintForMissingSubject($table->getName(), 'job_lastcheck_reserved'); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + if ($schema->hasTable('direct_edit')) { |
|
| 224 | + $table = $schema->getTable('direct_edit'); |
|
| 225 | + if (!$table->hasIndex('direct_edit_timestamp')) { |
|
| 226 | + $subject->addHintForMissingSubject($table->getName(), 'direct_edit_timestamp'); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ($schema->hasTable('preferences')) { |
|
| 231 | + $table = $schema->getTable('preferences'); |
|
| 232 | + if (!$table->hasIndex('preferences_app_key')) { |
|
| 233 | + $subject->addHintForMissingSubject($table->getName(), 'preferences_app_key'); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + if ($schema->hasTable('mounts')) { |
|
| 238 | + $table = $schema->getTable('mounts'); |
|
| 239 | + if (!$table->hasIndex('mounts_class_index')) { |
|
| 240 | + $subject->addHintForMissingSubject($table->getName(), 'mounts_class_index'); |
|
| 241 | + } |
|
| 242 | + if (!$table->hasIndex('mounts_user_root_path_index')) { |
|
| 243 | + $subject->addHintForMissingSubject($table->getName(), 'mounts_user_root_path_index'); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + ); |
|
| 248 | + |
|
| 249 | + $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, |
|
| 250 | + function (GenericEvent $event) use ($container) { |
|
| 251 | + /** @var MissingPrimaryKeyInformation $subject */ |
|
| 252 | + $subject = $event->getSubject(); |
|
| 253 | + |
|
| 254 | + $schema = new SchemaWrapper($container->query(Connection::class)); |
|
| 255 | + |
|
| 256 | + if ($schema->hasTable('federated_reshares')) { |
|
| 257 | + $table = $schema->getTable('federated_reshares'); |
|
| 258 | + |
|
| 259 | + if (!$table->hasPrimaryKey()) { |
|
| 260 | + $subject->addHintForMissingSubject($table->getName()); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if ($schema->hasTable('systemtag_object_mapping')) { |
|
| 265 | + $table = $schema->getTable('systemtag_object_mapping'); |
|
| 266 | + |
|
| 267 | + if (!$table->hasPrimaryKey()) { |
|
| 268 | + $subject->addHintForMissingSubject($table->getName()); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + if ($schema->hasTable('comments_read_markers')) { |
|
| 273 | + $table = $schema->getTable('comments_read_markers'); |
|
| 274 | + |
|
| 275 | + if (!$table->hasPrimaryKey()) { |
|
| 276 | + $subject->addHintForMissingSubject($table->getName()); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + if ($schema->hasTable('collres_resources')) { |
|
| 281 | + $table = $schema->getTable('collres_resources'); |
|
| 282 | + |
|
| 283 | + if (!$table->hasPrimaryKey()) { |
|
| 284 | + $subject->addHintForMissingSubject($table->getName()); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if ($schema->hasTable('collres_accesscache')) { |
|
| 289 | + $table = $schema->getTable('collres_accesscache'); |
|
| 290 | + |
|
| 291 | + if (!$table->hasPrimaryKey()) { |
|
| 292 | + $subject->addHintForMissingSubject($table->getName()); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + if ($schema->hasTable('filecache_extended')) { |
|
| 297 | + $table = $schema->getTable('filecache_extended'); |
|
| 298 | + |
|
| 299 | + if (!$table->hasPrimaryKey()) { |
|
| 300 | + $subject->addHintForMissingSubject($table->getName()); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + ); |
|
| 305 | + |
|
| 306 | + $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, |
|
| 307 | + function (GenericEvent $event) use ($container) { |
|
| 308 | + /** @var MissingColumnInformation $subject */ |
|
| 309 | + $subject = $event->getSubject(); |
|
| 310 | + |
|
| 311 | + $schema = new SchemaWrapper($container->query(Connection::class)); |
|
| 312 | + |
|
| 313 | + if ($schema->hasTable('comments')) { |
|
| 314 | + $table = $schema->getTable('comments'); |
|
| 315 | + |
|
| 316 | + if (!$table->hasColumn('reference_id')) { |
|
| 317 | + $subject->addHintForMissingColumn($table->getName(), 'reference_id'); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + ); |
|
| 322 | + |
|
| 323 | + $eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); |
|
| 324 | + $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class); |
|
| 325 | + $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class); |
|
| 326 | + $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class); |
|
| 327 | + $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class); |
|
| 328 | + $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class); |
|
| 329 | + $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class); |
|
| 330 | + $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class); |
|
| 331 | + $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class); |
|
| 332 | + $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class); |
|
| 333 | + $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class); |
|
| 334 | + $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class); |
|
| 335 | + |
|
| 336 | + // Metadata |
|
| 337 | + /** @var IConfig $config */ |
|
| 338 | + $config = $container->get(IConfig::class); |
|
| 339 | + if ($config->getSystemValueBool('enable_file_metadata', true)) { |
|
| 340 | + /** @psalm-suppress InvalidArgument */ |
|
| 341 | + $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class); |
|
| 342 | + /** @psalm-suppress InvalidArgument */ |
|
| 343 | + $eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class); |
|
| 344 | + /** @psalm-suppress InvalidArgument */ |
|
| 345 | + $eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + // Tags |
|
| 349 | + $eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class); |
|
| 350 | + } |
|
| 351 | 351 | } |