diff --git a/src/Appwrite/Migration/Version/V11.php b/src/Appwrite/Migration/Version/V11.php index b94768116..896dce8f3 100644 --- a/src/Appwrite/Migration/Version/V11.php +++ b/src/Appwrite/Migration/Version/V11.php @@ -194,7 +194,7 @@ class V11 extends Migration $new = $this->fixDocument($document); - if (empty($new->getId())) { + if (is_null($new) || empty($new->getId())) { Console::warning('Skipped Document due to missing ID.'); continue; } @@ -413,10 +413,10 @@ class V11 extends Migration * Migrates single docuemnt. * * @param OldDocument $oldDocument - * @return Document + * @return Document|null * @throws Exception */ - protected function fixDocument(OldDocument $oldDocument): Document + protected function fixDocument(OldDocument $oldDocument): Document|null { $document = new Document($oldDocument->getArrayCopy()); $document = $this->migratePermissions($document); @@ -487,15 +487,20 @@ class V11 extends Migration if (!empty($document->getAttribute('usersAuthLimit'))) { $newAuths['limit'] = $document->getAttribute('usersAuthLimit'); - $document->removeAttribute('usersAuthLimit'); } + $document->removeAttribute('usersAuthLimit'); + $document->setAttribute('auths', $newProviders); break; case OldDatabase::SYSTEM_COLLECTION_PLATFORMS: $projectId = $this->getProjectIdFromReadPermissions($document); + if (is_null($projectId)) { + return null; + } + /** * Set Project ID */ @@ -533,6 +538,10 @@ class V11 extends Migration case OldDatabase::SYSTEM_COLLECTION_DOMAINS: $projectId = $this->getProjectIdFromReadPermissions($document); + if (is_null($projectId)) { + return null; + } + /** * Set Project ID */ @@ -557,6 +566,10 @@ class V11 extends Migration case OldDatabase::SYSTEM_COLLECTION_KEYS: $projectId = $this->getProjectIdFromReadPermissions($document); + if (is_null($projectId)) { + return null; + } + /** * Set Project ID */ @@ -585,6 +598,10 @@ class V11 extends Migration case OldDatabase::SYSTEM_COLLECTION_WEBHOOKS: $projectId = $this->getProjectIdFromReadPermissions($document); + if (is_null($projectId)) { + return null; + } + /** * Set Project ID */ @@ -780,7 +797,7 @@ class V11 extends Migration } /** - * @param Document $document + * @param Document $document * @return string|null * @throws Exception */ @@ -788,11 +805,17 @@ class V11 extends Migration { $readPermissions = $document->getRead(); $teamId = str_replace('team:', '', reset($readPermissions)); - return $this->oldConsoleDB->getCollectionFirst([ + $project = $this->oldConsoleDB->getCollectionFirst([ 'filters' => [ '$collection=' . OldDatabase::SYSTEM_COLLECTION_PROJECTS, 'teamId=' . $teamId ] - ])->getId(); + ]); + + if (!$project) { + return null; + } + + return $project->getId(); } }