diff options
author | Zoltan Flamis <flamisz@gmail.com> | 2021-03-17 23:12:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-17 23:12:22 +0300 |
commit | 7527bce11d1b3f9a5ace08eb26e5379f7702cf7c (patch) | |
tree | 9dfe39298ec62e5a34103eb88c069c18c69941ed | |
parent | 4778bc5c065c7bb325b14f7dbcc6b097d7a4097f (diff) |
Development mode notifications when Matomo not installed through git (#17300)
* not git installed exception for generate commands
* notify superadmin about development mode
* throw error in initalize method
* add guide url to the exception message
* modify exception message
* add development mode check
-rw-r--r-- | core/Exception/NotGitInstalledException.php | 16 | ||||
-rw-r--r-- | core/Plugin/ConsoleCommand.php | 11 | ||||
-rw-r--r-- | core/Plugin/ControllerAdmin.php | 27 | ||||
-rw-r--r-- | lang/en.json | 1 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/DevelopmentEnable.php | 6 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/GenerateAngularComponent.php | 2 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/GeneratePluginBase.php | 14 |
7 files changed, 75 insertions, 2 deletions
diff --git a/core/Exception/NotGitInstalledException.php b/core/Exception/NotGitInstalledException.php new file mode 100644 index 0000000000..e066994819 --- /dev/null +++ b/core/Exception/NotGitInstalledException.php @@ -0,0 +1,16 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Exception; + + +class NotGitInstalledException extends Exception +{ + +} diff --git a/core/Plugin/ConsoleCommand.php b/core/Plugin/ConsoleCommand.php index d281af0048..7c62be3f42 100644 --- a/core/Plugin/ConsoleCommand.php +++ b/core/Plugin/ConsoleCommand.php @@ -30,6 +30,17 @@ class ConsoleCommand extends SymfonyCommand $output->writeln(''); } + public function writeComment(OutputInterface $output, $messages) + { + $output->writeln(''); + + foreach ($messages as $message) { + $output->writeln('<comment>' . $message . '</comment>'); + } + + $output->writeln(''); + } + protected function checkAllRequiredOptionsAreNotEmpty(InputInterface $input) { $options = $this->getDefinition()->getOptions(); diff --git a/core/Plugin/ControllerAdmin.php b/core/Plugin/ControllerAdmin.php index 3277c01ca7..7dad96a41f 100644 --- a/core/Plugin/ControllerAdmin.php +++ b/core/Plugin/ControllerAdmin.php @@ -23,6 +23,7 @@ use Piwik\Url; use Piwik\Version; use Piwik\View; use Piwik\ProxyHttp; +use Piwik\SettingsPiwik; /** * Base class of plugin controllers that provide administrative functionality. @@ -170,6 +171,29 @@ abstract class ControllerAdmin extends Controller Notification\Manager::notify('ControllerAdmin_HttpIsUsed', $notification); } + private static function notifyIfDevelopmentModeOnButNotInstalledThroughGit() + { + if (!Piwik::hasUserSuperUserAccess()) { + return; + } + + if (!Development::isEnabled()) { + return; + } + + if (SettingsPiwik::isGitDeployment()) { + return; + } + + $message = Piwik::translate('General_WarningDevelopmentModeOnButNotGitInstalled'); + + $notification = new Notification($message); + $notification->context = Notification::CONTEXT_WARNING; + $notification->raw = true; + $notification->flags = Notification::FLAG_CLEAR; + Notification\Manager::notify('ControllerAdmin_DevelopmentModeOn', $notification); + } + /** * @ignore */ @@ -313,6 +337,7 @@ abstract class ControllerAdmin extends Controller self::notifyWhenTrackingStatisticsDisabled(); self::notifyIfEAcceleratorIsUsed(); self::notifyIfURLIsNotSecure(); + self::notifyIfDevelopmentModeOnButNotInstalledThroughGit(); $view->topMenu = MenuTop::getInstance()->getMenu(); @@ -336,7 +361,7 @@ abstract class ControllerAdmin extends Controller /** * Posted when rendering an admin page and notifications about any warnings or errors should be triggered. * You can use it for example when you have a plugin that needs to be configured in order to work and the - * plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling + * plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling * eg `Notification\Manager::cancel($notificationId)`. * * **Example** diff --git a/lang/en.json b/lang/en.json index 8b976da0de..e563adac20 100644 --- a/lang/en.json +++ b/lang/en.json @@ -487,6 +487,7 @@ "WarningFileIntegrityNoMd5file": "File integrity check could not be completed due to missing md5_file() function.", "WarningPasswordStored": "%1$sWarning:%2$s This password will be stored in the config file visible to everybody who can access it.", "WarningDebugOnDemandEnabled": "Tracker %1$s mode is enabled. For security reasons this should be enabled only for a short time frame. To disable it set %2$s to %3$s in %4$s", + "WarningDevelopmentModeOnButNotGitInstalled": "You are currently using Matomo in development mode, but it was not installed through git. It's not recommended to use Matomo in development mode in production environment.", "Website": "Website", "Weekly": "Weekly", "WeeklyReport": "weekly", diff --git a/plugins/CoreConsole/Commands/DevelopmentEnable.php b/plugins/CoreConsole/Commands/DevelopmentEnable.php index 192f4889f4..ec1df4735c 100644 --- a/plugins/CoreConsole/Commands/DevelopmentEnable.php +++ b/plugins/CoreConsole/Commands/DevelopmentEnable.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\CoreConsole\Commands; use Piwik\Config; use Piwik\Filesystem; +use Piwik\SettingsPiwik; use Piwik\Plugin\ConsoleCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -51,6 +52,11 @@ class DevelopmentEnable extends ConsoleCommand Filesystem::deleteAllCacheOnUpdate(); $this->writeSuccessMessage($output, array($message)); + + if ($enable && !SettingsPiwik::isGitDeployment()) { + $comment = 'Development mode should be only enabled when installed through git. Not every development feature will be available.'; + $this->writeComment($output, [$comment]); + } } } diff --git a/plugins/CoreConsole/Commands/GenerateAngularComponent.php b/plugins/CoreConsole/Commands/GenerateAngularComponent.php index 46a7be1737..55311d10cc 100644 --- a/plugins/CoreConsole/Commands/GenerateAngularComponent.php +++ b/plugins/CoreConsole/Commands/GenerateAngularComponent.php @@ -72,4 +72,4 @@ class GenerateAngularComponent extends GenerateAngularConstructBase 'If you are not familiar with this have a look at <comment>https://developer.matomo.org/guides/working-with-piwiks-ui</comment>' )); } -}
\ No newline at end of file +} diff --git a/plugins/CoreConsole/Commands/GeneratePluginBase.php b/plugins/CoreConsole/Commands/GeneratePluginBase.php index bc86e67a79..345518f8cd 100644 --- a/plugins/CoreConsole/Commands/GeneratePluginBase.php +++ b/plugins/CoreConsole/Commands/GeneratePluginBase.php @@ -18,9 +18,16 @@ use Piwik\Plugin\Manager; use Piwik\Version; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Piwik\SettingsPiwik; +use Piwik\Exception\NotGitInstalledException; abstract class GeneratePluginBase extends ConsoleCommand { + protected function initialize(InputInterface $input, OutputInterface $output) + { + $this->throwErrorIfNotGitInstalled(); + } + public function isEnabled() { return Development::isEnabled(); @@ -397,4 +404,11 @@ abstract class GeneratePluginBase extends ConsoleCommand return $contentToReplace; } + protected function throwErrorIfNotGitInstalled() + { + if (!SettingsPiwik::isGitDeployment()) { + $url = 'https://developer.matomo.org/guides/getting-started-part-1'; + throw new NotGitInstalledException("This development feature requires Matomo to be checked out from git. For more information please visit {$url}."); + } + } } |