Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2016-03-10 00:55:45 +0300
committerThomas Steur <thomas.steur@gmail.com>2016-04-11 05:11:33 +0300
commitb52ae4e7e488e0474d67c54578e1d6c1aa066bff (patch)
treef94b02f774cbc24faaa18f29ee1e19fef8b338af /core/Measurable
parent6ba622a68a26792af8cc22131f488f7ff5189d2c (diff)
refs #7983 let plugins add or remove fields to websites and better settings api
Diffstat (limited to 'core/Measurable')
-rw-r--r--core/Measurable/Measurable.php13
-rw-r--r--core/Measurable/MeasurableSetting.php70
-rw-r--r--core/Measurable/MeasurableSettings.php103
-rw-r--r--core/Measurable/Settings/Storage.php104
-rw-r--r--core/Measurable/Type.php3
-rw-r--r--core/Measurable/Type/TypeManager.php10
6 files changed, 9 insertions, 294 deletions
diff --git a/core/Measurable/Measurable.php b/core/Measurable/Measurable.php
index d80c1f0323..6223a6931f 100644
--- a/core/Measurable/Measurable.php
+++ b/core/Measurable/Measurable.php
@@ -9,7 +9,6 @@
namespace Piwik\Measurable;
-use Exception;
use Piwik\Site;
/**
@@ -17,16 +16,4 @@ use Piwik\Site;
*/
class Measurable extends Site
{
-
- public function getSettingValue($name)
- {
- $settings = new MeasurableSettings($this->id, $this->getType());
- $setting = $settings->getSetting($name);
-
- if (!empty($setting)) {
- return $setting->getValue(); // Calling `getValue` makes sure we respect read permission of this setting
- }
-
- throw new Exception(sprintf('Setting %s does not exist', $name));
- }
}
diff --git a/core/Measurable/MeasurableSetting.php b/core/Measurable/MeasurableSetting.php
deleted file mode 100644
index 91e0970442..0000000000
--- a/core/Measurable/MeasurableSetting.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * Piwik - free/libre analytics platform
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
- */
-
-namespace Piwik\Measurable;
-
-use Piwik\Piwik;
-
-/**
- * Describes a Type setting for a website, mobile app, ...
- *
- * See {@link \Piwik\Plugin\Settings}.
- */
-class MeasurableSetting extends \Piwik\Settings\Setting
-{
- /**
- * By default the value of the type setting is only readable by users having at least view access to one site
- *
- * @var bool
- * @since 2.14.0
- */
- public $readableByCurrentUser = false;
-
- /**
- * By default the value of the type setting is only writable by users having at least admin access to one site
- * @var bool
- * @internal
- */
- public $writableByCurrentUser = false;
-
- /**
- * Constructor.
- *
- * @param string $name The persisted name of the setting.
- * @param string $title The display name of the setting.
- */
- public function __construct($name, $title)
- {
- parent::__construct($name, $title);
-
- $this->writableByCurrentUser = Piwik::isUserHasSomeAdminAccess();
- $this->readableByCurrentUser = Piwik::isUserHasSomeViewAccess();
- }
-
- /**
- * Returns `true` if this setting is writable for the current user, `false` if otherwise. In case it returns
- * writable for the current user it will be visible in the Plugin settings UI.
- *
- * @return bool
- */
- public function isWritableByCurrentUser()
- {
- return $this->writableByCurrentUser;
- }
-
- /**
- * Returns `true` if this setting can be displayed for the current user, `false` if otherwise.
- *
- * @return bool
- */
- public function isReadableByCurrentUser()
- {
- return $this->readableByCurrentUser;
- }
-}
diff --git a/core/Measurable/MeasurableSettings.php b/core/Measurable/MeasurableSettings.php
deleted file mode 100644
index 7d627e0a2c..0000000000
--- a/core/Measurable/MeasurableSettings.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-/**
- * Piwik - free/libre analytics platform
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
- */
-namespace Piwik\Measurable;
-
-use Piwik\Db;
-use Piwik\Piwik;
-use Piwik\Plugin\Settings;
-use Piwik\Measurable\Settings\Storage;
-use Piwik\Settings\Setting;
-use Piwik\Measurable\Type\TypeManager;
-
-class MeasurableSettings extends Settings
-{
-
- /**
- * @var int
- */
- private $idSite = null;
-
- /**
- * @var string
- */
- private $idType = null;
-
- /**
- * @param int $idSite The id of a site. If you want to get settings for a not yet created site just pass an empty value ("0")
- * @param string $idType If no typeId is given, the type of the site will be used.
- *
- * @throws \Exception
- */
- public function __construct($idSite, $idType)
- {
- $this->idSite = $idSite;
- $this->idType = $idType;
- $this->storage = new Storage(Db::get(), $this->idSite);
- $this->pluginName = 'MeasurableSettings';
-
- $this->init();
- }
-
- protected function init()
- {
- $typeManager = new TypeManager();
- $type = $typeManager->getType($this->idType);
- $type->configureMeasurableSettings($this);
-
- /**
- * This event is posted when generating settings for a Measurable (website). You can add any Measurable settings
- * that you wish to be shown in the Measurable manager (websites manager). If you need to add settings only for
- * eg MobileApp measurables you can use eg `$type->getId() === Piwik\Plugins\MobileAppMeasurable\Type::ID` and
- * add only settings if the condition is true.
- *
- * @since Piwik 2.14.0
- * @deprecated will be removed in Piwik 3.0.0
- *
- * @param MeasurableSettings $this
- * @param \Piwik\Measurable\Type $type
- * @param int $idSite
- */
- Piwik::postEvent('Measurable.initMeasurableSettings', array($this, $type, $this->idSite));
- }
-
- public function addSetting(Setting $setting)
- {
- if ($this->idSite && $setting instanceof MeasurableSetting) {
- $setting->writableByCurrentUser = Piwik::isUserHasAdminAccess($this->idSite);
- }
-
- parent::addSetting($setting);
- }
-
- public function save()
- {
- Piwik::checkUserHasAdminAccess($this->idSite);
-
- $typeManager = new TypeManager();
- $type = $typeManager->getType($this->idType);
-
- /**
- * Triggered just before Measurable settings are about to be saved. You can use this event for example
- * to validate not only one setting but multiple ssetting. For example whether username
- * and password matches.
- *
- * @since Piwik 2.14.0
- * @deprecated will be removed in Piwik 3.0.0
- *
- * @param MeasurableSettings $this
- * @param \Piwik\Measurable\Type $type
- * @param int $idSite
- */
- Piwik::postEvent('Measurable.beforeSaveSettings', array($this, $type, $this->idSite));
-
- $this->storage->save();
- }
-
-}
-
diff --git a/core/Measurable/Settings/Storage.php b/core/Measurable/Settings/Storage.php
deleted file mode 100644
index df9748af5e..0000000000
--- a/core/Measurable/Settings/Storage.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * Piwik - free/libre analytics platform
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
- */
-
-namespace Piwik\Measurable\Settings;
-
-use Piwik\Db;
-use Piwik\Common;
-use Piwik\Settings\Setting;
-
-/**
- * Storage for site settings
- */
-class Storage extends \Piwik\Settings\Storage
-{
- private $idSite = null;
-
- /**
- * @var Db
- */
- private $db = null;
-
- private $toBeDeleted = array();
-
- public function __construct(Db\AdapterInterface $db, $idSite)
- {
- $this->db = $db;
- $this->idSite = $idSite;
- }
-
- protected function deleteSettingsFromStorage()
- {
- $table = $this->getTableName();
- $sql = "DELETE FROM $table WHERE `idsite` = ?";
- $bind = array($this->idSite);
-
- $this->db->query($sql, $bind);
- }
-
- public function deleteValue(Setting $setting)
- {
- $this->toBeDeleted[$setting->getName()] = true;
- parent::deleteValue($setting);
- }
-
- public function setValue(Setting $setting, $value)
- {
- $this->toBeDeleted[$setting->getName()] = false; // prevent from deleting this setting, we will create/update it
- parent::setValue($setting, $value);
- }
-
- /**
- * Saves (persists) the current setting values in the database.
- */
- public function save()
- {
- $table = $this->getTableName();
-
- foreach ($this->toBeDeleted as $name => $delete) {
- if ($delete) {
- $sql = "DELETE FROM $table WHERE `idsite` = ? and `setting_name` = ?";
- $bind = array($this->idSite, $name);
-
- $this->db->query($sql, $bind);
- }
- }
-
- $this->toBeDeleted = array();
-
- foreach ($this->settingsValues as $name => $value) {
- $value = serialize($value);
-
- $sql = "INSERT INTO $table (`idsite`, `setting_name`, `setting_value`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `setting_value` = ?";
- $bind = array($this->idSite, $name, $value, $value);
-
- $this->db->query($sql, $bind);
- }
- }
-
- protected function loadSettings()
- {
- $sql = "SELECT `setting_name`, `setting_value` FROM " . $this->getTableName() . " WHERE idsite = ?";
- $bind = array($this->idSite);
-
- $settings =$this->db->fetchAll($sql, $bind);
-
- $flat = array();
- foreach ($settings as $setting) {
- $flat[$setting['setting_name']] = unserialize($setting['setting_value']);
- }
-
- return $flat;
- }
-
- private function getTableName()
- {
- return Common::prefixTable('site_setting');
- }
-}
diff --git a/core/Measurable/Type.php b/core/Measurable/Type.php
index e9457a660f..5d24f04409 100644
--- a/core/Measurable/Type.php
+++ b/core/Measurable/Type.php
@@ -55,8 +55,5 @@ class Type
return $this->howToSetupUrl;
}
- public function configureMeasurableSettings(MeasurableSettings $settings)
- {
- }
}
diff --git a/core/Measurable/Type/TypeManager.php b/core/Measurable/Type/TypeManager.php
index af40d9c624..a514abbbdc 100644
--- a/core/Measurable/Type/TypeManager.php
+++ b/core/Measurable/Type/TypeManager.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Measurable\Type;
+use Piwik\Container\StaticContainer;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\Measurable\Type;
@@ -18,7 +19,14 @@ class TypeManager
*/
public function getAllTypes()
{
- return PluginManager::getInstance()->findComponents('Type', '\\Piwik\\Measurable\\Type');
+ $components = PluginManager::getInstance()->findComponents('Type', '\\Piwik\\Measurable\\Type');
+
+ $instances = array();
+ foreach ($components as $component) {
+ $instances[] = StaticContainer::get($component);
+ }
+
+ return $instances;
}
/**