diff --git a/app/workers/deletes.php b/app/workers/deletes.php index ca5299e8af..605f989ee1 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -254,7 +254,7 @@ class DeletesV1 extends Worker protected function deleteProject(Document $document): void { // Delete project tables - $dbForProject = $this->getProjectDBFromDocument($document); + $dbForProject = $this->getProjectDB($document->getId(), $document); $limit = 50; $offset = 0; diff --git a/src/Appwrite/Resque/Worker.php b/src/Appwrite/Resque/Worker.php index b01bace9ea..6de22c6441 100644 --- a/src/Appwrite/Resque/Worker.php +++ b/src/Appwrite/Resque/Worker.php @@ -165,31 +165,20 @@ abstract class Worker * @return Database * @throws Exception */ - protected function getProjectDB(string $projectId): Database + protected function getProjectDB(string $projectId, ?Document $project = null): Database { - $consoleDB = $this->getConsoleDB(); + if ($project === null) { + $consoleDB = $this->getConsoleDB(); - if ($projectId === 'console') { - return $consoleDB; + if ($projectId === 'console') { + return $consoleDB; + } + + /** @var Document $project */ + $project = Authorization::skip(fn() => $consoleDB->getDocument('projects', $projectId)); } - /** @var Document $project */ - $project = Authorization::skip(fn() => $consoleDB->getDocument('projects', $projectId)); - - return $this->getDB(self::DATABASE_PROJECT, $projectId, $project->getInternalId()); - } - - /** - * Get internal project database given the project document - * - * Allows avoiding race conditions when modifying the projects collection - * @param Document $project - * @return Database - * @throws Exception - */ - protected function getProjectDBFromDocument(Document $project): Database - { - return $this->getDB(self::DATABASE_PROJECT, project: $project); + return $this->getDB(self::DATABASE_PROJECT, $projectId, $project->getInternalId(), $project); } /**