From 400b28de8a7b2298ff645558df2aee8a412a598c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 21 Feb 2024 03:25:01 +1300 Subject: [PATCH] Replace resourceCollection with switch --- app/config/collections.php | 11 ----------- app/controllers/api/functions.php | 1 - app/controllers/api/messaging.php | 6 ------ src/Appwrite/Platform/Tasks/ScheduleBase.php | 14 ++++++++++++-- src/Appwrite/Platform/Workers/Deletes.php | 7 ++++++- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index e8a24c910..a8965c011 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -4362,17 +4362,6 @@ $consoleCollections = array_merge([ 'array' => false, 'filters' => [], ], - [ - '$id' => ID::custom('resourceCollection'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => Database::LENGTH_KEY, - 'signed' => true, - 'required' => true, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => ID::custom('resourceInternalId'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 42e95e27a..84ae975a0 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -233,7 +233,6 @@ App::post('/v1/functions') fn () => $dbForConsole->createDocument('schedules', new Document([ 'region' => App::getEnv('_APP_REGION', 'default'), // Todo replace with projects region 'resourceType' => 'function', - 'resourceCollection' => 'functions', 'resourceId' => $function->getId(), 'resourceInternalId' => $function->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index d8af44f7f..22d9e12bf 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2642,7 +2642,6 @@ App::post('/v1/messaging/messages/email') $schedule = $dbForConsole->createDocument('schedules', new Document([ 'region' => App::getEnv('_APP_REGION', 'default'), 'resourceType' => 'message', - 'resourceCollection' => 'messages', 'resourceId' => $message->getId(), 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), @@ -2751,7 +2750,6 @@ App::post('/v1/messaging/messages/sms') $schedule = $dbForConsole->createDocument('schedules', new Document([ 'region' => App::getEnv('_APP_REGION', 'default'), 'resourceType' => 'message', - 'resourceCollection' => 'messages', 'resourceId' => $message->getId(), 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), @@ -2877,7 +2875,6 @@ App::post('/v1/messaging/messages/push') $schedule = $dbForConsole->createDocument('schedules', new Document([ 'region' => App::getEnv('_APP_REGION', 'default'), 'resourceType' => 'message', - 'resourceCollection' => 'messages', 'resourceId' => $message->getId(), 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), @@ -3231,7 +3228,6 @@ App::patch('/v1/messaging/messages/email/:messageId') $schedule = $dbForConsole->createDocument('schedules', new Document([ 'region' => App::getEnv('_APP_REGION', 'default'), 'resourceType' => 'message', - 'resourceCollection' => 'messages', 'resourceId' => $message->getId(), 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), @@ -3350,7 +3346,6 @@ App::patch('/v1/messaging/messages/sms/:messageId') $schedule = $dbForConsole->createDocument('schedules', new Document([ 'region' => App::getEnv('_APP_REGION', 'default'), 'resourceType' => 'message', - 'resourceCollection' => 'messages', 'resourceId' => $message->getId(), 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), @@ -3509,7 +3504,6 @@ App::patch('/v1/messaging/messages/push/:messageId') $schedule = $dbForConsole->createDocument('schedules', new Document([ 'region' => App::getEnv('_APP_REGION', 'default'), 'resourceType' => 'message', - 'resourceCollection' => 'messages', 'resourceId' => $message->getId(), 'resourceInternalId' => $message->getInternalId(), 'resourceUpdatedAt' => DateTime::now(), diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index f0aa559a7..fbb2320a3 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -64,8 +64,13 @@ abstract class ScheduleBase extends Action $getSchedule = function (Document $schedule) use ($dbForConsole, $getProjectDB): array { $project = $dbForConsole->getDocument('projects', $schedule->getAttribute('projectId')); + $collectionId = match ($schedule->getAttribute('resourceType')) { + 'function' => 'functions', + 'message' => 'messages' + }; + $resource = $getProjectDB($project)->getDocument( - $schedule->getAttribute('resourceCollection'), + $collectionId, $schedule->getAttribute('resourceId') ); @@ -108,7 +113,12 @@ abstract class ScheduleBase extends Action try { $this->schedules[$document['resourceId']] = $getSchedule($document); } catch (\Throwable $th) { - Console::error("Failed to load schedule for project {$document['projectId']} {$document['resourceCollection']} {$document['resourceId']}"); + $collectionId = match ($document->getAttribute('resourceType')) { + 'function' => 'functions', + 'message' => 'messages' + }; + + Console::error("Failed to load schedule for project {$document['projectId']} {$collectionId} {$document['resourceId']}"); Console::error($th->getMessage()); } } diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 473bdc6de..ea967c0da 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -203,8 +203,13 @@ class Deletes extends Action return; } + $collectionId = match ($document->getAttribute('resourceType')) { + 'function' => 'functions', + 'message' => 'messages' + }; + $resource = $getProjectDB($project)->getDocument( - $document->getAttribute('resourceCollection'), + $collectionId, $document->getAttribute('resourceId') );