diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index c16fba36c1..5b73e6a75c 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -136,6 +136,9 @@ class Databases extends Action $options = $attribute->getAttribute('options', []); $project = $dbForPlatform->getDocument('projects', $projectId); + $relatedAttribute = new Document(); + $relatedCollection = new Document(); + try { switch ($type) { case Database::VAR_RELATIONSHIP: @@ -175,7 +178,7 @@ class Databases extends Action if ($e instanceof DatabaseException) { $attribute->setAttribute('error', $e->getMessage()); - if (isset($relatedAttribute)) { + if (! $relatedAttribute->isEmpty()) { $relatedAttribute->setAttribute('error', $e->getMessage()); } } @@ -186,7 +189,7 @@ class Databases extends Action $attribute->setAttribute('status', 'failed') ); - if (isset($relatedAttribute)) { + if (! $relatedAttribute->isEmpty()) { $dbForProject->updateDocument( 'attributes', $relatedAttribute->getId(), @@ -198,7 +201,7 @@ class Databases extends Action } finally { $this->trigger($database, $collection, $attribute, $project, $projectId, $events); - if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { + if (! $relatedCollection->isEmpty()) { $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); } @@ -364,7 +367,7 @@ class Databases extends Action } finally { $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId); - if (!$relatedCollection->isEmpty() && !$relatedAttribute->isEmpty()) { + if (! $relatedCollection->isEmpty()) { $dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId()); } }