diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index cf6fc435ef..a2971ea4c9 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -85,6 +85,7 @@ App::post('/v1/functions') 'deployment' => '', 'events' => $events, 'schedule' => $schedule, + 'scheduleInternalId' => '', 'timeout' => $timeout, 'search' => implode(' ', [$functionId, $name, $runtime]) ])); @@ -420,12 +421,10 @@ App::put('/v1/functions/:functionId') ]))); $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); - $schedule ->setAttribute('resourceUpdatedAt', DateTime::now()) ->setAttribute('schedule', $function->getAttribute('schedule')) ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); - Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); $eventsInstance->setParam('functionId', $function->getId()); @@ -478,7 +477,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId') $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deploymentInternalId' => $deployment->getInternalId(), - 'deployment' => $deployment->getId() + 'deployment' => $deployment->getId(), ]))); $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); @@ -528,12 +527,9 @@ App::delete('/v1/functions/:functionId') } $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); - $schedule ->setAttribute('resourceUpdatedAt', DateTime::now()) - ->setAttribute('active', false) - ; - + ->setAttribute('active', false); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); $deletes @@ -1355,6 +1351,13 @@ App::post('/v1/functions/:functionId/variables') $dbForProject->deleteCachedDocument('functions', $function->getId()); + $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); + $schedule + ->setAttribute('resourceUpdatedAt', DateTime::now()) + ->setAttribute('schedule', $function->getAttribute('schedule')) + ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); + Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); + $response ->setStatusCode(Response::STATUS_CODE_CREATED) ->dynamic($variable, Response::MODEL_VARIABLE); @@ -1479,6 +1482,13 @@ App::put('/v1/functions/:functionId/variables/:variableId') $dbForProject->deleteCachedDocument('functions', $function->getId()); + $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); + $schedule + ->setAttribute('resourceUpdatedAt', DateTime::now()) + ->setAttribute('schedule', $function->getAttribute('schedule')) + ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); + Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); + $response->dynamic($variable, Response::MODEL_VARIABLE); }); @@ -1526,5 +1536,12 @@ App::delete('/v1/functions/:functionId/variables/:variableId') $dbForProject->deleteCachedDocument('functions', $function->getId()); + $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); + $schedule + ->setAttribute('resourceUpdatedAt', DateTime::now()) + ->setAttribute('schedule', $function->getAttribute('schedule')) + ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); + Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); + $response->noContent(); }); diff --git a/app/workers/functions.php b/app/workers/functions.php index 98151bbc87..851defb5ca 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -93,7 +93,7 @@ Server::setResource('execute', function () { 'response' => '', 'stderr' => '', 'duration' => 0.0, - 'search' => implode(' ', [$functionId, $executionId]), + 'search' => implode(' ', [$function->getId(), $executionId]), ])); // TODO: @Meldiron Trigger executions.create event here diff --git a/src/Appwrite/Migration/Version/V17.php b/src/Appwrite/Migration/Version/V17.php index f50087d2b8..59c57ff794 100644 --- a/src/Appwrite/Migration/Version/V17.php +++ b/src/Appwrite/Migration/Version/V17.php @@ -156,6 +156,16 @@ class V17 extends Migration } catch (\Throwable $th) { Console::warning("'scheduleInternalId' from {$id}: {$th->getMessage()}"); } + + try { + /** + * Delete 'scheduleUpdatedAt' attribute + */ + $this->projectDB->deleteAttribute($id, 'scheduleUpdatedAt'); + $this->projectDB->deleteCachedCollection($id); + } catch (\Throwable $th) { + Console::warning("'scheduleUpdatedAt' from {$id}: {$th->getMessage()}"); + } break; case 'deployments':