mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
functions and more tests
This commit is contained in:
@@ -13,8 +13,8 @@ use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
use Utopia\Database\Helpers\Role;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Swoole\Request;
|
||||
use Utopia\System\System;
|
||||
use Utopia\VCS\Adapter\Git\GitHub;
|
||||
@@ -53,7 +53,7 @@ class Base extends Action
|
||||
return $allowedSpecifications[0] ?? APP_COMPUTE_SPECIFICATION_DEFAULT;
|
||||
}
|
||||
|
||||
public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Build $queueForBuilds, Document $template, GitHub $github, bool $activate, string $referenceType = 'branch', string $reference = ''): Document
|
||||
public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Database $dbForPlatform, Build $queueForBuilds, Document $template, GitHub $github, bool $activate, string $referenceType = 'branch', string $reference = ''): Document
|
||||
{
|
||||
$deploymentId = ID::unique();
|
||||
$entrypoint = $function->getAttribute('entrypoint', '');
|
||||
@@ -134,6 +134,8 @@ class Base extends Action
|
||||
->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', ''));
|
||||
$dbForProject->updateDocument('functions', $function->getId(), $function);
|
||||
|
||||
$this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform);
|
||||
|
||||
$queueForBuilds
|
||||
->setType(BUILD_TYPE_DEPLOYMENT)
|
||||
->setResource($function)
|
||||
@@ -328,7 +330,7 @@ class Base extends Action
|
||||
}
|
||||
}
|
||||
|
||||
$this->updateManualRuleForNewSiteDeployment($project, $site, $deployment, $dbForPlatform);
|
||||
$this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform);
|
||||
|
||||
$queueForBuilds
|
||||
->setType(BUILD_TYPE_DEPLOYMENT)
|
||||
@@ -340,8 +342,8 @@ class Base extends Action
|
||||
}
|
||||
|
||||
/**
|
||||
* Update manual rule for new site deployment.
|
||||
* In case of fresh site, deployment ID will be empty in the rules, so we need to update it here.
|
||||
* Update empty manual rule for deployment.
|
||||
* In case of first deployment, deployment ID will be empty in the rules, so we need to update it here.
|
||||
*
|
||||
* @param \Utopia\Database\Document $project
|
||||
* @param \Utopia\Database\Document $site
|
||||
@@ -349,22 +351,20 @@ class Base extends Action
|
||||
* @param \Utopia\Database\Database $dbForPlatform
|
||||
* @return void
|
||||
*/
|
||||
public function updateManualRuleForNewSiteDeployment(Document $project, Document $site, Document $deployment, Database $dbForPlatform)
|
||||
public function updateEmptyManualRule(Document $project, Document $resource, Document $deployment, Database $dbForPlatform)
|
||||
{
|
||||
$queries = [
|
||||
Query::equal('projectInternalId', [$project->getSequence()]),
|
||||
Query::equal('deploymentResourceInternalId', [$resource->getSequence()]),
|
||||
Query::equal('deploymentId', ['']),
|
||||
Query::equal('type', ['deployment']),
|
||||
Query::equal('deploymentResourceInternalId', [$site->getSequence()]),
|
||||
Query::equal('deploymentResourceType', ['site']),
|
||||
Query::equal('trigger', ['manual']),
|
||||
];
|
||||
$dbForPlatform->forEach('rules', function (Document $rule) use ($deployment, $dbForPlatform) {
|
||||
if (empty($rule->getAttribute('deploymentId', ''))) {
|
||||
Authorization::skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
|
||||
'deploymentId' => $deployment->getId(),
|
||||
'deploymentInternalId' => $deployment->getSequence(),
|
||||
])));
|
||||
}
|
||||
Authorization::skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
|
||||
'deploymentId' => $deployment->getId(),
|
||||
'deploymentInternalId' => $deployment->getSequence(),
|
||||
])));
|
||||
}, $queries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Appwrite\Platform\Modules\Functions\Http\Deployments;
|
||||
use Appwrite\Event\Build;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Platform\Modules\Compute\Base;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\ContentType;
|
||||
use Appwrite\SDK\Method;
|
||||
@@ -30,7 +31,7 @@ use Utopia\System\System;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class Create extends Action
|
||||
class Create extends Base
|
||||
{
|
||||
use HTTP;
|
||||
|
||||
@@ -81,6 +82,7 @@ class Create extends Action
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('dbForPlatform')
|
||||
->inject('queueForEvents')
|
||||
->inject('project')
|
||||
->inject('deviceForFunctions')
|
||||
@@ -99,6 +101,7 @@ class Create extends Action
|
||||
Request $request,
|
||||
Response $response,
|
||||
Database $dbForProject,
|
||||
Database $dbForPlatform,
|
||||
Event $queueForEvents,
|
||||
Document $project,
|
||||
Device $deviceForFunctions,
|
||||
@@ -300,6 +303,8 @@ class Create extends Action
|
||||
}
|
||||
}
|
||||
|
||||
$this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform);
|
||||
|
||||
$metadata = null;
|
||||
|
||||
$queueForEvents
|
||||
|
||||
@@ -116,6 +116,7 @@ class Create extends Base
|
||||
project: $project,
|
||||
installation: $installation,
|
||||
dbForProject: $dbForProject,
|
||||
dbForPlatform: $dbForPlatform,
|
||||
queueForBuilds: $queueForBuilds,
|
||||
template: $template,
|
||||
github: $github,
|
||||
@@ -157,6 +158,9 @@ class Create extends Base
|
||||
->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', ''));
|
||||
$dbForProject->updateDocument('functions', $function->getId(), $function);
|
||||
|
||||
|
||||
$this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform);
|
||||
|
||||
$queueForBuilds
|
||||
->setType(BUILD_TYPE_DEPLOYMENT)
|
||||
->setResource($function)
|
||||
|
||||
@@ -105,6 +105,7 @@ class Create extends Base
|
||||
project: $project,
|
||||
installation: $installation,
|
||||
dbForProject: $dbForProject,
|
||||
dbForPlatform: $dbForPlatform,
|
||||
queueForBuilds: $queueForBuilds,
|
||||
template: $template,
|
||||
github: $github,
|
||||
|
||||
@@ -311,6 +311,7 @@ class Create extends Base
|
||||
project: $project,
|
||||
installation: $installation,
|
||||
dbForProject: $dbForProject,
|
||||
dbForPlatform: $dbForPlatform,
|
||||
queueForBuilds: $queueForBuilds,
|
||||
template: $template,
|
||||
github: $github,
|
||||
|
||||
@@ -273,7 +273,7 @@ class Update extends Base
|
||||
|
||||
// Redeploy logic
|
||||
if (!$isConnected && !empty($providerRepositoryId)) {
|
||||
$this->redeployVcsFunction($request, $function, $project, $installation, $dbForProject, $queueForBuilds, new Document(), $github, true);
|
||||
$this->redeployVcsFunction($request, $function, $project, $installation, $dbForProject, $dbForPlatform, $queueForBuilds, new Document(), $github, true);
|
||||
}
|
||||
|
||||
// Inform scheduler if function is still active
|
||||
|
||||
@@ -365,7 +365,7 @@ class Create extends Base
|
||||
}
|
||||
}
|
||||
|
||||
$this->updateManualRuleForNewSiteDeployment($project, $site, $deployment, $dbForPlatform);
|
||||
$this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform);
|
||||
|
||||
$metadata = null;
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ class Create extends Base
|
||||
]))
|
||||
);
|
||||
|
||||
$this->updateManualRuleForNewSiteDeployment($project, $site, $deployment, $dbForPlatform);
|
||||
$this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform);
|
||||
|
||||
$queueForBuilds
|
||||
->setType(BUILD_TYPE_DEPLOYMENT)
|
||||
|
||||
@@ -272,7 +272,7 @@ class Update extends Base
|
||||
|
||||
// Redeploy logic
|
||||
if (!$isConnected && !empty($providerRepositoryId)) {
|
||||
$this->redeployVcsFunction($request, $site, $project, $installation, $dbForProject, $queueForBuilds, new Document(), $github, true);
|
||||
$this->redeployVcsFunction($request, $site, $project, $installation, $dbForProject, $dbForPlatform, $queueForBuilds, new Document(), $github, true);
|
||||
}
|
||||
|
||||
$queueForEvents->setParam('siteId', $site->getId());
|
||||
|
||||
Reference in New Issue
Block a user