From 9647293f1b687d70703de88584fcf5fae895fab7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 18 Dec 2014 17:11:30 +0100 Subject: [PATCH 001/157] Add our own dispatcher prototype for namespaced controllers refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 library/Icinga/Web/Controller/Dispatcher.php diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php new file mode 100644 index 000000000..51e492ab5 --- /dev/null +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -0,0 +1,62 @@ +setResponse($response); + $controllerName = $request->getControllerName(); + if (! $controllerName) { + throw new LogicException('Controller name not found'); + } + $controllerName = ucfirst($controllerName) . 'Controller'; + if ($this->_defaultModule === $this->_curModule) { + $controllerClass = 'Icinga\\Controllers\\' . $controllerName; + } else { + $controllerClass = 'Icinga\\Module\\' . $this->_curModule . '\\Controllers\\' . $controllerName; + } + if (! class_exists($controllerClass)) { + return parent::dispatch($request, $response); + } + $controller = new $controllerClass($request, $response, $this->getParams()); + $actionName = $request->getActionName(); + if (! $actionName) { + throw new LogicException('Action name not found'); + } + $actionName = $actionName . 'Action'; + $request->setDispatched(true); + // Buffer output by default + $disableOb = $this->getParam('disableOutputBuffering'); + $obLevel = ob_get_level(); + if (empty($disableOb)) { + ob_start(); + } + try { + $controller->dispatch($actionName); + } catch (Exception $e) { + // Clean output buffer on error + $curObLevel = ob_get_level(); + if ($curObLevel > $obLevel) { + do { + ob_get_clean(); + $curObLevel = ob_get_level(); + } while ($curObLevel > $obLevel); + } + throw $e; + } + if (empty($disableOb)) { + $content = ob_get_clean(); + $response->appendBody($content); + } + } +} From fdd06697b3778be0c0911449f434444a6c5eb149 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 18 Dec 2014 17:12:11 +0100 Subject: [PATCH 002/157] Web: Use our own dispatcher refs #5786 --- library/Icinga/Application/Web.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 37ec5138a..fefb14fef 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -12,6 +12,7 @@ use Icinga\Exception\ConfigurationError; use Icinga\Exception\NotReadableError; use Icinga\Application\Logger; use Icinga\Util\TimezoneDetect; +use Icinga\Web\Controller\Dispatcher; use Icinga\Web\Request; use Icinga\Web\Response; use Icinga\Web\View; @@ -232,6 +233,8 @@ class Web extends ApplicationBootstrap { $this->frontController = Zend_Controller_Front::getInstance(); + $this->frontController->setDispatcher(new Dispatcher()); + $this->frontController->setRequest($this->request); $this->frontController->setControllerDirectory($this->getApplicationDir('/controllers')); @@ -335,6 +338,10 @@ class Web extends ApplicationBootstrap 'Icinga\\Forms', $this->getApplicationDir('forms') ); + $this->getLoader()->registerNamespace( + 'Icinga\\Controllers', + $this->getApplicationDir('controllers') + ); return $this; } } From f972a034e798abe68e115f37f54ebef172e6229a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:08:41 +0200 Subject: [PATCH 003/157] Fix license header in Dispatcher refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index 51e492ab5..54384baf9 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -1,6 +1,5 @@ Date: Mon, 17 Aug 2015 13:10:01 +0200 Subject: [PATCH 004/157] Add PHPDoc to the Dispatcher refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index 54384baf9..923f3072a 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -9,8 +9,14 @@ use Zend_Controller_Dispatcher_Standard; use Zend_Controller_Request_Abstract; use Zend_Controller_Response_Abstract; +/** + * Dispatcher supporting Zend-style and namespaced controllers + */ class Dispatcher extends Zend_Controller_Dispatcher_Standard { + /** + * {@inheritdoc} + */ public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response) { $this->setResponse($response); From d4de7c0519f6ea63caaec525e933ff6916eb5add Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:29:15 +0200 Subject: [PATCH 005/157] lib: Make Loader::registerNamespace() fluent refs #5786 --- library/Icinga/Application/Loader.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/Icinga/Application/Loader.php b/library/Icinga/Application/Loader.php index 8c1c0b9e7..a0564667b 100644 --- a/library/Icinga/Application/Loader.php +++ b/library/Icinga/Application/Loader.php @@ -33,6 +33,7 @@ class Loader * @param string $namespace * @param string $directory * + * @return $this * @throws ProgrammingError */ public function registerNamespace($namespace, $directory) @@ -46,6 +47,8 @@ class Loader } $this->namespaces[$namespace] = $directory; + + return $this; } /** From 8b32edd6e9339a21cf1d1ff6f86f1f8a11e675ad Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:29:47 +0200 Subject: [PATCH 006/157] Default to Zend's dispatcher if the controller name is empty refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index 923f3072a..853e1c3e0 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -11,18 +11,23 @@ use Zend_Controller_Response_Abstract; /** * Dispatcher supporting Zend-style and namespaced controllers + * + * Does not support a namespaced default controller in combination w/ the Zend parameter useDefaultControllerAlways. */ class Dispatcher extends Zend_Controller_Dispatcher_Standard { /** - * {@inheritdoc} + * Dispatch request to a controller and action + * + * @param Zend_Controller_Request_Abstract $request + * @param Zend_Controller_Response_Abstract $resposne */ public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response) { $this->setResponse($response); $controllerName = $request->getControllerName(); if (! $controllerName) { - throw new LogicException('Controller name not found'); + return parent::dispatch($request, $response); } $controllerName = ucfirst($controllerName) . 'Controller'; if ($this->_defaultModule === $this->_curModule) { From 965fee1e9e5b951549285b5ccfbeb348b3b7817d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:31:05 +0200 Subject: [PATCH 007/157] Fix 'void' method result used in the Dispatcher refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index 853e1c3e0..d1e0bdb82 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -27,7 +27,8 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard $this->setResponse($response); $controllerName = $request->getControllerName(); if (! $controllerName) { - return parent::dispatch($request, $response); + parent::dispatch($request, $response); + return; } $controllerName = ucfirst($controllerName) . 'Controller'; if ($this->_defaultModule === $this->_curModule) { @@ -36,7 +37,8 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard $controllerClass = 'Icinga\\Module\\' . $this->_curModule . '\\Controllers\\' . $controllerName; } if (! class_exists($controllerClass)) { - return parent::dispatch($request, $response); + parent::dispatch($request, $response); + return; } $controller = new $controllerClass($request, $response, $this->getParams()); $actionName = $request->getActionName(); From 1e1d4531c698442aa8d6db8bd14635a9e621ff49 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:31:26 +0200 Subject: [PATCH 008/157] Register the controller namespace refs #5786 --- library/Icinga/Application/Web.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index ed9ba5c8f..5556b4cd4 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -89,7 +89,7 @@ class Web extends EmbeddedWeb ->setupLogger() ->setupInternationalization() ->setupZendMvc() - ->setupFormNamespace() + ->setupNamespaces() ->setupModuleManager() ->setupUserBackendFactory() ->loadSetupModuleIfNecessary() @@ -298,16 +298,22 @@ class Web extends EmbeddedWeb } /** - * Setup an autoloader namespace for Icinga\Forms + * Setup auto loader namespaces for Icinga\Controllers and Icinga\Forms * * @return $this */ - private function setupFormNamespace() + private function setupNamespaces() { - $this->getLoader()->registerNamespace( - 'Icinga\\Forms', - $this->getApplicationDir('forms') - ); + $this + ->getLoader() + ->registerNamespace( + 'Icinga\\Controllers', + $this->getApplicationDir('controllers') + ) + ->registerNamespace( + 'Icinga\\Forms', + $this->getApplicationDir('forms') + ); return $this; } } From e26a7fd4d15bd5c3aa6aed3c0a0762874e6a3a48 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:34:47 +0200 Subject: [PATCH 009/157] Use Zend_Cotroller_Dispatcher_Standard::getActionMethod() in the Dispatcher refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index d1e0bdb82..c96805fa1 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -4,7 +4,6 @@ namespace Icinga\Web\Controller; use Exception; -use LogicException; use Zend_Controller_Dispatcher_Standard; use Zend_Controller_Request_Abstract; use Zend_Controller_Response_Abstract; @@ -19,8 +18,10 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard /** * Dispatch request to a controller and action * - * @param Zend_Controller_Request_Abstract $request - * @param Zend_Controller_Response_Abstract $resposne + * @param Zend_Controller_Request_Abstract $request + * @param Zend_Controller_Response_Abstract $response + * + * @throws Exception If dispatching the request fails */ public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response) { @@ -41,11 +42,7 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard return; } $controller = new $controllerClass($request, $response, $this->getParams()); - $actionName = $request->getActionName(); - if (! $actionName) { - throw new LogicException('Action name not found'); - } - $actionName = $actionName . 'Action'; + $action = $this->getActionMethod($request); $request->setDispatched(true); // Buffer output by default $disableOb = $this->getParam('disableOutputBuffering'); @@ -54,7 +51,7 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard ob_start(); } try { - $controller->dispatch($actionName); + $controller->dispatch($action); } catch (Exception $e) { // Clean output buffer on error $curObLevel = ob_get_level(); From 06e879f078600c8937d0317af72ade4a7e4a4091 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:38:16 +0200 Subject: [PATCH 010/157] Throw an expcetion in our Dispatcher if the controller is not an instance of Zend_Controller_Action_Interface refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index c96805fa1..efa0e02b2 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -4,6 +4,9 @@ namespace Icinga\Web\Controller; use Exception; +use Zend_Controller_Action; +use Zend_Controller_Action_Interface; +use Zend_Controller_Dispatcher_Exception; use Zend_Controller_Dispatcher_Standard; use Zend_Controller_Request_Abstract; use Zend_Controller_Response_Abstract; @@ -21,7 +24,9 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard * @param Zend_Controller_Request_Abstract $request * @param Zend_Controller_Response_Abstract $response * - * @throws Exception If dispatching the request fails + * @throws Zend_Controller_Dispatcher_Exception If the controller is not an instance of + * Zend_Controller_Action_Interface + * @throws Exception If dispatching the request fails */ public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response) { @@ -42,6 +47,13 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard return; } $controller = new $controllerClass($request, $response, $this->getParams()); + if (! $controller instanceof Zend_Controller_Action + && ! $controller instanceof Zend_Controller_Action_Interface + ) { + throw new Zend_Controller_Dispatcher_Exception( + 'Controller "' . $controllerClass . '" is not an instance of Zend_Controller_Action_Interface' + ); + } $action = $this->getActionMethod($request); $request->setDispatched(true); // Buffer output by default From 7252f3237aeddd2adec515c91a16a25dca43aee8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 13:43:34 +0200 Subject: [PATCH 011/157] Introduce a constant for the controller namespace refs #5786 --- library/Icinga/Application/Web.php | 2 +- library/Icinga/Web/Controller/Dispatcher.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 5556b4cd4..85ad0949e 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -307,7 +307,7 @@ class Web extends EmbeddedWeb $this ->getLoader() ->registerNamespace( - 'Icinga\\Controllers', + 'Icinga\\' . Dispatcher::CONTROLLER_NAMESPACE, $this->getApplicationDir('controllers') ) ->registerNamespace( diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index efa0e02b2..6e1f32e02 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -18,6 +18,13 @@ use Zend_Controller_Response_Abstract; */ class Dispatcher extends Zend_Controller_Dispatcher_Standard { + /** + * Controller namespace + * + * @var string + */ + const CONTROLLER_NAMESPACE = 'Controller'; + /** * Dispatch request to a controller and action * @@ -38,9 +45,10 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard } $controllerName = ucfirst($controllerName) . 'Controller'; if ($this->_defaultModule === $this->_curModule) { - $controllerClass = 'Icinga\\Controllers\\' . $controllerName; + $controllerClass = 'Icinga\\' . self::CONTROLLER_NAMESPACE . '\\' . $controllerName; } else { - $controllerClass = 'Icinga\\Module\\' . $this->_curModule . '\\Controllers\\' . $controllerName; + $controllerClass = 'Icinga\\Module\\' . $this->_curModule . '\\' . self::CONTROLLER_NAMESPACE . '\\' + . $controllerName; } if (! class_exists($controllerClass)) { parent::dispatch($request, $response); From 7563a7a0baa6c74dde7ca44b2d262f78449a3000 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 14:34:39 +0200 Subject: [PATCH 012/157] Rename Loader::unRegister() to Loader::register() --- library/Icinga/Application/Loader.php | 4 ++-- test/php/library/Icinga/Application/LoaderTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Application/Loader.php b/library/Icinga/Application/Loader.php index a0564667b..d3cd0ef40 100644 --- a/library/Icinga/Application/Loader.php +++ b/library/Icinga/Application/Loader.php @@ -24,7 +24,7 @@ class Loader */ public function __destruct() { - $this->unRegister(); + $this->unregister(); } /** @@ -134,7 +134,7 @@ class Loader /** * Detach autoloader from spl registration */ - public function unRegister() + public function unregister() { spl_autoload_unregister(array(&$this, 'loadClass')); } diff --git a/test/php/library/Icinga/Application/LoaderTest.php b/test/php/library/Icinga/Application/LoaderTest.php index 3ae94f8d3..2b6fdd977 100644 --- a/test/php/library/Icinga/Application/LoaderTest.php +++ b/test/php/library/Icinga/Application/LoaderTest.php @@ -56,7 +56,7 @@ EOD; } $this->assertTrue($check); - $loader->unRegister(); + $loader->unregister(); $check = true; foreach (spl_autoload_functions() as $functions) { From b6fdbf055e44da3f94853e66b108daf7b7d97a90 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 17 Aug 2015 14:35:35 +0200 Subject: [PATCH 013/157] Remove unnecessary pass by refenrece in the loader refs #5786 --- library/Icinga/Application/Loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Application/Loader.php b/library/Icinga/Application/Loader.php index d3cd0ef40..70f2877ed 100644 --- a/library/Icinga/Application/Loader.php +++ b/library/Icinga/Application/Loader.php @@ -128,7 +128,7 @@ class Loader { // Think about to add class pathes to php include path // this could be faster (tg) - spl_autoload_register(array(&$this, 'loadClass')); + spl_autoload_register(array($this, 'loadClass')); } /** @@ -136,6 +136,6 @@ class Loader */ public function unregister() { - spl_autoload_unregister(array(&$this, 'loadClass')); + spl_autoload_unregister(array($this, 'loadClass')); } } From 13fc7e16f2fb875c8b4b07c39cbd861f403f9653 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 09:06:58 +0200 Subject: [PATCH 014/157] Rename Loader to ClassLoader refs #5786 --- library/Icinga/Application/ApplicationBootstrap.php | 8 ++++---- .../Application/{Loader.php => ClassLoader.php} | 2 +- test/php/bootstrap.php | 4 ++-- test/php/library/Icinga/Application/LoaderTest.php | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) rename library/Icinga/Application/{Loader.php => ClassLoader.php} (99%) diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index a8d185023..ab18e35a5 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -80,7 +80,7 @@ abstract class ApplicationBootstrap /** * Icinga auto loader * - * @var Loader + * @var ClassLoader */ private $loader; @@ -183,7 +183,7 @@ abstract class ApplicationBootstrap /** * Getter for class loader * - * @return Loader + * @return ClassLoader */ public function getLoader() { @@ -345,9 +345,9 @@ abstract class ApplicationBootstrap */ public function setupAutoloader() { - require $this->libDir . '/Icinga/Application/Loader.php'; + require $this->libDir . '/Icinga/Application/ClassLoader.php'; - $this->loader = new Loader(); + $this->loader = new ClassLoader(); $this->loader->registerNamespace('Icinga', $this->libDir. '/Icinga'); $this->loader->register(); diff --git a/library/Icinga/Application/Loader.php b/library/Icinga/Application/ClassLoader.php similarity index 99% rename from library/Icinga/Application/Loader.php rename to library/Icinga/Application/ClassLoader.php index 70f2877ed..051c2ae12 100644 --- a/library/Icinga/Application/Loader.php +++ b/library/Icinga/Application/ClassLoader.php @@ -5,7 +5,7 @@ namespace Icinga\Application; use Icinga\Exception\ProgrammingError; -class Loader +class ClassLoader { /** * Namespace separator diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php index 6a41e7eab..4757c5018 100644 --- a/test/php/bootstrap.php +++ b/test/php/bootstrap.php @@ -22,9 +22,9 @@ require_once 'Mockery/Loader.php'; $mockeryLoader = new \Mockery\Loader; $mockeryLoader->register(); -require_once($libraryPath . '/Icinga/Application/Loader.php'); +require_once($libraryPath . '/Icinga/Application/ClassLoader.php'); -$loader = new Icinga\Application\Loader(); +$loader = new Icinga\Application\ClassLoader(); $loader->registerNamespace('Tests', $testLibraryPath); $loader->registerNamespace('Icinga', $libraryPath . '/Icinga'); $loader->registerNamespace('Icinga\\Forms', $applicationPath . '/forms'); diff --git a/test/php/library/Icinga/Application/LoaderTest.php b/test/php/library/Icinga/Application/LoaderTest.php index 2b6fdd977..ec62a5975 100644 --- a/test/php/library/Icinga/Application/LoaderTest.php +++ b/test/php/library/Icinga/Application/LoaderTest.php @@ -4,7 +4,7 @@ namespace Tests\Icinga\Application; use Icinga\Test\BaseTestCase; -use Icinga\Application\Loader; +use Icinga\Application\ClassLoader; class LoaderTest extends BaseTestCase { @@ -43,7 +43,7 @@ EOD; public function testObjectCreation1() { - $loader = new Loader(); + $loader = new ClassLoader(); $loader->register(); $check = false; @@ -71,7 +71,7 @@ EOD; public function testNamespaces() { - $loader = new Loader(); + $loader = new ClassLoader(); $loader->registerNamespace('Test\\Laola', '/tmp'); $loader->registerNamespace('Dings\\Var', '/var/tmp'); @@ -89,7 +89,7 @@ EOD; $classFile = $this->baseDir. self::$classFile; $this->assertFileExists($classFile); - $loader = new Loader(); + $loader = new ClassLoader(); $loader->registerNamespace('My\\Library', dirname($classFile)); $this->assertFalse($loader->loadClass('DOES\\NOT\\EXISTS')); $this->assertTrue($loader->loadClass('My\\Library\\TestStruct')); @@ -100,7 +100,7 @@ EOD; $classFile = $this->baseDir. self::$classFile; $this->assertFileExists($classFile); - $loader = new Loader(); + $loader = new ClassLoader(); $loader->registerNamespace('My\\Library', dirname($classFile)); $loader->register(); @@ -113,7 +113,7 @@ EOD; */ public function testNonexistingDirectory() { - $loader = new Loader(); + $loader = new ClassLoader(); $loader->registerNamespace('My\\Library', '/trullalla/123'); } } From a382a563d512fbd0c9e7bf6bb47c77767e230784 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 09:10:23 +0200 Subject: [PATCH 015/157] Move Loader::__destruct to the bottom of the method list refs #5786 --- library/Icinga/Application/ClassLoader.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Application/ClassLoader.php b/library/Icinga/Application/ClassLoader.php index 051c2ae12..17d7e9e33 100644 --- a/library/Icinga/Application/ClassLoader.php +++ b/library/Icinga/Application/ClassLoader.php @@ -19,14 +19,6 @@ class ClassLoader */ private $namespaces = array(); - /** - * Detach spl autoload method from stack - */ - public function __destruct() - { - $this->unregister(); - } - /** * Register new namespace for directory * @@ -138,4 +130,12 @@ class ClassLoader { spl_autoload_unregister(array($this, 'loadClass')); } + + /** + * Detach spl autoload method from stack + */ + public function __destruct() + { + $this->unregister(); + } } From ac99e54f17295e58183c1e3ce94982eaeaabc0fe Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 09:27:34 +0200 Subject: [PATCH 016/157] Fix PHPDoc in ClassLoader refs #5786 --- library/Icinga/Application/ClassLoader.php | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/library/Icinga/Application/ClassLoader.php b/library/Icinga/Application/ClassLoader.php index 17d7e9e33..e31aa49af 100644 --- a/library/Icinga/Application/ClassLoader.php +++ b/library/Icinga/Application/ClassLoader.php @@ -5,6 +5,9 @@ namespace Icinga\Application; use Icinga\Exception\ProgrammingError; +/** + * PSR-4 class loader + */ class ClassLoader { /** @@ -13,14 +16,14 @@ class ClassLoader const NAMESPACE_SEPARATOR = '\\'; /** - * List of namespaces + * Namespaces * * @var array */ private $namespaces = array(); /** - * Register new namespace for directory + * Register a base directory for a namespace prefix * * @param string $namespace * @param string $directory @@ -44,9 +47,9 @@ class ClassLoader } /** - * Test if a namespace exists + * Test whether a namespace exists * - * @param string $namespace + * @param string $namespace * * @return bool */ @@ -56,13 +59,11 @@ class ClassLoader } /** - * Class loader + * Load the given class or interface * - * Ignores all but classes in registered namespaces. + * @param string $class Name of the class or interface * - * @param string $class - * - * @return boolean + * @return bool Whether the class or interface has been loaded */ public function loadClass($class) { @@ -82,7 +83,7 @@ class ClassLoader } /** - * Test if we have a registered namespaces for this class + * Get the namespace for the given class * * Return is the longest match in the array found * @@ -114,17 +115,15 @@ class ClassLoader } /** - * Effectively registers the autoloader the PHP/SPL way + * Register {@link loadClass()} as an autoloader */ public function register() { - // Think about to add class pathes to php include path - // this could be faster (tg) spl_autoload_register(array($this, 'loadClass')); } /** - * Detach autoloader from spl registration + * Unregister {@link loadClass()} as an autoloader */ public function unregister() { @@ -132,7 +131,7 @@ class ClassLoader } /** - * Detach spl autoload method from stack + * Unregister this as an autloader */ public function __destruct() { From 5ecde41ba3b2343559c94a05ec82351d602f0313 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 09:31:26 +0200 Subject: [PATCH 017/157] Rename LoaderTest to ClassLoaderTest refs #5786 --- .../Icinga/Application/{LoaderTest.php => ClassLoaderTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename test/php/library/Icinga/Application/{LoaderTest.php => ClassLoaderTest.php} (98%) diff --git a/test/php/library/Icinga/Application/LoaderTest.php b/test/php/library/Icinga/Application/ClassLoaderTest.php similarity index 98% rename from test/php/library/Icinga/Application/LoaderTest.php rename to test/php/library/Icinga/Application/ClassLoaderTest.php index ec62a5975..ebc3c7572 100644 --- a/test/php/library/Icinga/Application/LoaderTest.php +++ b/test/php/library/Icinga/Application/ClassLoaderTest.php @@ -6,7 +6,7 @@ namespace Tests\Icinga\Application; use Icinga\Test\BaseTestCase; use Icinga\Application\ClassLoader; -class LoaderTest extends BaseTestCase +class ClassLoaderTest extends BaseTestCase { private static $classFile = 'test/My/Library/TestStruct.php'; From 234dc951d26f5991b74f513adeacf3ef022aa7e5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 09:32:00 +0200 Subject: [PATCH 018/157] Remove the is_dir check from the ClassLoader refs #5786 --- library/Icinga/Application/ClassLoader.php | 9 --------- test/php/library/Icinga/Application/ClassLoaderTest.php | 9 --------- 2 files changed, 18 deletions(-) diff --git a/library/Icinga/Application/ClassLoader.php b/library/Icinga/Application/ClassLoader.php index e31aa49af..ab3326f84 100644 --- a/library/Icinga/Application/ClassLoader.php +++ b/library/Icinga/Application/ClassLoader.php @@ -29,18 +29,9 @@ class ClassLoader * @param string $directory * * @return $this - * @throws ProgrammingError */ public function registerNamespace($namespace, $directory) { - if (!is_dir($directory)) { - throw new ProgrammingError( - 'Directory "%s" for namespace "%s" does not exist', - $directory, - $namespace - ); - } - $this->namespaces[$namespace] = $directory; return $this; diff --git a/test/php/library/Icinga/Application/ClassLoaderTest.php b/test/php/library/Icinga/Application/ClassLoaderTest.php index ebc3c7572..86975df43 100644 --- a/test/php/library/Icinga/Application/ClassLoaderTest.php +++ b/test/php/library/Icinga/Application/ClassLoaderTest.php @@ -107,13 +107,4 @@ EOD; $o = new \My\Library\TestStruct(); $this->assertTrue($o->testFlag()); } - - /** - * @expectedException Icinga\Exception\ProgrammingError - */ - public function testNonexistingDirectory() - { - $loader = new ClassLoader(); - $loader->registerNamespace('My\\Library', '/trullalla/123'); - } } From fae2e0979a06f900a371266cb998a424e5be70cb Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 10:50:29 +0200 Subject: [PATCH 019/157] Fix class loading to not rely on the longest namespace match refs #5786 --- library/Icinga/Application/ClassLoader.php | 74 ++++++++-------------- 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/library/Icinga/Application/ClassLoader.php b/library/Icinga/Application/ClassLoader.php index ab3326f84..3247d3250 100644 --- a/library/Icinga/Application/ClassLoader.php +++ b/library/Icinga/Application/ClassLoader.php @@ -3,8 +3,6 @@ namespace Icinga\Application; -use Icinga\Exception\ProgrammingError; - /** * PSR-4 class loader */ @@ -49,6 +47,30 @@ class ClassLoader return array_key_exists($namespace, $this->namespaces); } + /** + * Get the source file of the given class or interface + * + * @param string $class Name of the class or interface + * + * @return string|null + */ + public function getSourceFile($class) + { + foreach ($this->namespaces as $namespace => $dir) { + if ($class === strstr($class, $namespace)) { + $classPath = str_replace( + self::NAMESPACE_SEPARATOR, + DIRECTORY_SEPARATOR, + substr($class, strlen($namespace)) + ) . '.php'; + if (file_exists($file = $dir . $classPath)) { + return $file; + } + } + } + return null; + } + /** * Load the given class or interface * @@ -58,50 +80,10 @@ class ClassLoader */ public function loadClass($class) { - $namespace = $this->getNamespaceForClass($class); - - if ($namespace) { - $file = $this->namespaces[$namespace] . preg_replace('/^' . preg_quote($namespace) . '/', '', $class); - $file = str_replace(self::NAMESPACE_SEPARATOR, '/', $file) . '.php'; - - if (@file_exists($file)) { - require_once $file; - return true; - } + if ($file = $this->getSourceFile($class)) { + require $file; + return true; } - - return false; - } - - /** - * Get the namespace for the given class - * - * Return is the longest match in the array found - * - * @param string $className - * - * @return bool|string - */ - private function getNamespaceForClass($className) - { - $testNamespace = ''; - $testLength = 0; - - foreach (array_keys($this->namespaces) as $namespace) { - $stub = preg_replace( - '/^' . preg_quote($namespace) . '(' . preg_quote(self::NAMESPACE_SEPARATOR) . '|$)/', '', $className - ); - $length = strlen($className) - strlen($stub); - if ($length > $testLength) { - $testLength = $length; - $testNamespace = $namespace; - } - } - - if ($testLength > 0) { - return $testNamespace; - } - return false; } @@ -122,7 +104,7 @@ class ClassLoader } /** - * Unregister this as an autloader + * Unregister this as an autoloader */ public function __destruct() { From e31dce97a9bd1fc0d4ff6b6bf431f98b81c2a5c8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 11:11:28 +0200 Subject: [PATCH 020/157] Fix dispatching namespaced module controllers refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index 6e1f32e02..b7f8d2c5e 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -44,10 +44,10 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard return; } $controllerName = ucfirst($controllerName) . 'Controller'; - if ($this->_defaultModule === $this->_curModule) { + if ($this->_defaultModule === $moduleName = $request->getModuleName()) { $controllerClass = 'Icinga\\' . self::CONTROLLER_NAMESPACE . '\\' . $controllerName; } else { - $controllerClass = 'Icinga\\Module\\' . $this->_curModule . '\\' . self::CONTROLLER_NAMESPACE . '\\' + $controllerClass = 'Icinga\\Module\\' . ucfirst($moduleName) . '\\' . self::CONTROLLER_NAMESPACE . '\\' . $controllerName; } if (! class_exists($controllerClass)) { From cb8fb93ab0a11afe4635f274ed956637bfeebcbe Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 12:50:46 +0200 Subject: [PATCH 021/157] Fix PHPDoc in ApplicationBootstrap to read class loader instead of auto loader refs #5786 --- library/Icinga/Application/ApplicationBootstrap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index ab18e35a5..c46aa3a27 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -78,7 +78,7 @@ abstract class ApplicationBootstrap protected $configDir; /** - * Icinga auto loader + * Icinga class loader * * @var ClassLoader */ @@ -339,7 +339,7 @@ abstract class ApplicationBootstrap } /** - * Setup Icinga auto loader + * Setup Icinga class loader * * @return $this */ From d267686ef45f45f1fb0e44bb5e54dec065ea273b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 12:51:46 +0200 Subject: [PATCH 022/157] Fix PHPDoc in Web to read class loader instead of auto loader refs #5786 --- library/Icinga/Application/Web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 85ad0949e..d77afc0d8 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -298,7 +298,7 @@ class Web extends EmbeddedWeb } /** - * Setup auto loader namespaces for Icinga\Controllers and Icinga\Forms + * Setup class loader namespaces for Icinga\Controllers and Icinga\Forms * * @return $this */ From 3c812e6d2b09a77e5a0026b55f3482bcc3cc5038 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 13:02:54 +0200 Subject: [PATCH 023/157] Register module controller namespace refs #5786 --- library/Icinga/Application/Modules/Module.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 9ec35b565..41fdb762d 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -4,23 +4,24 @@ namespace Icinga\Application\Modules; use Exception; -use Zend_Controller_Router_Route_Abstract; +use Icinga\Web\Controller\Dispatcher; use Zend_Controller_Router_Route as Route; +use Zend_Controller_Router_Route_Abstract; use Zend_Controller_Router_Route_Regex as RegexRoute; use Icinga\Application\ApplicationBootstrap; use Icinga\Application\Config; use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Data\ConfigObject; +use Icinga\Exception\IcingaException; +use Icinga\Exception\ProgrammingError; +use Icinga\Module\Setup\SetupWizard; +use Icinga\Util\File; use Icinga\Util\Translator; use Icinga\Web\Hook; use Icinga\Web\Menu; use Icinga\Web\Widget; use Icinga\Web\Widget\Dashboard\Pane; -use Icinga\Module\Setup\SetupWizard; -use Icinga\Util\File; -use Icinga\Exception\ProgrammingError; -use Icinga\Exception\IcingaException; /** * Module handling @@ -934,7 +935,7 @@ class Module } /** - * Register module namespaces on the autoloader + * Register module namespaces on our class loader * * @return $this */ @@ -944,16 +945,25 @@ class Module return $this; } + $loader = $this->app->getLoader(); $moduleName = ucfirst($this->getName()); $moduleLibraryDir = $this->getLibDir(). '/'. $moduleName; if (is_dir($moduleLibraryDir)) { - $this->app->getLoader()->registerNamespace('Icinga\\Module\\' . $moduleName, $moduleLibraryDir); + $loader->registerNamespace('Icinga\\Module\\' . $moduleName, $moduleLibraryDir); } $moduleFormDir = $this->getFormDir(); if (is_dir($moduleFormDir)) { - $this->app->getLoader()->registerNamespace('Icinga\\Module\\' . $moduleName. '\\Forms', $moduleFormDir); + $loader->registerNamespace('Icinga\\Module\\' . $moduleName. '\\Forms', $moduleFormDir); + } + + $moduleControllerDir = $this->getControllerDir(); + if (is_dir($moduleControllerDir)) { + $loader->registerNamespace( + 'Icinga\\Module\\' . $moduleName . '\\' . Dispatcher::CONTROLLER_NAMESPACE, + $moduleControllerDir + ); } $this->registeredAutoloader = true; From c2d5d8f33997cccf8c7d7304c7989a9374d37c20 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 13:03:25 +0200 Subject: [PATCH 024/157] Namespace the DashboardController refs #5786 --- application/controllers/DashboardController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index b00ddf2b8..7a2101527 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -1,6 +1,8 @@ Date: Tue, 18 Aug 2015 13:06:43 +0200 Subject: [PATCH 025/157] Optimize imports in the DashboardController refs #5786 --- application/controllers/DashboardController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 7a2101527..47e39d1f5 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -6,9 +6,9 @@ namespace Icinga\Controller; use Icinga\Exception\ProgrammingError; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\Dashboard\DashletForm; +use Icinga\Web\Controller\ActionController; use Icinga\Web\Form; use Icinga\Web\Notification; -use Icinga\Web\Controller\ActionController; use Icinga\Web\Url; use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Tabextension\DashboardSettings; From fba9780405745b05f8c0e16bf9f1ce4db0c6fadc Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 13:07:01 +0200 Subject: [PATCH 026/157] Add missing imports in the DashboardController after namespacing refs #5786 --- application/controllers/DashboardController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 47e39d1f5..b67912384 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -3,6 +3,8 @@ namespace Icinga\Controller; +use Exception; +use Zend_Controller_Action_Exception; use Icinga\Exception\ProgrammingError; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\Dashboard\DashletForm; From f24449b2251ee5a224863f5fe1d41b01f2f52e27 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 20 Aug 2015 16:24:12 +0200 Subject: [PATCH 027/157] modules: Register controller namesoace in Module::registerWebIntegration() Else we get an exception when loading modules on the CLI because Zend classes are not autoloaded. refs #5786 --- library/Icinga/Application/Modules/Module.php | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 41fdb762d..8da58005a 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -958,14 +958,6 @@ class Module $loader->registerNamespace('Icinga\\Module\\' . $moduleName. '\\Forms', $moduleFormDir); } - $moduleControllerDir = $this->getControllerDir(); - if (is_dir($moduleControllerDir)) { - $loader->registerNamespace( - 'Icinga\\Module\\' . $moduleName . '\\' . Dispatcher::CONTROLLER_NAMESPACE, - $moduleControllerDir - ); - } - $this->registeredAutoloader = true; return $this; @@ -1025,19 +1017,23 @@ class Module */ protected function registerWebIntegration() { - if (!$this->app->isWeb()) { + if (! $this->app->isWeb()) { return $this; } - - if (file_exists($this->controllerdir) && is_dir($this->controllerdir)) { + $moduleControllerDir = $this->getControllerDir(); + if (is_dir($moduleControllerDir)) { $this->app->getfrontController()->addControllerDirectory( - $this->controllerdir, - $this->name + $moduleControllerDir, + $this->getName() + ); + $this->app->getLoader()->registerNamespace( + 'Icinga\\Module\\' . ucfirst($this->getName()) . '\\' . Dispatcher::CONTROLLER_NAMESPACE, + $moduleControllerDir ); } - - $this->registerLocales() - ->registerRoutes(); + $this + ->registerLocales() + ->registerRoutes(); return $this; } From 28009eb563c290ee4bc5f873a2a3fa0b61677bb5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:03:45 +0200 Subject: [PATCH 028/157] Rename controller namespace to Controllers refs #5786 --- application/controllers/DashboardController.php | 2 +- library/Icinga/Web/Controller/Dispatcher.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index b67912384..6c8eaa480 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -1,7 +1,7 @@ Date: Thu, 27 Aug 2015 13:05:20 +0200 Subject: [PATCH 029/157] Namespace the AboutController refs #5786 --- application/controllers/AboutController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/AboutController.php b/application/controllers/AboutController.php index a4247f234..4bd440d98 100644 --- a/application/controllers/AboutController.php +++ b/application/controllers/AboutController.php @@ -1,7 +1,7 @@ Date: Thu, 27 Aug 2015 13:06:31 +0200 Subject: [PATCH 030/157] lib: Add PHPDoc to Version --- library/Icinga/Application/Version.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/Icinga/Application/Version.php b/library/Icinga/Application/Version.php index 65b6138d9..3b7b51e50 100644 --- a/library/Icinga/Application/Version.php +++ b/library/Icinga/Application/Version.php @@ -3,6 +3,9 @@ namespace Icinga\Application; +/** + * Retrieve the version of Icinga Web 2 + */ class Version { /** From ba09b02f5c1c8ba007a4a5af16244a2cc4cc7471 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:06:49 +0200 Subject: [PATCH 031/157] lib: Fix PHPDoc of Version::get() --- library/Icinga/Application/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Application/Version.php b/library/Icinga/Application/Version.php index 3b7b51e50..c06eca2c2 100644 --- a/library/Icinga/Application/Version.php +++ b/library/Icinga/Application/Version.php @@ -11,7 +11,7 @@ class Version /** * Get the version of this instance of Icinga Web 2 * - * @return array|bool array on success, false otherwise + * @return array|false array on success, false otherwise */ public static function get() { From 358735a0a352a0b2939c5f0b83a5bed39943619c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:07:10 +0200 Subject: [PATCH 032/157] Optimize imports in the AboutController --- application/controllers/AboutController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/AboutController.php b/application/controllers/AboutController.php index 4bd440d98..fc1c78931 100644 --- a/application/controllers/AboutController.php +++ b/application/controllers/AboutController.php @@ -3,8 +3,8 @@ namespace Icinga\Controllers; -use Icinga\Web\Controller\ActionController; use Icinga\Application\Version; +use Icinga\Web\Controller\ActionController; class AboutController extends ActionController { From 5518f61614ba6e1415fc6ade74bcc9f080a469e0 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:09:58 +0200 Subject: [PATCH 033/157] Namespace the AuthenticationController refs #5786 --- application/controllers/AuthenticationController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index 7ed492b63..1a16408b0 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -1,7 +1,7 @@ Date: Thu, 27 Aug 2015 13:10:21 +0200 Subject: [PATCH 034/157] Remove unused alias in the AuthenticationController --- application/controllers/AuthenticationController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index 1a16408b0..e0dc06505 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -6,7 +6,6 @@ namespace Icinga\Controllers; use Icinga\Application\Icinga; use Icinga\Forms\Authentication\LoginForm; use Icinga\Web\Controller; -use Icinga\Web\Cookie; use Icinga\Web\Url; /** From e92414ea6d8dd545f696f89ce5742afb2b9a89b8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:21:43 +0200 Subject: [PATCH 035/157] Use Request::setBody() for cookies disabled message --- application/controllers/AuthenticationController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index e0dc06505..4ea5043d0 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -38,8 +38,11 @@ class AuthenticationController extends Controller } if (! $requiresSetup) { if (! $this->getRequest()->hasCookieSupport()) { - echo $this->translate("Cookies must be enabled to run this application.\n"); - $this->getResponse()->setHttpResponseCode(403)->sendHeaders(); + $this + ->getResponse() + ->setBody("Cookies must be enabled to run this application.\n") + ->setHttpResponseCode(403) + ->sendResponse(); exit(); } $form->handleRequest(); From e9c73c18106857476aed320d2fd48bc11c82602f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:22:49 +0200 Subject: [PATCH 036/157] Namespace the ConfigController refs #5786 --- application/controllers/ConfigController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 30f46db50..9cef5f95c 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 13:23:12 +0200 Subject: [PATCH 037/157] Add missing aliases in the ConfigController after namespacing refs #5786 --- application/controllers/ConfigController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 9cef5f95c..9b2ca2a7a 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -3,6 +3,8 @@ namespace Icinga\Controllers; +use Exception; +use InvalidArgumentException; use Icinga\Application\Config; use Icinga\Application\Icinga; use Icinga\Application\Modules\Module; From 204e6fe94060b4645a4b0d261db9de6d7fcea780 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:23:48 +0200 Subject: [PATCH 038/157] Remove unused alias in the ConfigController --- application/controllers/ConfigController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 9b2ca2a7a..f099b95db 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -19,7 +19,6 @@ use Icinga\Forms\ConfirmRemovalForm; use Icinga\Security\SecurityException; use Icinga\Web\Controller; use Icinga\Web\Notification; -use Icinga\Web\Url; use Icinga\Web\Widget; /** From 3809ca1b4319eaefe3b402bb89b230748cd380bf Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:25:23 +0200 Subject: [PATCH 039/157] Namespace the ErrorController refs #5786 --- application/controllers/ErrorController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 1c01b1672..71085c32d 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 13:25:46 +0200 Subject: [PATCH 040/157] Add missing alias in the ErrorController after namespacing refs #5786 --- application/controllers/ErrorController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 71085c32d..b68f9e220 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -3,6 +3,7 @@ namespace Icinga\Controllers; +use Zend_Controller_Plugin_ErrorHandler; use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Exception\Http\HttpMethodNotAllowedException; From def92088b29633df5e21f4411fdb034d095e071d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:27:22 +0200 Subject: [PATCH 041/157] Remove the FilterController --- application/controllers/FilterController.php | 92 -------------------- 1 file changed, 92 deletions(-) delete mode 100644 application/controllers/FilterController.php diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php deleted file mode 100644 index 461977c7a..000000000 --- a/application/controllers/FilterController.php +++ /dev/null @@ -1,92 +0,0 @@ -registry = new Filter(); - $query = $this->getRequest()->getParam('query', ''); - $target = $this->getRequest()->getParam('filter_domain', ''); - - if ($this->getRequest()->getHeader('accept') == 'application/json') { - $this->getResponse()->setHeader('Content-Type', 'application/json'); - $this->setupQueries( - $target, - $this->getParam('filter_module', '') - ); - $this->_helper->json($this->parse($query, $target)); - } else { - $this->setupQueries( - $target, - $this->getParam('filter_module') - ); - $urlTarget = $this->parse($query, $target); - $this->redirect($urlTarget['urlParam']); - } - - - } - - /** - * Set up the query handler for the given domain and module - * - * @param string $domain The domain to use - * @param string $module The module to use - */ - private function setupQueries($domain, $module = 'default') - { - $class = '\\Icinga\\Module\\' . ucfirst($module) . '\\Filter\\Registry'; - $factory = strtolower($domain) . 'Filter'; - $this->moduleRegistry = $class; - $this->registry->addDomain($class::$factory()); - } - - /** - * Parse the given query text and returns the json as expected by the semantic search box - * - * @param String $text The query to parse - * @return array The result structure to be returned in json format - */ - private function parse($text, $target) - { - try { - - $queryTree = $this->registry->createQueryTreeForFilter($text); - $registry = $this->moduleRegistry; - return array( - 'state' => 'success', - 'proposals' => $this->registry->getProposalsForQuery($text), - 'urlParam' => $registry::getUrlForTarget($target, $queryTree), - 'valid' => count($this->registry->getIgnoredQueryParts()) === 0 - ); - } catch (\Exception $exc) { - Logger::error($exc); - $this->getResponse()->setHttpResponseCode(500); - return array( - 'state' => 'error', - 'message' => 'Search service is currently not available' - ); - } - } -} From cd9c445b8287eb962fa8cf15375bc8bfa4b9b686 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:28:00 +0200 Subject: [PATCH 042/157] Namespace the GroupController refs #5786 --- application/controllers/GroupController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php index ed30aac86..f852c11b9 100644 --- a/application/controllers/GroupController.php +++ b/application/controllers/GroupController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 13:29:06 +0200 Subject: [PATCH 043/157] Optimize import in the GroupController --- application/controllers/GroupController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php index f852c11b9..5534dc027 100644 --- a/application/controllers/GroupController.php +++ b/application/controllers/GroupController.php @@ -5,8 +5,8 @@ namespace Icinga\Controllers; use Icinga\Application\Logger; use Icinga\Data\DataArray\ArrayDatasource; -use Icinga\Data\Reducible; use Icinga\Data\Filter\Filter; +use Icinga\Data\Reducible; use Icinga\Exception\NotFoundError; use Icinga\Forms\Config\UserGroup\AddMemberForm; use Icinga\Forms\Config\UserGroup\UserGroupForm; From 896a01fdf698d444baffa43dd222adcb0c1b4b11 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:29:36 +0200 Subject: [PATCH 044/157] Add missing alias in the GroupController after namespacing refs #5786 --- application/controllers/GroupController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php index 5534dc027..4900ecf82 100644 --- a/application/controllers/GroupController.php +++ b/application/controllers/GroupController.php @@ -3,6 +3,7 @@ namespace Icinga\Controllers; +use Exception; use Icinga\Application\Logger; use Icinga\Data\DataArray\ArrayDatasource; use Icinga\Data\Filter\Filter; From 43e7bf97ce7d2f7db45126a3f2ea920c7ff22f57 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:30:43 +0200 Subject: [PATCH 045/157] Optimize imports in the ConfigController --- application/controllers/ConfigController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index f099b95db..c3fe3921d 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -11,10 +11,10 @@ use Icinga\Application\Modules\Module; use Icinga\Data\ResourceFactory; use Icinga\Exception\ConfigurationError; use Icinga\Exception\NotFoundError; -use Icinga\Forms\Config\UserBackendConfigForm; -use Icinga\Forms\Config\UserBackendReorderForm; use Icinga\Forms\Config\GeneralConfigForm; use Icinga\Forms\Config\ResourceConfigForm; +use Icinga\Forms\Config\UserBackendConfigForm; +use Icinga\Forms\Config\UserBackendReorderForm; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Security\SecurityException; use Icinga\Web\Controller; From 72315100804ddfb60716206a2a2acfc601f3c34b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:31:36 +0200 Subject: [PATCH 046/157] Namespace the IndexController --- application/controllers/IndexController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index 5ffd1970a..fd84402fa 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -1,7 +1,7 @@ Date: Thu, 27 Aug 2015 13:31:50 +0200 Subject: [PATCH 047/157] Remove unused alias in the IndexController --- application/controllers/IndexController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index fd84402fa..14f8d071e 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -4,7 +4,6 @@ namespace Icinga\Controllers; use Icinga\Web\Controller\ActionController; -use Icinga\Application\Benchmark; use Icinga\Web\Url; /** From af8949dde277c337e99d971b6a58744bed4a9e3c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:32:35 +0200 Subject: [PATCH 048/157] Add TODO in the IndexController: Avoid landing page redirects refs #9656 --- application/controllers/IndexController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index 14f8d071e..048ea1b4d 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -17,6 +17,7 @@ class IndexController extends ActionController public function preDispatch() { if ($this->getRequest()->getActionName() !== 'welcome') { + // @TODO(el): Avoid landing page redirects: https://dev.icinga.org/issues/9656 $this->redirectNow(Url::fromRequest()->setPath('dashboard')); } } From 0e7b6d7f44ec60013993132e4b8ef47e3ab166bb Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:33:17 +0200 Subject: [PATCH 049/157] Optimize imports in the LayoutController --- application/controllers/LayoutController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/LayoutController.php b/application/controllers/LayoutController.php index 8e391da35..a7c23b41d 100644 --- a/application/controllers/LayoutController.php +++ b/application/controllers/LayoutController.php @@ -1,10 +1,10 @@ Date: Thu, 27 Aug 2015 13:33:36 +0200 Subject: [PATCH 050/157] Namespace the LayoutController --- application/controllers/LayoutController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/LayoutController.php b/application/controllers/LayoutController.php index a7c23b41d..335bee8e0 100644 --- a/application/controllers/LayoutController.php +++ b/application/controllers/LayoutController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 13:34:37 +0200 Subject: [PATCH 051/157] Namespace the ListController refs #5786 --- application/controllers/ListController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 9a20755c9..b78502b25 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 13:35:06 +0200 Subject: [PATCH 052/157] Fix PHPDoc of ListController --- application/controllers/ListController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index b78502b25..b39811c0c 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -13,8 +13,6 @@ use Icinga\Web\Widget\Tabextension\DashboardAction; use Icinga\Web\Widget\Tabextension\OutputFormat; /** - * Class ListController - * * Application wide controller for various listing actions */ class ListController extends Controller From 28815a936a03022e663a1c9894bd1b91f36934d5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:35:32 +0200 Subject: [PATCH 053/157] Optimize imports in the PreferenceController --- application/controllers/PreferenceController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index a466ed48f..5f7231a9e 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -1,13 +1,13 @@ Date: Thu, 27 Aug 2015 13:36:33 +0200 Subject: [PATCH 054/157] Namespace the PreferenceController --- application/controllers/PreferenceController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index 5f7231a9e..311b26d20 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 13:38:19 +0200 Subject: [PATCH 055/157] Add PreferenceController renaming TODO refs #10014 --- application/controllers/PreferenceController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index 311b26d20..6437a7c97 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -13,6 +13,8 @@ use Icinga\Web\Widget\Tab; /** * Application wide preference controller for user preferences + * + * @TODO(el): Rename to PreferencesController: https://dev.icinga.org/issues/10014 */ class PreferenceController extends BasePreferenceController { From 652bdb6e3e069c6d574628238517fe77ea597e08 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:40:06 +0200 Subject: [PATCH 056/157] Add RoleController renaming TODO refs #10015 --- application/controllers/RoleController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index 971a7efc9..c94cbf40f 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -7,6 +7,11 @@ use Icinga\Forms\Security\RoleForm; use Icinga\Web\Controller\AuthBackendController; use Icinga\Web\Notification; +/** + * Manage user permissions and restrictions based on roles + * + * @TODO(el): Rename to RolesController: https://dev.icinga.org/issues/10015 + */ class RoleController extends AuthBackendController { /** From f09c27aa516f9cb44448c6eba780e7093fd87c24 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:40:44 +0200 Subject: [PATCH 057/157] Namespace the RoleController refs #5786 --- application/controllers/RoleController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index c94cbf40f..9485af95e 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 13:44:00 +0200 Subject: [PATCH 058/157] Add missing aliases to the RoleController after namespacing refs #5786 --- application/controllers/RoleController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index 9485af95e..795630280 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -3,6 +3,8 @@ namespace Icinga\Controllers; +use InvalidArgumentException; +use Zend_Controller_Action_Exception; use Icinga\Application\Config; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\Security\RoleForm; From 853d4fd5340e3b47b76539bf9d11314bfc1aca58 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:44:49 +0200 Subject: [PATCH 059/157] Use UrlParams::getRequired() in RoleController::editAction() --- application/controllers/RoleController.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index 795630280..809bc59a3 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -69,13 +69,7 @@ class RoleController extends AuthBackendController public function editAction() { $this->assertPermission('config/authentication/roles/edit'); - $name = $this->_request->getParam('role'); - if (empty($name)) { - throw new Zend_Controller_Action_Exception( - sprintf($this->translate('Required parameter \'%s\' missing'), 'role'), - 400 - ); - } + $name = $this->params->getRequired('role'); $role = new RoleForm(); $role->setTitle(sprintf($this->translate('Update Role %s'), $name)); $role->setSubmitLabel($this->translate('Update Role')); From fd8b5ec510b5832be5d673b202e61af45d532ff5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:46:28 +0200 Subject: [PATCH 060/157] Use UrlParams::getRequired() in RoleController::removeAction() --- application/controllers/RoleController.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index 809bc59a3..a4c83b113 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -114,13 +114,7 @@ class RoleController extends AuthBackendController public function removeAction() { $this->assertPermission('config/authentication/roles/remove'); - $name = $this->_request->getParam('role'); - if (empty($name)) { - throw new Zend_Controller_Action_Exception( - sprintf($this->translate('Required parameter \'%s\' missing'), 'role'), - 400 - ); - } + $name = $this->params->getRequired('role'); $role = new RoleForm(); try { $role From c5d0094e8effcd3abf8fd3db7d118099108bb93d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:56:24 +0200 Subject: [PATCH 061/157] lib: Add AlreadyExistsException --- library/Icinga/Exception/AlreadyExistsException.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 library/Icinga/Exception/AlreadyExistsException.php diff --git a/library/Icinga/Exception/AlreadyExistsException.php b/library/Icinga/Exception/AlreadyExistsException.php new file mode 100644 index 000000000..ea1a1399a --- /dev/null +++ b/library/Icinga/Exception/AlreadyExistsException.php @@ -0,0 +1,11 @@ + Date: Thu, 27 Aug 2015 13:57:10 +0200 Subject: [PATCH 062/157] Throw NotFoundError instead of InvalidArgumentException in RoleForm::load() --- application/forms/Security/RoleForm.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index dba7ebe9f..8a9ee4187 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -3,6 +3,7 @@ namespace Icinga\Forms\Security; +use Icinga\Exception\NotFoundError; use InvalidArgumentException; use LogicException; use Zend_Form_Element; @@ -170,10 +171,10 @@ class RoleForm extends ConfigForm throw new LogicException(sprintf('Can\'t load role \'%s\'. Config is not set', $name)); } if (! $this->config->hasSection($name)) { - throw new InvalidArgumentException(sprintf( + throw new NotFoundError( $this->translate('Can\'t load role \'%s\'. Role does not exist'), $name - )); + ); } $role = $this->config->getSection($name)->toArray(); $role['permissions'] = ! empty($role['permissions']) From 2e970b2965b776663e35a56f8f5bb940e81f9c7b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:58:07 +0200 Subject: [PATCH 063/157] Fix PHPDoc of RoleForm::load() --- application/forms/Security/RoleForm.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index 8a9ee4187..a77746e68 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -163,6 +163,7 @@ class RoleForm extends ConfigForm * @return $this * * @throws LogicException If the config is not set + * @throws NotFoundError If the given role does not exist * @see ConfigForm::setConfig() For setting the config. */ public function load($name) From 1135643fe10d63a99bcd1e4258b3640653a09d35 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:58:51 +0200 Subject: [PATCH 064/157] Throw AlreadyExistsException instead of InvalidArgumentException in RoleForm::add() --- application/forms/Security/RoleForm.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index a77746e68..e1dbe5480 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -3,6 +3,7 @@ namespace Icinga\Forms\Security; +use Icinga\Exception\AlreadyExistsException; use Icinga\Exception\NotFoundError; use InvalidArgumentException; use LogicException; @@ -203,9 +204,9 @@ class RoleForm extends ConfigForm * * @return $this * - * @throws LogicException If the config is not set - * @throws InvalidArgumentException If the role to add already exists - * @see ConfigForm::setConfig() For setting the config. + * @throws LogicException If the config is not set + * @throws AlreadyExistsException If the role to add already exists + * @see ConfigForm::setConfig() For setting the config. */ public function add($name, array $values) { @@ -213,10 +214,10 @@ class RoleForm extends ConfigForm throw new LogicException(sprintf('Can\'t add role \'%s\'. Config is not set', $name)); } if ($this->config->hasSection($name)) { - throw new InvalidArgumentException(sprintf( + throw new AlreadyExistsException( $this->translate('Can\'t add role \'%s\'. Role already exists'), $name - )); + ); } $this->config->setSection($name, $values); return $this; From 0681cd27828a9afac4550910735e04bd7b1c42c2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 13:59:34 +0200 Subject: [PATCH 065/157] Throw NotFoundError instead of InvalidArgumentException in RoleForm::remove() --- application/forms/Security/RoleForm.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index e1dbe5480..90570fff3 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -230,9 +230,9 @@ class RoleForm extends ConfigForm * * @return $this * - * @throws LogicException If the config is not set - * @throws InvalidArgumentException If the role does not exist - * @see ConfigForm::setConfig() For setting the config. + * @throws LogicException If the config is not set + * @throws NotFoundError If the role does not exist + * @see ConfigForm::setConfig() For setting the config. */ public function remove($name) { @@ -240,10 +240,10 @@ class RoleForm extends ConfigForm throw new LogicException(sprintf('Can\'t remove role \'%s\'. Config is not set', $name)); } if (! $this->config->hasSection($name)) { - throw new InvalidArgumentException(sprintf( + throw new NotFoundError( $this->translate('Can\'t remove role \'%s\'. Role does not exist'), $name - )); + ); } $this->config->removeSection($name); return $this; From dad9f5ba7cf89602a63a62e8aac1d7118399034f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:00:24 +0200 Subject: [PATCH 066/157] Throw NotFoundError instead of InvalidArgumentException in RoleForm::update() --- application/forms/Security/RoleForm.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index 90570fff3..d558ee0c7 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -258,9 +258,9 @@ class RoleForm extends ConfigForm * * @return $this * - * @throws LogicException If the config is not set - * @throws InvalidArgumentException If the role to update does not exist - * @see ConfigForm::setConfig() For setting the config. + * @throws LogicException If the config is not set + * @throws NotFoundError If the role to update does not exist + * @see ConfigForm::setConfig() For setting the config. */ public function update($name, array $values, $oldName) { @@ -273,10 +273,10 @@ class RoleForm extends ConfigForm $this->add($name, $values); } else { if (! $this->config->hasSection($name)) { - throw new InvalidArgumentException(sprintf( + throw new NotFoundError( $this->translate('Can\'t update role \'%s\'. Role does not exist'), $name - )); + ); } $this->config->setSection($name, $values); } From a134522e9e2a8981a86c5c2d9c4dcd313078bbf5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:00:56 +0200 Subject: [PATCH 067/157] Fix PHPDoc indents in the RoleForm --- application/forms/Security/RoleForm.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index d558ee0c7..70fc04dac 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -199,7 +199,7 @@ class RoleForm extends ConfigForm /** * Add a role * - * @param string $name The name of the role + * @param string $name The name of the role * @param array $values * * @return $this @@ -226,7 +226,7 @@ class RoleForm extends ConfigForm /** * Remove a role * - * @param string $name The name of the role + * @param string $name The name of the role * * @return $this * @@ -252,9 +252,9 @@ class RoleForm extends ConfigForm /** * Update a role * - * @param string $name The possibly new name of the role + * @param string $name The possibly new name of the role * @param array $values - * @param string $oldName The name of the role to update + * @param string $oldName The name of the role to update * * @return $this * From 898883f613de67e84263007279dc33f33ba1b5a3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:01:07 +0200 Subject: [PATCH 068/157] Remove unused alias in the RoleForm --- application/forms/Security/RoleForm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index 70fc04dac..ee1b04759 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -5,7 +5,6 @@ namespace Icinga\Forms\Security; use Icinga\Exception\AlreadyExistsException; use Icinga\Exception\NotFoundError; -use InvalidArgumentException; use LogicException; use Zend_Form_Element; use Icinga\Application\Icinga; From 8af77e49e969ff3479372af81f63a9b63f00a1ff Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:01:29 +0200 Subject: [PATCH 069/157] Optimize imports in the RoleForm --- application/forms/Security/RoleForm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index ee1b04759..4632dfcb1 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -3,11 +3,11 @@ namespace Icinga\Forms\Security; -use Icinga\Exception\AlreadyExistsException; -use Icinga\Exception\NotFoundError; use LogicException; use Zend_Form_Element; use Icinga\Application\Icinga; +use Icinga\Exception\AlreadyExistsException; +use Icinga\Exception\NotFoundError; use Icinga\Forms\ConfigForm; use Icinga\Util\String; From 5c883d902e480d9103ac3b9cd8322d7dcc04efa5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:03:49 +0200 Subject: [PATCH 070/157] Don't throw exceptions manually in the RoleController --- application/controllers/RoleController.php | 28 +++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index a4c83b113..f7d1383b1 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -3,9 +3,9 @@ namespace Icinga\Controllers; -use InvalidArgumentException; -use Zend_Controller_Action_Exception; use Icinga\Application\Config; +use Icinga\Exception\AlreadyExistsException; +use Icinga\Exception\NotFoundError; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\Security\RoleForm; use Icinga\Web\Controller\AuthBackendController; @@ -40,7 +40,7 @@ class RoleController extends AuthBackendController $values = $role->getValues(); try { $role->add($name, $values); - } catch (InvalidArgumentException $e) { + } catch (AlreadyExistsException $e) { $role->addError($e->getMessage()); return false; } @@ -63,8 +63,6 @@ class RoleController extends AuthBackendController /** * Update a role - * - * @throws Zend_Controller_Action_Exception If the required parameter 'role' is missing or the role does not exist */ public function editAction() { @@ -77,11 +75,8 @@ class RoleController extends AuthBackendController $role ->setIniConfig(Config::app('roles', true)) ->load($name); - } catch (InvalidArgumentException $e) { - throw new Zend_Controller_Action_Exception( - $e->getMessage(), - 400 - ); + } catch (NotFoundError $e) { + $this->httpNotFound($e->getMessage()); } $role ->setOnSuccess(function (RoleForm $role) use ($name) { @@ -90,7 +85,7 @@ class RoleController extends AuthBackendController $values = $role->getValues(); try { $role->update($name, $values, $oldName); - } catch (InvalidArgumentException $e) { + } catch (NotFoundError $e) { $role->addError($e->getMessage()); return false; } @@ -108,8 +103,6 @@ class RoleController extends AuthBackendController /** * Remove a role - * - * @throws Zend_Controller_Action_Exception If the required parameter 'role' is missing or the role does not exist */ public function removeAction() { @@ -120,17 +113,14 @@ class RoleController extends AuthBackendController $role ->setIniConfig(Config::app('roles', true)) ->load($name); - } catch (InvalidArgumentException $e) { - throw new Zend_Controller_Action_Exception( - $e->getMessage(), - 400 - ); + } catch (NotFoundError $e) { + $this->httpNotFound($e->getMessage()); } $confirmation = new ConfirmRemovalForm(array( 'onSuccess' => function (ConfirmRemovalForm $confirmation) use ($name, $role) { try { $role->remove($name); - } catch (InvalidArgumentException $e) { + } catch (NotFoundError $e) { Notification::error($e->getMessage()); return false; } From 3e6a55bc07948c2c2b22a75b7625d8b5bbc88f5f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:05:05 +0200 Subject: [PATCH 071/157] Fix array indent in RoleController::createListTabs() --- application/controllers/RoleController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index f7d1383b1..9bfd2d175 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -149,15 +149,15 @@ class RoleController extends AuthBackendController $tabs->add( 'role/list', array( - 'title' => $this->translate( + 'baseTarget' => '_main', + 'label' => $this->translate('Roles'), + 'title' => $this->translate( 'Configure roles to permit or restrict users and groups accessing Icinga Web 2' ), - 'label' => $this->translate('Roles'), - 'url' => 'role/list', - 'baseTarget' => '_main' + 'url' => 'role/list' + ) ); - return $tabs; } } From fe3c7ec52b1a4bf7ceeb9d6533fea9779e8f1acd Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:05:32 +0200 Subject: [PATCH 072/157] Namespace the SearchController refs #5786 --- application/controllers/SearchController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/SearchController.php b/application/controllers/SearchController.php index aa5cfaf9d..d14654cdb 100644 --- a/application/controllers/SearchController.php +++ b/application/controllers/SearchController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 14:07:00 +0200 Subject: [PATCH 073/157] Let StaticController extend Controller instead of ActionController --- application/controllers/StaticController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 9f461838c..764eaaa0d 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -1,7 +1,7 @@ Date: Thu, 27 Aug 2015 14:07:46 +0200 Subject: [PATCH 074/157] Don't throw exceptions manually in the StaticController --- application/controllers/StaticController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 764eaaa0d..efbf8b6fe 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -5,7 +5,6 @@ use Icinga\Web\Controller; use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Web\FileCache; -use Zend_Controller_Action_Exception as ActionException; /** * Delivery static content to clients @@ -64,10 +63,7 @@ class StaticController extends Controller $filePath = realpath($basedir . '/public/img/' . $file); if (! $filePath || strpos($filePath, $basedir) !== 0) { - throw new ActionException(sprintf( - '%s does not exist', - $filePath - ), 404); + $this->httpNotFound('%s does not exist', $filePath); } if (preg_match('/\.([a-z]+)$/i', $file, $m)) { $extension = $m[1]; From d638868524e8463b467c98e0cc5fe12a45288a1c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:08:12 +0200 Subject: [PATCH 075/157] Namespace the StaticController refs #5786 --- application/controllers/StaticController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index efbf8b6fe..225ba6388 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 14:09:54 +0200 Subject: [PATCH 076/157] Add PHPDoc to StaticController::stylesheetAction() --- application/controllers/StaticController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 225ba6388..433448ffb 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -152,6 +152,9 @@ class StaticController extends Controller ); } + /** + * Send application's and modules' CSS + */ public function stylesheetAction() { $lessCompiler = new \Icinga\Web\LessCompiler(); From 3dd58a6ca79f79380f97e8a720df914e86a68698 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:10:30 +0200 Subject: [PATCH 077/157] Don't use absolute alias in the StaticController --- application/controllers/StaticController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 433448ffb..969b41e64 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -7,6 +7,7 @@ use Icinga\Web\Controller; use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Web\FileCache; +use Icinga\Web\LessCompiler; /** * Delivery static content to clients @@ -157,7 +158,7 @@ class StaticController extends Controller */ public function stylesheetAction() { - $lessCompiler = new \Icinga\Web\LessCompiler(); + $lessCompiler = new LessCompiler(); $moduleManager = Icinga::app()->getModuleManager(); $publicDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); From 22b628c0841092b5d178ad979f18bb4822e0bd0a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:13:03 +0200 Subject: [PATCH 078/157] Fix StaticController::setCacheHeader() not using $maxAge --- application/controllers/StaticController.php | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 969b41e64..10a1c4094 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -121,7 +121,7 @@ class StaticController extends Controller } $response = $this->getResponse(); $response->setHeader('Content-Type', 'text/javascript'); - $this->setCacheHeader(3600); + $this->setCacheHeader(); $response->setHeader( 'Last-Modified', @@ -135,22 +135,22 @@ class StaticController extends Controller } /** - * Set cache header for this response + * Set cache header for the response * - * @param integer $maxAge The maximum age to set + * @param int $maxAge The maximum age to set */ - private function setCacheHeader($maxAge) + private function setCacheHeader($maxAge = 3600) { - $this->_response->setHeader('Cache-Control', 'max-age=3600', true); - $this->_response->setHeader('Pragma', 'cache', true); - $this->_response->setHeader( - 'Expires', - gmdate( - 'D, d M Y H:i:s', - time()+3600 - ) . ' GMT', - true - ); + $maxAge = (int) $maxAge; + $this + ->getResponse() + ->setHeader('Cache-Control', sprintf('max-age=%d', $maxAge), true) + ->setHeader('Pragma', 'cache', true) + ->setHeader( + 'Expires', + gmdate('D, d M Y H:i:s', time() + $maxAge) . ' GMT', + true + ); } /** From a8e6daa678aef245b4d0e358cfac52fe059f9df6 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:15:32 +0200 Subject: [PATCH 079/157] Fix some coding standard violations in the StaticController --- application/controllers/StaticController.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 10a1c4094..3c4e301e2 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -79,10 +79,7 @@ class StaticController extends Controller header(sprintf('ETag: "%x-%x-%x"', $s['ino'], $s['size'], (float) str_pad($s['mtime'], 16, '0'))); header('Cache-Control: public, max-age=3600'); header('Pragma: cache'); - header('Last-Modified: ' . gmdate( - 'D, d M Y H:i:s', - $s['mtime'] - ) . ' GMT'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $s['mtime']) . ' GMT'); readfile($filePath); } @@ -99,7 +96,7 @@ class StaticController extends Controller $basedir = Icinga::app()->getApplicationDir('../public/js/icinga/components/'); $filePath = $basedir . $file; } else { - if (!Icinga::app()->getModuleManager()->hasEnabled($module)) { + if (! Icinga::app()->getModuleManager()->hasEnabled($module)) { Logger::error( 'Non-existing frontend component "' . $module . '/' . $file . '" was requested. The module "' . $module . '" does not exist or is not active.' @@ -111,7 +108,7 @@ class StaticController extends Controller $filePath = $basedir . '/public/js/' . $file; } - if (!file_exists($filePath)) { + if (! file_exists($filePath)) { Logger::error( 'Non-existing frontend component "' . $module . '/' . $file . '" was requested, which would resolve to the the path: ' . $filePath @@ -125,10 +122,7 @@ class StaticController extends Controller $response->setHeader( 'Last-Modified', - gmdate( - 'D, d M Y H:i:s', - filemtime($filePath) - ) . ' GMT' + gmdate('D, d M Y H:i:s', filemtime($filePath)) . ' GMT' ); readfile($filePath); @@ -174,7 +168,7 @@ class StaticController extends Controller } } - $this->_response->setHeader('Content-Type', 'text/css'); + $this->getResponse()->setHeader('Content-Type', 'text/css'); $this->setCacheHeader(3600); $lessCompiler->printStack(); From 142264b7846a73111fec5cdff03b82f735f7c408 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:16:02 +0200 Subject: [PATCH 080/157] Optimize imports in the UserController --- application/controllers/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index eaff798df..400de99ce 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -2,11 +2,11 @@ /* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ use Icinga\Application\Logger; +use Icinga\Data\DataArray\ArrayDatasource; use Icinga\Exception\ConfigurationError; use Icinga\Exception\NotFoundError; use Icinga\Forms\Config\User\CreateMembershipForm; use Icinga\Forms\Config\User\UserForm; -use Icinga\Data\DataArray\ArrayDatasource; use Icinga\User; use Icinga\Web\Controller\AuthBackendController; use Icinga\Web\Form; From 2ed3af8f11ae94847513b6c2f543277bd7cb1585 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:16:17 +0200 Subject: [PATCH 081/157] Namespace the UserController refs #5786 --- application/controllers/UserController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index 400de99ce..eede09ed2 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 14:17:19 +0200 Subject: [PATCH 082/157] Add missing alias to the UserController after namespacing refs #5786 --- application/controllers/UserController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index eede09ed2..aa00fdadb 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -3,6 +3,7 @@ namespace Icinga\Controllers; +use Exception; use Icinga\Application\Logger; use Icinga\Data\DataArray\ArrayDatasource; use Icinga\Exception\ConfigurationError; From f1a8cef5c0b1d448975daeffecca04879519396c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:17:50 +0200 Subject: [PATCH 083/157] Optimize imports in the UsergroupbackendController --- application/controllers/UsergroupbackendController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/controllers/UsergroupbackendController.php b/application/controllers/UsergroupbackendController.php index 4c641586c..eef6afd92 100644 --- a/application/controllers/UsergroupbackendController.php +++ b/application/controllers/UsergroupbackendController.php @@ -3,11 +3,10 @@ use Icinga\Application\Config; use Icinga\Exception\NotFoundError; -use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\Config\UserGroup\UserGroupBackendForm; +use Icinga\Forms\ConfirmRemovalForm; use Icinga\Web\Controller; use Icinga\Web\Notification; -use Icinga\Web\Url; /** * Controller to configure user group backends From 7550f48a7154f8c2ed58ed0a7dc63224bba43e72 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:18:17 +0200 Subject: [PATCH 084/157] Namespace the UsergroupbackendController --- application/controllers/UsergroupbackendController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/UsergroupbackendController.php b/application/controllers/UsergroupbackendController.php index eef6afd92..82f8b4a4f 100644 --- a/application/controllers/UsergroupbackendController.php +++ b/application/controllers/UsergroupbackendController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 14:18:32 +0200 Subject: [PATCH 085/157] Add missing alias to the UsergroupbackendController after namespacing refs #5786 --- application/controllers/UsergroupbackendController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/UsergroupbackendController.php b/application/controllers/UsergroupbackendController.php index 82f8b4a4f..4c00335f7 100644 --- a/application/controllers/UsergroupbackendController.php +++ b/application/controllers/UsergroupbackendController.php @@ -3,6 +3,7 @@ namespace Icinga\Controllers; +use Exception; use Icinga\Application\Config; use Icinga\Exception\NotFoundError; use Icinga\Forms\Config\UserGroup\UserGroupBackendForm; From 1888f1a0a4fdad40dc3a3b10b01cf9cdabe828b3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:20:53 +0200 Subject: [PATCH 086/157] setup: Optimize imports in the IndexController --- modules/setup/application/controllers/IndexController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setup/application/controllers/IndexController.php b/modules/setup/application/controllers/IndexController.php index eec43a737..036d3f7d9 100644 --- a/modules/setup/application/controllers/IndexController.php +++ b/modules/setup/application/controllers/IndexController.php @@ -1,8 +1,8 @@ Date: Thu, 27 Aug 2015 14:21:29 +0200 Subject: [PATCH 087/157] setup: Namespace the IndexController refs #5786 --- modules/setup/application/controllers/IndexController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/setup/application/controllers/IndexController.php b/modules/setup/application/controllers/IndexController.php index 036d3f7d9..fabc64dd2 100644 --- a/modules/setup/application/controllers/IndexController.php +++ b/modules/setup/application/controllers/IndexController.php @@ -1,10 +1,12 @@ Date: Thu, 27 Aug 2015 14:22:35 +0200 Subject: [PATCH 088/157] doc: Namespace the StyleController refs #5786 --- modules/doc/application/controllers/StyleController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/doc/application/controllers/StyleController.php b/modules/doc/application/controllers/StyleController.php index 8661d024a..62d373ebd 100644 --- a/modules/doc/application/controllers/StyleController.php +++ b/modules/doc/application/controllers/StyleController.php @@ -1,11 +1,13 @@ Date: Thu, 27 Aug 2015 14:22:59 +0200 Subject: [PATCH 089/157] doc: Optimize imports in the SearchController --- modules/doc/application/controllers/SearchController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/doc/application/controllers/SearchController.php b/modules/doc/application/controllers/SearchController.php index 5d71681eb..c71bab799 100644 --- a/modules/doc/application/controllers/SearchController.php +++ b/modules/doc/application/controllers/SearchController.php @@ -5,9 +5,9 @@ use Icinga\Application\Icinga; use Icinga\Module\Doc\DocController; use Icinga\Module\Doc\DocParser; use Icinga\Module\Doc\Exception\DocException; +use Icinga\Module\Doc\Renderer\DocSearchRenderer; use Icinga\Module\Doc\Search\DocSearch; use Icinga\Module\Doc\Search\DocSearchIterator; -use Icinga\Module\Doc\Renderer\DocSearchRenderer; class Doc_SearchController extends DocController { From f0f24bee94b7b48c1091b2371e8289618c40b7ac Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:23:35 +0200 Subject: [PATCH 090/157] doc: Namespace the SearchController refs #5786 --- modules/doc/application/controllers/SearchController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/doc/application/controllers/SearchController.php b/modules/doc/application/controllers/SearchController.php index c71bab799..c36e0e4e8 100644 --- a/modules/doc/application/controllers/SearchController.php +++ b/modules/doc/application/controllers/SearchController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 14:24:25 +0200 Subject: [PATCH 091/157] doc: Fix PHPDoc of SearchController::getWebPath() --- modules/doc/application/controllers/SearchController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/doc/application/controllers/SearchController.php b/modules/doc/application/controllers/SearchController.php index c36e0e4e8..19624e29b 100644 --- a/modules/doc/application/controllers/SearchController.php +++ b/modules/doc/application/controllers/SearchController.php @@ -79,9 +79,7 @@ class SearchController extends DocController /** * Get the path to Icinga Web 2's documentation * - * @return string - * - * @throws Zend_Controller_Action_Exception If Icinga Web 2's documentation is not available + * @return string */ protected function getWebPath() { From 66e50ad341b918b1c7b18f8924e7976422839794 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:35:26 +0200 Subject: [PATCH 092/157] doc: Remove unused alias in the ModuleController Thanks for not reviewing commits! --- modules/doc/application/controllers/ModuleController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/doc/application/controllers/ModuleController.php b/modules/doc/application/controllers/ModuleController.php index f9e9a2e2a..6faf7cc12 100644 --- a/modules/doc/application/controllers/ModuleController.php +++ b/modules/doc/application/controllers/ModuleController.php @@ -4,7 +4,6 @@ use Icinga\Application\Icinga; use Icinga\Module\Doc\DocController; use Icinga\Module\Doc\Exception\DocException; -use Icinga\File\Ini\Parser; class Doc_ModuleController extends DocController { From 26c403832e2606343d7ae585213c8c06aa71ef51 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:36:26 +0200 Subject: [PATCH 093/157] doc: Namespace the ModuleController refs #5786 --- modules/doc/application/controllers/ModuleController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/doc/application/controllers/ModuleController.php b/modules/doc/application/controllers/ModuleController.php index 6faf7cc12..a5184555c 100644 --- a/modules/doc/application/controllers/ModuleController.php +++ b/modules/doc/application/controllers/ModuleController.php @@ -1,11 +1,13 @@ Date: Thu, 27 Aug 2015 14:37:44 +0200 Subject: [PATCH 094/157] doc: Namespace IndexController refs #5786 --- modules/doc/application/controllers/IndexController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/doc/application/controllers/IndexController.php b/modules/doc/application/controllers/IndexController.php index 67d1aad64..2a23409a4 100644 --- a/modules/doc/application/controllers/IndexController.php +++ b/modules/doc/application/controllers/IndexController.php @@ -1,9 +1,11 @@ Date: Thu, 27 Aug 2015 14:38:36 +0200 Subject: [PATCH 095/157] doc: Add PHPDoc to IndexController --- modules/doc/application/controllers/IndexController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/doc/application/controllers/IndexController.php b/modules/doc/application/controllers/IndexController.php index 2a23409a4..8ec7ddc0a 100644 --- a/modules/doc/application/controllers/IndexController.php +++ b/modules/doc/application/controllers/IndexController.php @@ -5,8 +5,16 @@ namespace Icinga\Module\Doc\Controllers; use Icinga\Module\Doc\DocController; +/** + * Documentation module index + */ class IndexController extends DocController { + /** + * Documentation module landing page + * + * Lists documentation links + */ public function indexAction() { } From 7ea559e6be9936b1313a63a2423c8bce25d6c7c7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 14:39:15 +0200 Subject: [PATCH 096/157] doc: Namespace the IcingawebController refs #5786 --- modules/doc/application/controllers/IcingawebController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/doc/application/controllers/IcingawebController.php b/modules/doc/application/controllers/IcingawebController.php index 9fccd32fa..7d8f8aad8 100644 --- a/modules/doc/application/controllers/IcingawebController.php +++ b/modules/doc/application/controllers/IcingawebController.php @@ -1,10 +1,12 @@ Date: Thu, 27 Aug 2015 14:40:49 +0200 Subject: [PATCH 097/157] doc: Fix PHPDoc of IcingawebController::getPath() --- modules/doc/application/controllers/IcingawebController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/doc/application/controllers/IcingawebController.php b/modules/doc/application/controllers/IcingawebController.php index 7d8f8aad8..252e0cfe6 100644 --- a/modules/doc/application/controllers/IcingawebController.php +++ b/modules/doc/application/controllers/IcingawebController.php @@ -13,7 +13,7 @@ class IcingawebController extends DocController * * @return string * - * @throws Zend_Controller_Action_Exception If Icinga Web 2's documentation is not available + * @throws \Icinga\Exception\Http\HttpNotFoundException If Icinga Web 2's documentation is not available */ protected function getPath() { From 1eed806edffc7480e730b899637b9930bc9c939f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:18:57 +0200 Subject: [PATCH 098/157] monitoring: Optimize imports in the AlertsummaryController --- .../application/controllers/AlertsummaryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index 23cc17442..d981941f0 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -6,8 +6,8 @@ use Icinga\Chart\Unit\LinearUnit; use Icinga\Chart\Unit\StaticAxis; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Web\Widget\SelectBox; -use Icinga\Web\Widget\Tabextension\DashboardAction; use Icinga\Web\Url; +use Icinga\Web\Widget\Tabextension\DashboardAction; class Monitoring_AlertsummaryController extends Controller { From d60fed23f735b4d9ee50975b541f83b8d5a47258 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:19:43 +0200 Subject: [PATCH 099/157] monitoring: Namespace the Alertsummarycontroller refs #5786 --- .../application/controllers/AlertsummaryController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index d981941f0..34d24ecc9 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 15:35:27 +0200 Subject: [PATCH 100/157] monitoring: Add missing aliases in the AlertsummaryController after namespacing --- .../application/controllers/AlertsummaryController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index 34d24ecc9..aa32f470b 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -3,6 +3,11 @@ namespace Icinga\Module\Monitoring\Controllers; +use stdClass; +use DateInterval; +use DatePeriod; +use DateTime; +use Zend_Controller_Action_Exception; use Icinga\Chart\GridChart; use Icinga\Chart\Unit\LinearUnit; use Icinga\Chart\Unit\StaticAxis; From 9d926fb4c688344064577970ab6edabc4ab5f8fd Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:37:01 +0200 Subject: [PATCH 101/157] monitoring: Don't use absolute alias in the AlertsummaryController --- .../controllers/AlertsummaryController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index aa32f470b..88100d01b 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -11,6 +11,7 @@ use Zend_Controller_Action_Exception; use Icinga\Chart\GridChart; use Icinga\Chart\Unit\LinearUnit; use Icinga\Chart\Unit\StaticAxis; +use Icinga\Data\Filter\FilterExpression; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Web\Widget\SelectBox; use Icinga\Web\Url; @@ -102,7 +103,7 @@ class AlertsummaryController extends Controller $this->applyRestriction('monitoring/filter/objects', $query); $query->addFilter( - new Icinga\Data\Filter\FilterExpression( + new FilterExpression( 'notification_start_time', '>=', $this->getBeginDate($interval)->format('Y-m-d H:i:s') @@ -151,7 +152,7 @@ class AlertsummaryController extends Controller $this->applyRestriction('monitoring/filter/objects', $query); $query->addFilter( - new Icinga\Data\Filter\FilterExpression( + new FilterExpression( 'notification_start_time', '>=', $beginDate->format('Y-m-d H:i:s') @@ -219,7 +220,7 @@ class AlertsummaryController extends Controller $this->applyRestriction('monitoring/filter/objects', $query); $query->addFilter( - new Icinga\Data\Filter\FilterExpression( + new FilterExpression( 'notification_start_time', '>=', $this->getBeginDate($interval)->format('Y-m-d H:i:s') @@ -270,7 +271,7 @@ class AlertsummaryController extends Controller $this->applyRestriction('monitoring/filter/objects', $query); $query->addFilter( - new Icinga\Data\Filter\FilterExpression( + new FilterExpression( 'timestamp', '>=', $this->getBeginDate($interval)->getTimestamp() @@ -278,7 +279,7 @@ class AlertsummaryController extends Controller ); $query->addFilter( - new Icinga\Data\Filter\FilterExpression( + new FilterExpression( 'state', '>', 0 @@ -336,7 +337,7 @@ class AlertsummaryController extends Controller $this->applyRestriction('monitoring/filter/objects', $query); $query->addFilter( - new Icinga\Data\Filter\FilterExpression( + new FilterExpression( 'notification_start_time', '>=', $this->getBeginDate($interval)->format('Y-m-d H:i:s') From 3af82547ac31649716f692c4519d4f7ae8599855 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:37:42 +0200 Subject: [PATCH 102/157] monitoring: Optimize imports in the ChartController --- .../monitoring/application/controllers/ChartController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/controllers/ChartController.php b/modules/monitoring/application/controllers/ChartController.php index d2e9f990c..f871d8c9d 100644 --- a/modules/monitoring/application/controllers/ChartController.php +++ b/modules/monitoring/application/controllers/ChartController.php @@ -1,12 +1,11 @@ Date: Thu, 27 Aug 2015 15:40:01 +0200 Subject: [PATCH 103/157] monitoring: Namespace the ChartController refs #5786 --- .../monitoring/application/controllers/ChartController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/ChartController.php b/modules/monitoring/application/controllers/ChartController.php index f871d8c9d..fab0d0e05 100644 --- a/modules/monitoring/application/controllers/ChartController.php +++ b/modules/monitoring/application/controllers/ChartController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 15:41:15 +0200 Subject: [PATCH 104/157] monitoring: Add fixing TODO to the ChartController refs #10019 --- .../monitoring/application/controllers/ChartController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/monitoring/application/controllers/ChartController.php b/modules/monitoring/application/controllers/ChartController.php index fab0d0e05..63e8eae29 100644 --- a/modules/monitoring/application/controllers/ChartController.php +++ b/modules/monitoring/application/controllers/ChartController.php @@ -10,9 +10,7 @@ use Icinga\Chart\Unit\StaticAxis; use Icinga\Module\Monitoring\Controller; /** - * Class Monitoring_CommandController - * - * Interface to send commands and display forms + * @TODO(el): Fix and reuse the controller or remove it: https://dev.icinga.org/issues/10019 */ class ChartController extends Controller { From 98851236e84ca4897daf32295ad94b46a7c98781 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:42:27 +0200 Subject: [PATCH 105/157] monitoring: Namespace the CommentController refs #5786 --- .../monitoring/application/controllers/CommentController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/CommentController.php b/modules/monitoring/application/controllers/CommentController.php index 59ad90fc7..3328ffb79 100644 --- a/modules/monitoring/application/controllers/CommentController.php +++ b/modules/monitoring/application/controllers/CommentController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 15:52:13 +0200 Subject: [PATCH 106/157] lib: Fix PHPDoc of Form::populate() --- library/Icinga/Web/Form.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 8dd3d1b7a..720654c07 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -1012,6 +1012,8 @@ class Form extends Zend_Form * Populate the elements with the given values * * @param array $defaults The values to populate the elements with + * + * @return $this */ public function populate(array $defaults) { From 6ff7882fc03f9e23b559dac209941b0d54cb84bb Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:52:27 +0200 Subject: [PATCH 107/157] monitoring: Reduce complexity of the CommentController --- .../controllers/CommentController.php | 49 ++++++------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentController.php b/modules/monitoring/application/controllers/CommentController.php index 3328ffb79..1b86ff1c9 100644 --- a/modules/monitoring/application/controllers/CommentController.php +++ b/modules/monitoring/application/controllers/CommentController.php @@ -16,7 +16,7 @@ class CommentController extends Controller /** * The fetched comment * - * @var stdClass + * @var object */ protected $comment; @@ -43,19 +43,18 @@ class CommentController extends Controller ))->where('comment_internal_id', $commentId); $this->applyRestriction('monitoring/filter/objects', $query); - $this->comment = $query->getQuery()->fetchRow(); - if ($this->comment === false) { + if (false === $this->comment = $query->getQuery()->fetchRow()) { $this->httpNotFound($this->translate('Comment not found')); } $this->getTabs()->add( 'comment', array( + 'icon' => 'comment', + 'label' => $this->translate('Comment'), 'title' => $this->translate( 'Display detailed information about a comment.' ), - 'icon' => 'comment', - 'label' => $this->translate('Comment'), 'url' =>'monitoring/comments/show' ) )->activate('comment')->extend(new DashboardAction()); @@ -66,37 +65,19 @@ class CommentController extends Controller */ public function showAction() { - $listCommentsLink = Url::fromPath('monitoring/list/comments') - ->setQueryString('comment_type=(comment|ack)'); - $this->view->comment = $this->comment; + if ($this->hasPermission('monitoring/command/comment/delete')) { - $this->view->delCommentForm = $this->createDelCommentForm(); - $this->view->delCommentForm->populate( - array( - 'redirect' => $listCommentsLink, - 'comment_id' => $this->comment->id, - 'comment_is_service' => isset($this->comment->service_description) - ) - ); + $listUrl = Url::fromPath('monitoring/list/comments')->setQueryString('comment_type=(comment|ack)'); + $form = new DeleteCommentCommandForm(); + $form + ->populate(array( + 'redirect' => $listUrl, + 'comment_id' => $this->comment->id, + 'comment_is_service' => isset($this->comment->service_description) + )) + ->handleRequest(); + $this->view->delCommentForm = $form; } } - - /** - * Create a command form to delete a single comment - * - * @return DeleteCommentsCommandForm - */ - private function createDelCommentForm() - { - $this->assertPermission('monitoring/command/comment/delete'); - - $delCommentForm = new DeleteCommentCommandForm(); - $delCommentForm->setAction( - Url::fromPath('monitoring/comment/show') - ->setParam('comment_id', $this->comment->id) - ); - $delCommentForm->handleRequest(); - return $delCommentForm; - } } From d1f7943ffbff84f4651c04322efd15e58fef36d1 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 15:54:12 +0200 Subject: [PATCH 108/157] monitoring: Optimize imports in CommentsController --- .../monitoring/application/controllers/CommentsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/CommentsController.php b/modules/monitoring/application/controllers/CommentsController.php index a86b30310..dda294a18 100644 --- a/modules/monitoring/application/controllers/CommentsController.php +++ b/modules/monitoring/application/controllers/CommentsController.php @@ -1,10 +1,10 @@ Date: Thu, 27 Aug 2015 15:54:44 +0200 Subject: [PATCH 109/157] monitoring: Namespace the CommentsController refs #5786 --- .../monitoring/application/controllers/CommentsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/CommentsController.php b/modules/monitoring/application/controllers/CommentsController.php index dda294a18..011ccf8df 100644 --- a/modules/monitoring/application/controllers/CommentsController.php +++ b/modules/monitoring/application/controllers/CommentsController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 16:04:24 +0200 Subject: [PATCH 110/157] monitoring: Fix mess in CommentsController and the related view script --- .../controllers/CommentsController.php | 36 ++++++++++--------- .../views/scripts/comments/show.phtml | 19 +++++----- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentsController.php b/modules/monitoring/application/controllers/CommentsController.php index 011ccf8df..c47f69b0b 100644 --- a/modules/monitoring/application/controllers/CommentsController.php +++ b/modules/monitoring/application/controllers/CommentsController.php @@ -9,28 +9,33 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm; use Icinga\Web\Url; /** - * Display detailed information about a comment + * Display detailed information about comments */ class CommentsController extends Controller { /** - * The fetched comments + * The comments view * - * @var array + * @var \Icinga\Module\Monitoring\DataView\Comment */ protected $comments; /** - * Fetch all comments matching the current filter and add tabs + * Filter from request * - * @throws Zend_Controller_Action_Exception + * @var Filter + */ + protected $filter; + + /** + * Fetch all comments matching the current filter and add tabs */ public function init() { $this->filter = Filter::fromQueryString(str_replace( 'comment_id', 'comment_internal_id', - (string)$this->params + (string) $this->params )); $query = $this->backend->select()->from('comment', array( 'id' => 'comment_internal_id', @@ -48,19 +53,16 @@ class CommentsController extends Controller ))->addFilter($this->filter); $this->applyRestriction('monitoring/filter/objects', $query); - $this->comments = $query->getQuery()->fetchAll(); - if (false === $this->comments) { - throw new Zend_Controller_Action_Exception($this->translate('Comment not found')); - } + $this->comments = $query; $this->getTabs()->add( 'comments', array( + 'icon' => 'comment', + 'label' => $this->translate('Comments') . sprintf(' (%d)', $query->count()), 'title' => $this->translate( 'Display detailed information about multiple comments.' ), - 'icon' => 'comment', - 'label' => $this->translate('Comments') . sprintf(' (%d)', count($this->comments)), 'url' =>'monitoring/comments/show' ) )->activate('comments'); @@ -73,9 +75,9 @@ class CommentsController extends Controller { $this->view->comments = $this->comments; $this->view->listAllLink = Url::fromPath('monitoring/list/comments') - ->setQueryString($this->filter->toQueryString()); + ->setQueryString($this->filter->toQueryString()); $this->view->removeAllLink = Url::fromPath('monitoring/comments/delete-all') - ->setParams($this->params); + ->setParams($this->params); } /** @@ -91,14 +93,14 @@ class CommentsController extends Controller $delCommentForm->setTitle($this->view->translate('Remove all Comments')); $delCommentForm->addDescription(sprintf( $this->translate('Confirm removal of %d comments.'), - count($this->comments) + $this->comments->count() )); - $delCommentForm->setComments($this->comments) + $delCommentForm->setComments($this->comments->fetchAll()) ->setRedirectUrl($listCommentsLink) ->handleRequest(); $this->view->delCommentForm = $delCommentForm; $this->view->comments = $this->comments; $this->view->listAllLink = Url::fromPath('monitoring/list/comments') - ->setQueryString($this->filter->toQueryString()); + ->setQueryString($this->filter->toQueryString()); } } diff --git a/modules/monitoring/application/views/scripts/comments/show.phtml b/modules/monitoring/application/views/scripts/comments/show.phtml index 4f9c64d47..0ae91f5bf 100644 --- a/modules/monitoring/application/views/scripts/comments/show.phtml +++ b/modules/monitoring/application/views/scripts/comments/show.phtml @@ -1,24 +1,23 @@
- compact): ?> - tabs; ?> - - -
- render('partials/comment/comments-header.phtml'); ?> -
+compact): ?> + tabs ?> + +
+ render('partials/comment/comments-header.phtml') ?> +
-

icon('reschedule') ?> translate('Commands') ?>

+

icon('reschedule') ?>translate('Commands') ?>

qlink( sprintf( $this->translate('Remove %d comments'), - count($comments) + $comments->count() ), $removeAllLink, null, array( - 'icon' => 'trash', + 'icon' => 'trash', 'title' => $this->translate('Remove all selected comments.') ) ) ?> From f1c7f856cda57546a53625a8515006df2f29a891 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:04:56 +0200 Subject: [PATCH 111/157] monitoring: Optimize imports in ConfigController --- .../monitoring/application/controllers/ConfigController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php index 2622b9c54..b13214ef1 100644 --- a/modules/monitoring/application/controllers/ConfigController.php +++ b/modules/monitoring/application/controllers/ConfigController.php @@ -4,11 +4,11 @@ use Icinga\Data\ResourceFactory; use Icinga\Exception\ConfigurationError; use Icinga\Forms\ConfirmRemovalForm; -use Icinga\Web\Controller; -use Icinga\Web\Notification; use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm; use Icinga\Module\Monitoring\Forms\Config\InstanceConfigForm; use Icinga\Module\Monitoring\Forms\Config\SecurityConfigForm; +use Icinga\Web\Controller; +use Icinga\Web\Notification; /** * Configuration controller for editing monitoring resources From 15be844d765437e8eb627330a01dbc43cb7901d1 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:05:57 +0200 Subject: [PATCH 112/157] monitoring: Namespace the ConfigController refs #5786 --- .../monitoring/application/controllers/ConfigController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php index b13214ef1..ca1a4b7f8 100644 --- a/modules/monitoring/application/controllers/ConfigController.php +++ b/modules/monitoring/application/controllers/ConfigController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 16:06:26 +0200 Subject: [PATCH 113/157] monitoring: Add missing alias in the ConfigController after namespacing --- modules/monitoring/application/controllers/ConfigController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php index ca1a4b7f8..d00f271ea 100644 --- a/modules/monitoring/application/controllers/ConfigController.php +++ b/modules/monitoring/application/controllers/ConfigController.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Monitoring\Controllers; +use Exception; use Icinga\Data\ResourceFactory; use Icinga\Exception\ConfigurationError; use Icinga\Forms\ConfirmRemovalForm; From c3e6e4756044a8a134036495bc57fc678e240d22 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:07:03 +0200 Subject: [PATCH 114/157] monitoring: Add missing alias in the ConfigController --- modules/monitoring/application/controllers/ConfigController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php index d00f271ea..55094bbba 100644 --- a/modules/monitoring/application/controllers/ConfigController.php +++ b/modules/monitoring/application/controllers/ConfigController.php @@ -6,6 +6,7 @@ namespace Icinga\Module\Monitoring\Controllers; use Exception; use Icinga\Data\ResourceFactory; use Icinga\Exception\ConfigurationError; +use Icinga\Exception\NotFoundError; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm; use Icinga\Module\Monitoring\Forms\Config\InstanceConfigForm; From dce8afd5bd0fe0ce95aa78fe38203c928712eb80 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:07:30 +0200 Subject: [PATCH 115/157] monitoring: Optimize imports in the DowntimeController refs #5786 --- .../application/controllers/DowntimeController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/controllers/DowntimeController.php b/modules/monitoring/application/controllers/DowntimeController.php index 077f7e264..62e928392 100644 --- a/modules/monitoring/application/controllers/DowntimeController.php +++ b/modules/monitoring/application/controllers/DowntimeController.php @@ -2,10 +2,9 @@ /* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ use Icinga\Module\Monitoring\Controller; -use Icinga\Module\Monitoring\Object\Service; -use Icinga\Module\Monitoring\Object\Host; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm; -use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand; +use Icinga\Module\Monitoring\Object\Host; +use Icinga\Module\Monitoring\Object\Service; use Icinga\Web\Url; use Icinga\Web\Widget\Tabextension\DashboardAction; From a50d2110be12fc5b9aaba1dc2084ae2e8abee706 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:08:09 +0200 Subject: [PATCH 116/157] monitoring: Namespace the DowntimeController refs #5786 --- .../monitoring/application/controllers/DowntimeController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/DowntimeController.php b/modules/monitoring/application/controllers/DowntimeController.php index 62e928392..48706d66f 100644 --- a/modules/monitoring/application/controllers/DowntimeController.php +++ b/modules/monitoring/application/controllers/DowntimeController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 16:19:18 +0200 Subject: [PATCH 117/157] monitoring: Reduce DowntimeController complexity --- .../controllers/DowntimeController.php | 93 ++++++------------- 1 file changed, 26 insertions(+), 67 deletions(-) diff --git a/modules/monitoring/application/controllers/DowntimeController.php b/modules/monitoring/application/controllers/DowntimeController.php index 48706d66f..946b69985 100644 --- a/modules/monitoring/application/controllers/DowntimeController.php +++ b/modules/monitoring/application/controllers/DowntimeController.php @@ -18,17 +18,10 @@ class DowntimeController extends Controller /** * The fetched downtime * - * @var stdClass + * @var object */ protected $downtime; - /** - * If the downtime is a service or not - * - * @var boolean - */ - protected $isService; - /** * Fetch the downtime matching the given id and add tabs */ @@ -59,29 +52,20 @@ class DowntimeController extends Controller ))->where('downtime_internal_id', $downtimeId); $this->applyRestriction('monitoring/filter/objects', $query); - $this->downtime = $query->getQuery()->fetchRow(); - if ($this->downtime === false) { + if (false === $this->downtime = $query->fetchRow()) { $this->httpNotFound($this->translate('Downtime not found')); } - if (isset($this->downtime->service_description)) { - $this->isService = true; - } else { - $this->isService = false; - } + $this->getTabs()->add( + 'downtime', + array( - $this->getTabs() - ->add( - 'downtime', - array( - 'title' => $this->translate( - 'Display detailed information about a downtime.' - ), - 'icon' => 'plug', - 'label' => $this->translate('Downtime'), - 'url' =>'monitoring/downtimes/show' - ) - )->activate('downtime')->extend(new DashboardAction()); + 'icon' => 'plug', + 'label' => $this->translate('Downtime'), + 'title' => $this->translate('Display detailed information about a downtime.'), + 'url' =>'monitoring/downtimes/show' + ) + )->activate('downtime')->extend(new DashboardAction()); } /** @@ -89,52 +73,27 @@ class DowntimeController extends Controller */ public function showAction() { + $isService = isset($this->downtime->service_description); $this->view->downtime = $this->downtime; - $this->view->isService = $this->isService; - $this->view->stateName = isset($this->downtime->service_description) ? - Service::getStateText($this->downtime->service_state) : - Host::getStateText($this->downtime->host_state); + $this->view->isService = $isService; $this->view->listAllLink = Url::fromPath('monitoring/list/downtimes'); - $this->view->showHostLink = Url::fromPath('monitoring/host/show') - ->setParam('host', $this->downtime->host_name); + $this->view->showHostLink = Url::fromPath('monitoring/host/show')->setParam('host', $this->downtime->host_name); $this->view->showServiceLink = Url::fromPath('monitoring/service/show') ->setParam('host', $this->downtime->host_name) ->setParam('service', $this->downtime->service_description); + $this->view->stateName = $isService ? Service::getStateText($this->downtime->service_state) + : Host::getStateText($this->downtime->host_state); + if ($this->hasPermission('monitoring/command/downtime/delete')) { - $this->view->delDowntimeForm = $this->createDelDowntimeForm(); - $this->view->delDowntimeForm->populate( - array( - 'redirect' => Url::fromPath('monitoring/list/downtimes'), - 'downtime_id' => $this->downtime->id, - 'downtime_is_service' => $this->isService - ) - ); + $form = new DeleteDowntimeCommandForm(); + $form + ->populate(array( + 'downtime_id' => $this->downtime->id, + 'downtime_is_service' => $isService, + 'redirect' => Url::fromPath('monitoring/list/downtimes'), + )) + ->handleRequest(); + $this->view->delDowntimeForm = $form; } } - - /** - * Receive DeleteDowntimeCommandForm post from other controller - */ - public function removeAction() - { - $this->assertHttpMethod('POST'); - $this->createDelDowntimeForm(); - } - - /** - * Create a command form to delete a single comment - * - * @return DeleteDowntimeCommandForm - */ - private function createDelDowntimeForm() - { - $this->assertPermission('monitoring/command/downtime/delete'); - $delDowntimeForm = new DeleteDowntimeCommandForm(); - $delDowntimeForm->setAction( - Url::fromPath('monitoring/downtime/show') - ->setParam('downtime_id', $this->downtime->id) - ); - $delDowntimeForm->handleRequest(); - return $delDowntimeForm; - } } From e2a4b51429b051f4f62e0abcf62b638c7bb055f2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:20:28 +0200 Subject: [PATCH 118/157] monitoring: Don't call getQuery() on the comment data view in the CommentController --- .../application/controllers/CommentController.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentController.php b/modules/monitoring/application/controllers/CommentController.php index 1b86ff1c9..df170f1fa 100644 --- a/modules/monitoring/application/controllers/CommentController.php +++ b/modules/monitoring/application/controllers/CommentController.php @@ -43,7 +43,7 @@ class CommentController extends Controller ))->where('comment_internal_id', $commentId); $this->applyRestriction('monitoring/filter/objects', $query); - if (false === $this->comment = $query->getQuery()->fetchRow()) { + if (false === $this->comment = $query->fetchRow()) { $this->httpNotFound($this->translate('Comment not found')); } @@ -52,9 +52,7 @@ class CommentController extends Controller array( 'icon' => 'comment', 'label' => $this->translate('Comment'), - 'title' => $this->translate( - 'Display detailed information about a comment.' - ), + 'title' => $this->translate('Display detailed information about a comment.'), 'url' =>'monitoring/comments/show' ) )->activate('comment')->extend(new DashboardAction()); @@ -72,9 +70,9 @@ class CommentController extends Controller $form = new DeleteCommentCommandForm(); $form ->populate(array( - 'redirect' => $listUrl, 'comment_id' => $this->comment->id, - 'comment_is_service' => isset($this->comment->service_description) + 'comment_is_service' => isset($this->comment->service_description), + 'redirect' => $listUrl )) ->handleRequest(); $this->view->delCommentForm = $form; From e9380d2016d4586e3e16bfc68116a93cc269e9df Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:21:59 +0200 Subject: [PATCH 119/157] monitoring: Optimize imports in the DowntimesController refs #5786 --- .../application/controllers/DowntimesController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/DowntimesController.php b/modules/monitoring/application/controllers/DowntimesController.php index 35950acfe..dfb117ef8 100644 --- a/modules/monitoring/application/controllers/DowntimesController.php +++ b/modules/monitoring/application/controllers/DowntimesController.php @@ -3,9 +3,9 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; -use Icinga\Module\Monitoring\Object\Service; -use Icinga\Module\Monitoring\Object\Host; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm; +use Icinga\Module\Monitoring\Object\Host; +use Icinga\Module\Monitoring\Object\Service; use Icinga\Web\Url; /** From d68edc51490164e32b69a37860c7f57b1cf7112e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 16:23:16 +0200 Subject: [PATCH 120/157] Monitoring: Namespace the DowntimesController refs #5786 --- .../application/controllers/DowntimesController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/DowntimesController.php b/modules/monitoring/application/controllers/DowntimesController.php index dfb117ef8..7fd15fd00 100644 --- a/modules/monitoring/application/controllers/DowntimesController.php +++ b/modules/monitoring/application/controllers/DowntimesController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 23:14:48 +0200 Subject: [PATCH 121/157] monitoring: Don't loop downtimes in the DowntimesController --- .../controllers/DowntimesController.php | 50 +++++-------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/modules/monitoring/application/controllers/DowntimesController.php b/modules/monitoring/application/controllers/DowntimesController.php index 7fd15fd00..51c9b79ed 100644 --- a/modules/monitoring/application/controllers/DowntimesController.php +++ b/modules/monitoring/application/controllers/DowntimesController.php @@ -6,24 +6,22 @@ namespace Icinga\Module\Monitoring\Controllers; use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm; -use Icinga\Module\Monitoring\Object\Host; -use Icinga\Module\Monitoring\Object\Service; use Icinga\Web\Url; /** - * Display detailed information about a downtime + * Display detailed information about downtimes */ class DowntimesController extends Controller { /** - * The fetched downtimes + * The downtimes view * - * @var array + * @var \Icinga\Module\Monitoring\DataView\Downtime */ protected $downtimes; /** - * A filter matching all current downtimes + * Filter from request * * @var Filter */ @@ -31,15 +29,13 @@ class DowntimesController extends Controller /** * Fetch all downtimes matching the current filter and add tabs - * - * @throws Zend_Controller_Action_Exception */ public function init() { $this->filter = Filter::fromQueryString(str_replace( 'downtime_id', 'downtime_internal_id', - (string)$this->params + (string) $this->params )); $query = $this->backend->select()->from('downtime', array( 'id' => 'downtime_internal_id', @@ -64,38 +60,17 @@ class DowntimesController extends Controller ))->addFilter($this->filter); $this->applyRestriction('monitoring/filter/objects', $query); - $this->downtimes = $query->getQuery()->fetchAll(); - if (false === $this->downtimes) { - throw new Zend_Controller_Action_Exception( - $this->translate('Downtime not found') - ); - } + $this->downtimes = $query; $this->getTabs()->add( 'downtimes', array( - 'title' => $this->translate( - 'Display detailed information about multiple downtimes.' - ), 'icon' => 'plug', - 'label' => $this->translate('Downtimes') . sprintf(' (%d)', count($this->downtimes)), + 'label' => $this->translate('Downtimes') . sprintf(' (%d)', $query->count()), + 'title' => $this->translate('Display detailed information about multiple downtimes.'), 'url' =>'monitoring/downtimes/show' ) )->activate('downtimes'); - - foreach ($this->downtimes as $downtime) { - if (isset($downtime->service_description)) { - $downtime->isService = true; - } else { - $downtime->isService = false; - } - - if ($downtime->isService) { - $downtime->stateText = Service::getStateText($downtime->service_state); - } else { - $downtime->stateText = Host::getStateText($downtime->host_state); - } - } } /** @@ -105,9 +80,8 @@ class DowntimesController extends Controller { $this->view->downtimes = $this->downtimes; $this->view->listAllLink = Url::fromPath('monitoring/list/downtimes') - ->setQueryString($this->filter->toQueryString()); - $this->view->removeAllLink = Url::fromPath('monitoring/downtimes/delete-all') - ->setParams($this->params); + ->setQueryString($this->filter->toQueryString()); + $this->view->removeAllLink = Url::fromPath('monitoring/downtimes/delete-all')->setParams($this->params); } /** @@ -123,10 +97,10 @@ class DowntimesController extends Controller $delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes')); $delDowntimeForm->addDescription(sprintf( $this->translate('Confirm removal of %d downtimes.'), - count($this->downtimes) + $this->downtimes->count() )); $delDowntimeForm->setRedirectUrl(Url::fromPath('monitoring/list/downtimes')); - $delDowntimeForm->setDowntimes($this->downtimes)->handleRequest(); + $delDowntimeForm->setDowntimes($this->downtimes->fetchAll())->handleRequest(); $this->view->delDowntimeForm = $delDowntimeForm; } } From aceae4cb6ed4ff90eedcd5c89cec2ea01745a478 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:15:28 +0200 Subject: [PATCH 122/157] monitoring: Fix coding style in the downtimes/show view script --- .../views/scripts/downtimes/show.phtml | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/modules/monitoring/application/views/scripts/downtimes/show.phtml b/modules/monitoring/application/views/scripts/downtimes/show.phtml index 5adc984fa..9b4449cb5 100644 --- a/modules/monitoring/application/views/scripts/downtimes/show.phtml +++ b/modules/monitoring/application/views/scripts/downtimes/show.phtml @@ -1,23 +1,19 @@
- - compact): ?> - tabs; ?> - - - render('partials/downtime/downtimes-header.phtml'); ?> -

+compact): ?> + tabs ?> + + render('partials/downtime/downtimes-header.phtml') ?>
+
-

translate('Commands') ?>

+

icon('reschedule') ?>translate('Commands') ?>

qlink( - sprintf( - $this->translate('Remove all %d scheduled downtimes'), - count($downtimes) - ), + sprintf($this->translate('Remove all %d scheduled downtimes'), $downtimes->count()), $removeAllLink, null, array( - 'icon' => 'trash' + 'icon' => 'trash', + 'title' => $this->translate('Remove all selected downtimes') ) ) ?>
From d92f2cca0e081c2d4e8a9dd061fe583f9452ff6a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:15:56 +0200 Subject: [PATCH 123/157] monitoring: Fix coding style in the comments/show view script --- .../application/views/scripts/comments/show.phtml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/application/views/scripts/comments/show.phtml b/modules/monitoring/application/views/scripts/comments/show.phtml index 0ae91f5bf..d1c8431ee 100644 --- a/modules/monitoring/application/views/scripts/comments/show.phtml +++ b/modules/monitoring/application/views/scripts/comments/show.phtml @@ -2,23 +2,18 @@ compact): ?> tabs ?> -
- render('partials/comment/comments-header.phtml') ?> -
+ render('partials/comment/comments-header.phtml') ?>

icon('reschedule') ?>translate('Commands') ?>

qlink( - sprintf( - $this->translate('Remove %d comments'), - $comments->count() - ), + sprintf($this->translate('Remove %d comments'), $comments->count()), $removeAllLink, null, array( 'icon' => 'trash', - 'title' => $this->translate('Remove all selected comments.') + 'title' => $this->translate('Remove all selected comments') ) ) ?>
From f72c8e30fe9f8e0eb3d15468ece7a47456cd27e8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:16:25 +0200 Subject: [PATCH 124/157] monitoring: Don't loop more than 5 comments in the comments-header view script What the ... --- .../partials/comment/comments-header.phtml | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/monitoring/application/views/scripts/partials/comment/comments-header.phtml b/modules/monitoring/application/views/scripts/partials/comment/comments-header.phtml index 7e2a5d87c..6d5ba8f88 100644 --- a/modules/monitoring/application/views/scripts/partials/comment/comments-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/comment/comments-header.phtml @@ -1,32 +1,32 @@ - - 5) { - continue; +
+ + $comment): + if ($i > 5) { + break; } - $this->comment = $comment; ?> - - - + + - + +
- render('partials/comment/comment-description.phtml'); ?> - - render('partials/comment/comment-detail.phtml'); ?> - + partial('partials/comment/comment-description.phtml', array('comment' => $comment)) ?> + + partial('partials/comment/comment-detail.phtml', array('comment' => $comment)) ?> +
- +count() > 5): ?>

- 5): ?> qlink( - sprintf($this->translate('show all %d comments'), $i), + sprintf($this->translate('List all %d comments'), $comments->count()), $listAllLink, null, array( - 'icon' => $i > 5 ? 'down-open' : '', - 'data-base-target' => "_next" + 'data-base-target' => '_next', + 'icon' => 'down-open' ) ) ?> -

+ From 9ffe15162849527240f280db89fc70249f7f983d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:17:11 +0200 Subject: [PATCH 125/157] monitoring: Omit full stop for tooltips in the comment-description view script --- .../partials/comment/comment-description.phtml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml b/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml index 87a7308fc..da0ce7886 100644 --- a/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml +++ b/modules/monitoring/application/views/scripts/partials/comment/comment-description.phtml @@ -1,27 +1,28 @@ type) { +switch ($comment->type) { case 'flapping': $icon = 'flapping'; $title = $this->translate('Flapping'); - $tooltip = $this->translate('Comment was caused by a flapping host or service.'); + $tooltip = $this->translate('Comment was caused by a flapping host or service'); break; case 'comment': $icon = 'user'; $title = $this->translate('User Comment'); - $tooltip = $this->translate('Comment was created by an user.'); + $tooltip = $this->translate('Comment was created by an user'); break; case 'downtime': $icon = 'plug'; $title = $this->translate('Downtime'); - $tooltip = $this->translate('Comment was caused by a downtime.'); + $tooltip = $this->translate('Comment was caused by a downtime'); break; case 'ack': $icon = 'ok'; $title = $this->translate('Acknowledgement'); - $tooltip = $this->translate('Comment was caused by an acknowledgement.'); + $tooltip = $this->translate('Comment was caused by an acknowledgement'); break; } ?> -escape($title); ?>
+escape($title) ?> +
icon($icon, $tooltip) ?> -timeAgo($comment->timestamp, $this->compact); ?> +timeAgo($comment->timestamp, $this->compact) ?> From 2f47791a70e153d91406fd8b85f0fcf8455bfc2c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:17:34 +0200 Subject: [PATCH 126/157] monitoring: Fix coding style in the comment-detail view script --- .../partials/comment/comment-detail.phtml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml b/modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml index 8583bfc59..9d5da0648 100644 --- a/modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml +++ b/modules/monitoring/application/views/scripts/partials/comment/comment-detail.phtml @@ -1,17 +1,17 @@ objecttype === 'service'): ?> - icon('service', $this->translate('Service')); ?> + icon('service', $this->translate('Service')) ?> host_display_name, $comment->service_display_name ) ?> - icon('host', $this->translate('Host')); ?> - link()->host($comment->host_name, $comment->host_display_name); ?> + icon('host', $this->translate('Host')) ?> + link()->host($comment->host_name, $comment->host_display_name) ?> -
-icon('comment', $this->translate('Comment')); ?> author) - ? '[' . $this->escape($comment->author) . '] ' - : ''; -?>escape($comment->comment); ?> +icon('comment', $this->translate('Comment')) ?> +author)): ?> + [escape($comment->author) ?>] + +escape($comment->comment) ?> From 568c0f095515d22202cbd1ccc828b7234fa3430c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:17:57 +0200 Subject: [PATCH 127/157] monitoring: Fix mess in the downtimes-header view script --- .../partials/downtime/downtimes-header.phtml | 176 ++++++++++-------- 1 file changed, 96 insertions(+), 80 deletions(-) diff --git a/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml b/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml index 16e0daee7..e80ec72e3 100644 --- a/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/downtime/downtimes-header.phtml @@ -1,95 +1,111 @@ - + +
- 5) { + downtimes as $i => $downtime): + if ($i > 5) { break; - } ?> - - - + + - +
- start <= time() && ! $downtime->is_in_effect): ?> - translate('Ends'); ?> -
- timeUntil($downtime->is_flexible ? $downtime->scheduled_end : $downtime->end, $this->compact) ?> - - is_in_effect ? $this->translate('Expires') : $this->translate('Starts'); ?> -
- timeUntil($downtime->is_in_effect ? $downtime->end : $downtime->start, $this->compact) ?> - -
- isService): ?> - icon('service', $this->translate('Service')) ?> - link()->service( - $downtime->service_description, - $downtime->service_display_name, - $downtime->host_name, - $downtime->host_display_name - ); ?> - - icon('host', $this->translate('Host')) ?> - link()->host($downtime->host_name, $downtime->host_display_name); ?> - + } + if ($downtime->objecttype === 'service') { + $isService = true; + $stateText = Service::getStateText($downtime->service_state); + } else { + $isService = false; + $stateText = Host::getStateText($downtime->host_state); + } + ?> +
+ start <= time() && ! $downtime->is_in_effect): ?> + translate('Ends') ?> +
+ timeUntil( + $downtime->is_flexible ? $downtime->scheduled_end : $downtime->end, $this->compact + ) ?> + + + is_in_effect ? $this->translate('Expires') : $this->translate('Starts') ?> + +
+ timeUntil($downtime->is_in_effect ? $downtime->end : $downtime->start, $this->compact) ?> + +
+ + icon('service', $this->translate('Service')) ?> + link()->service( + $downtime->service_description, + $downtime->service_display_name, + $downtime->host_name, + $downtime->host_display_name + ) ?> + + icon('host', $this->translate('Host')) ?> + link()->host($downtime->host_name, $downtime->host_display_name) ?> +
- is_flexible): ?> - is_in_effect): ?> - isService - ? $this->translate('This flexible service downtime was started on %s at %s and lasts for %s until %s at %s.') - : $this->translate('This flexible host downtime was started on %s at %s and lasts for %s until %s at %s.'), - $this->formatDate($downtime->start), - $this->formatTime($downtime->start), - $this->formatDuration($downtime->duration), - $this->formatDate($downtime->end), - $this->formatTime($downtime->end) - ); ?> - - isService - ? $this->translate('This flexible service downtime has been scheduled to start between %s - %s and to last for %s.') - : $this->translate('This flexible host downtime has been scheduled to start between %s - %s and to last for %s.'), - $this->formatDateTime($downtime->scheduled_start), - $this->formatDateTime($downtime->scheduled_end), - $this->formatDuration($downtime->duration) - ); ?> - - - is_in_effect): ?> - isService - ? $this->translate('This fixed service downtime was started on %s at %s and expires on %s at %s.') - : $this->translate('This fixed host downtime was started on %s at %s and expires on %s at %s.'), - $this->formatDate($downtime->start), - $this->formatTime($downtime->start), - $this->formatDate($downtime->end), - $this->formatTime($downtime->end) - ); ?> - - isService - ? $this->translate('This fixed service downtime has been scheduled to start on %s at %s and to end on %s at %s.') - : $this->translate('This fixed host downtime has been scheduled to start on %s at %s and to end on %s at %s.'), - $this->formatDate($downtime->scheduled_start), - $this->formatTime($downtime->scheduled_start), - $this->formatDate($downtime->scheduled_end), - $this->formatTime($downtime->scheduled_end) - ); ?> - - + is_flexible): ?> + is_in_effect): ?> + translate('This flexible service downtime was started on %s at %s and lasts for %s until %s at %s.') + : $this->translate('This flexible host downtime was started on %s at %s and lasts for %s until %s at %s.'), + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDuration($downtime->duration), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) + ) ?> + + translate('This flexible service downtime has been scheduled to start between %s - %s and to last for %s.') + : $this->translate('This flexible host downtime has been scheduled to start between %s - %s and to last for %s.'), + $this->formatDateTime($downtime->scheduled_start), + $this->formatDateTime($downtime->scheduled_end), + $this->formatDuration($downtime->duration) + ) ?> + + + is_in_effect): ?> + translate('This fixed service downtime was started on %s at %s and expires on %s at %s.') + : $this->translate('This fixed host downtime was started on %s at %s and expires on %s at %s.'), + $this->formatDate($downtime->start), + $this->formatTime($downtime->start), + $this->formatDate($downtime->end), + $this->formatTime($downtime->end) + ) ?> + + translate('This fixed service downtime has been scheduled to start on %s at %s and to end on %s at %s.') + : $this->translate('This fixed host downtime has been scheduled to start on %s at %s and to end on %s at %s.'), + $this->formatDate($downtime->scheduled_start), + $this->formatTime($downtime->scheduled_start), + $this->formatDate($downtime->scheduled_end), + $this->formatTime($downtime->scheduled_end) + ) ?> + +
- - 5): ?> +count() > 5): ?>

qlink( - sprintf($this->translate('List all %d downtimes'), $i), + sprintf($this->translate('List all %d downtimes'), $downtimes->count()), $listAllLink, null, array( - 'icon' => 'down-open', - 'data-base-target' => "_next" + 'data-base-target' => '_next', + 'icon' => 'down-open' ) ) ?>

From 1f922a7da6fdd85c25904605ed185d41f9972da8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:18:48 +0200 Subject: [PATCH 128/157] monitoring: Namespace the HostController refs #5786 --- modules/monitoring/application/controllers/HostController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index 1016092cf..a0545ad2c 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 23:21:48 +0200 Subject: [PATCH 129/157] monitoring: Use @inheritdoc for HostController::$commandRedirectUrl --- .../monitoring/application/controllers/HostController.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index a0545ad2c..4a3f77a6a 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -15,9 +15,9 @@ use Icinga\Web\Hook; class HostController extends MonitoredObjectController { + /** - * (non-PHPDoc) - * @see MonitoredObjectController::$commandRedirectUrl For the property documentation. + * {@inheritdoc} */ protected $commandRedirectUrl = 'monitoring/host/show'; @@ -27,9 +27,7 @@ class HostController extends MonitoredObjectController public function init() { $host = new Host($this->backend, $this->params->getRequired('host')); - $this->applyRestriction('monitoring/filter/objects', $host); - if ($host->fetch() === false) { $this->httpNotFound($this->translate('Host not found')); } From 6931ad94115c5b00996fafcd14b69993edac2df8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:22:23 +0200 Subject: [PATCH 130/157] monitoring: Optimize imports in the HostsController --- modules/monitoring/application/controllers/HostsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 9d5da9e50..9534b980a 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -5,13 +5,13 @@ use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\FilterEqual; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm; -use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm; use Icinga\Module\Monitoring\Object\HostList; use Icinga\Web\Url; From 6e2afe5d574bf17f9a9378c6a17e2d25f95defee Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:22:55 +0200 Subject: [PATCH 131/157] monitoring: Namespace the HostsController refs #5786 --- .../monitoring/application/controllers/HostsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 9534b980a..192923cfe 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 23:27:29 +0200 Subject: [PATCH 132/157] monitoring: Remove HostsController::deleteCommentAction() Not used. --- .../application/controllers/HostsController.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 192923cfe..036b78c32 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -168,18 +168,6 @@ class HostsController extends Controller $this->handleCommandForm($form); } - /** - * Delete a comment - */ - public function deleteCommentAction() - { - $this->assertPermission('monitoring/command/comment/delete'); - - $form = new DeleteCommentCommandForm(); - $form->setTitle($this->translate('Delete Host Comments')); - $this->handleCommandForm($form); - } - /** * Acknowledge host problems */ From 5ec338877c887880cfd9498618ac0543413985f6 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Aug 2015 23:28:37 +0200 Subject: [PATCH 133/157] monitoring: Optimize impoerts in the ProcessController --- .../monitoring/application/controllers/ProcessController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ProcessController.php b/modules/monitoring/application/controllers/ProcessController.php index 2e52733bd..2746aea12 100644 --- a/modules/monitoring/application/controllers/ProcessController.php +++ b/modules/monitoring/application/controllers/ProcessController.php @@ -1,10 +1,10 @@ Date: Thu, 27 Aug 2015 23:30:32 +0200 Subject: [PATCH 134/157] monitoring: Namespace the ProcessController refs #5786 --- .../monitoring/application/controllers/ProcessController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ProcessController.php b/modules/monitoring/application/controllers/ProcessController.php index 2746aea12..25a52cf33 100644 --- a/modules/monitoring/application/controllers/ProcessController.php +++ b/modules/monitoring/application/controllers/ProcessController.php @@ -1,6 +1,8 @@ Date: Thu, 27 Aug 2015 23:31:12 +0200 Subject: [PATCH 135/157] monitoring: Remove ProcessController::performanceAction() Not used. --- .../controllers/ProcessController.php | 16 --- .../views/scripts/process/performance.phtml | 110 ------------------ 2 files changed, 126 deletions(-) delete mode 100644 modules/monitoring/application/views/scripts/process/performance.phtml diff --git a/modules/monitoring/application/controllers/ProcessController.php b/modules/monitoring/application/controllers/ProcessController.php index 25a52cf33..84a1a15f5 100644 --- a/modules/monitoring/application/controllers/ProcessController.php +++ b/modules/monitoring/application/controllers/ProcessController.php @@ -124,20 +124,4 @@ class ProcessController extends Controller $this->view->form = $form; } } - - /** - * @todo should be dropped later - */ - public function performanceAction() - { - $this->getTabs()->activate('performance'); - $this->setAutorefreshInterval(10); - $this->view->runtimevariables = (object) $this->backend->select() - ->from('runtimevariables', array('varname', 'varvalue')) - ->getQuery()->fetchPairs(); - - $this->view->checkperformance = $this->backend->select() - ->from('runtimesummary') - ->getQuery()->fetchAll(); - } } diff --git a/modules/monitoring/application/views/scripts/process/performance.phtml b/modules/monitoring/application/views/scripts/process/performance.phtml deleted file mode 100644 index 0bff8891f..000000000 --- a/modules/monitoring/application/views/scripts/process/performance.phtml +++ /dev/null @@ -1,110 +0,0 @@ -compact): ?> -
- tabs; ?> -
-runtimeVariables()->create($this->runtimevariables); -$cp = $this->checkPerformance()->create($this->checkperformance); - -?> - -
- -

Object summaries

- - - - - - - - - - - - - - - - - - - - - - - -
 # overall / scheduled
- Hosts - - total_hosts; ?> - / total_scheduled_hosts; ?> -
- Services - - total_services; ?> - / total_scheduled_services; ?> -
- Average services per host - - average_services_per_host); ?> - / average_scheduled_services_per_host); ?> -
- -

Active checks

- - - - - - - - - - - - - - - - - - - - - - - -
 #LatencyExecution time
- Host Checks - host_active_count; ?>host_active_latency_avg); ?>shost_active_execution_avg); ?>s
- Service Checks - service_active_count; ?>service_active_latency_avg); ?>sservice_active_execution_avg); ?>s
- -

Passive checks

- - - - - - - - - - - - - - - - - -
 #
- Host Checks - host_passive_count; ?>
- Service Checks - service_passive_count; ?>
- - -
From 67b22a56d231ab192e54521a37bfe6332b849a00 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:19:43 +0200 Subject: [PATCH 136/157] monitoring: Namespace the ServiceController refs #5786 --- .../monitoring/application/controllers/ServiceController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index cf7c4807c..45e9dde29 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -1,6 +1,8 @@ Date: Fri, 28 Aug 2015 09:20:33 +0200 Subject: [PATCH 137/157] monitoring: Use @inheritdoc for ServiceController::$commandRedirectUrl --- .../monitoring/application/controllers/ServiceController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index 45e9dde29..2c8f1f3f0 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -16,8 +16,7 @@ use Icinga\Web\Hook; class ServiceController extends MonitoredObjectController { /** - * (non-PHPDoc) - * @see MonitoredObjectController::$commandRedirectUrl For the property documentation. + * {@inheritdoc} */ protected $commandRedirectUrl = 'monitoring/service/show'; From 48c625d54de885032271a6e986bfe8ef3f0a1eeb Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:21:23 +0200 Subject: [PATCH 138/157] monitoring: Optimize imports in the ServicesController --- .../monitoring/application/controllers/ServicesController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index d67880565..9055a7dbc 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -4,14 +4,14 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm; -use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; -use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm; use Icinga\Module\Monitoring\Object\ServiceList; use Icinga\Web\Url; From dc5fddcbfe4ba22620d77cb4ce6f3292ebd59af7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:22:13 +0200 Subject: [PATCH 139/157] monitoring: Namespace the ServicesController refs #5786 --- .../monitoring/application/controllers/ServicesController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 9055a7dbc..722eabedd 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -1,6 +1,8 @@ Date: Fri, 28 Aug 2015 09:23:48 +0200 Subject: [PATCH 140/157] monitoring: Remove ServicesController::deleteCommentAction() Not in use. --- .../controllers/ServicesController.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 722eabedd..deee364fa 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -8,7 +8,6 @@ use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; -use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm; @@ -182,20 +181,6 @@ class ServicesController extends Controller $this->handleCommandForm($form); } - - /** - * Delete a comment - */ - public function deleteCommentAction() - { - $this->assertPermission('monitoring/command/comment/delete'); - - $form = new DeleteCommentCommandForm(); - $form->setTitle($this->translate('Delete Service Comments')); - $this->handleCommandForm($form); - } - - /** * Acknowledge service problems */ From 54ad809bf1351db536b405246d93f3555d9469e5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:25:16 +0200 Subject: [PATCH 141/157] monitoring: Optimize imports in the ShowController --- modules/monitoring/application/controllers/ShowController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index cfed8bd0d..f03aa4a39 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -1,9 +1,9 @@ Date: Fri, 28 Aug 2015 09:32:04 +0200 Subject: [PATCH 142/157] monitoring: Namespace the ShowController refs #5786 --- modules/monitoring/application/controllers/ShowController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index f03aa4a39..9afbaf835 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -1,6 +1,8 @@ Date: Fri, 28 Aug 2015 09:32:52 +0200 Subject: [PATCH 143/157] monitoring: Don't throw exception manually in ShowController::contactAction() --- .../application/controllers/ShowController.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index 9afbaf835..ad57b7f9b 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -49,14 +49,7 @@ class ShowController extends Controller public function contactAction() { - $contactName = $this->getParam('contact_name'); - - if (! $contactName) { - throw new Zend_Controller_Action_Exception( - $this->translate('The parameter `contact_name\' is required'), - 404 - ); - } + $contactName = $this->params->getRequired('contact_name'); $query = $this->backend->select()->from('contact', array( 'contact_name', From 411ad407b11598061daf168830a0251d3e1504d4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:34:23 +0200 Subject: [PATCH 144/157] monitoring: Remove deprecated actions from the ShowController Removed: * show/service * show/host * show/history --- .../controllers/ShowController.php | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index ad57b7f9b..184bb7ee8 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -19,34 +19,6 @@ class ShowController extends Controller */ protected $backend; - /** - * @deprecated - */ - public function serviceAction() - { - $this->redirectNow(Url::fromRequest()->setPath('monitoring/service/show')); - } - - /** - * @deprecated - */ - public function hostAction() - { - $this->redirectNow(Url::fromRequest()->setPath('monitoring/host/show')); - } - - /** - * @deprecated - */ - public function historyAction() - { - if ($this->params->has('service')) { - $this->redirectNow(Url::fromRequest()->setPath('monitoring/service/history')); - } - - $this->redirectNow(Url::fromRequest()->setPath('monitoring/host/history')); - } - public function contactAction() { $contactName = $this->params->getRequired('contact_name'); From cfab9d99ff37798f79079bede824d7d5af6fdaf4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:35:25 +0200 Subject: [PATCH 145/157] monitoring: Don't use Monitoring\Controller as MonitoringController in the TacticalController --- .../monitoring/application/controllers/TacticalController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/TacticalController.php b/modules/monitoring/application/controllers/TacticalController.php index fce4664f0..357fac3b7 100644 --- a/modules/monitoring/application/controllers/TacticalController.php +++ b/modules/monitoring/application/controllers/TacticalController.php @@ -1,11 +1,11 @@ Date: Fri, 28 Aug 2015 09:36:10 +0200 Subject: [PATCH 146/157] monitoring: Optimize imports in the TacticalController --- .../monitoring/application/controllers/TacticalController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/TacticalController.php b/modules/monitoring/application/controllers/TacticalController.php index 357fac3b7..e63b847e1 100644 --- a/modules/monitoring/application/controllers/TacticalController.php +++ b/modules/monitoring/application/controllers/TacticalController.php @@ -2,8 +2,8 @@ /* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ use Icinga\Module\Monitoring\Controller; -use Icinga\Web\Widget\Tabextension\DashboardAction; use Icinga\Web\Url; +use Icinga\Web\Widget\Tabextension\DashboardAction; class Monitoring_TacticalController extends Controller { From e9f9073d9065bc378697cadebaff2ea7943166b7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:36:34 +0200 Subject: [PATCH 147/157] monitoring: Namespace the TacticalController refs #5786 --- .../monitoring/application/controllers/TacticalController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/TacticalController.php b/modules/monitoring/application/controllers/TacticalController.php index e63b847e1..40641128b 100644 --- a/modules/monitoring/application/controllers/TacticalController.php +++ b/modules/monitoring/application/controllers/TacticalController.php @@ -1,11 +1,13 @@ Date: Fri, 28 Aug 2015 09:37:18 +0200 Subject: [PATCH 148/157] monitoring: Optimize imports in the TimelineController --- .../monitoring/application/controllers/TimelineController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index aa1e20b95..ae57b0bfd 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -1,12 +1,12 @@ Date: Fri, 28 Aug 2015 09:37:56 +0200 Subject: [PATCH 149/157] monitoring: Namespace the TimelineController refs #5786 --- .../monitoring/application/controllers/TimelineController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index ae57b0bfd..7cb888568 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -1,6 +1,8 @@ Date: Fri, 28 Aug 2015 09:39:12 +0200 Subject: [PATCH 150/157] monitoring: Add missing aliases in the TimelineController after namespacing --- .../monitoring/application/controllers/TimelineController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index 7cb888568..440513e63 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -3,6 +3,8 @@ namespace Icinga\Module\Monitoring\Controllers; +use DateInterval; +use DateTime; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Timeline\TimeLine; use Icinga\Module\Monitoring\Timeline\TimeRange; From 610675d3e9446fa9b97dc243635f0e204fc9d171 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:39:48 +0200 Subject: [PATCH 151/157] monitoring: Optimize imports in the ListController refs #5786 --- .../monitoring/application/controllers/ListController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 7fba86647..e8c0bead7 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -1,17 +1,17 @@ Date: Fri, 28 Aug 2015 09:40:28 +0200 Subject: [PATCH 152/157] monitoring: Namespace the ListController refs #5786 --- modules/monitoring/application/controllers/ListController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index e8c0bead7..c8ffe942b 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -1,6 +1,8 @@ Date: Fri, 28 Aug 2015 09:41:13 +0200 Subject: [PATCH 153/157] monitoring: Add missing alias in the ListController after namespacing --- modules/monitoring/application/controllers/ListController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index c8ffe942b..c6d51e7d7 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Monitoring\Controllers; +use Zend_Form; use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Backend; use Icinga\Module\Monitoring\Controller; From bcc02f50ec1f2157716df34a8697db8e827686a2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 09:42:49 +0200 Subject: [PATCH 154/157] lib: Optimize imports in webrouter --- library/Icinga/Application/webrouter.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Application/webrouter.php b/library/Icinga/Application/webrouter.php index 5a7d1c95c..5c8cbb6ea 100644 --- a/library/Icinga/Application/webrouter.php +++ b/library/Icinga/Application/webrouter.php @@ -3,11 +3,9 @@ namespace Icinga\Application; -use Icinga\Application\EmbeddedWeb; -use Icinga\Application\Web; -use Icinga\Web\StyleSheet; -use Icinga\Web\JavaScript; use Icinga\Chart\Inline\PieChart; +use Icinga\Web\JavaScript; +use Icinga\Web\StyleSheet; error_reporting(E_ALL | E_STRICT); From c0eb0cbe6ab3950c91000988e9cf3a7c40d757b2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 13:13:07 +0200 Subject: [PATCH 155/157] modules: Tell the dispatcher that the static controller is to be found in the default module refs #5786 --- library/Icinga/Application/Modules/Module.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 16104c4c7..61256c7d5 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -1055,8 +1055,9 @@ class Module new Zend_Controller_Router_Route( 'js/' . $this->name . '/:file', array( + 'action' => 'javascript', 'controller' => 'static', - 'action' =>'javascript', + 'module' => 'default', 'module_name' => $this->name ) ) @@ -1066,8 +1067,9 @@ class Module new Zend_Controller_Router_Route_Regex( 'img/' . $this->name . '/(.+)', array( - 'controller' => 'static', 'action' => 'img', + 'controller' => 'static', + 'module' => 'default', 'module_name' => $this->name ), array( From e7e1b1a98e9e98dfd6c9f173406c3c3a79d30651 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 13:13:20 +0200 Subject: [PATCH 156/157] Dispatcher: Default to the default module if no module has been given in the request This is most likely the case when custom routes have been added to the router w/o the module parameter being set. refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php index 5941eec77..ff3c98848 100644 --- a/library/Icinga/Web/Controller/Dispatcher.php +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -44,7 +44,8 @@ class Dispatcher extends Zend_Controller_Dispatcher_Standard return; } $controllerName = ucfirst($controllerName) . 'Controller'; - if ($this->_defaultModule === $moduleName = $request->getModuleName()) { + $moduleName = $request->getModuleName(); + if ($moduleName === null || $moduleName === $this->_defaultModule) { $controllerClass = 'Icinga\\' . self::CONTROLLER_NAMESPACE . '\\' . $controllerName; } else { $controllerClass = 'Icinga\\Module\\' . ucfirst($moduleName) . '\\' . self::CONTROLLER_NAMESPACE . '\\' From e5e64ab65419d492c405bc63e9057c1b55ceb8c4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 28 Aug 2015 13:14:33 +0200 Subject: [PATCH 157/157] Static content: Fix check whether an image exists --- application/controllers/StaticController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 3c4e301e2..7c2a36737 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -59,13 +59,14 @@ class StaticController extends Controller */ public function imgAction() { + // TODO(el): I think this action only retrieves images from modules $module = $this->_getParam('module_name'); $file = $this->_getParam('file'); $basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir(); $filePath = realpath($basedir . '/public/img/' . $file); - if (! $filePath || strpos($filePath, $basedir) !== 0) { + if ($filePath === false) { $this->httpNotFound('%s does not exist', $filePath); } if (preg_match('/\.([a-z]+)$/i', $file, $m)) {