Skip to content

Commit 3ff7a12

Browse files
committed
fix(database): hydrate deferred writes before staging values
1 parent 5433069 commit 3ff7a12

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/Handlers/DatabaseHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function get(string $class, string $property, ?string $context = null)
8181
public function set(string $class, string $property, $value = null, ?string $context = null): void
8282
{
8383
if ($this->deferWrites) {
84+
$this->hydrate($context);
8485
$this->markPending($class, $property, $value, $context);
8586
} else {
8687
$this->persist($class, $property, $value, $context);
@@ -104,6 +105,8 @@ public function setMany(array $settings, ?string $context = null): void
104105
}
105106

106107
if ($this->deferWrites) {
108+
$this->hydrate($context);
109+
107110
foreach ($settings as $setting) {
108111
$this->markPending($setting['class'], $setting['property'], $setting['value'], $context);
109112
$this->setStored($setting['class'], $setting['property'], $setting['value'], $context);

tests/DatabaseHandlerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,30 @@ public function testDeferredSetManyPersistsAfterPersist(): void
490490
]);
491491
}
492492

493+
public function testDeferredSetReturnsPendingValueBeforePersist(): void
494+
{
495+
$this->settings->set('Example.siteName', 'StoredSingle');
496+
497+
$deferredSettings = $this->createDeferredSettings();
498+
499+
$deferredSettings->set('Example.siteName', 'PendingSingle');
500+
501+
$this->assertSame('PendingSingle', $deferredSettings->get('Example.siteName'));
502+
}
503+
504+
public function testDeferredSetManyReturnsPendingValueBeforePersist(): void
505+
{
506+
$this->settings->set('Example.siteName', 'StoredBatch');
507+
508+
$deferredSettings = $this->createDeferredSettings();
509+
510+
$deferredSettings->setMany([
511+
'Example.siteName' => 'PendingBatch',
512+
]);
513+
514+
$this->assertSame('PendingBatch', $deferredSettings->get('Example.siteName'));
515+
}
516+
493517
public function testDeferredSetManyPersistsDifferentClassesAfterPersist(): void
494518
{
495519
$deferredSettings = $this->createDeferredSettings();

0 commit comments

Comments
 (0)