aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db/migrator.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/db/migrator.php')
-rw-r--r--phpBB/includes/db/migrator.php71
1 files changed, 38 insertions, 33 deletions
diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php
index 4456600b0a..89b253bc8c 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_return_on_error(false);
}
/**
@@ -228,9 +236,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);
}
}
}
@@ -323,7 +332,6 @@ class phpbb_db_migrator
if (!isset($this->migration_state[$name]))
{
$state['migration_start_time'] = time();
- $this->insert_migration($name, $state);
}
}
@@ -352,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;
}
@@ -425,20 +426,13 @@ 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;
}
- $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
{
@@ -651,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
@@ -660,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;
}
@@ -674,7 +678,7 @@ 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)
{
@@ -685,7 +689,7 @@ class phpbb_db_migrator
if (!class_exists($name))
{
- return true;
+ return $name;
}
$migration = $this->get_migration($name);
@@ -693,9 +697,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 +720,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;
}