1
0
Fork 0
mirror of synced 2024-05-21 05:02:37 +12:00

Set default tag

This commit is contained in:
Eldad Fux 2020-07-15 22:09:33 +03:00
parent abb7c04994
commit 1f46f0ef77

View file

@ -166,17 +166,22 @@ App::patch('/v1/functions/:functionId/tag')
->param('tag', '', function () { return new UID(); }, 'Tag unique ID.')
->action(function ($functionId, $tag, $response, $projectDB) {
$function = $projectDB->getDocument($functionId);
$tag = $projectDB->getDocument($tag);
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
throw new Exception('Function not found', 404);
}
if (empty($tag->getId()) || Database::SYSTEM_COLLECTION_TAGS != $tag->getCollection()) {
throw new Exception('Tag not found', 404);
}
$schedule = $function->getAttribute('schedule', '');
$cron = (!empty($function->getAttribute('tag')&& !empty($schedule))) ? CronExpression::factory($schedule) : null;
$next = (!empty($function->getAttribute('tag')&& !empty($schedule))) ? $cron->getNextRunDate()->format('U') : null;
$function = $projectDB->updateDocument(array_merge($function->getArrayCopy(), [
'tag' => $tag,
'tag' => $tag->getId(),
'next' => $next,
]));