Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,16 @@ public function getGlobalCollections(): array
return \array_keys($this->globalCollections);
}

/**
* Clear global collections
*
* @return void
*/
public function resetGlobalCollections(): void
{
$this->globalCollections = [];
}

/**
* Get list of keywords that cannot be used
*
Expand Down
54 changes: 54 additions & 0 deletions tests/e2e/Adapter/Scopes/CollectionTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1439,4 +1439,58 @@ public function testTransformations(): void

$this->assertTrue($result->isEmpty());
}

public function testSetGlobalCollection(): void
{
$db = static::getDatabase();

$collectionId = 'globalCollection';

// set collection as global
$db->setGlobalCollections([$collectionId]);

// metadata collection should not contain tenant in the cache key
[$collectionKey, $documentKey, $hashKey] = $db->getCacheKeys(
Database::METADATA,
$collectionId,
[]
);

$this->assertNotEmpty($collectionKey);
$this->assertNotEmpty($documentKey);
$this->assertNotEmpty($hashKey);

if ($db->getSharedTables()) {
$this->assertStringNotContainsString((string)$db->getAdapter()->getTenant(), $collectionKey);
}

// non global collection should containt tenant in the cache key
$nonGlobalCollectionId = 'nonGlobalCollection';
[$collectionKeyRegular] = $db->getCacheKeys(
Database::METADATA,
$nonGlobalCollectionId
);
if ($db->getSharedTables()) {
$this->assertStringContainsString((string)$db->getAdapter()->getTenant(), $collectionKeyRegular);
}

// Non metadata collection should contain tenant in the cache key
[$collectionKey, $documentKey, $hashKey] = $db->getCacheKeys(
$collectionId,
ID::unique(),
[]
);

$this->assertNotEmpty($collectionKey);
$this->assertNotEmpty($documentKey);
$this->assertNotEmpty($hashKey);

if ($db->getSharedTables()) {
$this->assertStringContainsString((string)$db->getAdapter()->getTenant(), $collectionKey);
}

$db->resetGlobalCollections();
$this->assertEmpty($db->getGlobalCollections());

}
}
Loading