diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-02-03 07:47:27 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-02-03 07:47:27 +0400 |
commit | 883ecc81b96336d3a61fb193af51ecd3fb9b6d91 (patch) | |
tree | 46b04484dbe42dc3afdb7767e1bfe3c1ab17d1ed | |
parent | 3332750e51f995044cb25260bc3a61d454d02f26 (diff) |
refs #4563 moved custom logo from config to database
-rw-r--r-- | config/global.ini.php | 5 | ||||
-rw-r--r-- | core/Config.php | 1 | ||||
-rw-r--r-- | core/Plugin/Controller.php | 7 | ||||
-rw-r--r-- | core/Updates/2.0.4-b8.php | 58 | ||||
-rw-r--r-- | plugins/CoreAdminHome/Controller.php | 18 | ||||
-rw-r--r-- | plugins/CoreAdminHome/CustomLogo.php | 22 | ||||
-rw-r--r-- | plugins/ScheduledReports/ScheduledReports.php | 4 |
7 files changed, 95 insertions, 20 deletions
diff --git a/config/global.ini.php b/config/global.ini.php index 69544f98b8..b246b87127 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -500,11 +500,6 @@ delete_logs_schedule_lowest_interval = 7 delete_logs_older_than = 180 enable_auto_database_size_estimate = 1 -[branding] -; custom logo -; if 1, custom logo is being displayed instead of piwik logo -use_custom_logo = 0 - [mail] defaultHostnameIfEmpty = defaultHostnameIfEmpty.example.org ; default Email @hostname, if current host can't be read from system variables transport = ; smtp (using the configuration below) or empty (using built-in mail() function) diff --git a/core/Config.php b/core/Config.php index 4601b6078b..8f76eb7d72 100644 --- a/core/Config.php +++ b/core/Config.php @@ -105,7 +105,6 @@ class Config extends Singleton // Ensure local mods do not affect tests if (is_null($pathGlobal)) { $this->configCache['Debug'] = $this->configGlobal['Debug']; - $this->configCache['branding'] = $this->configGlobal['branding']; $this->configCache['mail'] = $this->configGlobal['mail']; $this->configCache['General'] = $this->configGlobal['General']; $this->configCache['Segments'] = $this->configGlobal['Segments']; diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php index 7250654a13..7441eb2750 100644 --- a/core/Plugin/Controller.php +++ b/core/Plugin/Controller.php @@ -24,6 +24,7 @@ use Piwik\Period\Month; use Piwik\Period; use Piwik\Period\Range; use Piwik\Piwik; +use Piwik\Plugins\CoreAdminHome\CustomLogo; use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Plugins\UsersManager\API as APIUsersManager; @@ -528,7 +529,7 @@ abstract class Controller * **isSuperUser** - True if the current user is the Super User, false if otherwise. * **hasSomeAdminAccess** - True if the current user has admin access to at least one site, * false if otherwise. - * **isCustomLogo** - The value of the `[branding] use_custom_logo` INI config option. + * **isCustomLogo** - The value of the `branding_use_custom_logo` option. * **logoHeader** - The header logo URL to use. * **logoLarge** - The large logo URL to use. * **logoSVG** - The SVG logo URL to use. @@ -546,7 +547,9 @@ abstract class Controller $view->debugTrackVisitsInsidePiwikUI = PiwikConfig::getInstance()->Debug['track_visits_inside_piwik_ui']; $view->isSuperUser = Access::getInstance()->hasSuperUserAccess(); $view->hasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess(); - $view->isCustomLogo = PiwikConfig::getInstance()->branding['use_custom_logo']; + + $customLogo = new CustomLogo(); + $view->isCustomLogo = $customLogo->isEnabled(); $view->logoHeader = \Piwik\Plugins\API\API::getInstance()->getHeaderLogoUrl(); $view->logoLarge = \Piwik\Plugins\API\API::getInstance()->getLogoUrl(); diff --git a/core/Updates/2.0.4-b8.php b/core/Updates/2.0.4-b8.php new file mode 100644 index 0000000000..be19a93bf1 --- /dev/null +++ b/core/Updates/2.0.4-b8.php @@ -0,0 +1,58 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Updates; + +use Piwik\Common; +use Piwik\Date; +use Piwik\Db; +use Piwik\Option; +use Piwik\Plugins\CoreAdminHome\CustomLogo; +use Piwik\Plugins\UsersManager\API as UsersManagerApi; +use Piwik\Plugins\MobileMessaging\MobileMessaging; +use Piwik\Updater; +use Piwik\Config; +use Piwik\UpdaterErrorException; +use Piwik\Updates; + +/** + */ +class Updates_2_0_4_b8 extends Updates +{ + static function getSql($schema = 'Myisam') + { + return array(); + } + + static function update() + { + try { + self::migrateBrandingConfigToDatabase(); + } catch (\Exception $e) { + throw new UpdaterErrorException($e->getMessage()); + } + } + + private static function migrateBrandingConfigToDatabase() + { + $config = Config::getInstance(); + + $branding = $config->branding; + + if (!empty($branding) && array_key_exists('use_custom_logo', $branding)) { + $useCustomLogo = $branding['use_custom_logo']; + + $customLogo = new CustomLogo(); + $useCustomLogo ? $customLogo->enable() : $customLogo->disable(); + } + + $config->branding = array(); + $config->forceSave(); + } +} diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php index 0993f872c6..5c54d371a9 100644 --- a/plugins/CoreAdminHome/Controller.php +++ b/plugins/CoreAdminHome/Controller.php @@ -16,6 +16,7 @@ use Piwik\Config; use Piwik\DataTable\Renderer\Json; use Piwik\Menu\MenuTop; use Piwik\Nonce; +use Piwik\Option; use Piwik\Piwik; use Piwik\Plugins\LanguagesManager\API as APILanguagesManager; use Piwik\Plugins\LanguagesManager\LanguagesManager; @@ -53,13 +54,12 @@ class Controller extends \Piwik\Plugin\ControllerAdmin } $view->trustedHosts = $trustedHosts; - $view->branding = Config::getInstance()->branding; - $logo = new CustomLogo(); + $view->branding = array('use_custom_logo' => $logo->isEnabled()); $view->logosWriteable = $logo->isCustomLogoWritable(); - $view->pathUserLogo = CustomLogo::getPathUserLogo(); + $view->pathUserLogo = CustomLogo::getPathUserLogo(); $view->pathUserLogoSmall = CustomLogo::getPathUserLogoSmall(); - $view->pathUserLogoSVG = CustomLogo::getPathUserSvgLogo(); + $view->pathUserLogoSVG = CustomLogo::getPathUserSvgLogo(); $view->pathUserLogoDirectory = dirname($view->pathUserLogo) . '/'; } @@ -187,10 +187,12 @@ class Controller extends \Piwik\Plugin\ControllerAdmin Url::saveTrustedHostnameInConfig($trustedHosts); } - // update branding settings - $branding = Config::getInstance()->branding; - $branding['use_custom_logo'] = Common::getRequestVar('useCustomLogo', '0'); - Config::getInstance()->branding = $branding; + $customLogo = new CustomLogo(); + if (Common::getRequestVar('useCustomLogo', '0')) { + $customLogo->enable(); + } else { + $customLogo->disable(); + } Config::getInstance()->forceSave(); diff --git a/plugins/CoreAdminHome/CustomLogo.php b/plugins/CoreAdminHome/CustomLogo.php index 8e1dfc58dd..bc1f1da055 100644 --- a/plugins/CoreAdminHome/CustomLogo.php +++ b/plugins/CoreAdminHome/CustomLogo.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\CoreAdminHome; use Piwik\Config; use Piwik\Filesystem; +use Piwik\Option; use Piwik\SettingsPiwik; class CustomLogo @@ -42,14 +43,29 @@ class CustomLogo return $svg; } + public function isEnabled() + { + return (bool) Option::get('branding_use_custom_logo'); + } + + public function enable() + { + Option::set('branding_use_custom_logo', '1', true); + } + + public function disable() + { + Option::set('branding_use_custom_logo', '0', true); + } + public function hasSVGLogo() { - if (Config::getInstance()->branding['use_custom_logo'] == 0) { + if (!$this->isEnabled()) { /* We always have our application logo */ return true; } - if (Config::getInstance()->branding['use_custom_logo'] == 1 + if ($this->isEnabled() && file_exists(Filesystem::getPathToPiwikRoot() . '/' . CustomLogo::getPathUserSvgLogo()) ) { return true; @@ -93,7 +109,7 @@ class CustomLogo if (file_exists($pathToPiwikRoot . '/' . $themeLogo)) { $logo = $themeLogo; } - if (Config::getInstance()->branding['use_custom_logo'] == 1 + if ($this->isEnabled() && file_exists($pathToPiwikRoot . '/' . $customLogo) ) { $logo = $customLogo; diff --git a/plugins/ScheduledReports/ScheduledReports.php b/plugins/ScheduledReports/ScheduledReports.php index 82db8ad7b5..9d637832a0 100644 --- a/plugins/ScheduledReports/ScheduledReports.php +++ b/plugins/ScheduledReports/ScheduledReports.php @@ -16,6 +16,7 @@ use Piwik\Db; use Piwik\Mail; use Piwik\Menu\MenuTop; use Piwik\Piwik; +use Piwik\Plugins\CoreAdminHome\CustomLogo; use Piwik\Plugins\MobileMessaging\API as APIMobileMessaging; use Piwik\Plugins\MobileMessaging\MobileMessaging; use Piwik\Plugins\SegmentEditor\API as APISegmentEditor; @@ -272,7 +273,8 @@ class ScheduledReports extends \Piwik\Plugin $mail = new Mail(); $mail->setSubject($subject); - $fromEmailName = Config::getInstance()->branding['use_custom_logo'] + $customLogo = new CustomLogo(); + $fromEmailName = $customLogo->isEnabled() ? Piwik::translate('CoreHome_WebAnalyticsReports') : Piwik::translate('ScheduledReports_PiwikReports'); $fromEmailAddress = Config::getInstance()->General['noreply_email_address']; |