From c07f7b3342bae193b10bbabc09e3a3a5296229bd Mon Sep 17 00:00:00 2001 From: Vassyli Date: Fri, 5 Oct 2018 15:57:30 +0200 Subject: [PATCH] Removed auto-flushing for every event from EventManager. --- src/EventManager.php | 3 ++- src/ModuleManager.php | 3 ++- tests/EventManagerTest.php | 1 + tests/GameTest.php | 3 +++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/EventManager.php b/src/EventManager.php index 5563820..7e711fd 100644 --- a/src/EventManager.php +++ b/src/EventManager.php @@ -111,7 +111,8 @@ class EventManager 'class' => $class, 'library' => $library ]); - $e->save($this->g->getEntityManager()); + + $this->g->getEntityManager()->persist($e); } /** diff --git a/src/ModuleManager.php b/src/ModuleManager.php index 33d0d60..ed95155 100644 --- a/src/ModuleManager.php +++ b/src/ModuleManager.php @@ -79,7 +79,8 @@ class ModuleManager try { $class::onRegister($this->g, $m); - $m->save($this->g->getEntityManager()); + $this->g->getEntityManager()->persist($m); + $this->g->getEntityManager()->flush(); } catch (Throwable $e) { $this->g->getLogger()->error("Calling {$class}::onRegister failed with exception: {$e->getMessage()}"); unset($m); diff --git a/tests/EventManagerTest.php b/tests/EventManagerTest.php index 30b232d..99999bc 100644 --- a/tests/EventManagerTest.php +++ b/tests/EventManagerTest.php @@ -96,6 +96,7 @@ class EventManagerTest extends CoreModelTestCase $library = 'lotgd/tests'; $em->subscribe($pattern, $class, $library); + $this->getEntityManager()->flush(); $sub = EventSubscription::create([ 'pattern' => $pattern, diff --git a/tests/GameTest.php b/tests/GameTest.php index 325eb55..7f63c2b 100644 --- a/tests/GameTest.php +++ b/tests/GameTest.php @@ -159,6 +159,7 @@ class GameTest extends CoreModelTestCase $this->g->getEventManager()->subscribe('/h\/lotgd\/core\/default-scene/', DefaultSceneProvider::class, 'lotgd/core/tests'); $this->g->getEventManager()->subscribe('/h\/lotgd\/core\/navigate-to\/.*/', DefaultSceneProvider::class, 'lotgd/core/tests'); + $this->getEntityManager()->flush(); $v = $this->g->getViewpoint(); // Run it twice to make sure no additional DB operations happen. @@ -214,6 +215,7 @@ class GameTest extends CoreModelTestCase // subscribe event $this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests'); + $this->getEntityManager()->flush(); $action = new Action(7, null, ["foo" => "baz"]); $actionId = $action->getId(); @@ -243,6 +245,7 @@ class GameTest extends CoreModelTestCase // subscribe event $this->g->getEventManager()->subscribe('#h/lotgd/core/navigate-to/lotgd/tests/paramaters#', DefaultSceneProvider::class, 'lotgd/core/tests'); + $this->getEntityManager()->flush(); $action = new Action(7, null, ["foo" => "baz"]); $actionId = $action->getId();