Make feature flags controller return default feature value in case table doesn't exists
[MAILPOET-2373]
This commit is contained in:
committed by
Jack Kitterhing
parent
b2649ad635
commit
0daf7e8855
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace MailPoet\Features;
|
namespace MailPoet\Features;
|
||||||
|
|
||||||
|
use MailPoetVendor\Doctrine\DBAL\Exception\TableNotFoundException;
|
||||||
|
|
||||||
class FeaturesController {
|
class FeaturesController {
|
||||||
|
|
||||||
// Define features below in the following form:
|
// Define features below in the following form:
|
||||||
@@ -33,7 +35,12 @@ class FeaturesController {
|
|||||||
if (!$this->exists($feature)) {
|
if (!$this->exists($feature)) {
|
||||||
throw new \RuntimeException("Unknown feature '$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];
|
return $this->flags[$feature];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +65,8 @@ class FeaturesController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->flags = [];
|
|
||||||
$flagsMap = $this->getValueMap();
|
$flagsMap = $this->getValueMap();
|
||||||
|
$this->flags = [];
|
||||||
foreach ($this->defaults as $name => $default) {
|
foreach ($this->defaults as $name => $default) {
|
||||||
$this->flags[$name] = isset($flagsMap[$name]) ? $flagsMap[$name] : $default;
|
$this->flags[$name] = isset($flagsMap[$name]) ? $flagsMap[$name] : $default;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user