Skip to content

Commit 1c768ad

Browse files
authored
Merge pull request #835 from utopia-php/fix-mongo-perms
2 parents 503f13d + d9ef23f commit 1c768ad

5 files changed

Lines changed: 32 additions & 20 deletions

File tree

src/Database/Adapter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class Adapter
2323

2424
protected bool $sharedTables = false;
2525

26-
protected ?int $tenant = null;
26+
protected int|string|null $tenant = null;
2727

2828
protected bool $tenantPerDocument = false;
2929

@@ -219,11 +219,11 @@ public function getSharedTables(): bool
219219
*
220220
* Set tenant to use if tables are shared
221221
*
222-
* @param ?int $tenant
222+
* @param int|string|null $tenant
223223
*
224224
* @return bool
225225
*/
226-
public function setTenant(?int $tenant): bool
226+
public function setTenant(int|string|null $tenant): bool
227227
{
228228
$this->tenant = $tenant;
229229

@@ -235,9 +235,9 @@ public function setTenant(?int $tenant): bool
235235
*
236236
* Get tenant to use for shared tables
237237
*
238-
* @return ?int
238+
* @return int|string|null
239239
*/
240-
public function getTenant(): ?int
240+
public function getTenant(): int|string|null
241241
{
242242
return $this->tenant;
243243
}

src/Database/Adapter/Mongo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3601,13 +3601,13 @@ public function getSchemaAttributes(string $collection): array
36013601

36023602
/**
36033603
* @param string $collection
3604-
* @param array<int> $tenants
3605-
* @return int|null|array<string, array<int>>
3604+
* @param array<int|string> $tenants
3605+
* @return int|string|null|array<string, array<int|string|null>>
36063606
*/
36073607
public function getTenantFilters(
36083608
string $collection,
36093609
array $tenants = [],
3610-
): int|null|array {
3610+
): int|string|null|array {
36113611
$values = [];
36123612
if (!$this->sharedTables) {
36133613
return $values;

src/Database/Database.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,18 @@ public function getNamespace(): string
920920
return $this->adapter->getNamespace();
921921
}
922922

923+
/**
924+
* Get ID Attribute Type.
925+
*
926+
* Returns the type of the internal ID attribute (e.g. VAR_INTEGER for SQL, VAR_UUID7 for MongoDB)
927+
*
928+
* @return string
929+
*/
930+
public function getIdAttributeType(): string
931+
{
932+
return $this->adapter->getIdAttributeType();
933+
}
934+
923935
/**
924936
* Set database to use for current scope
925937
*
@@ -1224,10 +1236,10 @@ public function setSharedTables(bool $sharedTables): static
12241236
*
12251237
* Set tenant to use if tables are shared
12261238
*
1227-
* @param ?int $tenant
1239+
* @param int|string|null $tenant
12281240
* @return static
12291241
*/
1230-
public function setTenant(?int $tenant): static
1242+
public function setTenant(int|string|null $tenant): static
12311243
{
12321244
$this->adapter->setTenant($tenant);
12331245

@@ -1239,9 +1251,9 @@ public function setTenant(?int $tenant): static
12391251
*
12401252
* Get tenant to use if tables are shared
12411253
*
1242-
* @return ?int
1254+
* @return int|string|null
12431255
*/
1244-
public function getTenant(): ?int
1256+
public function getTenant(): int|string|null
12451257
{
12461258
return $this->adapter->getTenant();
12471259
}
@@ -1251,11 +1263,11 @@ public function getTenant(): ?int
12511263
*
12521264
* Execute a callback with a specific tenant
12531265
*
1254-
* @param int|null $tenant
1266+
* @param int|string|null $tenant
12551267
* @param callable $callback
12561268
* @return mixed
12571269
*/
1258-
public function withTenant(?int $tenant, callable $callback): mixed
1270+
public function withTenant(int|string|null $tenant, callable $callback): mixed
12591271
{
12601272
$previous = $this->adapter->getTenant();
12611273
$this->adapter->setTenant($tenant);

src/Database/Document.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ public function getUpdatedAt(): ?string
173173
}
174174

175175
/**
176-
* @return int|null
176+
* @return int|string|null
177177
*/
178-
public function getTenant(): ?int
178+
public function getTenant(): int|string|null
179179
{
180180
$tenant = $this->getAttribute('$tenant');
181181

182-
if ($tenant === null) {
183-
return null;
182+
if (\is_numeric($tenant)) {
183+
return (int) $tenant;
184184
}
185185

186-
return (int) $tenant;
186+
return $tenant;
187187
}
188188

189189
/**

src/Database/Mirror.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function setSharedTables(bool $sharedTables): static
123123
return $this;
124124
}
125125

126-
public function setTenant(?int $tenant): static
126+
public function setTenant(int|string|null $tenant): static
127127
{
128128
$this->delegate(__FUNCTION__, \func_get_args());
129129

0 commit comments

Comments
 (0)