mirror of
https://github.com/appwrite/appwrite
synced 2026-05-17 05:58:31 +00:00
Merge pull request #9722 from appwrite/events-compatibility
Events compat based on version
This commit is contained in:
commit
026150971f
3 changed files with 19 additions and 11 deletions
|
|
@ -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,18 +303,24 @@ 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 - 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 - Collections API
|
||||
$channels[] = 'documents';
|
||||
$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())
|
||||
: $table->getRead();
|
||||
|
|
|
|||
|
|
@ -769,7 +769,7 @@ class RealtimeCustomClientTest extends Scope
|
|||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(3, $response['data']['channels']);
|
||||
$this->assertCount(6, $response['data']['channels']); // includes old and new channels
|
||||
$this->assertContains('rows', $response['data']['channels']);
|
||||
$this->assertContains('databases.' . $databaseId . '.tables.' . $actorsId . '.rows.' . $documentId, $response['data']['channels']);
|
||||
$this->assertContains('databases.' . $databaseId . '.tables.' . $actorsId . '.rows', $response['data']['channels']);
|
||||
|
|
@ -813,7 +813,7 @@ class RealtimeCustomClientTest extends Scope
|
|||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(3, $response['data']['channels']);
|
||||
$this->assertCount(6, $response['data']['channels']); // includes old and new channels
|
||||
$this->assertContains('rows', $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows.{$documentId}", $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows", $response['data']['channels']);
|
||||
|
|
@ -867,7 +867,7 @@ class RealtimeCustomClientTest extends Scope
|
|||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(3, $response['data']['channels']);
|
||||
$this->assertCount(6, $response['data']['channels']); // includes old and new channels
|
||||
$this->assertContains('rows', $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows.{$documentId}", $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows", $response['data']['channels']);
|
||||
|
|
@ -987,7 +987,7 @@ class RealtimeCustomClientTest extends Scope
|
|||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(3, $response['data']['channels']);
|
||||
$this->assertCount(6, $response['data']['channels']); // includes old and new channels
|
||||
$this->assertContains('rows', $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows.{$documentId}", $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows", $response['data']['channels']);
|
||||
|
|
@ -1026,7 +1026,7 @@ class RealtimeCustomClientTest extends Scope
|
|||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(3, $response['data']['channels']);
|
||||
$this->assertCount(6, $response['data']['channels']); // includes old and new channels
|
||||
$this->assertContains('rows', $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows.{$documentId}", $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows", $response['data']['channels']);
|
||||
|
|
@ -1076,7 +1076,7 @@ class RealtimeCustomClientTest extends Scope
|
|||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(3, $response['data']['channels']);
|
||||
$this->assertCount(6, $response['data']['channels']); // includes old and new channels
|
||||
$this->assertContains('rows', $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows.{$documentId}", $response['data']['channels']);
|
||||
$this->assertContains("databases.{$databaseId}.tables.{$actorsId}.rows", $response['data']['channels']);
|
||||
|
|
|
|||
Loading…
Reference in a new issue