From f9cbf5b4c7ea4f4eb1438d98ccc1cb71b0fea2af Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 26 Feb 2013 19:25:51 -0600 Subject: [PATCH 1/2] [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(-) 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; From 51651b3d9f8622a195d877bbcf106acd413aee03 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 26 Feb 2013 19:44:03 -0600 Subject: [PATCH 2/2] [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(-) 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; }