قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-10-08 01:48:25 +00:00

* WIP PoC * Turn into a plugin that can be activated in plugin administration * Move getters to a separate folder * Limit plugin.setting explode to 2 items to keep possible dots in setting name intact * Add example controller and README * Add hasValue methods to Settings plugin * Add and use `hasSetting` method * Use default hierarchy * poc * saving progress * update * finish PoC with working example * v2 with working example * remove unnecessary additions * remove commented code * ws / cs / cleanup * Reuse existing "getPluginName" lookup * Require interfaces with trait usage * Connect new settings with old settings * Connect compliance settings and dashboard * Add optional template types to settings * rearrange code into different core folders * rename policies folder to policy to match core * hooked new settings up to dashboard * add required imports for phpstan * ws / cs * Remove return type override from API * Connect title/inlinehelp to settings pages * Stub actual feature usage of new "disable visitor log" setting * implement dashboard as full mvp (#23593) * reuse system and measurable traits to save policy status * complete implementing mvp dashboard * update existing tests and add new unit tests (#23594) * fix vue issue * update existing system tests * fix vue * fix missing test files * Build vue files * update broken UI tests * update policymanager to handle more generic functions * begin adding new unit tests * update unit tests to work correctly * fix return type issue and also fix some mocking * PHPCS * more PHPCS * simplify some code to make the tests run better * phpcs * add unit tests for some new setting code * cover extra function in policyComparisonTrait --------- Co-authored-by: innocraft-automation <innocraft-automation@users.noreply.github.com> * undo some example code * more undoing * add translations, remove example code * fix visitorlog isCompliant condition * fix merging issue * phpcs * Build vue files * update broken test * update broken tests * update broken tests * fix broken UI tests * add extra translations * abstract null checks in compareStrictness function * PHPCS * new PHPCS comma changes * update UI test images * Fix UI test selector * Update UI test screenshot --------- Co-authored-by: Michal Kleiner <michal@innocraft.com> Co-authored-by: Matt <1169490+caddoo@users.noreply.github.com> Co-authored-by: Marc Neudert <marc@innocraft.com> Co-authored-by: innocraft-automation <innocraft-automation@users.noreply.github.com>
136 خطوط
3.6 KiB
PHP
136 خطوط
3.6 KiB
PHP
<?php
|
|
|
|
namespace Piwik\Policy;
|
|
|
|
use Exception;
|
|
use Piwik\Plugin\Manager;
|
|
use Piwik\Settings\FieldConfig;
|
|
use Piwik\Settings\Interfaces\MeasurableSettingInterface;
|
|
use Piwik\Settings\Interfaces\SystemSettingInterface;
|
|
use Piwik\Settings\Interfaces\Traits\Setters\MeasurableSetterTrait;
|
|
use Piwik\Settings\Interfaces\Traits\Setters\SystemSetterTrait;
|
|
|
|
/**
|
|
* @implements SystemSettingInterface<bool>
|
|
* @implements MeasurableSettingInterface<bool>
|
|
*/
|
|
abstract class CompliancePolicy implements SystemSettingInterface, MeasurableSettingInterface
|
|
{
|
|
/**
|
|
* @use SystemSetterTrait<bool>
|
|
*/
|
|
use SystemSetterTrait;
|
|
|
|
/**
|
|
* @use MeasurableSetterTrait<bool>
|
|
*/
|
|
use MeasurableSetterTrait;
|
|
|
|
abstract public static function getName(): string;
|
|
abstract public static function getDescription(): string;
|
|
abstract public static function getTitle(): string;
|
|
|
|
/**
|
|
* @return array<string> of plugin names that are required for this policy to function
|
|
*/
|
|
abstract protected static function getMinimumRequiredPlugins(): array;
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public static function getDetails(): array
|
|
{
|
|
return [
|
|
'id' => static::getName(),
|
|
'title' => static::getTitle(),
|
|
'description' => static::getDescription(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @throws \Exception when required plugins are not active
|
|
*/
|
|
protected static function checkRequiredPluginsActive(): void
|
|
{
|
|
$plugins = static::getMinimumRequiredPlugins();
|
|
$pluginManager = static::getPluginManagerInstance();
|
|
|
|
foreach ($plugins as $plugin) {
|
|
if (!$pluginManager->isPluginActivated($plugin)) {
|
|
throw new Exception("Plugin $plugin is not activated");
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static function getPluginManagerInstance(): Manager
|
|
{
|
|
return Manager::getInstance();
|
|
}
|
|
|
|
protected static function getSystemDefaultValue()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
protected static function getSystemName(): string
|
|
{
|
|
return preg_replace('/\s+/', '', static::getName()) . '_policy_enabled';
|
|
}
|
|
|
|
protected static function getSystemType(): string
|
|
{
|
|
return FieldConfig::TYPE_BOOL;
|
|
}
|
|
|
|
protected static function getMeasurableDefaultValue()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
protected static function getMeasurableName(): string
|
|
{
|
|
return preg_replace('/\s+/', '', static::getName()) . '_policy_enabled';
|
|
}
|
|
|
|
protected static function getMeasurableType(): string
|
|
{
|
|
return FieldConfig::TYPE_BOOL;
|
|
}
|
|
|
|
/**
|
|
* If the policy is active at the instance level,
|
|
* disabling the policy for a site will also disable it
|
|
* for the instance.
|
|
*/
|
|
public static function setActiveStatus(?int $idSite, bool $isActive): void
|
|
{
|
|
if (isset($idSite)) {
|
|
static::setMeasurableValue($idSite, $isActive);
|
|
if (static::getSystemValue() && !$isActive) {
|
|
static::setSystemValue($isActive);
|
|
}
|
|
return;
|
|
}
|
|
static::setSystemValue($isActive);
|
|
}
|
|
|
|
/**
|
|
* If the policy is active at the instance level, then
|
|
* this function will return true for all sites.
|
|
*/
|
|
public static function isActive(?int $idSite): bool
|
|
{
|
|
try {
|
|
self::checkRequiredPluginsActive();
|
|
} catch (Exception $e) {
|
|
return false;
|
|
}
|
|
|
|
$instanceLevel = static::getSystemValue();
|
|
if (!$instanceLevel && isset($idSite)) {
|
|
return static::getMeasurableValue($idSite);
|
|
}
|
|
return $instanceLevel;
|
|
}
|
|
}
|