From 0daf7e88557d14edde1a9b48fa649c9636f1fa68 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Thu, 19 Sep 2019 15:10:28 +0200 Subject: [PATCH] Make feature flags controller return default feature value in case table doesn't exists [MAILPOET-2373] --- lib/Features/FeaturesController.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Features/FeaturesController.php b/lib/Features/FeaturesController.php index 5d58e94b06..7219018bce 100644 --- a/lib/Features/FeaturesController.php +++ b/lib/Features/FeaturesController.php @@ -2,6 +2,8 @@ namespace MailPoet\Features; +use MailPoetVendor\Doctrine\DBAL\Exception\TableNotFoundException; + class FeaturesController { // Define features below in the following form: @@ -33,7 +35,12 @@ class FeaturesController { if (!$this->exists($feature)) { throw new \RuntimeException("Unknown feature '$feature'"); } - $this->ensureFlagsLoaded(); + // ensure controller works even if used before migrator, return default value in such case + try { + $this->ensureFlagsLoaded(); + } catch (TableNotFoundException $e) { + return $this->defaults[$feature]; + } return $this->flags[$feature]; } @@ -58,8 +65,8 @@ class FeaturesController { return; } - $this->flags = []; $flagsMap = $this->getValueMap(); + $this->flags = []; foreach ($this->defaults as $name => $default) { $this->flags[$name] = isset($flagsMap[$name]) ? $flagsMap[$name] : $default; }