diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 4494208078..2bc7759620 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2854,7 +2854,7 @@ App::put('/v1/account/verification') $dbForProject->deleteCachedDocument('users', $profile->getId()); $queueForEvents - ->setParam('userId', $user->getId()) + ->setParam('userId', $userId) ->setParam('tokenId', $verificationDocument->getId()) ; diff --git a/app/init.php b/app/init.php index f977394ba4..bc1e95e077 100644 --- a/app/init.php +++ b/app/init.php @@ -18,7 +18,6 @@ ini_set('display_startup_errors', 1); ini_set('default_socket_timeout', -1); error_reporting(E_ALL); -use Appwrite\Event\Usage; use Appwrite\Event\Migration; use Appwrite\Extend\Exception; use Appwrite\Auth\Auth; @@ -70,7 +69,6 @@ use Utopia\Pools\Group; use Utopia\Pools\Pool; use Ahc\Jwt\JWT; use Ahc\Jwt\JWTException; -use Appwrite\Auth\OAuth2\Github; use Appwrite\Event\Build; use Appwrite\Event\Certificate; use Appwrite\Event\Func; diff --git a/app/worker.php b/app/worker.php index 4d11aba1bd..8aa52ab931 100644 --- a/app/worker.php +++ b/app/worker.php @@ -44,7 +44,8 @@ Server::setResource('dbForConsole', function (Cache $cache, Registry $register) $database = $pools ->get('console') ->pop() - ->getResource(); + ->getResource() + ; $adapter = new Database($database, $cache); $adapter->setNamespace('_console'); @@ -64,9 +65,10 @@ Server::setResource('dbForProject', function (Cache $cache, Registry $register, $database = $pools ->get($project->getAttribute('database')) ->pop() - ->getResource(); + ->getResource() + ; - $adapter = new Database($database, $cache); + $adapter = new Database($database, $cache); $adapter->setNamespace('_' . $project->getInternalId()); return $adapter; }, ['cache', 'register', 'message', 'dbForConsole']); @@ -111,7 +113,8 @@ Server::setResource('cache', function (Registry $register) { $adapters[] = $pools ->get($value) ->pop() - ->getResource(); + ->getResource() + ; } return new Cache(new Sharding($adapters)); diff --git a/composer.json b/composer.json index f7340a69ba..bd5b143f16 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "utopia-php/image": "0.5.*", "utopia-php/locale": "0.4.*", "utopia-php/logger": "0.3.*", - "utopia-php/messaging": "0.2.*", + "utopia-php/messaging": "0.1.*", "utopia-php/migration": "0.3.*", "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "0.5.*", diff --git a/composer.lock b/composer.lock index 4634780720..e45d242295 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e34e098996ca4769e2a956b423522e91", + "content-hash": "5060c891e467051fedd25f3853cd37b0", "packages": [ { "name": "adhocore/jwt", @@ -2516,16 +2516,16 @@ }, { "name": "utopia-php/messaging", - "version": "0.2.0", + "version": "0.1.1", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "2d0f474a106bb1da285f85e105c29b46085d3a43" + "reference": "a75d66ddd59b834ab500a4878a2c084e6572604a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/2d0f474a106bb1da285f85e105c29b46085d3a43", - "reference": "2d0f474a106bb1da285f85e105c29b46085d3a43", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/a75d66ddd59b834ab500a4878a2c084e6572604a", + "reference": "a75d66ddd59b834ab500a4878a2c084e6572604a", "shasum": "" }, "require": { @@ -2534,8 +2534,8 @@ }, "require-dev": { "laravel/pint": "^1.2", - "phpmailer/phpmailer": "6.8.*", - "phpunit/phpunit": "9.6.*" + "phpmailer/phpmailer": "6.6.*", + "phpunit/phpunit": "9.5.*" }, "type": "library", "autoload": { @@ -2558,9 +2558,9 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/0.2.0" + "source": "https://github.com/utopia-php/messaging/tree/0.1.1" }, - "time": "2023-09-14T20:48:42+00:00" + "time": "2023-02-07T05:42:46+00:00" }, { "name": "utopia-php/migration", diff --git a/docker-compose.yml b/docker-compose.yml index b5dd37aa96..4e34b1bad9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,7 +83,7 @@ services: - ./docs:/usr/src/code/docs - ./public:/usr/src/code/public - ./src:/usr/src/code/src - - ./dev:/usr/local/dev + - ./dev:/usr/src/code/dev depends_on: - mariadb - redis @@ -360,7 +360,7 @@ services: - appwrite volumes: - ./app:/usr/src/code/app - - ./src:/usr/src/code/srcrm + - ./src:/usr/src/code/src depends_on: - redis - mariadb diff --git a/src/Appwrite/Event/Build.php b/src/Appwrite/Event/Build.php index 58667344ac..496db87d64 100644 --- a/src/Appwrite/Event/Build.php +++ b/src/Appwrite/Event/Build.php @@ -114,8 +114,6 @@ class Build extends Event { $client = new Client($this->queue, $this->connection); - $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; - return $client->enqueue([ 'project' => $this->project, 'resource' => $this->resource, diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index eb22f8897f..e5a86ef840 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -2,7 +2,6 @@ namespace Appwrite\Event; -use Utopia\App; use Utopia\Database\Document; use Utopia\Queue\Client; use Utopia\Queue\Connection; diff --git a/src/Appwrite/Event/Delete.php b/src/Appwrite/Event/Delete.php index d93dffaf44..57300feb72 100644 --- a/src/Appwrite/Event/Delete.php +++ b/src/Appwrite/Event/Delete.php @@ -128,8 +128,6 @@ class Delete extends Event { $client = new Client($this->queue, $this->connection); - $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; - return $client->enqueue([ 'project' => $this->project, 'type' => $this->type, diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 07f496788f..46b430d122 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -50,6 +50,7 @@ class Event protected array $context = []; protected ?Document $project = null; protected ?Document $user = null; + protected bool $paused = false; /** * @param Connection $connection @@ -264,6 +265,9 @@ class Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } $client = new Client($this->queue, $this->connection); @@ -472,4 +476,22 @@ class Event */ return \array_values($events); } + + /** + * Get the value of paused + */ + public function isPaused(): bool + { + return $this->paused; + } + + /** + * Set the value of paused + */ + public function setPaused(bool $paused): self + { + $this->paused = $paused; + + return $this; + } } diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index f211ec31be..11c9e980ed 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -188,6 +188,10 @@ class Func extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index 393df3d979..c2de8023b0 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -2,7 +2,6 @@ namespace Appwrite\Event; -use Utopia\Database\Document; use Utopia\Queue\Client; use Utopia\Queue\Connection; diff --git a/src/Appwrite/Event/Migration.php b/src/Appwrite/Event/Migration.php index 93126cb358..478291829b 100644 --- a/src/Appwrite/Event/Migration.php +++ b/src/Appwrite/Event/Migration.php @@ -2,9 +2,6 @@ namespace Appwrite\Event; -use DateTime; -use Resque; -use ResqueScheduler; use Utopia\Database\Document; use Utopia\Queue\Client; use Utopia\Queue\Connection; diff --git a/src/Appwrite/Event/Phone.php b/src/Appwrite/Event/Phone.php index 9f27345a95..45f193a540 100644 --- a/src/Appwrite/Event/Phone.php +++ b/src/Appwrite/Event/Phone.php @@ -75,8 +75,6 @@ class Phone extends Event { $client = new Client($this->queue, $this->connection); - $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; - return $client->enqueue([ 'project' => $this->project, 'user' => $this->user, diff --git a/src/Appwrite/Platform/Tasks/CalcTierStats.php b/src/Appwrite/Platform/Tasks/CalcTierStats.php index b614f4c8be..2a2bc20af9 100644 --- a/src/Appwrite/Platform/Tasks/CalcTierStats.php +++ b/src/Appwrite/Platform/Tasks/CalcTierStats.php @@ -200,9 +200,8 @@ class CalcTierStats extends Action try { /** Get Domains */ - $stats['Domains'] = $dbForConsole->count('rules', [ + $stats['Domains'] = $dbForConsole->count('domains', [ Query::equal('projectInternalId', [$project->getInternalId()]), - Query::limit(APP_LIMIT_COUNT) ]); } catch (\Throwable) { $stats['Domains'] = 0; diff --git a/src/Appwrite/Platform/Tasks/Schedule.php b/src/Appwrite/Platform/Tasks/Schedule.php index 57c9d22c4f..a136ee62b1 100644 --- a/src/Appwrite/Platform/Tasks/Schedule.php +++ b/src/Appwrite/Platform/Tasks/Schedule.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Tasks; -use Appwrite\Extend\Exception; use Cron\CronExpression; use Swoole\Timer; use Utopia\App; @@ -27,9 +26,6 @@ class Schedule extends Action return 'schedule'; } - /** - * @throws Exception - */ public function __construct() { $this diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 3ecc845a96..8fb5094a8f 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -213,6 +213,7 @@ class Certificates extends Action $certificate = new Document(\array_merge($certificateDocument->getArrayCopy(), $certificate->getArrayCopy())); $certificate = $dbForConsole->updateDocument('certificates', $certificate->getId(), $certificate); } else { + $certificate->removeAttribute('$internalId'); $certificate = $dbForConsole->createDocument('certificates', $certificate); } diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 896ad40bf9..7e43bed6bd 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -22,6 +22,7 @@ use Utopia\Database\Exception\Structure; use Utopia\Database\Query; use Utopia\Platform\Action; use Utopia\Queue\Message; +use Utopia\Storage\Device; class Deletes extends Action { @@ -100,7 +101,7 @@ class Deletes extends Action $this->deleteInstallation($dbForConsole, $getProjectDB, $document, $project); break; case DELETE_TYPE_RULES: - $this->deleteRule($dbForConsole, $document, $project); + $this->deleteRule($dbForConsole, $document); break; default: if (\str_starts_with($document->getCollection(), 'database_')) { @@ -130,7 +131,7 @@ class Deletes extends Action break; case DELETE_TYPE_REALTIME: - $this->deleteRealtimeUsage($dbForConsole, $getProjectDB, $datetime); + $this->deleteRealtimeUsage($dbForConsole, $datetime); break; case DELETE_TYPE_SESSIONS: @@ -162,7 +163,7 @@ class Deletes extends Action * @throws Authorization * @throws Throwable */ - protected function deleteSchedules(Database $dbForConsole, callable $getProjectDB, string $datetime): void + private function deleteSchedules(Database $dbForConsole, callable $getProjectDB, string $datetime): void { $this->listByGroup( 'schedules', @@ -198,7 +199,7 @@ class Deletes extends Action * @return void * @throws Authorization */ - protected function deleteCacheByResource(Document $project, callable $getProjectDB, string $resource): void + private function deleteCacheByResource(Document $project, callable $getProjectDB, string $resource): void { $projectId = $project->getId(); $dbForProject = $getProjectDB($project); @@ -234,7 +235,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteCacheByDate(Document $project, callable $getProjectDB, string $datetime): void + private function deleteCacheByDate(Document $project, callable $getProjectDB, string $datetime): void { $projectId = $project->getId(); $dbForProject = $getProjectDB($project); @@ -270,7 +271,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteDatabase(callable $getProjectDB, Document $document, Document $project): void + private function deleteDatabase(callable $getProjectDB, Document $document, Document $project): void { $databaseId = $document->getId(); $dbForProject = $getProjectDB($project); @@ -290,7 +291,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteCollection(callable $getProjectDB, Document $document, Document $project): void + private function deleteCollection(callable $getProjectDB, Document $document, Document $project): void { $collectionId = $document->getId(); $collectionInternalId = $document->getInternalId(); @@ -336,7 +337,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteUsageStats(Database $dbForConsole, callable $getProjectDB, string $hourlyUsageRetentionDatetime): void + private function deleteUsageStats(Database $dbForConsole, callable $getProjectDB, string $hourlyUsageRetentionDatetime): void { $this->deleteForProjectIds($dbForConsole, function (Document $project) use ($getProjectDB, $hourlyUsageRetentionDatetime) { $dbForProject = $getProjectDB($project); @@ -355,7 +356,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteMemberships(callable $getProjectDB, Document $document, Document $project): void + private function deleteMemberships(callable $getProjectDB, Document $document, Document $project): void { $dbForProject = $getProjectDB($project); $teamInternalId = $document->getInternalId(); @@ -384,7 +385,7 @@ class Deletes extends Action * @throws Restricted * @throws Structure */ - protected function deleteProjectsByTeam(Database $dbForConsole, callable $getProjectDB, callable $getFilesDevice, callable $getFunctionsDevice, callable $getBuildsDevice, callable $getCacheDevice, Document $document): void + private function deleteProjectsByTeam(Database $dbForConsole, callable $getProjectDB, callable $getFilesDevice, callable $getFunctionsDevice, callable $getBuildsDevice, callable $getCacheDevice, Document $document): void { $projects = $dbForConsole->find('projects', [ @@ -409,7 +410,7 @@ class Deletes extends Action * @throws Authorization * @throws \Utopia\Database\Exception */ - protected function deleteProject(Database $dbForConsole, callable $getProjectDB, callable $getFilesDevice, callable $getFunctionsDevice, callable $getBuildsDevice, callable $getCacheDevice, Document $document): void + private function deleteProject(Database $dbForConsole, callable $getProjectDB, callable $getFilesDevice, callable $getFunctionsDevice, callable $getBuildsDevice, callable $getCacheDevice, Document $document): void { $projectId = $document->getId(); $projectInternalId = $document->getInternalId(); @@ -434,10 +435,12 @@ class Deletes extends Action Query::equal('projectInternalId', [$projectInternalId]) ], $dbForConsole); - // Delete Domains - $this->deleteByGroup('domains', [ + // Delete project and function rules + $this->deleteByGroup('rules', [ Query::equal('projectInternalId', [$projectInternalId]) - ], $dbForConsole); + ], $dbForConsole, function (Document $document) use ($dbForConsole) { + $this->deleteRule($dbForConsole, $document); + }); // Delete Keys $this->deleteByGroup('keys', [ @@ -476,7 +479,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteUser(callable $getProjectDB, Document $document, Document $project): void + private function deleteUser(callable $getProjectDB, Document $document, Document $project): void { $userId = $document->getId(); $userInternalId = $document->getInternalId(); @@ -525,7 +528,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteExecutionLogs(database $dbForConsole, callable $getProjectDB, string $datetime): void + private function deleteExecutionLogs(database $dbForConsole, callable $getProjectDB, string $datetime): void { $this->deleteForProjectIds($dbForConsole, function (Document $project) use ($getProjectDB, $datetime) { $dbForProject = $getProjectDB($project); @@ -542,7 +545,7 @@ class Deletes extends Action * @return void * @throws Exception|Throwable */ - protected function deleteExpiredSessions(Database $dbForConsole, callable $getProjectDB): void + private function deleteExpiredSessions(Database $dbForConsole, callable $getProjectDB): void { $this->deleteForProjectIds($dbForConsole, function (Document $project) use ($dbForConsole, $getProjectDB) { @@ -560,20 +563,16 @@ class Deletes extends Action /** * @param Database $dbForConsole - * @param callable $getProjectDB * @param string $datetime * @return void * @throws Exception */ - protected function deleteRealtimeUsage(Database $dbForConsole, callable $getProjectDB, string $datetime): void + private function deleteRealtimeUsage(Database $dbForConsole, string $datetime): void { - $this->deleteForProjectIds($dbForConsole, function (Document $project) use ($datetime, $getProjectDB) { - $dbForProject = $getProjectDB($project); - // Delete Dead Realtime Logs - $this->deleteByGroup('realtime', [ - Query::lessThan('timestamp', $datetime) - ], $dbForProject); - }); + // Delete Dead Realtime Logs + $this->deleteByGroup('realtime', [ + Query::lessThan('timestamp', $datetime) + ], $dbForConsole); } /** @@ -583,7 +582,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteAbuseLogs(Database $dbForConsole, callable $getProjectDB, string $datetime): void + private function deleteAbuseLogs(Database $dbForConsole, callable $getProjectDB, string $datetime): void { if (empty($datetime)) { throw new Exception('Failed to delete audit logs. No datetime provided'); @@ -608,7 +607,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteAuditLogs(Database $dbForConsole, callable $getProjectDB, string $datetime): void + private function deleteAuditLogs(Database $dbForConsole, callable $getProjectDB, string $datetime): void { if (empty($datetime)) { throw new Exception('Failed to delete audit logs. No datetime provided'); @@ -632,7 +631,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteAuditLogsByResource(callable $getProjectDB, string $resource, Document $project): void + private function deleteAuditLogsByResource(callable $getProjectDB, string $resource, Document $project): void { $dbForProject = $getProjectDB($project); @@ -650,7 +649,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteFunction(Database $dbForConsole, callable $getProjectDB, callable $getFunctionsDevice, callable $getBuildsDevice, Document $document, Document $project): void + private function deleteFunction(Database $dbForConsole, callable $getProjectDB, callable $getFunctionsDevice, callable $getBuildsDevice, Document $document, Document $project): void { $projectId = $project->getId(); $dbForProject = $getProjectDB($project); @@ -666,7 +665,7 @@ class Deletes extends Action Query::equal('resourceInternalId', [$functionInternalId]), Query::equal('projectInternalId', [$project->getInternalId()]) ], $dbForConsole, function (Document $document) use ($project, $dbForConsole) { - $this->deleteRule($dbForConsole, $document, $project); + $this->deleteRule($dbForConsole, $document); }); /** @@ -688,14 +687,10 @@ class Deletes extends Action Query::equal('resourceInternalId', [$functionInternalId]) ], $dbForProject, function (Document $document) use ($storageFunctions, &$deploymentInternalIds) { $deploymentInternalIds[] = $document->getInternalId(); - if ($storageFunctions->delete($document->getAttribute('path', ''), true)) { - Console::success('Deleted deployment files: ' . $document->getAttribute('path', '')); - } else { - Console::error('Failed to delete deployment files: ' . $document->getAttribute('path', '')); - } + $this->deleteDeploymentFiles($storageFunctions, $document); }); - /** + /** * Delete builds */ Console::info("Deleting builds for function " . $functionId); @@ -704,11 +699,7 @@ class Deletes extends Action $this->deleteByGroup('builds', [ Query::equal('deploymentInternalId', [$deploymentInternalId]) ], $dbForProject, function (Document $document) use ($storageBuilds) { - if ($storageBuilds->delete($document->getAttribute('path', ''), true)) { - Console::success('Deleted build files: ' . $document->getAttribute('path', '')); - } else { - Console::error('Failed to delete build files: ' . $document->getAttribute('path', '')); - } + $this->deleteBuildFiles($storageBuilds, $document); }); } @@ -727,6 +718,68 @@ class Deletes extends Action $this->deleteRuntimes($getProjectDB, $document, $project); } + /** + * @param Device $device + * @param Document $deployment + * @return void + */ + private function deleteDeploymentFiles(Device $device, Document $deployment): void + { + $deploymentId = $deployment->getId(); + $deploymentPath = $deployment->getAttribute('path', ''); + + if (empty($deploymentPath)) { + Console::info("No deployment files for deployment " . $deploymentId); + return; + } + + Console::info("Deleting deployment files for deployment " . $deploymentId); + + try { + if ($device->delete($deploymentPath, true)) { + Console::success('Deleted deployment files: ' . $deploymentPath); + } else { + Console::error('Failed to delete deployment files: ' . $deploymentPath); + } + } catch (\Throwable $th) { + Console::error('Failed to delete deployment files: ' . $deploymentPath); + Console::error('[Error] Type: ' . get_class($th)); + Console::error('[Error] Message: ' . $th->getMessage()); + Console::error('[Error] File: ' . $th->getFile()); + Console::error('[Error] Line: ' . $th->getLine()); + } + } + + /** + * @param Device $device + * @param Document $build + * @return void + */ + private function deleteBuildFiles(Device $device, Document $build): void + { + $buildId = $build->getId(); + $buildPath = $build->getAttribute('path', ''); + + if (empty($buildPath)) { + Console::info("No build files for build " . $buildId); + return; + } + + try { + if ($device->delete($buildPath, true)) { + Console::success('Deleted build files: ' . $buildPath); + } else { + Console::error('Failed to delete build files: ' . $buildPath); + } + } catch (\Throwable $th) { + Console::error('Failed to delete deployment files: ' . $buildPath); + Console::error('[Error] Type: ' . get_class($th)); + Console::error('[Error] Message: ' . $th->getMessage()); + Console::error('[Error] File: ' . $th->getFile()); + Console::error('[Error] Line: ' . $th->getLine()); + } + } + /** * @param callable $getProjectDB * @param callable $getFunctionsDevice @@ -736,7 +789,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteDeployment(callable $getProjectDB, callable $getFunctionsDevice, callable $getBuildsDevice, Document $document, Document $project): void + private function deleteDeployment(callable $getProjectDB, callable $getFunctionsDevice, callable $getBuildsDevice, Document $document, Document $project): void { $projectId = $project->getId(); $dbForProject = $getProjectDB($project); @@ -746,30 +799,20 @@ class Deletes extends Action /** * Delete deployment files */ - Console::info("Deleting deployment files for deployment " . $deploymentId); $storageFunctions = $getFunctionsDevice($projectId); - if ($storageFunctions->delete($document->getAttribute('path', ''), true)) { - Console::success('Deleted deployment files: ' . $document->getAttribute('path', '')); - } else { - Console::error('Failed to delete deployment files: ' . $document->getAttribute('path', '')); - } + $this->deleteDeploymentFiles($storageFunctions, $document); /** * Delete builds */ Console::info("Deleting builds for deployment " . $deploymentId); - $storageBuilds = $getBuildsDevice($projectId); + $storageBuilds = $$getBuildsDevice($projectId); $this->deleteByGroup('builds', [ Query::equal('deploymentInternalId', [$deploymentInternalId]) ], $dbForProject, function (Document $document) use ($storageBuilds) { - if ($storageBuilds->delete($document->getAttribute('path', ''), true)) { - Console::success('Deleted build files: ' . $document->getAttribute('path', '')); - } else { - Console::error('Failed to delete build files: ' . $document->getAttribute('path', '')); - } + $this->deleteBuildFiles($storageBuilds, $document); }); - /** * Request executor to delete all deployment containers */ @@ -781,9 +824,9 @@ class Deletes extends Action * @param Document $document to be deleted * @param Database $database to delete it from * @param callable|null $callback to perform after document is deleted - * @return bool + * @return void */ - protected function deleteById(Document $document, Database $database, callable $callback = null): bool + private function deleteById(Document $document, Database $database, callable $callback = null): void { if ($database->deleteDocument($document->getCollection(), $document->getId())) { Console::success('Deleted document "' . $document->getId() . '" successfully'); @@ -791,11 +834,8 @@ class Deletes extends Action if (is_callable($callback)) { $callback($document); } - - return true; } else { Console::error('Failed to delete document: ' . $document->getId()); - return false; } } @@ -804,7 +844,7 @@ class Deletes extends Action * @param callable $callback * @throws Exception */ - protected function deleteForProjectIds(database $dbForConsole, callable $callback): void + private function deleteForProjectIds(database $dbForConsole, callable $callback): void { // TODO: @Meldiron name of this method no longer matches. It does not delete, and it gives whole document $count = 0; @@ -840,7 +880,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteByGroup(string $collection, array $queries, Database $database, callable $callback = null): void + private function deleteByGroup(string $collection, array $queries, Database $database, callable $callback = null): void { $count = 0; $chunk = 0; @@ -877,7 +917,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function listByGroup(string $collection, array $queries, Database $database, callable $callback = null): void + private function listByGroup(string $collection, array $queries, Database $database, callable $callback = null): void { $count = 0; $chunk = 0; @@ -910,10 +950,9 @@ class Deletes extends Action /** * @param Database $dbForConsole * @param Document $document rule document - * @param Document $project project document * @return void */ - protected function deleteRule(Database $dbForConsole, Document $document, Document $project): void + private function deleteRule(Database $dbForConsole, Document $document): void { $domain = $document->getAttribute('domain'); @@ -942,7 +981,7 @@ class Deletes extends Action * @param Document $project * @return void */ - protected function deleteBucket(callable $getProjectDB, callable $getFilesDevice, Document $document, Document $project): void + private function deleteBucket(callable $getProjectDB, callable $getFilesDevice, Document $document, Document $project): void { $projectId = $project->getId(); $dbForProject = $getProjectDB($project); @@ -962,7 +1001,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteInstallation(Database $dbForConsole, callable $getProjectDB, Document $document, Document $project): void + private function deleteInstallation(Database $dbForConsole, callable $getProjectDB, Document $document, Document $project): void { $dbForProject = $getProjectDB($project); @@ -991,7 +1030,7 @@ class Deletes extends Action * @return void * @throws Exception */ - protected function deleteRuntimes(callable $getProjectDB, ?Document $function, Document $project): void + private function deleteRuntimes(callable $getProjectDB, ?Document $function, Document $project): void { $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index d7607d626b..6b7b5efe03 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -125,7 +125,8 @@ class Functions extends Action path: '/', method: 'POST', headers: [ - 'user-agent' => 'Appwrite/' . APP_VERSION_STABLE + 'user-agent' => 'Appwrite/' . APP_VERSION_STABLE, + 'content-type' => 'application/json' ], data: null, user: $user, diff --git a/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php b/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php index 04ac00c263..91a0d089ae 100644 --- a/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php +++ b/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php @@ -263,7 +263,7 @@ class DatabasesConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'limit' => 1 + 'queries' => ['limit(1)'] ]); $this->assertEquals(200, $logs['headers']['status-code']); @@ -275,7 +275,7 @@ class DatabasesConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'offset' => 1 + 'queries' => ['offset(1)'] ]); $this->assertEquals(200, $logs['headers']['status-code']); @@ -286,8 +286,7 @@ class DatabasesConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'offset' => 1, - 'limit' => 1 + 'queries' => ['offset(1)', 'limit(1)'] ]); $this->assertEquals(200, $logs['headers']['status-code']);