Replace resourceCollection with switch

This commit is contained in:
Jake Barnby
2024-02-21 03:25:01 +13:00
parent b9b54b808c
commit 400b28de8a
5 changed files with 18 additions and 21 deletions
+12 -2
View File
@@ -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());
}
}
+6 -1
View File
@@ -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')
);