mirror of
https://github.com/appwrite/appwrite
synced 2026-05-16 05:28:31 +00:00
Implement a fix
This commit is contained in:
parent
675179def8
commit
501d29f696
4 changed files with 21 additions and 86 deletions
|
|
@ -4,7 +4,6 @@ namespace Appwrite\Platform\Modules\Compute;
|
|||
|
||||
use Appwrite\Event\Build;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Query;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
|
|
@ -235,41 +234,4 @@ class Base extends Action
|
|||
|
||||
return $deployment;
|
||||
}
|
||||
|
||||
protected function listRules(Document $project, array $queries, Database $database, callable $callback): void
|
||||
{
|
||||
$limit = 100;
|
||||
$cursor = null;
|
||||
|
||||
do {
|
||||
\var_dump("Project internal ID: " . $project->getInternalId());
|
||||
|
||||
$queries = \array_merge([
|
||||
Query::limit($limit),
|
||||
Query::equal("projectInternalId", [$project->getInternalId()])
|
||||
], $queries);
|
||||
|
||||
if ($cursor !== null) {
|
||||
$queries[] = Query::cursorAfter($cursor);
|
||||
}
|
||||
|
||||
\var_dump($queries);
|
||||
$results = Authorization::skip(fn () => $database->find('rules', $queries));
|
||||
|
||||
$total = \count($results);
|
||||
if ($total > 0) {
|
||||
$cursor = $results[$total - 1];
|
||||
}
|
||||
|
||||
if ($total < $limit) {
|
||||
$cursor = null;
|
||||
}
|
||||
|
||||
foreach ($results as $document) {
|
||||
if (is_callable($callback)) {
|
||||
$callback($document);
|
||||
}
|
||||
}
|
||||
} while (!\is_null($cursor));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace Appwrite\Platform\Modules\Functions\Http\Functions\Deployment;
|
|||
use Appwrite\Event\Event;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Platform\Modules\Compute\Base;
|
||||
use Appwrite\Query;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
|
|
@ -13,6 +12,7 @@ use Appwrite\Utopia\Response;
|
|||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
|
|
@ -109,14 +109,15 @@ class Update extends Base
|
|||
Query::equal("deploymentResourceType", ["function"]),
|
||||
Query::equal("deploymentResourceInternalId", [$function->getInternalId()]),
|
||||
Query::equal("deploymentVcsProviderBranch", [""]),
|
||||
Query::equal("projectInternalId", [$project->getInternalId()])
|
||||
];
|
||||
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
|
||||
Authorization::skip(fn () => $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
->setAttribute('deploymentInternalId', $deployment->getInternalId());
|
||||
Authorization::skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), $rule));
|
||||
});
|
||||
}, $queries));
|
||||
|
||||
$queueForEvents
|
||||
->setParam('functionId', $function->getId())
|
||||
|
|
|
|||
|
|
@ -1087,16 +1087,17 @@ class Builds extends Action
|
|||
Query::equal('deploymentResourceType', ['function']),
|
||||
Query::equal('trigger', ['manual']),
|
||||
Query::equal('deploymentVcsProviderBranch', ['']),
|
||||
Query::equal("projectInternalId", [$project->getInternalId()])
|
||||
];
|
||||
|
||||
$rulesUpdated = false;
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) {
|
||||
$dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) {
|
||||
$rulesUpdated = true;
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
->setAttribute('deploymentInternalId', $deployment->getInternalId());
|
||||
$dbForPlatform->updateDocument('rules', $rule->getId(), $rule);
|
||||
});
|
||||
}, $queries);
|
||||
break;
|
||||
case 'sites':
|
||||
$resource->setAttribute('deploymentId', $deployment->getId());
|
||||
|
|
@ -1112,14 +1113,15 @@ class Builds extends Action
|
|||
Query::equal('deploymentResourceType', ['site']),
|
||||
Query::equal('trigger', ['manual']),
|
||||
Query::equal('deploymentVcsProviderBranch', ['']),
|
||||
Query::equal("projectInternalId", [$project->getInternalId()])
|
||||
];
|
||||
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
->setAttribute('deploymentInternalId', $deployment->getInternalId());
|
||||
$dbForPlatform->updateDocument('rules', $rule->getId(), $rule);
|
||||
});
|
||||
}, $queries);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -1161,19 +1163,22 @@ class Builds extends Action
|
|||
$dbForPlatform->updateDocument('rules', $rule->getId(), $rule);
|
||||
}
|
||||
|
||||
$this->listRules($project, [
|
||||
$queries = [
|
||||
Query::equal("projectInternalId", [$project->getInternalId()]),
|
||||
Query::equal("type", ["deployment"]),
|
||||
Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]),
|
||||
Query::equal('deploymentResourceType', ['site']),
|
||||
Query::equal("deploymentVcsProviderBranch", [$branchName]),
|
||||
Query::equal("trigger", ['manual']),
|
||||
], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
Query::equal("projectInternalId", [$project->getInternalId()])
|
||||
];
|
||||
|
||||
$dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
->setAttribute('deploymentInternalId', $deployment->getInternalId());
|
||||
$dbForPlatform->updateDocument('rules', $rule->getId(), $rule);
|
||||
});
|
||||
}, $queries);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1476,38 +1481,4 @@ class Builds extends Action
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function listRules(Document $project, array $queries, Database $database, callable $callback): void
|
||||
{
|
||||
$limit = 100;
|
||||
$cursor = null;
|
||||
|
||||
do {
|
||||
$queries = \array_merge([
|
||||
Query::limit($limit),
|
||||
Query::equal("projectInternalId", [$project->getInternalId()])
|
||||
], $queries);
|
||||
|
||||
if ($cursor !== null) {
|
||||
$queries[] = Query::cursorAfter($cursor);
|
||||
}
|
||||
|
||||
$results = $database->find('rules', $queries);
|
||||
|
||||
$total = \count($results);
|
||||
if ($total > 0) {
|
||||
$cursor = $results[$total - 1];
|
||||
}
|
||||
|
||||
if ($total < $limit) {
|
||||
$cursor = null;
|
||||
}
|
||||
|
||||
foreach ($results as $document) {
|
||||
if (is_callable($callback)) {
|
||||
$callback($document);
|
||||
}
|
||||
}
|
||||
} while (!\is_null($cursor));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ namespace Appwrite\Platform\Modules\Sites\Http\Sites\Deployment;
|
|||
use Appwrite\Event\Event;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Platform\Modules\Compute\Base;
|
||||
use Appwrite\Query;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
|
|
@ -101,14 +101,15 @@ class Update extends Base
|
|||
Query::equal("deploymentResourceType", ["site"]),
|
||||
Query::equal("deploymentResourceInternalId", [$site->getInternalId()]),
|
||||
Query::equal("deploymentVcsProviderBranch", [""]),
|
||||
Query::equal("projectInternalId", [$project->getInternalId()])
|
||||
];
|
||||
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
Authorization::skip(fn () => $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
->setAttribute('deploymentInternalId', $deployment->getInternalId());
|
||||
Authorization::skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), $rule));
|
||||
});
|
||||
}, $queries));
|
||||
|
||||
$queueForEvents
|
||||
->setParam('siteId', $site->getId())
|
||||
|
|
|
|||
Loading…
Reference in a new issue