Skip to content

Commit 27027de

Browse files
committed
[ticket/14434] Refactored to check migrations when setting them
PHPBB3-14434
1 parent fb1acb0 commit 27027de

6 files changed

Lines changed: 26 additions & 38 deletions

File tree

phpBB/phpbb/console/command/db/list_command.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
3939

4040
foreach ($this->load_migrations() as $name)
4141
{
42-
// Ignore non-migration files
43-
if (\phpbb\db\migrator::is_migration($name) === false)
44-
{
45-
continue;
46-
}
47-
4842
if ($this->migrator->migration_state($name) !== false)
4943
{
5044
$installed[] = $name;

phpBB/phpbb/console/command/db/migration_command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function load_migrations()
4545

4646
$this->migrator->set_migrations($migrations);
4747

48-
return $migrations;
48+
return $this->migrator->get_migrations();
4949
}
5050

5151
protected function finalise_update()

phpBB/phpbb/db/migrator.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,27 @@ public function load_migration_state()
170170
*/
171171
public function set_migrations($class_names)
172172
{
173+
foreach ($class_names as $key => $class)
174+
{
175+
if (!self::is_migration($class))
176+
{
177+
unset($class_names[$key]);
178+
}
179+
}
180+
173181
$this->migrations = $class_names;
174182
}
175183

184+
/**
185+
* Get the list of available migration class names
186+
*
187+
* @return array Array of all migrations available to be run
188+
*/
189+
public function get_migrations()
190+
{
191+
return $this->migrations;
192+
}
193+
176194
/**
177195
* Runs a single update step from the next migration to be applied.
178196
*
@@ -226,7 +244,7 @@ protected function update_do()
226244
*/
227245
protected function try_apply($name)
228246
{
229-
if (!self::is_migration($name))
247+
if (!class_exists($name))
230248
{
231249
$this->output_handler->write(array('MIGRATION_NOT_VALID', $name), migrator_output_handler_interface::VERBOSITY_DEBUG);
232250
return false;
@@ -401,7 +419,7 @@ protected function revert_do($migration)
401419
*/
402420
protected function try_revert($name)
403421
{
404-
if (!self::is_migration($name))
422+
if (!class_exists($name))
405423
{
406424
return false;
407425
}
@@ -719,7 +737,7 @@ public function unfulfillable($name)
719737
return false;
720738
}
721739

722-
if (!self::is_migration($name))
740+
if (!class_exists($name))
723741
{
724742
return $name;
725743
}

phpBB/phpbb/extension/base.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ public function is_enableable()
7373
*/
7474
public function enable_step($old_state)
7575
{
76-
$migrations = $this->get_migration_file_list();
77-
78-
$this->migrator->set_migrations($migrations);
76+
$this->get_migration_file_list();
7977

8078
$this->migrator->update();
8179

@@ -103,8 +101,6 @@ public function purge_step($old_state)
103101
{
104102
$migrations = $this->get_migration_file_list();
105103

106-
$this->migrator->set_migrations($migrations);
107-
108104
foreach ($migrations as $migration)
109105
{
110106
while ($this->migrator->migration_state($migration) !== false)
@@ -137,16 +133,9 @@ protected function get_migration_file_list()
137133

138134
$migrations = $this->extension_finder->get_classes_from_files($migrations);
139135

140-
// Unset classes that are not a valid migration
141-
foreach ($migrations as $key => $migration)
142-
{
143-
if (\phpbb\db\migrator::is_migration($migration) === true)
144-
{
145-
continue;
146-
}
136+
$this->migrator->set_migrations($migrations);
147137

148-
unset($migrations[$key]);
149-
}
138+
$migrations = $this->migrator->get_migrations();
150139

151140
return $migrations;
152141
}

phpBB/phpbb/install/module/update_database/task/update.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,8 @@ public function run()
139139
->extension_directory('/migrations')
140140
->get_classes();
141141

142-
// Unset classes that are not a valid migration
143-
foreach ($migrations as $key => $migration_class)
144-
{
145-
if (\phpbb\db\migrator::is_migration($migration_class) === false)
146-
{
147-
unset($migrations[$key]);
148-
}
149-
}
150-
151142
$this->migrator->set_migrations($migrations);
152-
$migration_count = count($migrations);
143+
$migration_count = count($this->migrator->get_migrations());
153144
$this->iohandler->set_task_count($migration_count, true);
154145
$progress_count = $this->installer_config->get('database_update_count', 0);
155146

tests/mock/migrator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ public function load_migration_state()
2121
{
2222
}
2323

24-
public function set_migrations($class_names)
25-
{
26-
}
27-
2824
public function update()
2925
{
3026
}

0 commit comments

Comments
 (0)