Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7766a85

Browse files
authored
fix: only use PersistedObjectsTracker when auto-refresh is enabled (#1013)
1 parent f0917cc commit 7766a85

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ public static function bootForDataProvider(\Closure|self $configuration): void
140140
self::$instance->bootedForDataProvider = true;
141141
}
142142

143+
/**
144+
* /!\ Until PHPUnit 9 support is not dropped, this method MUST NOT call Configuration::instance()
145+
* Otherwise, it will reboot the kernel, leading to complex bugs
146+
*/
143147
public static function shutdown(): void
144148
{
145149
PersistedObjectsTracker::reset();

src/Persistence/PersistenceManager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public function save(object $object): object
8686
$this->flush($om);
8787
}
8888

89-
PersistedObjectsTracker::updateIds();
89+
if (Configuration::instance()->autoRefreshWithLazyObjectsIsEnabled()) {
90+
Configuration::instance()->persistedObjectsTracker?->updateIds();
91+
}
9092

9193
return $object;
9294
}
@@ -426,7 +428,10 @@ private function flushAllStrategies(): void
426428
$this->flush($om);
427429
}
428430
}
429-
PersistedObjectsTracker::updateIds();
431+
432+
if (Configuration::instance()->autoRefreshWithLazyObjectsIsEnabled()) {
433+
Configuration::instance()->persistedObjectsTracker?->updateIds();
434+
}
430435
}
431436

432437
/**

src/Persistence/Proxy/PersistedObjectsTracker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function add(object ...$objects): void
4848
}
4949
}
5050

51-
public static function updateIds(): void
51+
public function updateIds(): void
5252
{
5353
foreach (self::$buffer as $object => $id) {
5454
if ($id) {

src/ZenstruckFoundryBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,9 @@ private function configureAutoRefreshWithLazyObjects(ContainerBuilder $container
460460

461461
if (null === $enableAutoRefreshWithLazyObjects && \PHP_VERSION_ID >= 80400) {
462462
trigger_deprecation('zenstruck/foundry', '2.7', 'Not setting a value for "zenstruck_foundry.enable_auto_refresh_with_lazy_objects" is deprecated. This option will be forced to true in 3.0.');
463+
}
463464

465+
if ($container->has('.foundry.persistence.objects_tracker') && !$enableAutoRefreshWithLazyObjects) {
464466
$container->removeDefinition('.foundry.persistence.objects_tracker');
465467
}
466468
}

0 commit comments

Comments
 (0)