From 94d49f96853ff40a5d80d281eb29480abdef6bc5 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 5 Jan 2022 12:49:53 +0100 Subject: [PATCH 1/3] fix: migration for leftover documents on deleted projects --- src/Appwrite/Migration/Version/V11.php | 30 ++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Migration/Version/V11.php b/src/Appwrite/Migration/Version/V11.php index b94768116..bb35710be 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; } @@ -496,6 +496,10 @@ class V11 extends Migration case OldDatabase::SYSTEM_COLLECTION_PLATFORMS: $projectId = $this->getProjectIdFromReadPermissions($document); + if (is_null($projectId)) { + return null; + } + /** * Set Project ID */ @@ -533,6 +537,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 +565,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 +597,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 +796,7 @@ class V11 extends Migration } /** - * @param Document $document + * @param Document $document * @return string|null * @throws Exception */ @@ -788,11 +804,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(); } } From f477d2c3597c510e4b00cac4b850babb5b5ec125 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 5 Jan 2022 12:52:33 +0100 Subject: [PATCH 2/3] fix: function head --- src/Appwrite/Migration/Version/V11.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Migration/Version/V11.php b/src/Appwrite/Migration/Version/V11.php index bb35710be..cd1b080c8 100644 --- a/src/Appwrite/Migration/Version/V11.php +++ b/src/Appwrite/Migration/Version/V11.php @@ -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); From 9f0644c4898a8ac046552a8d31926d503428fe92 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 5 Jan 2022 13:54:23 +0100 Subject: [PATCH 3/3] fix: migration for unknown userlimit --- src/Appwrite/Migration/Version/V11.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Migration/Version/V11.php b/src/Appwrite/Migration/Version/V11.php index cd1b080c8..896dce8f3 100644 --- a/src/Appwrite/Migration/Version/V11.php +++ b/src/Appwrite/Migration/Version/V11.php @@ -487,9 +487,10 @@ 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;