aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-01-13 12:39:08 -0600
committerNathan Guse <nathaniel.guse@gmail.com>2013-01-13 12:39:08 -0600
commit26c16559c3496f5496ad6e83e55c40f03edda5bd (patch)
tree7fae40060eb2da6b5aaa68cb20516d3b233dbd8f
parent93f9ebbb258a06e34198cffda0f5fd8dfdf29597 (diff)
downloadforums-26c16559c3496f5496ad6e83e55c40f03edda5bd.tar
forums-26c16559c3496f5496ad6e83e55c40f03edda5bd.tar.gz
forums-26c16559c3496f5496ad6e83e55c40f03edda5bd.tar.bz2
forums-26c16559c3496f5496ad6e83e55c40f03edda5bd.tar.xz
forums-26c16559c3496f5496ad6e83e55c40f03edda5bd.zip
[feature/migrations] Function effectively_installed() in migrations
Allows you to check if the migration is effectively installed (entirely optionall) This function is intended to help moving to migrations from a previous database updater, where some migrations may have been installed already even though they are not yet listed in the migrations table. PHPBB3-9737
-rw-r--r--phpBB/includes/db/migration/migration.php15
-rw-r--r--phpBB/includes/db/migrator.php20
-rw-r--r--tests/dbal/migration/installed.php30
-rw-r--r--tests/dbal/migrator_test.php21
4 files changed, 83 insertions, 3 deletions
diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php
index 4271751362..cf1e97b3b1 100644
--- a/phpBB/includes/db/migration/migration.php
+++ b/phpBB/includes/db/migration/migration.php
@@ -84,6 +84,21 @@ abstract class phpbb_db_migration
}
/**
+ * Allows you to check if the migration is effectively installed (entirely optionall)
+ *
+ * This is checked when a migration is installed. If true is returned, the migration will be set as
+ * installed without performing the database changes.
+ * This function is intended to help moving to migrations from a previous database updater, where some
+ * migrations may have been installed already even though they are not yet listed in the migrations table.
+ *
+ * @return bool True if this migration is installed, False if this migration is not installed (checked on install)
+ */
+ public function effectively_installed()
+ {
+ return false;
+ }
+
+ /**
* Updates the database schema by providing a set of change instructions
*
* @return array Array of schema changes (compatible with db_tools->perform_schema_changes())
diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php
index 6b249e3ee0..b56da95b1a 100644
--- a/phpBB/includes/db/migrator.php
+++ b/phpBB/includes/db/migrator.php
@@ -271,10 +271,24 @@ class phpbb_db_migrator
'class' => $migration,
);
- if (!isset($this->migration_state[$name]))
+ if ($migration->effectively_installed())
{
- $state['migration_start_time'] = time();
- $this->insert_migration($name, $state);
+ $state = array(
+ 'migration_depends_on' => $migration->depends_on(),
+ 'migration_schema_done' => true,
+ 'migration_data_done' => true,
+ 'migration_data_state' => '',
+ 'migration_start_time' => 0,
+ 'migration_end_time' => 0,
+ );
+ }
+ else
+ {
+ if (!isset($this->migration_state[$name]))
+ {
+ $state['migration_start_time'] = time();
+ $this->insert_migration($name, $state);
+ }
}
if (!$state['migration_schema_done'])
diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php
new file mode 100644
index 0000000000..01829f7a99
--- /dev/null
+++ b/tests/dbal/migration/installed.php
@@ -0,0 +1,30 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_installed extends phpbb_db_migration
+{
+ function effectively_installed()
+ {
+ return true;
+ }
+
+ function update_data()
+ {
+ return array(
+ array('custom', array(array(&$this, 'test'))),
+ );
+ }
+
+ function test()
+ {
+ global $migrator_test_installed_failed;
+
+ $migrator_test_installed_failed = true;
+ }
+}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index 69db7ca047..9460e76f37 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -19,6 +19,7 @@ require_once dirname(__FILE__) . '/migration/recall.php';
require_once dirname(__FILE__) . '/migration/revert.php';
require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
require_once dirname(__FILE__) . '/migration/fail.php';
+require_once dirname(__FILE__) . '/migration/installed.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
@@ -233,4 +234,24 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->fail('Revert did not remove test_column.');
}
}
+
+ public function test_installed()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_installed'));
+
+ global $migrator_test_installed_failed;
+ $migrator_test_installed_failed = false;
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false);
+
+ if ($migrator_test_installed_failed)
+ {
+ $this->fail('Installed test failed');
+ }
+ }
}