Use Doctrine to get all User Flags
[MAILPOET-2219]
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Features;
|
namespace MailPoet\Features;
|
||||||
|
|
||||||
use function MailPoet\Util\array_column;
|
use MailPoet\Entities\FeatureFlagEntity;
|
||||||
|
|
||||||
class FeatureFlagsController {
|
class FeatureFlagsController {
|
||||||
|
|
||||||
@ -26,14 +26,22 @@ class FeatureFlagsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getAll() {
|
function getAll() {
|
||||||
$flags = FeatureFlag::findArray();
|
$flags = $this->feature_flags_repository->findAll();
|
||||||
$flagsMap = array_combine(array_column($flags, 'name'), $flags);
|
$flagsMap = array_combine(
|
||||||
|
array_map(
|
||||||
|
function (FeatureFlagEntity $flag) {
|
||||||
|
return $flag->getName();
|
||||||
|
},
|
||||||
|
$flags
|
||||||
|
),
|
||||||
|
$flags
|
||||||
|
);
|
||||||
|
|
||||||
$output = [];
|
$output = [];
|
||||||
foreach ($this->features_controller->getDefaults() as $name => $default) {
|
foreach ($this->features_controller->getDefaults() as $name => $default) {
|
||||||
$output[] = [
|
$output[] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'value' => isset($flagsMap[$name]) ? (bool)$flagsMap[$name]['value'] : $default,
|
'value' => isset($flagsMap[$name]) ? (bool)$flagsMap[$name]->getValue() : $default,
|
||||||
'default' => $default,
|
'default' => $default,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace MailPoet\Features;
|
namespace MailPoet\Features;
|
||||||
|
|
||||||
use MailPoet\Models\FeatureFlag;
|
|
||||||
|
|
||||||
class FeaturesController {
|
class FeaturesController {
|
||||||
|
|
||||||
// Define features below in the following form:
|
// Define features below in the following form:
|
||||||
@ -19,6 +17,13 @@ class FeaturesController {
|
|||||||
/** @var array */
|
/** @var array */
|
||||||
private $flags;
|
private $flags;
|
||||||
|
|
||||||
|
/** @var FeatureFlagsRepository */
|
||||||
|
private $feature_flags_repository;
|
||||||
|
|
||||||
|
public function __construct(FeatureFlagsRepository $feature_flags_repository) {
|
||||||
|
$this->feature_flags_repository = $feature_flags_repository;
|
||||||
|
}
|
||||||
|
|
||||||
/** @return bool */
|
/** @return bool */
|
||||||
function isSupported($feature) {
|
function isSupported($feature) {
|
||||||
if (!$this->exists($feature)) {
|
if (!$this->exists($feature)) {
|
||||||
@ -57,10 +62,10 @@ class FeaturesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getValueMap() {
|
private function getValueMap() {
|
||||||
$features = FeatureFlag::selectMany(['name', 'value'])->findMany();
|
$features = $this->feature_flags_repository->findAll();
|
||||||
$featuresMap = [];
|
$featuresMap = [];
|
||||||
foreach ($features as $feature) {
|
foreach ($features as $feature) {
|
||||||
$featuresMap[$feature->name] = (bool)$feature->value;
|
$featuresMap[$feature->getName()] = (bool)$feature->getValue();
|
||||||
}
|
}
|
||||||
return $featuresMap;
|
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