From 000b8fefd2788c7f9f6aa6efc1d93658a00e48bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:21:01 -0600 Subject: [PATCH] [feature/migrations] Function to populate the migrations table (for install) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index b56da95b1a..69a5a4dd9c 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -124,6 +124,42 @@ class phpbb_db_migrator $this->migrations = $class_names; } + /** + * This function adds all migrations in a specified directory to the migrations table + * + * THIS SHOULD NOT GENERALLY BE USED! THIS IS FOR THE PHPBB INSTALLER. + * THIS WILL THROW ERRORS IF MIGRATIONS ALREADY EXIST IN THE TABLE, DO NOT CALL MORE THAN ONCE! + * + * @param string $path Path to migration data files + * @param bool $recursive Set to true to also load data files from subdirectories + * @return null + */ + public function populate_migrations_from_directory($path, $recursive = true) + { + $existing_migrations = $this->migrations; + + $this->migrations = array(); + $this->load_migrations($path, true, $recursive); + + foreach ($this->migrations as $name) + { + if ($this->migration_state($name) === false) + { + $state = array( + 'migration_depends_on' => $name::depends_on(), + 'migration_schema_done' => true, + 'migration_data_done' => true, + 'migration_data_state' => '', + 'migration_start_time' => time(), + 'migration_end_time' => time(), + ); + $this->insert_migration($name, $state); + } + } + + $this->migrations = $existing_migrations; + } + /** * Load migration data files from a directory *