mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
add functionsEvents and webhooksEvents
This commit is contained in:
parent
834c18f9fa
commit
6c1f967509
3 changed files with 74 additions and 4 deletions
|
|
@ -276,6 +276,28 @@ return [
|
|||
'array' => false,
|
||||
'filters' => ['subQueryWebhooks'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('webhookEvents'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => [],
|
||||
'array' => true,
|
||||
'filters' => ['subQueryWebhookEvents'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('functionEvents'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => [],
|
||||
'array' => true,
|
||||
'filters' => ['subQueryFunctionEvents'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('keys'),
|
||||
'type' => Database::VAR_STRING,
|
||||
|
|
|
|||
|
|
@ -170,6 +170,44 @@ Database::addFilter(
|
|||
}
|
||||
);
|
||||
|
||||
Database::addFilter(
|
||||
'subQueryWebhookEvents',
|
||||
function (mixed $value) {
|
||||
return;
|
||||
},
|
||||
function (mixed $value, Document $document, Database $database) {
|
||||
$webhooks = $database
|
||||
->find('webhooks', [
|
||||
Query::equal('projectInternalId', [$document->getSequence()]),
|
||||
Query::limit(APP_LIMIT_SUBQUERY),
|
||||
]);
|
||||
|
||||
$events = [];
|
||||
foreach ($webhooks as $webhook) {
|
||||
$webhookEvents = $webhook->getAttribute('events', []);
|
||||
if (!empty($webhookEvents)) {
|
||||
$events = array_merge($events, $webhookEvents);
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($events);
|
||||
}
|
||||
);
|
||||
|
||||
Database::addFilter(
|
||||
'subQueryFunctionEvents',
|
||||
function (mixed $value) {
|
||||
return;
|
||||
},
|
||||
function (mixed $value, Document $document, Database $database) {
|
||||
// Functions are stored in the project database, not platform database
|
||||
// This filter will return empty array when called from platform DB
|
||||
// Function events will need to be computed separately when dbForProject is available
|
||||
// For now, return empty to avoid errors
|
||||
return [];
|
||||
}
|
||||
);
|
||||
|
||||
Database::addFilter(
|
||||
'subQuerySessions',
|
||||
function (mixed $value) {
|
||||
|
|
|
|||
|
|
@ -378,11 +378,21 @@ abstract class Action extends DatabasesAction
|
|||
->from($queueForEvents)
|
||||
->trigger();
|
||||
|
||||
$queueForFunctions
|
||||
->from($queueForEvents)
|
||||
->trigger();
|
||||
$project = $queueForEvents->getProject();
|
||||
$generatedEvents = Event::generateEvents(
|
||||
$queueForEvents->getEvent(),
|
||||
$queueForEvents->getParams()
|
||||
);
|
||||
|
||||
if (!empty($queueForEvents->getProject()?->getAttribute('webhooks', []))) {
|
||||
$functionEvents = $project?->getAttribute('functionEvents', []);
|
||||
if (!empty($functionEvents) && !empty(array_intersect($functionEvents, $generatedEvents))) {
|
||||
$queueForFunctions
|
||||
->from($queueForEvents)
|
||||
->trigger();
|
||||
}
|
||||
|
||||
$webhookEvents = $project?->getAttribute('webhookEvents', []);
|
||||
if (!empty($webhookEvents) && !empty(array_intersect($webhookEvents, $generatedEvents))) {
|
||||
$queueForWebhooks
|
||||
->from($queueForEvents)
|
||||
->trigger();
|
||||
|
|
|
|||
Loading…
Reference in a new issue