From db72931c1e78d4e63a7cf37b3b1420d56727a10c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 5 Oct 2018 06:08:08 +0200 Subject: [PATCH] Migrations: cleanup --- .../controllers/DashboardController.php | 4 ---- application/controllers/IndexController.php | 4 ---- library/Director/Db/Migration.php | 6 +++++ library/Director/Db/Migrations.php | 23 ++++++++++++++++++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 7968eb4c..18c45fbe 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -25,10 +25,6 @@ class DashboardController extends ActionController } } - /** - * @throws \Icinga\Exception\ConfigurationError - * @throws \Icinga\Exception\Http\HttpNotFoundException - */ public function indexAction() { if ($this->getRequest()->isGet()) { diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index fe7de30f..c59485e9 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -11,10 +11,6 @@ class IndexController extends DashboardController { protected $hasDeploymentEndpoint; - /** - * @throws \Icinga\Exception\ConfigurationError - * @throws \Icinga\Exception\Http\HttpNotFoundException - */ public function indexAction() { if ($this->Config()->get('db', 'resource')) { diff --git a/library/Director/Db/Migration.php b/library/Director/Db/Migration.php index 1026991a..cd78350a 100644 --- a/library/Director/Db/Migration.php +++ b/library/Director/Db/Migration.php @@ -24,8 +24,14 @@ class Migration $this->sql = $sql; } + /** + * @param DbConnection $connection + * @return $this + * @throws IcingaException + */ public function apply(DbConnection $connection) { + /** @var \Zend_Db_Adapter_Pdo_Abstract $db */ $db = $connection->getDbAdapter(); // TODO: this is fagile and depends on accordingly written schema files: diff --git a/library/Director/Db/Migrations.php b/library/Director/Db/Migrations.php index c03c7002..c8e06044 100644 --- a/library/Director/Db/Migrations.php +++ b/library/Director/Db/Migrations.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Db; use DirectoryIterator; use Exception; use Icinga\Application\Icinga; +use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Data\Db\DbConnection; use RuntimeException; @@ -67,6 +68,9 @@ class Migrations return count($this->listPendingMigrations()); } + /** + * @return Migration[] + */ public function getPendingMigrations() { $migrations = array(); @@ -80,6 +84,10 @@ class Migrations return $migrations; } + /** + * @return $this + * @throws \Icinga\Exception\IcingaException + */ public function applyPendingMigrations() { foreach ($this->getPendingMigrations() as $migration) { @@ -171,7 +179,15 @@ class Migrations protected function getSchemaDir($sub = null) { - $dir = $this->getModuleDir('/schema'); + try { + $dir = $this->getModuleDir('/schema'); + } catch (ProgrammingError $e) { + throw new RuntimeException( + 'Unable to detect the schema directory for this module', + 0, + $e + ); + } if ($sub === null) { return $dir; } else { @@ -179,6 +195,11 @@ class Migrations } } + /** + * @param string $sub + * @return string + * @throws ProgrammingError + */ protected function getModuleDir($sub = '') { return Icinga::app()->getModuleManager()->getModuleDir(