diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ff8b7d5bc9..0f009aa404 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -321,6 +321,7 @@ App::put('/v1/functions/:functionId') if ($next && $schedule !== $original) { ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ 'projectId' => $project->getId(), + 'webhooks' => $project->getAttribute('webhooks', []), 'functionId' => $function->getId(), 'executionId' => null, 'trigger' => 'schedule', @@ -375,6 +376,7 @@ App::patch('/v1/functions/:functionId/tag') if ($next) { // Init first schedule ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ 'projectId' => $project->getId(), + 'webhooks' => $project->getAttribute('webhooks', []), 'functionId' => $function->getId(), 'executionId' => null, 'trigger' => 'schedule', @@ -766,6 +768,7 @@ App::post('/v1/functions/:functionId/executions') Resque::enqueue('v1-functions', 'FunctionsV1', [ 'projectId' => $project->getId(), + 'webhooks' => $project->getAttribute('webhooks', []), 'functionId' => $function->getId(), 'executionId' => $execution->getId(), 'trigger' => 'http', diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 8b3971079d..a6c2b4173d 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -76,6 +76,7 @@ App::init(function ($utopia, $request, $response, $project, $user, $register, $e */ $events ->setParam('projectId', $project->getId()) + ->setParam('webhooks', $project->getAttribute('webhooks', [])) ->setParam('userId', $user->getId()) ->setParam('event', $route->getLabel('event', '')) ->setParam('eventData', []) diff --git a/app/tasks/sdks.php b/app/tasks/sdks.php index 1d7a87307b..501de50211 100644 --- a/app/tasks/sdks.php +++ b/app/tasks/sdks.php @@ -21,20 +21,6 @@ use Appwrite\SDK\Language\Swift; $cli ->task('sdks') ->action(function () { - function getSSLPage($url) - { - $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_HEADER, false); - \curl_setopt($ch, CURLOPT_URL, $url); - \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - \curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $result = \curl_exec($ch); - \curl_close($ch); - - return $result; - } - $platforms = Config::getParam('platforms'); $selected = \strtolower(Console::confirm('Choose SDK ("*" for all):')); $version = Console::confirm('Choose an Appwrite version'); diff --git a/app/workers/functions.php b/app/workers/functions.php index 7ea356464e..8bf719e607 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -141,6 +141,7 @@ class FunctionsV1 $projectId = $this->args['projectId'] ?? ''; $functionId = $this->args['functionId'] ?? ''; + $webhooks = $this->args['webhooks'] ?? []; $executionId = $this->args['executionId'] ?? ''; $trigger = $this->args['trigger'] ?? ''; $event = $this->args['event'] ?? ''; @@ -196,7 +197,7 @@ class FunctionsV1 Console::success('Triggered function: '.$event); - $this->execute('event', $projectId, '', $database, $function, $event, $eventData, $data, $userId, $jwt); + $this->execute('event', $projectId, '', $database, $function, $event, $eventData, $data, $webhooks, $userId, $jwt); } } break; @@ -246,13 +247,14 @@ class FunctionsV1 ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ 'projectId' => $projectId, + 'webhooks' => $webhooks, 'functionId' => $function->getId(), 'executionId' => null, 'trigger' => 'schedule', 'scheduleOriginal' => $function->getAttribute('schedule', ''), ]); // Async task rescheduale - $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $userId, $jwt); + $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $webhooks, $userId, $jwt); break; case 'http': @@ -264,7 +266,7 @@ class FunctionsV1 throw new Exception('Function not found ('.$functionId.')'); } - $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $userId, $jwt); + $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $webhooks, $userId, $jwt); break; default: @@ -284,10 +286,13 @@ class FunctionsV1 * @param string $event * @param string $eventData * @param string $data + * @param array $webhooks + * @param string $userId + * @param string $jwt * * @return void */ - public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $eventData = '', string $data = '', string $userId = '', string $jwt = ''): void + public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $eventData = '', string $data = '', array $webhooks = [], string $userId = '', string $jwt = ''): void { global $list; @@ -479,6 +484,7 @@ class FunctionsV1 $executionUpdate ->setParam('projectId', $projectId) ->setParam('userId', $userId) + ->setParam('webhooks', $webhooks) ->setParam('event', 'functions.executions.update') ->setParam('eventData', [ '$id' => $execution['$id'], diff --git a/app/workers/mails.php b/app/workers/mails.php index 6f4422b57f..11f41e4446 100644 --- a/app/workers/mails.php +++ b/app/workers/mails.php @@ -29,7 +29,6 @@ class MailsV1 return; } - $event = $this->args['event']; $from = $this->args['from']; $recipient = $this->args['recipient']; $name = $this->args['name']; diff --git a/app/workers/webhooks.php b/app/workers/webhooks.php index 75cc54bf57..6acc38f646 100644 --- a/app/workers/webhooks.php +++ b/app/workers/webhooks.php @@ -2,11 +2,6 @@ use Utopia\App; use Utopia\CLI\Console; -use Utopia\Config\Config; -use Appwrite\Database\Database; -use Appwrite\Database\Adapter\MySQL as MySQLAdapter; -use Appwrite\Database\Adapter\Redis as RedisAdapter; -use Appwrite\Database\Validator\Authorization; require_once __DIR__.'/../init.php'; @@ -24,34 +19,16 @@ class WebhooksV1 public function perform() { - global $register; - - $consoleDB = new Database(); - $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); - $consoleDB->setNamespace('app_console'); // Main DB - $consoleDB->setMocks(Config::getParam('collections', [])); - $errors = []; // Event $projectId = $this->args['projectId'] ?? ''; + $webhooks = $this->args['webhooks'] ?? []; $userId = $this->args['userId'] ?? ''; $event = $this->args['event'] ?? ''; $eventData = \json_encode($this->args['eventData']); - // Webhook - - Authorization::disable(); - - $project = $consoleDB->getDocument($projectId); - - Authorization::reset(); - - if (\is_null($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) { - throw new Exception('Project Not Found'); - } - - foreach ($project->getAttribute('webhooks', []) as $webhook) { + foreach ($webhooks as $webhook) { if (!(isset($webhook['events']) && \is_array($webhook['events']) && \in_array($event, $webhook['events']))) { continue; }