diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-11-04 05:31:50 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-11-04 05:31:50 +0300 |
commit | ffa5c1e86e578ff166d5c55a5edb1ca14f1e3d28 (patch) | |
tree | 775467ba3e6c16d625f63e574738f5d3a99bc72f | |
parent | bde45453cda42c88b19d660ca406c61cb1130ce0 (diff) |
refs #6564 refactored out HtmlMessageException and introduced some other exceptions instead
-rw-r--r-- | core/Exception/AuthenticationFailedException.php | 13 | ||||
-rw-r--r-- | core/Exception/Exception.php (renamed from core/Exceptions/HtmlMessageException.php) | 24 | ||||
-rw-r--r-- | core/Exception/MissingFilePermissionException.php | 13 | ||||
-rw-r--r-- | core/Exception/NoPrivilegesException.php | 13 | ||||
-rw-r--r-- | core/Exception/NoWebsiteFoundException.php | 13 | ||||
-rw-r--r-- | core/Filechecks.php | 9 | ||||
-rw-r--r-- | core/FrontController.php | 23 | ||||
-rw-r--r-- | core/Plugin/Controller.php | 15 | ||||
-rw-r--r-- | core/Session.php | 7 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/Controller.php | 9 | ||||
-rw-r--r-- | plugins/Installation/Exception/DatabaseConnectionFailedException.php | 15 | ||||
-rw-r--r-- | plugins/Installation/Installation.php | 7 |
12 files changed, 126 insertions, 35 deletions
diff --git a/core/Exception/AuthenticationFailedException.php b/core/Exception/AuthenticationFailedException.php new file mode 100644 index 0000000000..ca3efc25c1 --- /dev/null +++ b/core/Exception/AuthenticationFailedException.php @@ -0,0 +1,13 @@ +<?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\Exception; + +class AuthenticationFailedException extends Exception +{ +}
\ No newline at end of file diff --git a/core/Exceptions/HtmlMessageException.php b/core/Exception/Exception.php index 243a0f1726..106034bf5a 100644 --- a/core/Exceptions/HtmlMessageException.php +++ b/core/Exception/Exception.php @@ -6,25 +6,25 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * */ -namespace Piwik\Exceptions; +namespace Piwik\Exception; -use Exception; +use Exception as PhpException; /** * An exception whose message has HTML content. When these exceptions are caught * the message will not be sanitized before being displayed to the user. - * - * @api */ -class HtmlMessageException extends Exception +abstract class Exception extends PhpException { - /** - * Returns the exception message. - * - * @return string - */ - public function getHtmlMessage() + private $isHtmlMessage = false; + + public function setIsHtmlMessage() + { + $this->isHtmlMessage = true; + } + + public function isHtmlMessage() { - return $this->getMessage(); + return $this->isHtmlMessage; } }
\ No newline at end of file diff --git a/core/Exception/MissingFilePermissionException.php b/core/Exception/MissingFilePermissionException.php new file mode 100644 index 0000000000..268725c70b --- /dev/null +++ b/core/Exception/MissingFilePermissionException.php @@ -0,0 +1,13 @@ +<?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\Exception; + +class MissingFilePermissionException extends Exception +{ +}
\ No newline at end of file diff --git a/core/Exception/NoPrivilegesException.php b/core/Exception/NoPrivilegesException.php new file mode 100644 index 0000000000..3ee8c9ce2b --- /dev/null +++ b/core/Exception/NoPrivilegesException.php @@ -0,0 +1,13 @@ +<?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\Exception; + +class NoPrivilegesException extends Exception +{ +}
\ No newline at end of file diff --git a/core/Exception/NoWebsiteFoundException.php b/core/Exception/NoWebsiteFoundException.php new file mode 100644 index 0000000000..eb97cad37a --- /dev/null +++ b/core/Exception/NoWebsiteFoundException.php @@ -0,0 +1,13 @@ +<?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\Exception; + +class NoWebsiteFoundException extends Exception +{ +}
\ No newline at end of file diff --git a/core/Filechecks.php b/core/Filechecks.php index eab93fd260..0c37680fc4 100644 --- a/core/Filechecks.php +++ b/core/Filechecks.php @@ -8,7 +8,7 @@ */ namespace Piwik; -use Piwik\Exceptions\HtmlMessageException; +use Piwik\Exception\MissingFilePermissionException; class Filechecks { @@ -96,7 +96,7 @@ class Filechecks } } - $directoryMessage = "<p><b>Piwik couldn't write to some directories $optionalUserInfo</b>.</p>"; + $directoryMessage = "<p><b>Piwik couldn't write to some directories $optionalUserInfo</b>.</p>"; $directoryMessage .= "<p>Try to Execute the following commands on your server, to allow Write access on these directories" . ":</p>" . "<blockquote>$directoryList</blockquote>" @@ -104,7 +104,10 @@ class Filechecks . "<p>After applying the modifications, you can <a href='index.php'>refresh the page</a>.</p>" . "<p>If you need more help, try <a href='?module=Proxy&action=redirect&url=http://piwik.org'>Piwik.org</a>.</p>"; - throw new HtmlMessageException($directoryMessage); + $ex = new MissingFilePermissionException($directoryMessage); + $ex->setIsHtmlMessage(); + + throw $ex; } /** diff --git a/core/FrontController.php b/core/FrontController.php index 0fa143d4b6..ea33c4e8f2 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -12,7 +12,7 @@ namespace Piwik; use Exception; use Piwik\API\Request; use Piwik\API\ResponseBuilder; -use Piwik\Exceptions\HtmlMessageException; +use Piwik\Exception\AuthenticationFailedException; use Piwik\Http\Router; use Piwik\Plugin\Controller; use Piwik\Plugin\Report; @@ -419,10 +419,15 @@ class FrontController extends Singleton try { $authAdapter = Registry::get('auth'); } catch (Exception $e) { - throw new HtmlMessageException("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated? - <br />You can activate the plugin by adding:<br /> - <code>Plugins[] = Login</code><br /> - under the <code>[Plugins]</code> section in your config/config.ini.php"); + $message = "Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated? + <br />You can activate the plugin by adding:<br /> + <code>Plugins[] = Login</code><br /> + under the <code>[Plugins]</code> section in your config/config.ini.php"; + + $ex = new AuthenticationFailedException($message); + $ex->setIsHtmlMessage(); + + throw $ex; } Access::getInstance()->reloadAccess($authAdapter); @@ -613,10 +618,10 @@ class FrontController extends Singleton { $debugTrace = $ex->getTraceAsString(); - if (method_exists($ex, 'getHtmlMessage')) { - $message = $ex->getHtmlMessage(); - } else { - $message = Common::sanitizeInputValue($ex->getMessage()); + $message = $ex->getMessage(); + + if (!method_exists($ex, 'isHtmlMessage') || !$ex->isHtmlMessage()) { + $message = Common::sanitizeInputValue($message); } $logo = new CustomLogo(); diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php index 9985c100d5..4afcbf25ad 100644 --- a/core/Plugin/Controller.php +++ b/core/Plugin/Controller.php @@ -17,7 +17,8 @@ use Piwik\Config as PiwikConfig; use Piwik\Config; use Piwik\DataTable\Filter\CalculateEvolutionFilter; use Piwik\Date; -use Piwik\Exceptions\HtmlMessageException; +use Piwik\Exception\NoPrivilegesException; +use Piwik\Exception\NoWebsiteFoundException; use Piwik\FrontController; use Piwik\Menu\MenuTop; use Piwik\Menu\MenuUser; @@ -841,16 +842,22 @@ abstract class Controller $message = "Error: no website was found in this Piwik installation. <br />Check the table '$siteTableName' in your database, it should contain your Piwik websites."; - throw new HtmlMessageException($message); + $ex = new NoWebsiteFoundException($message); + $ex->setIsHtmlMessage(); + + throw $ex; } if (!Piwik::isUserIsAnonymous()) { $currentLogin = Piwik::getCurrentUserLogin(); $emails = implode(',', Piwik::getAllSuperUserAccessEmailAddresses()); - $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . $emails . "?subject=Access to Piwik for user $currentLogin'>", "</a>"); + $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . $emails . "?subject=Access to Piwik for user $currentLogin'>", "</a>"); $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Registry::get('auth')->getName() . "&action=logout'>› " . Piwik::translate('General_Logout') . "</a></b><br />"; - throw new HtmlMessageException($errorMessage); + $ex = new NoPrivilegesException($errorMessage); + $ex->setIsHtmlMessage(); + + throw $ex; } echo FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false); diff --git a/core/Session.php b/core/Session.php index 24595cd764..d267ebd0b3 100644 --- a/core/Session.php +++ b/core/Session.php @@ -9,7 +9,7 @@ namespace Piwik; use Exception; -use Piwik\Exceptions\HtmlMessageException; +use Piwik\Exception\MissingFilePermissionException; use Piwik\Session\SaveHandler\DbTable; use Zend_Session; @@ -132,7 +132,10 @@ class Session extends Zend_Session $e->getMessage() ); - throw new HtmlMessageException($message, $e->getCode(), $e); + $ex = new MissingFilePermissionException($message, $e->getCode(), $e); + $ex->setIsHtmlMessage(); + + throw $ex; } } diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index b87fc91579..02020c710d 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -11,7 +11,7 @@ namespace Piwik\Plugins\CorePluginsAdmin; use Exception; use Piwik\API\Request; use Piwik\Common; -use Piwik\Exceptions\HtmlMessageException; +use Piwik\Exception\MissingFilePermissionException; use Piwik\Filechecks; use Piwik\Filesystem; use Piwik\Nonce; @@ -444,10 +444,13 @@ class Controller extends Plugin\ControllerAdmin $messageIntro = Piwik::translate("Warning: \"%s\" could not be uninstalled. Piwik did not have enough permission to delete the files in $path. ", $pluginName); - $exitMessage = $messageIntro . "<br/><br/>" . $messagePermissions; + $exitMessage = $messageIntro . "<br/><br/>" . $messagePermissions; $exitMessage .= "<br> Or manually delete this directory (using FTP or SSH access)"; - throw new HtmlMessageException($exitMessage); + $ex = new MissingFilePermissionException($exitMessage); + $ex->setIsHtmlMessage(); + + throw $ex; } $this->redirectAfterModification($redirectAfter); diff --git a/plugins/Installation/Exception/DatabaseConnectionFailedException.php b/plugins/Installation/Exception/DatabaseConnectionFailedException.php new file mode 100644 index 0000000000..b5883f0f6d --- /dev/null +++ b/plugins/Installation/Exception/DatabaseConnectionFailedException.php @@ -0,0 +1,15 @@ +<?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\Plugins\Installation\Exception; + +use Piwik\Exception\Exception; + +class DatabaseConnectionFailedException extends Exception +{ +}
\ No newline at end of file diff --git a/plugins/Installation/Installation.php b/plugins/Installation/Installation.php index 8bd1a00fab..427d3d502e 100644 --- a/plugins/Installation/Installation.php +++ b/plugins/Installation/Installation.php @@ -10,9 +10,9 @@ namespace Piwik\Plugins\Installation; use Piwik\Common; use Piwik\Config; -use Piwik\Exceptions\HtmlMessageException; use Piwik\FrontController; use Piwik\Piwik; +use Piwik\Plugins\Installation\Exception\DatabaseConnectionFailedException; use Piwik\Translate; use Piwik\View as PiwikView; @@ -43,7 +43,10 @@ class Installation extends \Piwik\Plugin $view = new PiwikView("@Installation/cannotConnectToDb"); $view->exceptionMessage = $exception->getMessage(); - throw new HtmlMessageException($view->render()); + $ex = new DatabaseConnectionFailedException($view->render()); + $ex->setIsHtmlMessage(); + + throw $ex; } public function dispatchIfNotInstalledYet(&$module, &$action, &$parameters) |