Returns a migrator for a module.
public getMigrator ( string $app, Horde_Log_Logger $logger = null ) : Horde_Db_Migration_Migrator | ||
$app | string | An application or library name. |
$logger | Horde_Log_Logger | A logger instance. |
return | Horde_Db_Migration_Migrator | A migrator for the specified module. |
/** * Creates or updates the database tables. * * @throws Horde_Db_Exception */ public function migrateDb() { $this->_cli->writeln(); echo 'Creating and updating database tables...'; $migration = new Horde_Core_Db_Migration(null, $this->_pearconf); // Try twice to work around unresolved migration dependencies. for ($i = 0; $i < 2; $i++) { $error = null; foreach ($migration->apps as $app) { $migrator = $migration->getMigrator($app); if ($migrator->getTargetVersion() <= $migrator->getCurrentVersion()) { continue; } try { $migrator->up(); } catch (Exception $error) { if ($i) { throw $error; } } } if (!$error) { break; } } $this->_cli->writeln($this->_cli->green(' done.')); }
/** * Perform all functions for this task. */ public function execute() { /* Check if test script is active. */ if (empty($GLOBALS['conf']['testdisable'])) { $GLOBALS['notification']->push(_("The test script is currently enabled. For security reasons, disable test scripts when you are done testing (see horde/docs/INSTALL)."), 'horde.warning'); } if (!empty($GLOBALS['conf']['sql']['phptype'])) { /* Check for outdated DB schemas. */ $migration = new Horde_Core_Db_Migration(); foreach ($migration->apps as $app) { $migrator = $migration->getMigrator($app); if ($migrator->getTargetVersion() > $migrator->getCurrentVersion()) { $GLOBALS['notification']->push(Horde::link(Horde::url('admin/config/index.php', false, array('app' => 'horde'))) . _("At least one database schema is outdated.") . '</a>', 'horde.warning', array('content.raw', 'sticky')); break; } } } }
$form->setSubmitted(true); if ($form->validate($vars)) { $config = new Horde_Config($app); if (!$config->writePHPConfig($vars)) { $notification->push(sprintf(_("Could not save the configuration file %s. Use one of the options below to save the code."), Horde_Util::realPath($config->configFile())), 'horde.warning', array('content.raw', 'sticky')); } } else { $notification->push(sprintf(_("The configuration for %s cannot be updated automatically. Please update the configuration manually."), $app), 'horde.error'); } } } /* Update schema if requested. */ if ($vars->action == 'schema') { $apps = isset($vars->app) ? array($vars->app) : $migration->apps; foreach ($apps as $app) { $migrator = $migration->getMigrator($app); if ($migrator->getTargetVersion() <= $migrator->getCurrentVersion()) { continue; } try { $migrator->up(); $notification->push(sprintf(_("Updated schema for %s."), $app), 'horde.success'); } catch (Exception $e) { $notification->push($e); } } } /* Create NoSQL indices if requested. */ if ($vars->action == 'nosql_indices') { $nosql->buildIndices($vars->app); }