From 439fade88df235408f1f6f24cd34ce20c1f3c8ee Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Thu, 29 Aug 2013 16:30:22 +0200 Subject: [PATCH] Simplify SystemPermissionException refs #4606 --- application/views/scripts/error/error.phtml | 14 +---- .../Icinga/Application/Modules/Manager.php | 59 +++++++++++++------ .../Exception/SystemPermissionException.php | 20 ++----- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/application/views/scripts/error/error.phtml b/application/views/scripts/error/error.phtml index 149109e98..f9c73e026 100755 --- a/application/views/scripts/error/error.phtml +++ b/application/views/scripts/error/error.phtml @@ -11,16 +11,6 @@

Message: exception->getMessage(); ?> - - exception->action)): ?> -
- Action: exception->action; ?> - - - exception->action)): ?> -
- Target: exception->target; ?> -

Stack trace:

@@ -29,8 +19,8 @@

Request Parameters:

-
getParams(), true) ?>
+      
getParams(), true); ?>
     
- + diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 3a83affc9..9a5d37638 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -1,5 +1,29 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ // {{{ICINGA_LICENSE_HEADER}}} namespace Icinga\Application\Modules; @@ -7,6 +31,8 @@ namespace Icinga\Application\Modules; use \Icinga\Application\ApplicationBootstrap; use \Icinga\Application\Icinga; use \Icinga\Application\Logger; +use \Icinga\Data\ArrayDatasource; +use \Icinga\Data\ArrayQuery; use \Icinga\Exception\ConfigurationError; use \Icinga\Exception\SystemPermissionException; use \Icinga\Exception\ProgrammingError; @@ -27,9 +53,9 @@ class Manager * * null if modules haven't been scanned yet * - * @var array|null + * @var array */ - private $installedBaseDirs = null; + private $installedBaseDirs = array(); /** * Array of all enabled modules base dirs @@ -112,11 +138,11 @@ class Manager /** * Query interface for the module manager * - * @return \Icinga\Data\ArrayQuery + * @return ArrayQuery */ public function select() { - $source = new \Icinga\Data\ArrayDatasource($this->getModuleInfo()); + $source = new ArrayDatasource($this->getModuleInfo()); return $source->select(); } @@ -205,8 +231,8 @@ class Manager * @param string $name The module to enable * * @return self - * @throws \Icinga\Exception\ConfigurationError When trying to enable a module that is not installed - * @throws \Icinga\Exception\SystemPermissionException When insufficient permissions for the application exist + * @throws ConfigurationError When trying to enable a module that is not installed + * @throws SystemPermissionException When insufficient permissions for the application exist */ public function enableModule($name) { @@ -224,9 +250,7 @@ class Manager $link = $this->enableDir . '/' . $name; if (!is_writable($this->enableDir)) { throw new SystemPermissionException( - "Insufficient system permissions for enabling modules", - "write", - $this->enableDir + "Insufficient system permissions for enabling modules" ); } if (file_exists($link) && is_link($link)) { @@ -235,7 +259,7 @@ class Manager if (!@symlink($target, $link)) { $error = error_get_last(); if (strstr($error["message"], "File exists") === false) { - throw new SystemPermissionException($error["message"], "symlink", $link); + throw new SystemPermissionException($error["message"]); } } $this->enabledDirs[$name] = $link; @@ -249,8 +273,8 @@ class Manager * * @return self * - * @throws \Icinga\Exception\ConfigurationError When the module is not installed or it's not symlinked - * @throws \Icinga\Exception\SystemPermissionException When the module can't be disabled + * @throws ConfigurationError When the module is not installed or it's not symlinked + * @throws SystemPermissionException When the module can't be disabled */ public function disableModule($name) { @@ -258,8 +282,7 @@ class Manager return $this; } if (!is_writable($this->enableDir)) { - throw new SystemPermissionException("Can't write the module directory", "write", $this->enableDir); - return $this; + throw new SystemPermissionException("Can't write the module directory"); } $link = $this->enableDir . '/' . $name; if (!file_exists($link)) { @@ -277,7 +300,7 @@ class Manager if (file_exists($link) && is_link($link)) { if (!@unlink($link)) { $error = error_get_last(); - throw new SystemPermissionException($error['message'], 'unlink', $link); + throw new SystemPermissionException($error['message']); } } else { @@ -323,7 +346,7 @@ class Manager */ public function hasInstalled($name) { - if ($this->installedBaseDirs === null) { + if (!count($this->installedBaseDirs)) { $this->detectInstalledModules(); } return array_key_exists($name, $this->installedBaseDirs); @@ -449,11 +472,11 @@ class Manager */ public function listInstalledModules() { - if ($this->installedBaseDirs === null) { + if (!count($this->installedBaseDirs)) { $this->detectInstalledModules(); } - if ($this->installedBaseDirs !== null) { + if (count($this->installedBaseDirs)) { return array_keys($this->installedBaseDirs); } } diff --git a/library/Icinga/Exception/SystemPermissionException.php b/library/Icinga/Exception/SystemPermissionException.php index e2193a087..5dde6936a 100644 --- a/library/Icinga/Exception/SystemPermissionException.php +++ b/library/Icinga/Exception/SystemPermissionException.php @@ -28,19 +28,11 @@ namespace Icinga\Exception; -/** - * Class ProgrammingError - * @package Icinga\Exception - */ -class SystemPermissionException extends \Exception -{ - public $action; - public $target; +use \Exception; - public function __construct($message, $action, $target = "") - { - parent::__construct($message); - $this->action = $action; - $this->target = $target; - } +/** + * Handle problems according to file system permissions + */ +class SystemPermissionException extends Exception +{ }