Use Doctrine to get all User Flags
[MAILPOET-2219]
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
namespace MailPoet\Features;
|
||||
|
||||
use function MailPoet\Util\array_column;
|
||||
use MailPoet\Entities\FeatureFlagEntity;
|
||||
|
||||
class FeatureFlagsController {
|
||||
|
||||
@ -26,14 +26,22 @@ class FeatureFlagsController {
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$flags = FeatureFlag::findArray();
|
||||
$flagsMap = array_combine(array_column($flags, 'name'), $flags);
|
||||
$flags = $this->feature_flags_repository->findAll();
|
||||
$flagsMap = array_combine(
|
||||
array_map(
|
||||
function (FeatureFlagEntity $flag) {
|
||||
return $flag->getName();
|
||||
},
|
||||
$flags
|
||||
),
|
||||
$flags
|
||||
);
|
||||
|
||||
$output = [];
|
||||
foreach ($this->features_controller->getDefaults() as $name => $default) {
|
||||
$output[] = [
|
||||
'name' => $name,
|
||||
'value' => isset($flagsMap[$name]) ? (bool)$flagsMap[$name]['value'] : $default,
|
||||
'value' => isset($flagsMap[$name]) ? (bool)$flagsMap[$name]->getValue() : $default,
|
||||
'default' => $default,
|
||||
];
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace MailPoet\Features;
|
||||
|
||||
use MailPoet\Models\FeatureFlag;
|
||||
|
||||
class FeaturesController {
|
||||
|
||||
// Define features below in the following form:
|
||||
@ -19,6 +17,13 @@ class FeaturesController {
|
||||
/** @var array */
|
||||
private $flags;
|
||||
|
||||
/** @var FeatureFlagsRepository */
|
||||
private $feature_flags_repository;
|
||||
|
||||
public function __construct(FeatureFlagsRepository $feature_flags_repository) {
|
||||
$this->feature_flags_repository = $feature_flags_repository;
|
||||
}
|
||||
|
||||
/** @return bool */
|
||||
function isSupported($feature) {
|
||||
if (!$this->exists($feature)) {
|
||||
@ -57,10 +62,10 @@ class FeaturesController {
|
||||
}
|
||||
|
||||
private function getValueMap() {
|
||||
$features = FeatureFlag::selectMany(['name', 'value'])->findMany();
|
||||
$features = $this->feature_flags_repository->findAll();
|
||||
$featuresMap = [];
|
||||
foreach ($features as $feature) {
|
||||
$featuresMap[$feature->name] = (bool)$feature->value;
|
||||
$featuresMap[$feature->getName()] = (bool)$feature->getValue();
|
||||
}
|
||||
return $featuresMap;
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
/**
|
||||
* @property string $name
|
||||
* @property bool $value
|
||||
*/
|
||||
class FeatureFlag extends Model {
|
||||
public static $_table = MP_FEATURE_FLAGS_TABLE;
|
||||
|
||||
static function createOrUpdate($data = []) {
|
||||
$keys = false;
|
||||
if (isset($data['name'])) {
|
||||
$keys = [
|
||||
'name' => $data['name'],
|
||||
];
|
||||
}
|
||||
return parent::_createOrUpdate($data, $keys);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user