From 595f831589acc87944a0439776abb8a953f1c70c Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Wed, 23 Apr 2014 19:41:55 +0200 Subject: [PATCH 1/3] [ticket/12432] Migrator should not revert custom functions https://tracker.phpbb.com/browse/PHPBB3-12432 PHPBB3-12432 --- phpBB/phpbb/db/migrator.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index d3bbbc63c5..5ad8563e5c 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -509,10 +509,17 @@ class migrator throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); } - return array( - $parameters[0], - array($last_result), - ); + if ($reverse) + { + return false; + } + else + { + return array( + $parameters[0], + array($last_result), + ); + } break; default: From 28176b0746807449d984823caed10b504dcd7305 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sat, 26 Apr 2014 12:12:51 +0200 Subject: [PATCH 2/3] [ticket/12432] Adding unit test PHPBB3-12432 --- tests/dbal/migration/revert.php | 8 ++++++++ tests/dbal/migrator_test.php | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index c2520f4d8a..1c98710ffb 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -35,6 +35,14 @@ class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration { return array( array('config.add', array('foobartest', 0)), + array('custom', array(array(&$this, 'my_custom_function'))), ); } + + function my_custom_function() + { + global $migrator_test_revert_counter; + + $migrator_test_revert_counter += 1; + } } diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index c18c49b2a0..d1e12e5b2e 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -174,10 +174,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case public function test_revert() { + global $migrator_test_revert_counter; + // Make sure there are no other migrations in the db, this could cause issues $this->db->sql_query("DELETE FROM phpbb_migrations"); $this->migrator->load_migration_state(); + $migrator_test_revert_counter = 0; + $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency')); $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); @@ -219,6 +223,11 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case { $this->fail('Revert did not remove test_column.'); } + + if ($migrator_test_revert_counter != 1) + { + $this->fail('Revert did not recall the customs functions.'); + } } public function test_fail() From ea15b879f127f3d121d8e78ae01457b43b702e58 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sat, 26 Apr 2014 18:54:47 +0200 Subject: [PATCH 3/3] [ticket/12432] Correcting the assertion PHPBB3-12432 --- tests/dbal/migrator_test.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index d1e12e5b2e..cc3e92071f 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -224,10 +224,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->fail('Revert did not remove test_column.'); } - if ($migrator_test_revert_counter != 1) - { - $this->fail('Revert did not recall the customs functions.'); - } + $this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again'); } public function test_fail()