Use getProjectDB instead of new function

This commit is contained in:
Jake Barnby 2023-01-12 22:27:20 +13:00
parent 4b0ef4598b
commit d49de9c6cf
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 11 additions and 22 deletions

View file

@ -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;

View file

@ -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);
}
/**