mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 16:38:32 +00:00
manage: events and channels.
This commit is contained in:
parent
9a45a0fc7b
commit
ee117b816a
3 changed files with 14 additions and 28 deletions
|
|
@ -483,26 +483,10 @@ App::init()
|
|||
/*
|
||||
* Background Jobs
|
||||
*/
|
||||
$events = $route->getLabel('event', '');
|
||||
$queueForEvents
|
||||
->setUser($user)
|
||||
->setEvent($events)
|
||||
->setProject($project);
|
||||
|
||||
if (str_contains($events, '.tables.')) {
|
||||
$requestFormat = $request->getHeader('x-appwrite-response-format', System::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', ''));
|
||||
if ($requestFormat && version_compare($requestFormat, '1.7.0', '<')) {
|
||||
$map = [
|
||||
'rows' => 'documents',
|
||||
'tables' => 'collections',
|
||||
'columns' => 'attributes',
|
||||
];
|
||||
|
||||
$compatibleEvents = str_replace(array_keys($map), array_values($map), $events);
|
||||
// override the events
|
||||
$queueForEvents->setEvent($compatibleEvents);
|
||||
}
|
||||
}
|
||||
->setEvent($route->getLabel('event', ''))
|
||||
->setProject($project)
|
||||
->setUser($user);
|
||||
|
||||
$queueForAudits
|
||||
->setMode($mode)
|
||||
|
|
|
|||
|
|
@ -76,16 +76,18 @@ class Realtime extends Event
|
|||
$payload = new Document($this->getPayload());
|
||||
|
||||
$db = $this->getContext('database');
|
||||
$table = $this->getContext('table');
|
||||
$bucket = $this->getContext('bucket');
|
||||
|
||||
// can be Tables API or Collections API, generated channels include both!
|
||||
$tableOrCollection = $this->getContext('table') ?? $this->getContext('collection');
|
||||
|
||||
$target = RealtimeAdapter::fromPayload(
|
||||
// Pass first, most verbose event pattern
|
||||
event: $allEvents[0],
|
||||
payload: $payload,
|
||||
project: $this->getProject(),
|
||||
database: $db,
|
||||
table: $table,
|
||||
table: $tableOrCollection,
|
||||
bucket: $bucket,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -303,23 +303,23 @@ class Realtime extends Adapter
|
|||
$channels[] = 'projects.' . $project->getId();
|
||||
$projectId = 'console';
|
||||
$roles = [Role::team($project->getAttribute('teamId'))->toString()];
|
||||
} elseif (($parts[4] ?? '') === 'rows') {
|
||||
} elseif (($parts[4] ?? '') === 'rows' || ($parts[4] ?? '') === 'documents') {
|
||||
if ($database->isEmpty()) {
|
||||
throw new \Exception('Database needs to be passed to Realtime for Row events in the Database.');
|
||||
throw new \Exception('Database needs to be passed to Realtime for Document/Row events in the Database.');
|
||||
}
|
||||
if ($table->isEmpty()) {
|
||||
throw new \Exception('Table needs to be passed to Realtime for Row events in the Database.');
|
||||
throw new \Exception('Collection or the Table needs to be passed to Realtime for Document/Row events in the Database.');
|
||||
}
|
||||
|
||||
// 1.7.x
|
||||
// 1.7.x - Tables API
|
||||
$channels[] = 'rows';
|
||||
$channels[] = 'databases.' . $database->getId() . '.tables.' . $payload->getAttribute('$tableId') . '.rows';
|
||||
$channels[] = 'databases.' . $database->getId() . '.tables.' . $payload->getAttribute('$tableId') . '.rows.' . $payload->getId();
|
||||
|
||||
// 1.6.x
|
||||
// 1.6.x - Collections API
|
||||
$channels[] = 'documents';
|
||||
$channels[] = 'databases.' . $database->getId() . '.collections.' . $payload->getAttribute('$tableId') . '.documents';
|
||||
$channels[] = 'databases.' . $database->getId() . '.collections.' . $payload->getAttribute('$tableId') . '.documents.' . $payload->getId();
|
||||
$channels[] = 'databases.' . $database->getId() . '.collections.' . $payload->getAttribute('$collectionId') . '.documents';
|
||||
$channels[] = 'databases.' . $database->getId() . '.collections.' . $payload->getAttribute('$collectionId') . '.documents.' . $payload->getId();
|
||||
|
||||
$roles = $table->getAttribute('documentSecurity', false)
|
||||
? \array_merge($table->getRead(), $payload->getRead())
|
||||
|
|
|
|||
Loading…
Reference in a new issue