Fix getting function for rule

This commit is contained in:
Jake Barnby 2025-05-17 01:39:25 +12:00
parent 04009699eb
commit a3722f53a5
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
3 changed files with 22 additions and 12 deletions

View file

@ -28,6 +28,11 @@ abstract class Migration
protected Database $dbForPlatform;
/**
* @var callable(Document): Database
*/
protected mixed $getProjectDB;
protected PDO $pdo;
/**
@ -115,11 +120,17 @@ abstract class Migration
* @param Database $dbForPlatform
* @return self
*/
public function setProject(Document $project, Database $dbForProject, Database $dbForPlatform): self
public function setProject(
Document $project,
Database $dbForProject,
Database $dbForPlatform,
?callable $getProjectDB = null
): self
{
$this->project = $project;
$this->dbForProject = $dbForProject;
$this->dbForPlatform = $dbForPlatform;
$this->getProjectDB = $getProjectDB;
return $this;
}

View file

@ -348,16 +348,15 @@ class V23 extends Migration
->setAttribute('search', \implode(' ', [$document->getId(), $document->getAttribute('domain', '')]));
if ($deploymentResourceType === 'function') {
if ($this->project->getInternalId() !== 'console') {
$function = $this->dbForProject->getDocument('functions', $resourceId);
$project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId'));
$dbForOwnerProject = ($this->getProjectDB)($project);
$function = $dbForOwnerProject->getDocument('functions', $resourceId);
$deploymentId = $function->getAttribute('deployment', $function->getAttribute('deploymentId', $document->getAttribute('deploymentId')));
$deploymentInternalId = $function->getAttribute('deploymentInternalId', $document->getAttribute('deploymentInternalId', ''));
$deploymentId = $function->getAttribute('deployment', $document->getAttribute('deploymentId', ''));
$deploymentInternalId = $function->getAttribute('deploymentInternalId', $document->getAttribute('deploymentInternalId', ''));
$document
->setAttribute('deploymentId', $deploymentId)
->setAttribute('deploymentInternalId', $deploymentInternalId);
}
$document
->setAttribute('deploymentId', $deploymentId)
->setAttribute('deploymentInternalId', $deploymentInternalId);
}
break;
case 'variables':

View file

@ -74,7 +74,7 @@ class Migrate extends Action
try {
$migration
->setProject($project, $dbForProject, $dbForPlatform)
->setProject($project, $dbForProject, $dbForPlatform, $getProjectDB)
->setPDO($register->get('db', true))
->execute();
} catch (\Throwable $th) {
@ -89,7 +89,7 @@ class Migrate extends Action
try {
$migration
->setProject($console, $getProjectDB($console), $dbForPlatform)
->setProject($console, $getProjectDB($console), $dbForPlatform, $getProjectDB)
->setPDO($register->get('db', true))
->execute();
} catch (\Throwable $th) {