From 1e95346205177967e78439eadd9ab39f183b81ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 30 Aug 2022 12:30:52 +0000 Subject: [PATCH] PR review changes --- app/controllers/api/functions.php | 24 ++++++++++-------------- app/workers/builds.php | 9 ++++----- app/workers/functions.php | 11 ++++------- composer.lock | 8 ++++---- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 6f82823c72..2f81b63f68 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -85,8 +85,7 @@ App::post('/v1/functions') 'schedulePrevious' => null, 'scheduleNext' => null, 'timeout' => $timeout, - 'search' => implode(' ', [$functionId, $name, $runtime]), - 'vars' => null + 'search' => implode(' ', [$functionId, $name, $runtime]) ])); $eventsInstance->setParam('functionId', $function->getId()); @@ -1048,13 +1047,10 @@ App::post('/v1/functions/:functionId/executions') return $response->dynamic($execution, Response::MODEL_EXECUTION); } - $vars = []; - - $variables = $function['vars']; - - foreach ($variables as $variable) { - $vars[$variable['key']] = $variable['value']; - } + $vars = array_reduce($function['vars'] ?? [], function (array $carry, Document $var) { + $carry[$var->getAttribute('key')] = $var->getAttribute('value'); + return $carry; + }, []); $vars = \array_merge($vars, [ 'APPWRITE_FUNCTION_ID' => $function->getId(), @@ -1380,8 +1376,8 @@ App::get('/v1/functions/:functionId/variables') } // Get cursor document if there was a cursor query - $cursor = Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE)[0] ?? null; - if ($cursor !== null) { + $cursor = reset(Query::getByType($queries, Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE)); + if ($cursor) { /** @var Query $cursor */ $variableId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('variables', $variableId); @@ -1424,7 +1420,7 @@ App::get('/v1/functions/:functionId/variables/:variableId') } $variable = $dbForProject->findOne('variables', [ - Query::equal('_uid', [$variableId]), + Query::equal('$id', [$variableId]), Query::equal('functionInternalId', [$function->getInternalId()]), ]); @@ -1464,7 +1460,7 @@ App::put('/v1/functions/:functionId/variables/:variableId') } $variable = $dbForProject->findOne('variables', [ - Query::equal('_uid', [$variableId]), + Query::equal('$id', [$variableId]), Query::equal('functionInternalId', [$function->getInternalId()]), ]); @@ -1511,7 +1507,7 @@ App::delete('/v1/functions/:functionId/variables/:variableId') } $variable = $dbForProject->findOne('variables', [ - Query::equal('_uid', [$variableId]), + Query::equal('$id', [$variableId]), Query::equal('functionInternalId', [$function->getInternalId()]), ]); diff --git a/app/workers/builds.php b/app/workers/builds.php index 520cd47b0a..c8bfa7fb83 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -145,12 +145,11 @@ class BuildsV1 extends Worker ); $source = $deployment->getAttribute('path'); - $vars = []; - $variables = $function['vars']; - foreach ($variables as $variable) { - $vars[$variable['key']] = $variable['value']; - } + $vars = array_reduce($function['vars'] ?? [], function (array $carry, Document $var) { + $carry[$var->getAttribute('key')] = $var->getAttribute('value'); + return $carry; + }, []); $baseImage = $runtime['image']; diff --git a/app/workers/functions.php b/app/workers/functions.php index c30b0942ef..bcc8cb8dd3 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -259,13 +259,10 @@ class FunctionsV1 extends Worker $execution->setAttribute('status', 'processing'); $execution = $dbForProject->updateDocument('executions', $executionId, $execution); - $vars = []; - - $variables = $function['vars']; - - foreach ($variables as $variable) { - $vars[$variable['key']] = $variable['value']; - } + $vars = array_reduce($function['vars'] ?? [], function (array $carry, Document $var) { + $carry[$var->getAttribute('key')] = $var->getAttribute('value'); + return $carry; + }, []); /** Collect environment variables */ $vars = \array_merge($vars, [ diff --git a/composer.lock b/composer.lock index d2f881d7cc..ebecc59afb 100644 --- a/composer.lock +++ b/composer.lock @@ -2841,12 +2841,12 @@ "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "bf05fc00755b9d27dac530669ca834f3ceb655ec" + "reference": "6e630a62f522ac68a7056bebf81cd032c7a053ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/bf05fc00755b9d27dac530669ca834f3ceb655ec", - "reference": "bf05fc00755b9d27dac530669ca834f3ceb655ec", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6e630a62f522ac68a7056bebf81cd032c7a053ba", + "reference": "6e630a62f522ac68a7056bebf81cd032c7a053ba", "shasum": "" }, "require": { @@ -2884,7 +2884,7 @@ "issues": "https://github.com/appwrite/sdk-generator/issues", "source": "https://github.com/appwrite/sdk-generator/tree/master" }, - "time": "2022-08-28T04:14:32+00:00" + "time": "2022-08-29T10:43:33+00:00" }, { "name": "doctrine/instantiator",