From f817e20f287a21e2dddfba9721f5e02dce162d29 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 15 Jul 2011 11:57:53 -0400 Subject: [feature/migrations] Basic migrations with schema and data changes The migrator takes care of applying migrations as necessary. RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41337 PHPBB3-9737 --- phpBB/includes/db/migrator.php | 227 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 phpBB/includes/db/migrator.php (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php new file mode 100644 index 0000000000..d5d938ca28 --- /dev/null +++ b/phpBB/includes/db/migrator.php @@ -0,0 +1,227 @@ +db = &$db; + $this->db_tools = &$db_tools; + $this->migrations_table = $migrations_table; + $this->migrations = array(); + + $this->load_migration_state(); + } + + /** + * Loads all migrations and their application state from the database. + * + * @return null + */ + function load_migration_state() + { + $sql = "SELECT * + FROM " . $this->migrations_table; + $result = $this->db->sql_query($sql); + + $this->migration_state = array(); + while ($migration = $this->db->sql_fetchrow($result)) + { + $this->migration_state[$migration['migration_name']] = $migration; + } + + $this->db->sql_freeresult($result); + } + + /** + * Sets the list of available migration class names to the given array. + * + * @param array $class_names An array of migration class names + * @return null + */ + function set_migrations($class_names) + { + $this->migrations = $class_names; + } + + /** + * Runs a single update step from the next migration to be applied. + * + * The update step can either be a schema or a (partial) data update. To + * check if update() needs to be called again use the finished() method. + * + * @return null + */ + function update() + { + foreach ($this->migrations as $name) + { + if (!isset($this->migration_state[$name]) || + !$this->migration_state[$name]['migration_schema_done'] || + !$this->migration_state[$name]['migration_data_done']) + { + if (!$this->try_apply($name)) + { + continue; + } + else + { + return; + } + } + } + } + + /** + * Attempts to apply a step of the given migration or one of its dependencies + * + * @param string The class name of the migration + * @return bool Whether any update step was successfully run + */ + function try_apply($name) + { + if (!class_exists($name)) + { + return false; + } + + $migration =& new $name($this->db, $this->db_tools); + $state = (isset($this->migration_state[$name])) ? + $this->migration_state[$name] : + array( + 'migration_schema_done' => false, + 'migration_data_done' => false, + 'migration_data_state' => '', + ); + + $depends = $migration->depends_on(); + + foreach ($depends as $depend) + { + if (!isset($this->migration_state[$depend]) || + !$this->migration_state[$depend]['migration_schema_done'] || + !$this->migration_state[$depend]['migration_data_done']) + { + return $this->try_apply($depend); + } + } + + if (!$state['migration_schema_done']) + { + $migration->update_schema(); + $state['migration_schema_done'] = true; + } + else + { + $migration->update_data(); + $state['migration_data_done'] = true; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + + return true; + } + + /** + * Checks if a migration's dependencies can even theoretically be satisfied. + * + * @param string $name The class name of the migration + * @return bool Whether the migration cannot be fulfilled + */ + function unfulfillable($name) + { + if (isset($this->migration_state[$name])) + { + return false; + } + + if (!class_exists($name)) + { + return true; + } + + $migration =& new $name($this->db, $this->db_tools); + $depends = $migration->depends_on(); + + foreach ($depends as $depend) + { + if ($this->unfulfillable($depend)) + { + return true; + } + } + + return false; + } + + /** + * Checks whether all available, fulfillable migrations have been applied. + * + * @return bool Whether the migrations have been applied + */ + function finished() + { + foreach ($this->migrations as $name) + { + if (!isset($this->migration_state[$name])) + { + // skip unfulfillable migrations, but fulfillables mean we + // are not finished yet + if ($this->unfulfillable($name)) + { + continue; + } + return false; + } + + $migration = $this->migration_state[$name]; + + if (!$migration['migration_schema_done'] || !$migration['migration_data_done']) + { + return false; + } + } + + return true; + } +} -- cgit v1.2.1 From d304b6449db6e7c6f3c9058062aca0c641f023a4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 7 Aug 2011 19:10:38 -0400 Subject: [feature/migrations] Store start and end time of migrations PHPBB3-9737 --- phpBB/includes/db/migrator.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index d5d938ca28..f4613e3aec 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -127,6 +127,8 @@ class phpbb_db_migrator 'migration_schema_done' => false, 'migration_data_done' => false, 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, ); $depends = $migration->depends_on(); @@ -141,6 +143,12 @@ class phpbb_db_migrator } } + if (!isset($this->migration_state[$name])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } + if (!$state['migration_schema_done']) { $migration->update_schema(); @@ -150,6 +158,7 @@ class phpbb_db_migrator { $migration->update_data(); $state['migration_data_done'] = true; + $state['migration_end_time'] = time(); } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -162,6 +171,18 @@ class phpbb_db_migrator return true; } + function insert_migration($name, $state) + { + $migration_row = $state; + $migration_row['migration_name'] = $name; + + $sql = 'INSERT INTO ' . $this->migrations_table . ' + ' . $this->db->sql_build_array('INSERT', $migration_row); + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + } + /** * Checks if a migration's dependencies can even theoretically be satisfied. * -- cgit v1.2.1 From 8645321f40d0b13de6201688c69f9f05bc649dcf Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 12:26:44 -0700 Subject: [feature/migrations] Return schema changes in database update style array Returning the set of schema changes allows potentially aggregating to generate the overall install schema automatically from a set of migrations PHPBB3-9737 --- phpBB/includes/db/migrator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index f4613e3aec..4a178af468 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -151,7 +151,7 @@ class phpbb_db_migrator if (!$state['migration_schema_done']) { - $migration->update_schema(); + $this->apply_schema_changes($migration->update_schema()); $state['migration_schema_done'] = true; } else @@ -245,4 +245,9 @@ class phpbb_db_migrator return true; } + + function apply_schema_changes($schema_changes) + { + $this->db_tools->perform_schema_changes($schema_changes); + } } -- cgit v1.2.1 From c802f2a66c577781036b7bfd6d6689159028c3a6 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 13:02:56 -0700 Subject: [feature/migrations] Standard vars for migrations and run sql with feedback PHPBB3-9737 --- phpBB/includes/db/migrator.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4a178af468..4ce54a4b92 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -24,6 +24,10 @@ class phpbb_db_migrator { var $db; var $db_tools; + var $table_prefix; + + var $phpbb_root_path; + var $php_ext; var $migrations_table; var $migration_state; @@ -35,16 +39,23 @@ class phpbb_db_migrator * * @param dbal $db Connected database abstraction instance * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools + * @param string $table_prefix The prefix for all table names * @param string $migrations_table The name of the db table storing * information on applied migrations + * @param string $phpbb_root_path + * @param string $php_ext */ - function phpbb_db_migrator(&$db, &$db_tools, $migrations_table) + function phpbb_db_migrator(&$db, &$db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { $this->db = &$db; $this->db_tools = &$db_tools; + $this->table_prefix = $table_prefix; $this->migrations_table = $migrations_table; $this->migrations = array(); + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->load_migration_state(); } @@ -120,7 +131,7 @@ class phpbb_db_migrator return false; } - $migration =& new $name($this->db, $this->db_tools); + $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -201,7 +212,7 @@ class phpbb_db_migrator return true; } - $migration =& new $name($this->db, $this->db_tools); + $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $depends = $migration->depends_on(); foreach ($depends as $depend) -- cgit v1.2.1 From 91a921a96bf26607879de850fca105be78eadf1d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 09:43:07 +0100 Subject: [feature/migrations] Change migration data processing to run step by step --- phpBB/includes/db/migrator.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4ce54a4b92..912a7b34ba 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -167,7 +167,7 @@ class phpbb_db_migrator } else { - $migration->update_data(); + $this->process_data_step($migration); $state['migration_data_done'] = true; $state['migration_end_time'] = time(); } @@ -182,6 +182,28 @@ class phpbb_db_migrator return true; } + function process_data_step(&$migration) + { + $continue = false; + $steps = $migration->update_data(); + + foreach ($steps as $step) + { + $continue = $this->run_step($step); + if (!$continue) + { + return false; + } + } + + return $continue; + } + + function run_step(&$step) + { + + } + function insert_migration($name, $state) { $migration_row = $state; -- cgit v1.2.1 From 82efb3e446efbb8ef05c6a777e3866901abfd07a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:12 -0600 Subject: [feature/migrations] Remove references as it is now 3.1 code PHPBB3-9737 --- phpBB/includes/db/migrator.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 912a7b34ba..9f94273c63 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -45,10 +45,10 @@ class phpbb_db_migrator * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migrator(&$db, &$db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { - $this->db = &$db; - $this->db_tools = &$db_tools; + $this->db = $db; + $this->db_tools = $db_tools; $this->table_prefix = $table_prefix; $this->migrations_table = $migrations_table; $this->migrations = array(); @@ -131,7 +131,7 @@ class phpbb_db_migrator return false; } - $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -182,7 +182,7 @@ class phpbb_db_migrator return true; } - function process_data_step(&$migration) + function process_data_step($migration) { $continue = false; $steps = $migration->update_data(); @@ -199,7 +199,7 @@ class phpbb_db_migrator return $continue; } - function run_step(&$step) + function run_step($step) { } @@ -234,7 +234,7 @@ class phpbb_db_migrator return true; } - $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $depends = $migration->depends_on(); foreach ($depends as $depend) -- cgit v1.2.1 From 41de95bc11c0b64eafa294f03432f619d3d712d5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 12:12:05 +0100 Subject: [feature/migrations] Process migration steps and move to PHP5 code --- phpBB/includes/db/migrator.php | 126 ++++++++++++++++++++++++++++++++++------- 1 file changed, 107 insertions(+), 19 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 9f94273c63..9187e09869 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,17 +22,17 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { - var $db; - var $db_tools; - var $table_prefix; + protected $db; + protected $db_tools; + protected $table_prefix; - var $phpbb_root_path; - var $php_ext; + protected $phpbb_root_path; + protected $php_ext; - var $migrations_table; - var $migration_state; + protected $migrations_table; + protected $migration_state; - var $migrations; + protected $migrations; /** * Constructor of the database migrator @@ -45,7 +45,7 @@ class phpbb_db_migrator * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + public function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { $this->db = $db; $this->db_tools = $db_tools; @@ -64,7 +64,7 @@ class phpbb_db_migrator * * @return null */ - function load_migration_state() + public function load_migration_state() { $sql = "SELECT * FROM " . $this->migrations_table; @@ -85,7 +85,7 @@ class phpbb_db_migrator * @param array $class_names An array of migration class names * @return null */ - function set_migrations($class_names) + public function set_migrations($class_names) { $this->migrations = $class_names; } @@ -98,7 +98,7 @@ class phpbb_db_migrator * * @return null */ - function update() + public function update() { foreach ($this->migrations as $name) { @@ -124,7 +124,7 @@ class phpbb_db_migrator * @param string The class name of the migration * @return bool Whether any update step was successfully run */ - function try_apply($name) + protected function try_apply($name) { if (!class_exists($name)) { @@ -182,7 +182,7 @@ class phpbb_db_migrator return true; } - function process_data_step($migration) + protected function process_data_step($migration) { $continue = false; $steps = $migration->update_data(); @@ -190,6 +190,7 @@ class phpbb_db_migrator foreach ($steps as $step) { $continue = $this->run_step($step); + if (!$continue) { return false; @@ -199,12 +200,99 @@ class phpbb_db_migrator return $continue; } - function run_step($step) + protected function run_step($step) { + try + { + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $parameters = $callable_and_parameters[1]; + + call_user_func_array($callable, $parameters); + + return false; + } + catch (phpbb_db_migration_exception $e) + { + echo $e;die(); + } + } + public function get_callable_from_step($step) + { + $type = $step[0]; + $parameters = $step[1]; + + $parts = explode('.', $type); + + $class = $parts[0]; + $method = false; + + if (isset($parts[1])) + { + $method = $parts[1]; + } + + switch ($class) + { + case 'if': + if (!isset($parameters[0])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_CONDITION', $step); + } + + if (!isset($parameters[1])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step); + } + + $condition = $parameters[0]; + $step = $parameters[1]; + + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $sub_parameters = $callable_and_parameters[1]; + return array( + function ($condition) use ($callable, $sub_parameters) { + return call_user_func_array($callable, $sub_parameters); + }, + array($condition) + ); + break; + case 'custom': + if (!is_callable($parameters[0])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); + } + + return array($parameters[0], array()); + break; + + default: + if (!$method) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNKNOWN_TYPE', $step); + } + + if (!isset($this->tools[$class])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_TOOL', $step); + } + + if (!method_exists(get_class($this->tools[$class]), $method)) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); + } + + return array( + array($this->tools[$class], $method), + $parameters + ); + break; + } } - function insert_migration($name, $state) + protected function insert_migration($name, $state) { $migration_row = $state; $migration_row['migration_name'] = $name; @@ -222,7 +310,7 @@ class phpbb_db_migrator * @param string $name The class name of the migration * @return bool Whether the migration cannot be fulfilled */ - function unfulfillable($name) + public function unfulfillable($name) { if (isset($this->migration_state[$name])) { @@ -253,7 +341,7 @@ class phpbb_db_migrator * * @return bool Whether the migrations have been applied */ - function finished() + public function finished() { foreach ($this->migrations as $name) { @@ -279,7 +367,7 @@ class phpbb_db_migrator return true; } - function apply_schema_changes($schema_changes) + protected function apply_schema_changes($schema_changes) { $this->db_tools->perform_schema_changes($schema_changes); } -- cgit v1.2.1 From 6c44dadecbf50d6550f98dd1e1694519f39be680 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:26 -0600 Subject: [feature/migrations] Move migrator to service container Version numbers 3.1 updates Restore database_update.php file to what it was in develop Get first forum to place global announcements in PHPBB3-9737 --- phpBB/includes/db/migrator.php | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 9187e09869..c9590fccf6 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,6 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { + protected $container; protected $db; protected $db_tools; protected $table_prefix; @@ -37,24 +38,26 @@ class phpbb_db_migrator /** * Constructor of the database migrator * - * @param dbal $db Connected database abstraction instance - * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools - * @param string $table_prefix The prefix for all table names - * @param string $migrations_table The name of the db table storing - * information on applied migrations - * @param string $phpbb_root_path - * @param string $php_ext + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + public function phpbb_db_migrator(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) { - $this->db = $db; - $this->db_tools = $db_tools; - $this->table_prefix = $table_prefix; - $this->migrations_table = $migrations_table; - $this->migrations = array(); - - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->container = $container; + $this->db = $this->container->get('dbal.conn'); + $this->db_tools = $this->container->get('dbal.tools'); + $this->table_prefix = $this->container->getParameters('core.table_prefix'); + $this->migrations_table = $this->container->getParameters('tables.migrations'); + $this->migrations = $migrations; + + $this->phpbb_root_path = $this->container->getParameters('core.root_path'); + $this->php_ext = $this->container->getParameters('core.php_ext'); + + /** @todo replace with collection_pass when merged */ + $this->tools = array( + 'config' => new phpbb_db_migration_tools_config, + 'module' => new phpbb_db_migration_tools_module, + 'permission' => new phpbb_db_migration_tools_permission, + ); $this->load_migration_state(); } -- cgit v1.2.1 From 61debcf14ca14afbb503b2535ef392a75002e8ae Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 12 Nov 2012 16:46:19 -0500 Subject: [feature/migrations] Update phpbb_db_migrator class for PHP 5.3.3 PHPBB3-9737 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index c9590fccf6..216faf9866 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -40,7 +40,7 @@ class phpbb_db_migrator * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migrator(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) + public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) { $this->container = $container; $this->db = $this->container->get('dbal.conn'); -- cgit v1.2.1 From 5c91e2569cb3a400acd20bf06cc0e609dd63a778 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:09:14 -0600 Subject: [feature/migrations] Migrations now somewhat works PHPBB3-9737 --- phpBB/includes/db/migrator.php | 113 +++++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 33 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 216faf9866..2fd795b659 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { - protected $container; + protected $config; protected $db; protected $db_tools; protected $table_prefix; @@ -33,31 +33,31 @@ class phpbb_db_migrator protected $migrations_table; protected $migration_state; - protected $migrations; + protected $migrations = array(); + + /** @var string Name of the last migration run */ + public $last_run_migration = false; /** * Constructor of the database migrator - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) + public function __construct($config, phpbb_db_driver $db, $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { - $this->container = $container; - $this->db = $this->container->get('dbal.conn'); - $this->db_tools = $this->container->get('dbal.tools'); - $this->table_prefix = $this->container->getParameters('core.table_prefix'); - $this->migrations_table = $this->container->getParameters('tables.migrations'); - $this->migrations = $migrations; - - $this->phpbb_root_path = $this->container->getParameters('core.root_path'); - $this->php_ext = $this->container->getParameters('core.php_ext'); - - /** @todo replace with collection_pass when merged */ - $this->tools = array( - 'config' => new phpbb_db_migration_tools_config, - 'module' => new phpbb_db_migration_tools_module, - 'permission' => new phpbb_db_migration_tools_permission, - ); + $this->config = $config; + $this->db = $db; + $this->db_tools = $db_tools; + + $this->migrations_table = $migrations_table; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->table_prefix = $table_prefix; + + foreach ($tools as $tool) + { + $this->tools[$tool->get_name()] = $tool; + } $this->load_migration_state(); } @@ -93,13 +93,44 @@ class phpbb_db_migrator $this->migrations = $class_names; } + /** + * Load migration data files from a directory + * + * @param string $path + * @return array Array of migrations with names + */ + public function load_migrations($path) + { + $handle = opendir($path); + while (($file = readdir($handle)) !== false) + { + if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) + { + $name = 'phpbb_db_migration_data_' . substr($file, 0, -(strlen($this->php_ext) + 1)); + + if (!in_array($name, $this->migrations)) + { + $this->migrations[] = $name; + } + } + } + + foreach ($this->migrations as $name) + { + if ($this->unfulfillable($name)) + { + throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + } + } + + return $this->migrations; + } + /** * Runs a single update step from the next migration to be applied. * * The update step can either be a schema or a (partial) data update. To * check if update() needs to be called again use the finished() method. - * - * @return null */ public function update() { @@ -134,7 +165,8 @@ class phpbb_db_migrator return false; } - $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = $this->get_migration($name); + $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -157,6 +189,11 @@ class phpbb_db_migrator } } + $this->last_run_migration = array( + 'name' => $name, + 'class' => $migration, + ); + if (!isset($this->migration_state[$name])) { $state['migration_start_time'] = time(); @@ -187,20 +224,20 @@ class phpbb_db_migrator protected function process_data_step($migration) { - $continue = false; + //$continue = false; $steps = $migration->update_data(); foreach ($steps as $step) { $continue = $this->run_step($step); - if (!$continue) + /*if ($continue === false) { return false; - } + }*/ } - return $continue; + //return $continue; } protected function run_step($step) @@ -211,13 +248,12 @@ class phpbb_db_migrator $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; - call_user_func_array($callable, $parameters); - - return false; + return call_user_func_array($callable, $parameters); } catch (phpbb_db_migration_exception $e) { - echo $e;die(); + echo $e; + die(); } } @@ -325,7 +361,7 @@ class phpbb_db_migrator return true; } - $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = $this->get_migration($name); $depends = $migration->depends_on(); foreach ($depends as $depend) @@ -374,4 +410,15 @@ class phpbb_db_migrator { $this->db_tools->perform_schema_changes($schema_changes); } + + /** + * Helper to get a migration + * + * @param string $name Name of the migration + * @return phpbb_db_migration + */ + protected function get_migration($name) + { + return new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); + } } -- cgit v1.2.1 From e3737978f76a962385a26de910959607d0ae0d30 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 14:27:01 -0600 Subject: [feature/migrations] Fixing returns of callables and handling data state Lots of comments and some other miscellaneous fixes. PHPBB3-9737 --- phpBB/includes/db/migrator.php | 158 +++++++++++++++++++++++++++++++---------- 1 file changed, 120 insertions(+), 38 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2fd795b659..2ba1eba427 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,26 +22,40 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { + /** @var phpbb_config */ protected $config; + + /** @var phpbb_db_driver */ protected $db; + + /** @var phpbb_db_tools */ protected $db_tools; + + /** @var string */ protected $table_prefix; + /** @var string */ protected $phpbb_root_path; + + /** @var string */ protected $php_ext; + /** @var string */ protected $migrations_table; + + /** @var array State of all migrations (SELECT * FROM migrations table) */ protected $migration_state; + /** @var array Array of all migrations available to be run */ protected $migrations = array(); - /** @var string Name of the last migration run */ + /** @var array 'name' and 'class' of the last migration run */ public $last_run_migration = false; /** * Constructor of the database migrator */ - public function __construct($config, phpbb_db_driver $db, $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; @@ -96,17 +110,42 @@ class phpbb_db_migrator /** * Load migration data files from a directory * - * @param string $path + * This does not loop through sub-directories. + * Migration data files loaded with this function MUST contain + * ONLY ONE class in them (or an exception will be thrown). + * + * @param string $path Path to migration data files + * @param bool $check_fulfillable If TRUE (default), we will check + * if all of the migrations are fulfillable after loading them. + * If FALSE, we will not check. You SHOULD check at least once + * to prevent errors (if including multiple directories, check + * with the last call to prevent throwing errors unnecessarily). * @return array Array of migrations with names */ - public function load_migrations($path) + public function load_migrations($path, $check_fulfillable = true) { $handle = opendir($path); while (($file = readdir($handle)) !== false) { if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) { - $name = 'phpbb_db_migration_data_' . substr($file, 0, -(strlen($this->php_ext) + 1)); + // We try to find what class existed by comparing the classes declared before and after including the file. + $declared_classes = get_declared_classes(); + + include ($path . $file); + + $added_classes = array_diff(get_declared_classes(), $declared_classes); + + if ( + // The phpbb_db_migrations class may not have been loaded until now, so make sure to ignore it. + !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && + sizeof($added_classes) != 1 + ) + { + throw new phpbb_db_migration_exception('MIGRATION DATA FILE INVALID', $path . $file); + } + + $name = array_pop($added_classes); if (!in_array($name, $this->migrations)) { @@ -115,11 +154,14 @@ class phpbb_db_migrator } } - foreach ($this->migrations as $name) + if ($check_fulfillable) { - if ($this->unfulfillable($name)) + foreach ($this->migrations as $name) { - throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + if ($this->unfulfillable($name)) + { + throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + } } } @@ -131,6 +173,8 @@ class phpbb_db_migrator * * The update step can either be a schema or a (partial) data update. To * check if update() needs to be called again use the finished() method. + * + * @return null */ public function update() { @@ -207,9 +251,11 @@ class phpbb_db_migrator } else { - $this->process_data_step($migration); - $state['migration_data_done'] = true; - $state['migration_end_time'] = time(); + $state = $this->process_data_step($migration); + + $state['migration_data_state'] = $state; + $state['migration_data_done'] = ($state === true); + $state['migration_end_time'] = ($state === true) ? time() : 0; } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -222,41 +268,74 @@ class phpbb_db_migrator return true; } + /** + * Apply schema changes from a migration + * + * Just calls db_tools->perform_schema_changes + * + * @param array $schema_changes from migration + */ + protected function apply_schema_changes($schema_changes) + { + $this->db_tools->perform_schema_changes($schema_changes); + } + + /** + * Process the data step of the migration + * + * @param phpbb_db_migration $migration + * @return mixed migration status or bool true if everything completed successfully + */ protected function process_data_step($migration) { - //$continue = false; $steps = $migration->update_data(); foreach ($steps as $step) { - $continue = $this->run_step($step); - - /*if ($continue === false) + try { - return false; - }*/ + // Result will be null or true if everything completed correctly + $result = $this->run_step($step); + if ($result !== null && $result !== true) + { + return $result; + } + } + catch (phpbb_db_migration_exception $e) + { + // We should try rolling back here + + echo $e; + die(); + } } - //return $continue; + return true; } + /** + * Run a single step + * + * An exception should be thrown if an error occurs + * + * @param mixed $step + * @return null + */ protected function run_step($step) { - try - { - $callable_and_parameters = $this->get_callable_from_step($step); - $callable = $callable_and_parameters[0]; - $parameters = $callable_and_parameters[1]; + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $parameters = $callable_and_parameters[1]; - return call_user_func_array($callable, $parameters); - } - catch (phpbb_db_migration_exception $e) - { - echo $e; - die(); - } + return call_user_func_array($callable, $parameters); } + /** + * Get a callable statement from a data step + * + * @param mixed $step Data step from migration + * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters + */ public function get_callable_from_step($step) { $type = $step[0]; @@ -291,6 +370,7 @@ class phpbb_db_migrator $callable_and_parameters = $this->get_callable_from_step($step); $callable = $callable_and_parameters[0]; $sub_parameters = $callable_and_parameters[1]; + return array( function ($condition) use ($callable, $sub_parameters) { return call_user_func_array($callable, $sub_parameters); @@ -325,12 +405,19 @@ class phpbb_db_migrator return array( array($this->tools[$class], $method), - $parameters + $parameters, ); break; } } + /** + * Insert migration row into the database + * + * @param string $name Name of the migration + * @param array $state + * @return null + */ protected function insert_migration($name, $state) { $migration_row = $state; @@ -346,8 +433,8 @@ class phpbb_db_migrator /** * Checks if a migration's dependencies can even theoretically be satisfied. * - * @param string $name The class name of the migration - * @return bool Whether the migration cannot be fulfilled + * @param string $name The class name of the migration + * @return bool Whether the migration cannot be fulfilled */ public function unfulfillable($name) { @@ -406,11 +493,6 @@ class phpbb_db_migrator return true; } - protected function apply_schema_changes($schema_changes) - { - $this->db_tools->perform_schema_changes($schema_changes); - } - /** * Helper to get a migration * -- cgit v1.2.1 From edf693e3bd4352ab75c62311b34f12fc98e7ef63 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 15:28:08 -0600 Subject: [feature/migrations] Store state properly and send past result to callable Fix return on module add PHPBB3-9737 --- phpBB/includes/db/migrator.php | 56 +++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2ba1eba427..7aa4cfa719 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -251,11 +251,11 @@ class phpbb_db_migrator } else { - $state = $this->process_data_step($migration); + $result = $this->process_data_step($migration, $state['migration_data_state']); - $state['migration_data_state'] = $state; - $state['migration_data_done'] = ($state === true); - $state['migration_end_time'] = ($state === true) ? time() : 0; + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -284,27 +284,50 @@ class phpbb_db_migrator * Process the data step of the migration * * @param phpbb_db_migration $migration - * @return mixed migration status or bool true if everything completed successfully + * @param bool|string $state Current state of the migration + * @return bool|string migration state. True if completed, serialized array if not finished */ - protected function process_data_step($migration) + protected function process_data_step($migration, $state) { + $state = ($state) ? unserialize($state) : false; + $steps = $migration->update_data(); foreach ($steps as $step) { + $last_result = false; + if ($state) + { + // Continue until we reach the step that matches the last step called + if ($state['step'] != $step) + { + continue; + } + + // We send the result from last time to the callable function + $last_result = $state['result']; + + // Set state to false since we reached the point we were at + $state = false; + } + try { // Result will be null or true if everything completed correctly - $result = $this->run_step($step); + $result = $this->run_step($step, $last_result); if ($result !== null && $result !== true) { - return $result; + return serialize(array( + 'result' => $result, + 'step' => $step, + )); } } catch (phpbb_db_migration_exception $e) { // We should try rolling back here + var_dump($step); echo $e; die(); } @@ -318,12 +341,13 @@ class phpbb_db_migrator * * An exception should be thrown if an error occurs * - * @param mixed $step + * @param mixed $step Data step from migration + * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return null */ - protected function run_step($step) + protected function run_step($step, $last_result = false) { - $callable_and_parameters = $this->get_callable_from_step($step); + $callable_and_parameters = $this->get_callable_from_step($step, $last_result); $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; @@ -334,9 +358,10 @@ class phpbb_db_migrator * Get a callable statement from a data step * * @param mixed $step Data step from migration + * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - public function get_callable_from_step($step) + public function get_callable_from_step($step, $last_result = false) { $type = $step[0]; $parameters = $step[1]; @@ -375,7 +400,7 @@ class phpbb_db_migrator function ($condition) use ($callable, $sub_parameters) { return call_user_func_array($callable, $sub_parameters); }, - array($condition) + array($condition), ); break; case 'custom': @@ -384,7 +409,10 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); } - return array($parameters[0], array()); + return array( + $parameters[0], + array($last_result), + ); break; default: -- cgit v1.2.1 From f56e400cd36b6d17ffde90a91e6e221cb83d2dbd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 15:41:04 -0600 Subject: [feature/migrations] Comments PHPBB3-9737 --- phpBB/includes/db/migrator.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 7aa4cfa719..5d8dc12f58 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -43,13 +43,27 @@ class phpbb_db_migrator /** @var string */ protected $migrations_table; - /** @var array State of all migrations (SELECT * FROM migrations table) */ - protected $migration_state; + /** + * State of all migrations + * + * (SELECT * FROM migrations table) + * + * @var array + */ + protected $migration_state = array(); - /** @var array Array of all migrations available to be run */ + /** + * Array of all migrations available to be run + * + * @var array + */ protected $migrations = array(); - /** @var array 'name' and 'class' of the last migration run */ + /** + * 'name' and 'class' of the last migration run + * + * @var array + */ public $last_run_migration = false; /** @@ -83,11 +97,12 @@ class phpbb_db_migrator */ public function load_migration_state() { + $this->migration_state = array(); + $sql = "SELECT * FROM " . $this->migrations_table; $result = $this->db->sql_query($sql); - $this->migration_state = array(); while ($migration = $this->db->sql_fetchrow($result)) { $this->migration_state[$migration['migration_name']] = $migration; @@ -137,8 +152,9 @@ class phpbb_db_migrator $added_classes = array_diff(get_declared_classes(), $declared_classes); if ( - // The phpbb_db_migrations class may not have been loaded until now, so make sure to ignore it. + // If two classes have been added and phpbb_db_migration is one of them, we've only added one real migration !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && + // Otherwise there should only be one class added sizeof($added_classes) != 1 ) { -- cgit v1.2.1 From 445667a62e80c42b5406c981d1116ef99a23df3b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:31:56 -0600 Subject: [feature/migrations] Fix if method (and create a test for it) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 5d8dc12f58..1042b767e8 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -364,6 +364,12 @@ class phpbb_db_migrator protected function run_step($step, $last_result = false) { $callable_and_parameters = $this->get_callable_from_step($step, $last_result); + + if ($callable_and_parameters === false) + { + return; + } + $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; @@ -377,7 +383,7 @@ class phpbb_db_migrator * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - public function get_callable_from_step($step, $last_result = false) + protected function get_callable_from_step($step, $last_result = false) { $type = $step[0]; $parameters = $step[1]; @@ -406,6 +412,12 @@ class phpbb_db_migrator } $condition = $parameters[0]; + + if (!$condition) + { + return false; + } + $step = $parameters[1]; $callable_and_parameters = $this->get_callable_from_step($step); @@ -413,10 +425,8 @@ class phpbb_db_migrator $sub_parameters = $callable_and_parameters[1]; return array( - function ($condition) use ($callable, $sub_parameters) { - return call_user_func_array($callable, $sub_parameters); - }, - array($condition), + $callable, + $sub_parameters, ); break; case 'custom': -- cgit v1.2.1 From 5f9e1f1e89f8df5420fd82b5256a461de0f98604 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:56:26 -0600 Subject: [feature/migrations] Make sure the path sent to load_migrations is a directory Prevent a lot++ of errors PHPBB3-9737 --- phpBB/includes/db/migrator.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 1042b767e8..359c34bf5d 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -139,6 +139,11 @@ class phpbb_db_migrator */ public function load_migrations($path, $check_fulfillable = true) { + if (!is_dir($path)) + { + throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); + } + $handle = opendir($path); while (($file = readdir($handle)) !== false) { -- cgit v1.2.1 From 3d4c00619f1c96df7a4c6f8bc1c03eb21abf49d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:24:32 -0600 Subject: [feature/migrations] Reverse data functionality If data step fails, attempt to roll back any previous calls from the migration that failed. Fix some failing tests PHPBB3-9737 --- phpBB/includes/db/migrator.php | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 359c34bf5d..dc2c746559 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -347,6 +347,17 @@ class phpbb_db_migrator catch (phpbb_db_migration_exception $e) { // We should try rolling back here + foreach ($steps as $reverse_step) + { + // Reverse the step that was run + $result = $this->run_step($step, false, true); + + // If we've reached the current step we can break because we reversed everything that was run + if ($reverse_step === $step) + { + break; + } + } var_dump($step); echo $e; @@ -364,11 +375,12 @@ class phpbb_db_migrator * * @param mixed $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) + * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return null */ - protected function run_step($step, $last_result = false) + protected function run_step($step, $last_result = false, $reverse = false) { - $callable_and_parameters = $this->get_callable_from_step($step, $last_result); + $callable_and_parameters = $this->get_callable_from_step($step, $last_result, $reverse); if ($callable_and_parameters === false) { @@ -386,9 +398,10 @@ class phpbb_db_migrator * * @param mixed $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) + * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - protected function get_callable_from_step($step, $last_result = false) + protected function get_callable_from_step($step, $last_result = false, $reverse = false) { $type = $step[0]; $parameters = $step[1]; @@ -425,14 +438,7 @@ class phpbb_db_migrator $step = $parameters[1]; - $callable_and_parameters = $this->get_callable_from_step($step); - $callable = $callable_and_parameters[0]; - $sub_parameters = $callable_and_parameters[1]; - - return array( - $callable, - $sub_parameters, - ); + return $this->get_callable_from_step($step); break; case 'custom': if (!is_callable($parameters[0])) @@ -462,6 +468,15 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); } + // Attempt to reverse operations + if ($reverse) + { + return array( + array($this->tools[$class], 'reverse'), + array_unshift($parameters, $method), + ); + } + return array( array($this->tools[$class], $method), $parameters, -- cgit v1.2.1 From 44c10f661ee548ae08fe81ba76f47f1c8134b96f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:59:15 -0600 Subject: [feature/migrations] Creating revert method to attempt reverting a migration This code is in progress PHPBB3-9737 --- phpBB/includes/db/migrator.php | 100 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index dc2c746559..e8d3735974 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -289,6 +289,91 @@ class phpbb_db_migrator return true; } + /** + * Runs a single revert step from the last migration installed + * + * The revert step can either be a schema or a (partial) data revert. To + * check if revert() needs to be called again use the migration_installed() method. + * + * @param string $migration String migration name to revert (including any that depend on this migration) + * @return null + */ + public function revert($migration) + { + if (!isset($this->migration_state[$name])) + { + // Not installed + return; + } + + // Iterate through all installed migrations and make sure any dependencies are removed first + foreach ($this->migration_state as $name => $state) + { + $migration_class = $this->get_migration($name); + + if (in_array($migration, $migration_class->depends_on())) + { + $this->revert($name); + } + } + + $this->try_revert($migration); + } + + /** + * Attempts to apply a step of the given migration or one of its dependencies + * + * @param string The class name of the migration + * @return bool Whether any update step was successfully run + */ + protected function try_revert($name) + { + if (!class_exists($name)) + { + return false; + } + + $migration = $this->get_migration($name); + + $state = $this->migration_state[$name]; + + $this->last_run_migration = array( + 'name' => $name, + 'class' => $migration, + ); + + // Left off here + + if (!isset($this->migration_state[$name])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } + + if (!$state['migration_schema_done']) + { + $this->apply_schema_changes($migration->update_schema()); + $state['migration_schema_done'] = true; + } + else + { + $result = $this->process_data_step($migration, $state['migration_data_state']); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + + return true; + } + /** * Apply schema changes from a migration * @@ -359,6 +444,7 @@ class phpbb_db_migrator } } + /** TODO Revert Schema **/ var_dump($step); echo $e; die(); @@ -567,6 +653,20 @@ class phpbb_db_migrator return true; } + /** + * Checks whether a migration is installed + * + * @param string $migration String migration name to check if it is installed + * @return bool Whether the migrations have been applied + */ + public function migration_installed($migration) + { + if (isset($this->migration_state[$migration])) + { + return true; + } + } + /** * Helper to get a migration * -- cgit v1.2.1 From dbe71bb170dc684311174bb025696c81f1d50883 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 13:53:09 -0600 Subject: [feature/migrations] Revert method completed PHPBB3-9737 --- phpBB/includes/db/migrator.php | 74 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index e8d3735974..13114e7df1 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -272,7 +272,7 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration, $state['migration_data_state']); + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); $state['migration_data_state'] = ($result === true) ? '' : $result; $state['migration_data_done'] = ($result === true); @@ -300,7 +300,7 @@ class phpbb_db_migrator */ public function revert($migration) { - if (!isset($this->migration_state[$name])) + if (!isset($this->migration_state[$migration])) { // Not installed return; @@ -342,34 +342,39 @@ class phpbb_db_migrator 'class' => $migration, ); - // Left off here - - if (!isset($this->migration_state[$name])) + if ($state['migration_data_done']) { - $state['migration_start_time'] = time(); - $this->insert_migration($name, $state); - } + if ($state['migration_data_state'] !== 'revert_data') + { + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state'], true); - if (!$state['migration_schema_done']) - { - $this->apply_schema_changes($migration->update_schema()); - $state['migration_schema_done'] = true; + $state['migration_data_state'] = ($result === true) ? 'revert_data' : $result; + } + else + { + $result = $this->process_data_step($migration->revert_data(), $state['migration_data_state'], false); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true) ? false : true; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; } else { - $result = $this->process_data_step($migration, $state['migration_data_state']); - - $state['migration_data_state'] = ($result === true) ? '' : $result; - $state['migration_data_done'] = ($result === true); - $state['migration_end_time'] = ($result === true) ? time() : 0; - } + $this->apply_schema_changes($migration->revert_schema()); - $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " - WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); + $sql = 'DELETE FROM ' . $this->migrations_table . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); - $this->migration_state[$name] = $state; + unset($this->migration_state[$name]); + } return true; } @@ -389,23 +394,22 @@ class phpbb_db_migrator /** * Process the data step of the migration * - * @param phpbb_db_migration $migration + * @param array $steps The steps to run * @param bool|string $state Current state of the migration + * @param bool $revert true to revert a data step * @return bool|string migration state. True if completed, serialized array if not finished */ - protected function process_data_step($migration, $state) + protected function process_data_step($steps, $state, $revert = false) { $state = ($state) ? unserialize($state) : false; - $steps = $migration->update_data(); - - foreach ($steps as $step) + foreach ($steps as $step_identifier => $step) { $last_result = false; if ($state) { // Continue until we reach the step that matches the last step called - if ($state['step'] != $step) + if ($state['step'] != $step_identifier) { continue; } @@ -420,12 +424,12 @@ class phpbb_db_migrator try { // Result will be null or true if everything completed correctly - $result = $this->run_step($step, $last_result); + $result = $this->run_step($step, $last_result, $revert); if ($result !== null && $result !== true) { return serialize(array( 'result' => $result, - 'step' => $step, + 'step' => $step_identifier, )); } } @@ -435,7 +439,7 @@ class phpbb_db_migrator foreach ($steps as $reverse_step) { // Reverse the step that was run - $result = $this->run_step($step, false, true); + $result = $this->run_step($step, false, !$revert); // If we've reached the current step we can break because we reversed everything that was run if ($reverse_step === $step) @@ -557,9 +561,11 @@ class phpbb_db_migrator // Attempt to reverse operations if ($reverse) { + array_unshift($parameters, $method); + return array( array($this->tools[$class], 'reverse'), - array_unshift($parameters, $method), + $parameters, ); } @@ -665,6 +671,8 @@ class phpbb_db_migrator { return true; } + + return false; } /** -- cgit v1.2.1 From d50500860fe44a78c8f29e0f2382b96da17c0b62 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 15:09:51 -0600 Subject: [feature/migrations] Store depends on in the database (serialized) This is required so that when migrations are reverted we can check through all installed migrations and make sure that all dependencies are handled properly and so that we are only required to load the migrations files that could be dependent on the ones installed. I believe in normal proper use the old way might have worked, but in case something happens and an unrelated migration file is installed, but cannot be loaded, this makes sure we do not stop everything unless we absolutely must (one of those files is dependent on something we want to revert). PHPBB3-9737 --- phpBB/includes/db/migrator.php | 79 ++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 33 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 13114e7df1..2ec44a5a45 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -106,6 +106,8 @@ class phpbb_db_migrator while ($migration = $this->db->sql_fetchrow($result)) { $this->migration_state[$migration['migration_name']] = $migration; + + $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); } $this->db->sql_freeresult($result); @@ -235,16 +237,15 @@ class phpbb_db_migrator $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( + 'migration_depends_on' => $migration->depends_on(), 'migration_schema_done' => false, - 'migration_data_done' => false, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, + 'migration_data_done' => false, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, ); - $depends = $migration->depends_on(); - - foreach ($depends as $depend) + foreach ($state['migration_depends_on'] as $depend) { if (!isset($this->migration_state[$depend]) || !$this->migration_state[$depend]['migration_schema_done'] || @@ -272,15 +273,28 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); + try + { + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; + } + catch (phpbb_db_migration_exception $e) + { + // Revert the schema changes + $this->revert($name); - $state['migration_data_state'] = ($result === true) ? '' : $result; - $state['migration_data_done'] = ($result === true); - $state['migration_end_time'] = ($result === true) ? time() : 0; + // Rethrow exception + throw $e; + } } + $insert = $state; + $insert['migration_depends_on'] = serialize($state['migration_depends_on']); $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " + SET ' . $this->db->sql_build_array('UPDATE', $insert) . " WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); @@ -292,8 +306,9 @@ class phpbb_db_migrator /** * Runs a single revert step from the last migration installed * + * YOU MUST ADD/SET ALL MIGRATIONS THAT COULD BE DEPENDENT ON THE MIGRATION TO REVERT TO BEFORE CALLING THIS METHOD! * The revert step can either be a schema or a (partial) data revert. To - * check if revert() needs to be called again use the migration_installed() method. + * check if revert() needs to be called again use the migration_state() method. * * @param string $migration String migration name to revert (including any that depend on this migration) * @return null @@ -306,12 +321,9 @@ class phpbb_db_migrator return; } - // Iterate through all installed migrations and make sure any dependencies are removed first foreach ($this->migration_state as $name => $state) { - $migration_class = $this->get_migration($name); - - if (in_array($migration, $migration_class->depends_on())) + if (!empty($state['migration_depends_on']) && in_array($migration, $state['migration_depends_on'])) { $this->revert($name); } @@ -358,8 +370,10 @@ class phpbb_db_migrator $state['migration_data_done'] = ($result === true) ? false : true; } + $insert = $state; + $insert['migration_depends_on'] = serialize($state['migration_depends_on']); $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " + SET ' . $this->db->sql_build_array('UPDATE', $insert) . " WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); @@ -436,22 +450,20 @@ class phpbb_db_migrator catch (phpbb_db_migration_exception $e) { // We should try rolling back here - foreach ($steps as $reverse_step) + foreach ($steps as $reverse_step_identifier => $reverse_step) { - // Reverse the step that was run - $result = $this->run_step($step, false, !$revert); - // If we've reached the current step we can break because we reversed everything that was run - if ($reverse_step === $step) + if ($reverse_step_identifier == $step_identifier) { break; } + + // Reverse the step that was run + $result = $this->run_step($reverse_step, false, !$revert); } - /** TODO Revert Schema **/ - var_dump($step); - echo $e; - die(); + // rethrow the exception + throw $e; } } @@ -588,6 +600,7 @@ class phpbb_db_migrator { $migration_row = $state; $migration_row['migration_name'] = $name; + $migration_row['migration_depends_on'] = serialize($state['migration_depends_on']); $sql = 'INSERT INTO ' . $this->migrations_table . ' ' . $this->db->sql_build_array('INSERT', $migration_row); @@ -660,19 +673,19 @@ class phpbb_db_migrator } /** - * Checks whether a migration is installed + * Gets a migration state (whether it is installed and to what extent) * * @param string $migration String migration name to check if it is installed - * @return bool Whether the migrations have been applied + * @return bool|array False if the migration has not at all been installed, array */ - public function migration_installed($migration) + public function migration_state($migration) { - if (isset($this->migration_state[$migration])) + if (!isset($this->migration_state[$migration])) { - return true; + return false; } - return false; + return $this->migration_state[$migration]; } /** -- cgit v1.2.1 From 93f9ebbb258a06e34198cffda0f5fd8dfdf29597 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 12 Jan 2013 18:27:33 -0600 Subject: [feature/migrations] Make load_migrations recursive (optionally) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2ec44a5a45..6b249e3ee0 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -127,7 +127,6 @@ class phpbb_db_migrator /** * Load migration data files from a directory * - * This does not loop through sub-directories. * Migration data files loaded with this function MUST contain * ONLY ONE class in them (or an exception will be thrown). * @@ -137,9 +136,10 @@ class phpbb_db_migrator * If FALSE, we will not check. You SHOULD check at least once * to prevent errors (if including multiple directories, check * with the last call to prevent throwing errors unnecessarily). - * @return array Array of migrations with names + * @param bool $recursive Set to true to also load data files from subdirectories + * @return array Array of migration names */ - public function load_migrations($path, $check_fulfillable = true) + public function load_migrations($path, $check_fulfillable = true, $recursive = true) { if (!is_dir($path)) { @@ -149,6 +149,17 @@ class phpbb_db_migrator $handle = opendir($path); while (($file = readdir($handle)) !== false) { + if ($file == '.' || $file == '..') + { + continue; + } + + // Recursion through subdirectories + if (is_dir($path . $file) && $recursive) + { + $this->load_migrations($path . $file . '/', $check_fulfillable, $recursive); + } + if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) { // We try to find what class existed by comparing the classes declared before and after including the file. -- cgit v1.2.1 From 26c16559c3496f5496ad6e83e55c40f03edda5bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 12:39:08 -0600 Subject: [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 --- phpBB/includes/db/migrator.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/db/migrator.php') 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']) -- cgit v1.2.1 From 000b8fefd2788c7f9f6aa6efc1d93658a00e48bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:21:01 -0600 Subject: [feature/migrations] Function to populate the migrations table (for install) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'phpBB/includes/db/migrator.php') 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 * -- cgit v1.2.1 From ccd08e21f6ae97ff0ff628ff29935a70bdd7a58d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:34:16 -0600 Subject: [feature/migrations] Make sure migration data not done before running data step PHPBB3-9737 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 69a5a4dd9c..d95283ae01 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -332,7 +332,7 @@ class phpbb_db_migrator $this->apply_schema_changes($migration->update_schema()); $state['migration_schema_done'] = true; } - else + else if (!$state['migration_data_done']) { try { -- cgit v1.2.1 From dfabdbca508a3fbd60c8df57ea756a974f4f135b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 22 Jan 2013 13:19:49 -0600 Subject: [ticket/9737] Fix a few minor things in migrations PHPBB3-9737 --- phpBB/includes/db/migrator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index d95283ae01..4456600b0a 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -394,7 +394,7 @@ class phpbb_db_migrator } /** - * Attempts to apply a step of the given migration or one of its dependencies + * Attempts to revert a step of the given migration or one of its dependencies * * @param string The class name of the migration * @return bool Whether any update step was successfully run @@ -559,12 +559,12 @@ class phpbb_db_migrator /** * Get a callable statement from a data step * - * @param mixed $step Data step from migration + * @param array $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - protected function get_callable_from_step($step, $last_result = false, $reverse = false) + protected function get_callable_from_step(array $step, $last_result = false, $reverse = false) { $type = $step[0]; $parameters = $step[1]; -- cgit v1.2.1 From cacaffee6e013e43b75212d49960922f88f9f69a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:56:42 -0600 Subject: [feature/migrations] Add language strings for migrations errors Unfulfillable returns string of the missing dependency name now if the migration is unfulfillable (this is significantly more helpful). PHPBB3-11351 --- phpBB/includes/db/migrator.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4456600b0a..3c311e96d7 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -228,9 +228,10 @@ class phpbb_db_migrator { foreach ($this->migrations as $name) { - if ($this->unfulfillable($name)) + $unfulfillable = $this->unfulfillable($name); + if ($unfulfillable !== false) { - throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); } } } @@ -674,13 +675,13 @@ class phpbb_db_migrator * Checks if a migration's dependencies can even theoretically be satisfied. * * @param string $name The class name of the migration - * @return bool Whether the migration cannot be fulfilled + * @return bool|string False if fulfillable, string of missing migration name if unfulfillable */ public function unfulfillable($name) { if (isset($this->migration_state[$name])) { - return false; + return $name; } if (!class_exists($name)) @@ -693,9 +694,10 @@ class phpbb_db_migrator foreach ($depends as $depend) { - if ($this->unfulfillable($depend)) + $unfulfillable = $this->unfulfillable($depend); + if ($unfulfillable !== false) { - return true; + return $unfulfillable; } } @@ -715,7 +717,7 @@ class phpbb_db_migrator { // skip unfulfillable migrations, but fulfillables mean we // are not finished yet - if ($this->unfulfillable($name)) + if ($this->unfulfillable($name) !== false) { continue; } -- cgit v1.2.1 From f9a1b27a99e30a41db4facd415b39a690614d6c6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:16:39 -0600 Subject: [feature/migrations] Fix unfulfillable function Returned unfulfillable name in the wrong place previously PHPBB3-11351 --- phpBB/includes/db/migrator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 3c311e96d7..41d996b1e3 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -681,12 +681,12 @@ class phpbb_db_migrator { if (isset($this->migration_state[$name])) { - return $name; + return false; } if (!class_exists($name)) { - return true; + return $name; } $migration = $this->get_migration($name); -- cgit v1.2.1 From 6045aa7aa2fb63358e3f736504b17533b1085712 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 25 Feb 2013 19:16:29 -0600 Subject: [ticket/11367] Migrator throws error if migrations table does not exist Force load_migration_state to not throw errors if the table does not exist. PHPBB3-11367 --- phpBB/includes/db/migrator.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 41d996b1e3..ea5de3372f 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -99,18 +99,26 @@ class phpbb_db_migrator { $this->migration_state = array(); + // prevent errors in case the table does not exist yet + $this->db->sql_return_on_error(true); + $sql = "SELECT * FROM " . $this->migrations_table; $result = $this->db->sql_query($sql); - while ($migration = $this->db->sql_fetchrow($result)) + if (!$this->db->sql_error_triggered) { - $this->migration_state[$migration['migration_name']] = $migration; + while ($migration = $this->db->sql_fetchrow($result)) + { + $this->migration_state[$migration['migration_name']] = $migration; + + $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); + } - $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); + $this->db->sql_freeresult($result); } - $this->db->sql_freeresult($result); + $this->db->sql_return_on_error(false); } /** -- cgit v1.2.1 From 9a319fefb2ffed58da1d3339d59e53de09521e03 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 26 Feb 2013 10:22:13 -0600 Subject: [ticket/11367] Always freeresult PHPBB3-11367 --- phpBB/includes/db/migrator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index ea5de3372f..74f71775f3 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -114,10 +114,10 @@ class phpbb_db_migrator $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); } - - $this->db->sql_freeresult($result); } + $this->db->sql_freeresult($result); + $this->db->sql_return_on_error(false); } -- cgit v1.2.1 From f9cbf5b4c7ea4f4eb1438d98ccc1cb71b0fea2af Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 26 Feb 2013 19:25:51 -0600 Subject: [ticket/11369] Reverting migration throws error String is attempted to be unserialized PHPBB3-11369 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 74f71775f3..d6bcae6ca6 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -434,7 +434,7 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration->revert_data(), $state['migration_data_state'], false); + $result = $this->process_data_step($migration->revert_data(), '', false); $state['migration_data_state'] = ($result === true) ? '' : $result; $state['migration_data_done'] = ($result === true) ? false : true; -- cgit v1.2.1 From 51651b3d9f8622a195d877bbcf106acd413aee03 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 26 Feb 2013 19:44:03 -0600 Subject: [ticket/11370] Effectively installed migrations not inserted into table insert_migration() function now handles inserting/updating Move all insert/update code to insert_migration() function to prevent this from occurring again. PHPBB3-11370 --- phpBB/includes/db/migrator.php | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 74f71775f3..691285d477 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -332,7 +332,6 @@ class phpbb_db_migrator if (!isset($this->migration_state[$name])) { $state['migration_start_time'] = time(); - $this->insert_migration($name, $state); } } @@ -361,14 +360,7 @@ class phpbb_db_migrator } } - $insert = $state; - $insert['migration_depends_on'] = serialize($state['migration_depends_on']); - $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $insert) . " - WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); - - $this->migration_state[$name] = $state; + $this->insert_migration($name, $state); return true; } @@ -440,14 +432,7 @@ class phpbb_db_migrator $state['migration_data_done'] = ($result === true) ? false : true; } - $insert = $state; - $insert['migration_depends_on'] = serialize($state['migration_depends_on']); - $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $insert) . " - WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); - - $this->migration_state[$name] = $state; + $this->insert_migration($name, $state); } else { @@ -660,7 +645,7 @@ class phpbb_db_migrator } /** - * Insert migration row into the database + * Insert/Update migration row into the database * * @param string $name Name of the migration * @param array $state @@ -669,12 +654,22 @@ class phpbb_db_migrator protected function insert_migration($name, $state) { $migration_row = $state; - $migration_row['migration_name'] = $name; $migration_row['migration_depends_on'] = serialize($state['migration_depends_on']); - $sql = 'INSERT INTO ' . $this->migrations_table . ' - ' . $this->db->sql_build_array('INSERT', $migration_row); - $this->db->sql_query($sql); + if (isset($this->migration_state[$name])) + { + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $migration_row) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + } + else + { + $migration_row['migration_name'] = $name; + $sql = 'INSERT INTO ' . $this->migrations_table . ' + ' . $this->db->sql_build_array('INSERT', $migration_row); + $this->db->sql_query($sql); + } $this->migration_state[$name] = $state; } -- cgit v1.2.1 From 9b554fbf3c9d1cb720fbd340bba552328790967f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 27 Feb 2013 13:52:45 -0600 Subject: [ticket/11372] Migrator should only check if effectively installed if not installed at all PHPBB3-11372 --- phpBB/includes/db/migrator.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 74f71775f3..1ba65d71a6 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -316,20 +316,20 @@ class phpbb_db_migrator 'class' => $migration, ); - if ($migration->effectively_installed()) + if (!isset($this->migration_state[$name])) { - $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])) + if ($migration->effectively_installed()) + { + $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 { $state['migration_start_time'] = time(); $this->insert_migration($name, $state); -- cgit v1.2.1 From 39ca212e17e80d14dbbd20cf5542ab37f27bd217 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:02:53 -0600 Subject: [ticket/11386] Use finder to find migration files PHPBB3-11386 --- phpBB/includes/db/migrator.php | 53 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index ec0b6a87da..824bca5e70 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -31,6 +31,9 @@ class phpbb_db_migrator /** @var phpbb_db_tools */ protected $db_tools; + /** @var phpbb_extension_manager */ + protected $extension_manager; + /** @var string */ protected $table_prefix; @@ -69,11 +72,12 @@ class phpbb_db_migrator /** * Constructor of the database migrator */ - public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, phpbb_extension_manager $extension_manager, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; $this->db_tools = $db_tools; + $this->extension_manager = $extension_manager; $this->migrations_table = $migrations_table; @@ -180,55 +184,26 @@ class phpbb_db_migrator * If FALSE, we will not check. You SHOULD check at least once * to prevent errors (if including multiple directories, check * with the last call to prevent throwing errors unnecessarily). - * @param bool $recursive Set to true to also load data files from subdirectories * @return array Array of migration names */ - public function load_migrations($path, $check_fulfillable = true, $recursive = true) + public function load_migrations($path, $check_fulfillable = true) { if (!is_dir($path)) { throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); } - $handle = opendir($path); - while (($file = readdir($handle)) !== false) + $finder = $this->extension_manager->get_finder(); + $migration_files = $finder + ->extension_directory("/") + ->find_from_paths(array('/' => $path)); + foreach ($migration_files as $migration) { - if ($file == '.' || $file == '..') - { - continue; - } + $migration_name = $migration['path'] . $migration['filename']; - // Recursion through subdirectories - if (is_dir($path . $file) && $recursive) + if (!in_array($migration_name, $this->migrations)) { - $this->load_migrations($path . $file . '/', $check_fulfillable, $recursive); - } - - if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) - { - // We try to find what class existed by comparing the classes declared before and after including the file. - $declared_classes = get_declared_classes(); - - include ($path . $file); - - $added_classes = array_diff(get_declared_classes(), $declared_classes); - - if ( - // If two classes have been added and phpbb_db_migration is one of them, we've only added one real migration - !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && - // Otherwise there should only be one class added - sizeof($added_classes) != 1 - ) - { - throw new phpbb_db_migration_exception('MIGRATION DATA FILE INVALID', $path . $file); - } - - $name = array_pop($added_classes); - - if (!in_array($name, $this->migrations)) - { - $this->migrations[] = $name; - } + $this->migrations[] = $migration_name; } } -- cgit v1.2.1 From 1368470f7488b278cdc214745a7d4c9557d407e2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:42:30 -0600 Subject: [ticket/11386] Forgot to get the migration classes PHPBB3-11386 --- phpBB/includes/db/migrator.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 824bca5e70..855e640554 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -193,17 +193,23 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); } + $migrations = array(); + $finder = $this->extension_manager->get_finder(); - $migration_files = $finder + $files = $finder ->extension_directory("/") ->find_from_paths(array('/' => $path)); - foreach ($migration_files as $migration) + foreach ($files as $file) { - $migration_name = $migration['path'] . $migration['filename']; + $migrations[$file['path'] . $file['filename']] = ''; + } + $migrations = $finder->get_classes_from_files($migrations); - if (!in_array($migration_name, $this->migrations)) + foreach ($migrations as $migration) + { + if (!in_array($migration, $this->migrations)) { - $this->migrations[] = $migration_name; + $this->migrations[] = $migration; } } -- cgit v1.2.1 From a6f877c0d84ff102d3812246eae7469e191983e2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 14:15:59 -0600 Subject: [ticket/11386] Fix circular reference error & serialize error PHPBB3-11386 --- phpBB/includes/db/migrator.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 855e640554..de9c06948c 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -72,12 +72,11 @@ class phpbb_db_migrator /** * Constructor of the database migrator */ - public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, phpbb_extension_manager $extension_manager, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; $this->db_tools = $db_tools; - $this->extension_manager = $extension_manager; $this->migrations_table = $migrations_table; @@ -94,6 +93,16 @@ class phpbb_db_migrator $this->load_migration_state(); } + /** + * Set Extension Manager (required) + * + * Not in constructor to prevent circular reference error + */ + public function set_extension_manager(phpbb_extension_manager $extension_manager) + { + $this->extension_manager = $extension_manager; + } + /** * Loads all migrations and their application state from the database. * -- cgit v1.2.1 From e4f782819968ec44f1dd207dc9de7ec703826d29 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 19:54:22 -0600 Subject: [ticket/11386] Send list of migrations instead of using load_migrations Remove dependency of extension manager for migrator. Keeping load_migrations function for others to use if they desire but requiring the finder be sent to it in order to use it. PHPBB3-11386 --- phpBB/includes/db/migrator.php | 188 ++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 106 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index de9c06948c..b925ca5297 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -29,10 +29,7 @@ class phpbb_db_migrator protected $db; /** @var phpbb_db_tools */ - protected $db_tools; - - /** @var phpbb_extension_manager */ - protected $extension_manager; + protected $db_tools /** @var string */ protected $table_prefix; @@ -93,16 +90,6 @@ class phpbb_db_migrator $this->load_migration_state(); } - /** - * Set Extension Manager (required) - * - * Not in constructor to prevent circular reference error - */ - public function set_extension_manager(phpbb_extension_manager $extension_manager) - { - $this->extension_manager = $extension_manager; - } - /** * Loads all migrations and their application state from the database. * @@ -145,98 +132,6 @@ 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 - * - * Migration data files loaded with this function MUST contain - * ONLY ONE class in them (or an exception will be thrown). - * - * @param string $path Path to migration data files - * @param bool $check_fulfillable If TRUE (default), we will check - * if all of the migrations are fulfillable after loading them. - * If FALSE, we will not check. You SHOULD check at least once - * to prevent errors (if including multiple directories, check - * with the last call to prevent throwing errors unnecessarily). - * @return array Array of migration names - */ - public function load_migrations($path, $check_fulfillable = true) - { - if (!is_dir($path)) - { - throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); - } - - $migrations = array(); - - $finder = $this->extension_manager->get_finder(); - $files = $finder - ->extension_directory("/") - ->find_from_paths(array('/' => $path)); - foreach ($files as $file) - { - $migrations[$file['path'] . $file['filename']] = ''; - } - $migrations = $finder->get_classes_from_files($migrations); - - foreach ($migrations as $migration) - { - if (!in_array($migration, $this->migrations)) - { - $this->migrations[] = $migration; - } - } - - if ($check_fulfillable) - { - foreach ($this->migrations as $name) - { - $unfulfillable = $this->unfulfillable($name); - if ($unfulfillable !== false) - { - throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); - } - } - } - - return $this->migrations; - } - /** * Runs a single update step from the next migration to be applied. * @@ -754,4 +649,85 @@ class phpbb_db_migrator { return new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); } + + /** + * This function adds all migrations sent to it 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 array $migrations Array of migrations (names) to add to the migrations table + * @return null + */ + public function populate_migrations($migrations) + { + foreach ($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); + } + } + } + + /** + * Load migration data files from a directory + * + * @param phpbb_extension_finder $finder + * @param string $path Path to migration data files + * @param bool $check_fulfillable If TRUE (default), we will check + * if all of the migrations are fulfillable after loading them. + * If FALSE, we will not check. You SHOULD check at least once + * to prevent errors (if including multiple directories, check + * with the last call to prevent throwing errors unnecessarily). + * @return array Array of migration names + */ + public function load_migrations(phpbb_extension_finder $finder, $path, $check_fulfillable = true) + { + if (!is_dir($path)) + { + throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); + } + + $migrations = array(); + + $files = $finder + ->extension_directory("/") + ->find_from_paths(array('/' => $path)); + foreach ($files as $file) + { + $migrations[$file['path'] . $file['filename']] = ''; + } + $migrations = $finder->get_classes_from_files($migrations); + + foreach ($migrations as $migration) + { + if (!in_array($migration, $this->migrations)) + { + $this->migrations[] = $migration; + } + } + + if ($check_fulfillable) + { + foreach ($this->migrations as $name) + { + $unfulfillable = $this->unfulfillable($name); + if ($unfulfillable !== false) + { + throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); + } + } + } + + return $this->migrations; + } } -- cgit v1.2.1 From 6cad032fbb2ceba892c861f8a2abab82574b12ae Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:18:05 -0600 Subject: [ticket/11393] Give more information on database updater PHPBB3-11393 --- phpBB/includes/db/migrator.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index de9c06948c..81beb14b76 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -63,7 +63,9 @@ class phpbb_db_migrator protected $migrations = array(); /** - * 'name' and 'class' of the last migration run + * 'name,' 'class,' and 'state' of the last migration run + * + * 'effectively_installed' set and set to true if the migration was effectively_installed * * @var array */ @@ -304,6 +306,7 @@ class phpbb_db_migrator $this->last_run_migration = array( 'name' => $name, 'class' => $migration, + 'state' => $state, ); if (!isset($this->migration_state[$name])) @@ -318,6 +321,8 @@ class phpbb_db_migrator 'migration_start_time' => 0, 'migration_end_time' => 0, ); + + $this->last_run_migration['effectively_installed'] = true; } else { @@ -662,6 +667,8 @@ class phpbb_db_migrator } $this->migration_state[$name] = $state; + + $this->last_run_migration['state'] = $state; } /** -- cgit v1.2.1 From ae15fabb323c8f76ad2c8c994c2d205aabeafcbe Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 20:59:21 -0600 Subject: [ticket/11396] Rename insert_migration to set_migration_state PHPBB3-11396 --- phpBB/includes/db/migrator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index de9c06948c..7b5e8cb2de 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -174,7 +174,7 @@ class phpbb_db_migrator 'migration_start_time' => time(), 'migration_end_time' => time(), ); - $this->insert_migration($name, $state); + $this->set_migration_state($name, $state); } } @@ -350,7 +350,7 @@ class phpbb_db_migrator } } - $this->insert_migration($name, $state); + $this->set_migration_state($name, $state); return true; } @@ -422,7 +422,7 @@ class phpbb_db_migrator $state['migration_data_done'] = ($result === true) ? false : true; } - $this->insert_migration($name, $state); + $this->set_migration_state($name, $state); } else { @@ -641,7 +641,7 @@ class phpbb_db_migrator * @param array $state * @return null */ - protected function insert_migration($name, $state) + protected function set_migration_state($name, $state) { $migration_row = $state; $migration_row['migration_depends_on'] = serialize($state['migration_depends_on']); -- cgit v1.2.1 From 071defded6f0e4d2a805b336f56f0a2524d5b1b6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 4 Mar 2013 09:55:23 -0600 Subject: [ticket/11386] Fix missing ; PHPBB3-11386 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/migrator.php') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index b925ca5297..9fe4f40df2 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -29,7 +29,7 @@ class phpbb_db_migrator protected $db; /** @var phpbb_db_tools */ - protected $db_tools + protected $db_tools; /** @var string */ protected $table_prefix; -- cgit v1.2.1