diff --git a/lib/Migration/Version20000Date20250612140256.php b/lib/Migration/Version20000Date20250612140256.php index 550101ab7..25ff689ef 100644 --- a/lib/Migration/Version20000Date20250612140256.php +++ b/lib/Migration/Version20000Date20250612140256.php @@ -49,9 +49,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt #[Override] public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { - $rootIds = $this->getJailedRootIds(); $storageId = $this->getJailedGroupFolderStorageId(); - if (count($rootIds) === 0 || $storageId === null) { + if ($storageId === null) { + return; + } + $rootIds = $this->getJailedRootIds($storageId); + if (count($rootIds) === 0) { return; } @@ -62,7 +65,8 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $query->update('group_folders') ->set('root_id', $query->createParameter('root_id')) ->set('storage_id', $query->createNamedParameter($storageId)) - ->where($query->expr()->eq('folder_id', $query->createParameter('folder_id'))); + ->where($query->expr()->eq('folder_id', $query->createParameter('folder_id'))) + ->andWhere($query->expr()->isNull('storage_id')); foreach ($rootIds as $folderId => $rootId) { $query->setParameter('root_id', $rootId); @@ -80,8 +84,8 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array /** * @return array */ - private function getJailedRootIds(): array { - $parentFolderId = $this->getJailedGroupFolderRootId(); + private function getJailedRootIds(int $storageId): array { + $parentFolderId = $this->getJailedGroupFolderRootId($storageId); if ($parentFolderId === null) { return []; } @@ -89,7 +93,8 @@ private function getJailedRootIds(): array { $query = $this->connection->getQueryBuilder(); $query->select('name', 'fileid') ->from('filecache') - ->where($query->expr()->eq('parent', $query->createNamedParameter($parentFolderId))); + ->where($query->expr()->eq('parent', $query->createNamedParameter($parentFolderId))) + ->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId))); $result = $query->executeQuery(); $rootIds = []; @@ -101,14 +106,15 @@ private function getJailedRootIds(): array { return $rootIds; } - private function getJailedGroupFolderRootId(): ?int { + private function getJailedGroupFolderRootId(int $storageId): ?int { $query = $this->connection->getQueryBuilder(); $query->select('fileid') ->from('filecache') - ->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5('__groupfolders')))); + ->where($query->expr()->eq('path_hash', $query->createNamedParameter(md5('__groupfolders')))) + ->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId))); $id = $query->executeQuery()->fetchOne(); - if ($id === null) { + if ($id === false) { return null; } else { return (int)$id; @@ -119,10 +125,11 @@ private function getJailedGroupFolderStorageId(): ?int { $query = $this->connection->getQueryBuilder(); $query->select('storage') ->from('filecache') + ->runAcrossAllShards() ->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5('__groupfolders')))); $id = $query->executeQuery()->fetchOne(); - if ($id === null) { + if ($id === false) { return null; } else { return (int)$id;