diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index a22b040b7..476b71f2e 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -3,7 +3,7 @@ namespace Icinga\Controllers; -use Icinga\Application\Hook\MigrationHook; +use Icinga\Application\Hook\DbMigrationHook; use Icinga\Application\MigrationManager; use Icinga\Exception\IcingaException; use Zend_Controller_Plugin_ErrorHandler; @@ -103,7 +103,7 @@ class ErrorController extends ActionController // safely unset this. $this->setParam('error_handler', null); $this->forward('hint', 'migrations', 'default', [ - MigrationHook::MIGRATION_PARAM => $moduleName + DbMigrationHook::MIGRATION_PARAM => $moduleName ]); return; diff --git a/application/controllers/MigrationsController.php b/application/controllers/MigrationsController.php index e1bcd5c4d..900d50ca4 100644 --- a/application/controllers/MigrationsController.php +++ b/application/controllers/MigrationsController.php @@ -5,7 +5,7 @@ namespace Icinga\Controllers; use Exception; -use Icinga\Application\Hook\MigrationHook; +use Icinga\Application\Hook\DbMigrationHook; use Icinga\Application\Icinga; use Icinga\Application\MigrationManager; use Icinga\Common\Database; @@ -57,10 +57,10 @@ class MigrationsController extends CompatController $migrateListForm->setRenderDatabaseUserChange(! $mm->validateDatabasePrivileges()); $migrateGlobalForm = new MigrationForm(); - $migrateGlobalForm->getAttributes()->set('name', sprintf('migrate-%s', MigrationHook::ALL_MIGRATIONS)); + $migrateGlobalForm->getAttributes()->set('name', sprintf('migrate-%s', DbMigrationHook::ALL_MIGRATIONS)); if ($canApply && $mm->hasPendingMigrations()) { - $migrateGlobalForm->addElement('submit', sprintf('migrate-%s', MigrationHook::ALL_MIGRATIONS), [ + $migrateGlobalForm->addElement('submit', sprintf('migrate-%s', DbMigrationHook::ALL_MIGRATIONS), [ 'required' => true, 'label' => $this->translate('Migrate All'), 'title' => $this->translate('Migrate all pending migrations') @@ -103,9 +103,9 @@ class MigrationsController extends CompatController // The forwarded request doesn't modify the original server query string, but adds the migration param to the // request param instead. So, there is no way to access the migration param other than via the request instance. /** @var ?string $module */ - $module = $this->getRequest()->getParam(MigrationHook::MIGRATION_PARAM); + $module = $this->getRequest()->getParam(DbMigrationHook::MIGRATION_PARAM); if ($module === null) { - throw new MissingParameterException(t('Required parameter \'%s\' missing'), MigrationHook::MIGRATION_PARAM); + throw new MissingParameterException(t('Required parameter \'%s\' missing'), DbMigrationHook::MIGRATION_PARAM); } $mm = MigrationManager::instance(); @@ -134,7 +134,7 @@ class MigrationsController extends CompatController public function migrationAction(): void { /** @var string $name */ - $name = $this->params->getRequired(MigrationHook::MIGRATION_PARAM); + $name = $this->params->getRequired(DbMigrationHook::MIGRATION_PARAM); $this->addTitleTab($this->translate('Migration')); $this->getTabs()->disableLegacyExtensions(); @@ -215,7 +215,7 @@ class MigrationsController extends CompatController if ($pressedButton) { $name = substr($pressedButton->getName(), 8); switch ($name) { - case MigrationHook::ALL_MIGRATIONS: + case DbMigrationHook::ALL_MIGRATIONS: if ($mm->applyAll($elevatedPrivileges)) { Notification::success($this->translate('Applied all migrations successfully')); } else { diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index ecc283e65..e484f6c03 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -740,7 +740,7 @@ abstract class ApplicationBootstrap */ protected function registerApplicationHooks(): self { - Hook::register('migration', DbMigration::class, DbMigration::class); + Hook::register('DbMigration', DbMigration::class, DbMigration::class); return $this; } diff --git a/library/Icinga/Application/Hook/MigrationHook.php b/library/Icinga/Application/Hook/DbMigrationHook.php similarity index 99% rename from library/Icinga/Application/Hook/MigrationHook.php rename to library/Icinga/Application/Hook/DbMigrationHook.php index dc31dd704..dfa048d8b 100644 --- a/library/Icinga/Application/Hook/MigrationHook.php +++ b/library/Icinga/Application/Hook/DbMigrationHook.php @@ -35,7 +35,7 @@ use stdClass; * * `{IcingaApp,Module}::baseDir()/schema/{mysql,pgsql}-upgrades` */ -abstract class MigrationHook implements Countable +abstract class DbMigrationHook implements Countable { use Translation; diff --git a/library/Icinga/Application/MigrationManager.php b/library/Icinga/Application/MigrationManager.php index 6151a84c2..31ea6b20b 100644 --- a/library/Icinga/Application/MigrationManager.php +++ b/library/Icinga/Application/MigrationManager.php @@ -6,7 +6,7 @@ namespace Icinga\Application; use Countable; use Generator; -use Icinga\Application\Hook\MigrationHook; +use Icinga\Application\Hook\DbMigrationHook; use Icinga\Exception\NotFoundError; use Icinga\Module\Setup\Utils\DbTool; use Icinga\Module\Setup\WebWizard; @@ -21,7 +21,7 @@ final class MigrationManager implements Countable { use Translation; - /** @var array All pending migration hooks */ + /** @var array All pending migration hooks */ protected $pendingMigrations; /** @var MigrationManager */ @@ -48,7 +48,7 @@ final class MigrationManager implements Countable /** * Get all pending migrations * - * @return array + * @return array */ public function getPendingMigrations(): array { @@ -83,11 +83,11 @@ final class MigrationManager implements Countable * * @param string $module * - * @return MigrationHook + * @return DbMigrationHook * * @throws NotFoundError When there are no pending migrations matching the given module name */ - public function getMigration(string $module): MigrationHook + public function getMigration(string $module): DbMigrationHook { if (! $this->hasMigrations($module)) { throw new NotFoundError('There are no pending migrations matching the given name: %s', $module); @@ -116,7 +116,7 @@ final class MigrationManager implements Countable public function applyByName(string $module): bool { $migration = $this->getMigration($module); - if ($migration->isModule() && $this->hasMigrations(MigrationHook::DEFAULT_MODULE)) { + if ($migration->isModule() && $this->hasMigrations(DbMigrationHook::DEFAULT_MODULE)) { return false; } @@ -126,14 +126,14 @@ final class MigrationManager implements Countable /** * Apply the given migration hook * - * @param MigrationHook $hook + * @param DbMigrationHook $hook * @param ?array $elevateConfig * * @return bool */ - public function apply(MigrationHook $hook, array $elevateConfig = null): bool + public function apply(DbMigrationHook $hook, array $elevateConfig = null): bool { - if ($hook->isModule() && $this->hasMigrations(MigrationHook::DEFAULT_MODULE)) { + if ($hook->isModule() && $this->hasMigrations(DbMigrationHook::DEFAULT_MODULE)) { Logger::error( 'Please apply the Icinga Web pending migration(s) first or apply all the migrations instead' ); @@ -166,7 +166,7 @@ final class MigrationManager implements Countable */ public function applyAll(array $elevateConfig = null): bool { - $default = MigrationHook::DEFAULT_MODULE; + $default = DbMigrationHook::DEFAULT_MODULE; if ($this->hasMigrations($default)) { $migration = $this->getMigration($default); if (! $this->apply($migration, $elevateConfig)) { @@ -189,7 +189,7 @@ final class MigrationManager implements Countable * * @param bool $modules * - * @return Generator + * @return Generator */ public function yieldMigrations(bool $modules = false): Generator { @@ -297,8 +297,8 @@ final class MigrationManager implements Countable { $this->pendingMigrations = []; - /** @var MigrationHook $hook */ - foreach (Hook::all('migration') as $hook) { + /** @var DbMigrationHook $hook */ + foreach (Hook::all('DbMigration') as $hook) { if (empty($hook->getMigrations())) { continue; } @@ -366,7 +366,7 @@ final class MigrationManager implements Countable public function toArray(): array { $framework = []; - $serialize = function (MigrationHook $hook): array { + $serialize = function (DbMigrationHook $hook): array { $serialized = [ 'name' => $hook->getName(), 'module' => $hook->getModuleName(), diff --git a/library/Icinga/Application/ProvidedHook/DbMigration.php b/library/Icinga/Application/ProvidedHook/DbMigration.php index 37d299535..06fd06f03 100644 --- a/library/Icinga/Application/ProvidedHook/DbMigration.php +++ b/library/Icinga/Application/ProvidedHook/DbMigration.php @@ -4,13 +4,13 @@ namespace Icinga\Application\ProvidedHook; -use Icinga\Application\Hook\MigrationHook; +use Icinga\Application\Hook\DbMigrationHook; use Icinga\Common\Database; use Icinga\Model\Schema; use ipl\Orm\Query; use ipl\Sql\Connection; -class DbMigration extends MigrationHook +class DbMigration extends DbMigrationHook { use Database { getDb as public getPublicDb; diff --git a/library/Icinga/Web/Widget/ItemList/MigrationList.php b/library/Icinga/Web/Widget/ItemList/MigrationList.php index cb6147bae..43699d3e5 100644 --- a/library/Icinga/Web/Widget/ItemList/MigrationList.php +++ b/library/Icinga/Web/Widget/ItemList/MigrationList.php @@ -6,7 +6,7 @@ namespace Icinga\Web\Widget\ItemList; use Generator; use Icinga\Application\Hook\Common\DbMigrationStep; -use Icinga\Application\Hook\MigrationHook; +use Icinga\Application\Hook\DbMigrationHook; use Icinga\Application\MigrationManager; use Icinga\Forms\MigrationForm; use ipl\I18n\Translation; @@ -19,7 +19,7 @@ class MigrationList extends BaseItemList protected $baseAttributes = ['class' => 'item-list']; - /** @var Generator */ + /** @var Generator */ protected $data; /** @var ?MigrationForm */ @@ -31,7 +31,7 @@ class MigrationList extends BaseItemList /** * Create a new migration list * - * @param Generator|array $data + * @param Generator|array $data * * @param ?MigrationForm $form */ @@ -82,7 +82,7 @@ class MigrationList extends BaseItemList $this->getAttributes()->add('class', 'file-list'); } - /** @var MigrationHook $data */ + /** @var DbMigrationHook $data */ foreach ($this->data as $data) { /** @var MigrationFileListItem|MigrationListItem $item */ $item = new $itemClass($data, $this); @@ -105,7 +105,7 @@ class MigrationList extends BaseItemList ); $mm = MigrationManager::instance(); - if ($data->isModule() && $mm->hasMigrations(MigrationHook::DEFAULT_MODULE)) { + if ($data->isModule() && $mm->hasMigrations(DbMigrationHook::DEFAULT_MODULE)) { $migrateButton->getAttributes() ->set('disabled', true) ->set( diff --git a/library/Icinga/Web/Widget/ItemList/MigrationListItem.php b/library/Icinga/Web/Widget/ItemList/MigrationListItem.php index 641ba5541..284ce4c84 100644 --- a/library/Icinga/Web/Widget/ItemList/MigrationListItem.php +++ b/library/Icinga/Web/Widget/ItemList/MigrationListItem.php @@ -5,7 +5,7 @@ namespace Icinga\Web\Widget\ItemList; use Icinga\Application\Hook\Common\DbMigrationStep; -use Icinga\Application\Hook\MigrationHook; +use Icinga\Application\Hook\DbMigrationHook; use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; use ipl\Html\Contract\FormElement; @@ -29,7 +29,7 @@ class MigrationListItem extends BaseListItem /** @var ?FormElement */ protected $migrateButton; - /** @var MigrationHook Just for type hint */ + /** @var DbMigrationHook Just for type hint */ protected $item; /** @@ -124,7 +124,7 @@ class MigrationListItem extends BaseListItem sprintf($this->translate('Show all %d migrations'), $this->item->count()), Url::fromPath( 'migrations/migration', - [MigrationHook::MIGRATION_PARAM => $this->item->getModuleName()] + [DbMigrationHook::MIGRATION_PARAM => $this->item->getModuleName()] ), [ 'data-base-target' => '_next',