mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/14434] Refactored to check migrations when setting them
PHPBB3-14434
This commit is contained in:
parent
fb1acb0ef4
commit
27027deb9c
6 changed files with 26 additions and 38 deletions
|
@ -39,12 +39,6 @@ class list_command extends \phpbb\console\command\db\migration_command
|
||||||
|
|
||||||
foreach ($this->load_migrations() as $name)
|
foreach ($this->load_migrations() as $name)
|
||||||
{
|
{
|
||||||
// Ignore non-migration files
|
|
||||||
if (\phpbb\db\migrator::is_migration($name) === false)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->migrator->migration_state($name) !== false)
|
if ($this->migrator->migration_state($name) !== false)
|
||||||
{
|
{
|
||||||
$installed[] = $name;
|
$installed[] = $name;
|
||||||
|
|
|
@ -45,7 +45,7 @@ abstract class migration_command extends \phpbb\console\command\command
|
||||||
|
|
||||||
$this->migrator->set_migrations($migrations);
|
$this->migrator->set_migrations($migrations);
|
||||||
|
|
||||||
return $migrations;
|
return $this->migrator->get_migrations();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function finalise_update()
|
protected function finalise_update()
|
||||||
|
|
|
@ -170,9 +170,27 @@ class migrator
|
||||||
*/
|
*/
|
||||||
public function set_migrations($class_names)
|
public function set_migrations($class_names)
|
||||||
{
|
{
|
||||||
|
foreach ($class_names as $key => $class)
|
||||||
|
{
|
||||||
|
if (!self::is_migration($class))
|
||||||
|
{
|
||||||
|
unset($class_names[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->migrations = $class_names;
|
$this->migrations = $class_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of available migration class names
|
||||||
|
*
|
||||||
|
* @return array Array of all migrations available to be run
|
||||||
|
*/
|
||||||
|
public function get_migrations()
|
||||||
|
{
|
||||||
|
return $this->migrations;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a single update step from the next migration to be applied.
|
* Runs a single update step from the next migration to be applied.
|
||||||
*
|
*
|
||||||
|
@ -226,7 +244,7 @@ class migrator
|
||||||
*/
|
*/
|
||||||
protected function try_apply($name)
|
protected function try_apply($name)
|
||||||
{
|
{
|
||||||
if (!self::is_migration($name))
|
if (!class_exists($name))
|
||||||
{
|
{
|
||||||
$this->output_handler->write(array('MIGRATION_NOT_VALID', $name), migrator_output_handler_interface::VERBOSITY_DEBUG);
|
$this->output_handler->write(array('MIGRATION_NOT_VALID', $name), migrator_output_handler_interface::VERBOSITY_DEBUG);
|
||||||
return false;
|
return false;
|
||||||
|
@ -401,7 +419,7 @@ class migrator
|
||||||
*/
|
*/
|
||||||
protected function try_revert($name)
|
protected function try_revert($name)
|
||||||
{
|
{
|
||||||
if (!self::is_migration($name))
|
if (!class_exists($name))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -719,7 +737,7 @@ class migrator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self::is_migration($name))
|
if (!class_exists($name))
|
||||||
{
|
{
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,7 @@ class base implements \phpbb\extension\extension_interface
|
||||||
*/
|
*/
|
||||||
public function enable_step($old_state)
|
public function enable_step($old_state)
|
||||||
{
|
{
|
||||||
$migrations = $this->get_migration_file_list();
|
$this->get_migration_file_list();
|
||||||
|
|
||||||
$this->migrator->set_migrations($migrations);
|
|
||||||
|
|
||||||
$this->migrator->update();
|
$this->migrator->update();
|
||||||
|
|
||||||
|
@ -103,8 +101,6 @@ class base implements \phpbb\extension\extension_interface
|
||||||
{
|
{
|
||||||
$migrations = $this->get_migration_file_list();
|
$migrations = $this->get_migration_file_list();
|
||||||
|
|
||||||
$this->migrator->set_migrations($migrations);
|
|
||||||
|
|
||||||
foreach ($migrations as $migration)
|
foreach ($migrations as $migration)
|
||||||
{
|
{
|
||||||
while ($this->migrator->migration_state($migration) !== false)
|
while ($this->migrator->migration_state($migration) !== false)
|
||||||
|
@ -137,16 +133,9 @@ class base implements \phpbb\extension\extension_interface
|
||||||
|
|
||||||
$migrations = $this->extension_finder->get_classes_from_files($migrations);
|
$migrations = $this->extension_finder->get_classes_from_files($migrations);
|
||||||
|
|
||||||
// Unset classes that are not a valid migration
|
$this->migrator->set_migrations($migrations);
|
||||||
foreach ($migrations as $key => $migration)
|
|
||||||
{
|
|
||||||
if (\phpbb\db\migrator::is_migration($migration) === true)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($migrations[$key]);
|
$migrations = $this->migrator->get_migrations();
|
||||||
}
|
|
||||||
|
|
||||||
return $migrations;
|
return $migrations;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,17 +139,8 @@ class update extends task_base
|
||||||
->extension_directory('/migrations')
|
->extension_directory('/migrations')
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
// Unset classes that are not a valid migration
|
|
||||||
foreach ($migrations as $key => $migration_class)
|
|
||||||
{
|
|
||||||
if (\phpbb\db\migrator::is_migration($migration_class) === false)
|
|
||||||
{
|
|
||||||
unset($migrations[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->migrator->set_migrations($migrations);
|
$this->migrator->set_migrations($migrations);
|
||||||
$migration_count = count($migrations);
|
$migration_count = count($this->migrator->get_migrations());
|
||||||
$this->iohandler->set_task_count($migration_count, true);
|
$this->iohandler->set_task_count($migration_count, true);
|
||||||
$progress_count = $this->installer_config->get('database_update_count', 0);
|
$progress_count = $this->installer_config->get('database_update_count', 0);
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,6 @@ class phpbb_mock_migrator extends \phpbb\db\migrator
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_migrations($class_names)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue