Migrations: cleanup

This commit is contained in:
Thomas Gelf 2018-10-05 06:08:08 +02:00
parent e16d7865c7
commit db72931c1e
4 changed files with 28 additions and 9 deletions

View File

@ -25,10 +25,6 @@ class DashboardController extends ActionController
} }
} }
/**
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\Http\HttpNotFoundException
*/
public function indexAction() public function indexAction()
{ {
if ($this->getRequest()->isGet()) { if ($this->getRequest()->isGet()) {

View File

@ -11,10 +11,6 @@ class IndexController extends DashboardController
{ {
protected $hasDeploymentEndpoint; protected $hasDeploymentEndpoint;
/**
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\Http\HttpNotFoundException
*/
public function indexAction() public function indexAction()
{ {
if ($this->Config()->get('db', 'resource')) { if ($this->Config()->get('db', 'resource')) {

View File

@ -24,8 +24,14 @@ class Migration
$this->sql = $sql; $this->sql = $sql;
} }
/**
* @param DbConnection $connection
* @return $this
* @throws IcingaException
*/
public function apply(DbConnection $connection) public function apply(DbConnection $connection)
{ {
/** @var \Zend_Db_Adapter_Pdo_Abstract $db */
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();
// TODO: this is fagile and depends on accordingly written schema files: // TODO: this is fagile and depends on accordingly written schema files:

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Db;
use DirectoryIterator; use DirectoryIterator;
use Exception; use Exception;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\Data\Db\DbConnection; use Icinga\Module\Director\Data\Db\DbConnection;
use RuntimeException; use RuntimeException;
@ -67,6 +68,9 @@ class Migrations
return count($this->listPendingMigrations()); return count($this->listPendingMigrations());
} }
/**
* @return Migration[]
*/
public function getPendingMigrations() public function getPendingMigrations()
{ {
$migrations = array(); $migrations = array();
@ -80,6 +84,10 @@ class Migrations
return $migrations; return $migrations;
} }
/**
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function applyPendingMigrations() public function applyPendingMigrations()
{ {
foreach ($this->getPendingMigrations() as $migration) { foreach ($this->getPendingMigrations() as $migration) {
@ -171,7 +179,15 @@ class Migrations
protected function getSchemaDir($sub = null) protected function getSchemaDir($sub = null)
{ {
try {
$dir = $this->getModuleDir('/schema'); $dir = $this->getModuleDir('/schema');
} catch (ProgrammingError $e) {
throw new RuntimeException(
'Unable to detect the schema directory for this module',
0,
$e
);
}
if ($sub === null) { if ($sub === null) {
return $dir; return $dir;
} else { } else {
@ -179,6 +195,11 @@ class Migrations
} }
} }
/**
* @param string $sub
* @return string
* @throws ProgrammingError
*/
protected function getModuleDir($sub = '') protected function getModuleDir($sub = '')
{ {
return Icinga::app()->getModuleManager()->getModuleDir( return Icinga::app()->getModuleManager()->getModuleDir(