Skip to content

Commit a893ea6

Browse files
authored
Merge pull request #640 from utopia-php/document-constructor
Fix $skipPermissionsUpdate
2 parents 7281582 + f76954b commit a893ea6

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/Database/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4941,7 +4941,7 @@ public function createOrUpdateDocumentsWithIncrease(
49414941
)));
49424942
}
49434943

4944-
$skipPermissionsUpdate = false;
4944+
$skipPermissionsUpdate = true;
49454945

49464946
if ($document->offsetExists('$permissions')) {
49474947
$originalPermissions = $old->getPermissions();

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,69 @@ public function testCreateDocumentsWithDifferentAttributes(): void
388388
$database->deleteCollection($collection);
389389
}
390390

391+
public function testSkipPermissions(): void
392+
{
393+
/** @var Database $database */
394+
$database = static::getDatabase();
395+
396+
if (!$database->getAdapter()->getSupportForUpserts()) {
397+
$this->expectNotToPerformAssertions();
398+
return;
399+
}
400+
401+
$database->createCollection(__FUNCTION__);
402+
$database->createAttribute(__FUNCTION__, 'number', Database::VAR_INTEGER, 0, false);
403+
404+
$data = [];
405+
for ($i = 1; $i <= 10; $i++) {
406+
$data[] = [
407+
'$id' => "$i",
408+
'number' => $i,
409+
];
410+
}
411+
412+
$documents = array_map(fn ($d) => new Document($d), $data);
413+
414+
$results = [];
415+
$count = $database->createDocuments(__FUNCTION__, $documents, onNext: function ($doc) use (&$results) {
416+
$results[] = $doc;
417+
});
418+
419+
$this->assertEquals($count, \count($results));
420+
$this->assertEquals(10, \count($results));
421+
422+
/**
423+
* Update 1 row
424+
*/
425+
$data[\array_key_last($data)]['number'] = 100;
426+
427+
/**
428+
* Add 1 row
429+
*/
430+
$data[] = [
431+
'$id' => "101",
432+
'number' => 101,
433+
];
434+
435+
$documents = array_map(fn ($d) => new Document($d), $data);
436+
437+
Authorization::disable();
438+
439+
$results = [];
440+
$count = $database->createOrUpdateDocuments(
441+
__FUNCTION__,
442+
$documents,
443+
onNext: function ($doc) use (&$results) {
444+
$results[] = $doc;
445+
}
446+
);
447+
448+
Authorization::reset();
449+
450+
$this->assertEquals(2, \count($results));
451+
$this->assertEquals(2, $count);
452+
}
453+
391454
public function testUpsertDocuments(): void
392455
{
393456
/** @var Database $database */

0 commit comments

Comments
 (0)