mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 12:28:52 +00:00
[feature/migrations] Standard vars for migrations and run sql with feedback
PHPBB3-9737
This commit is contained in:
parent
8645321f40
commit
c802f2a66c
3 changed files with 63 additions and 8 deletions
|
@ -28,17 +28,32 @@ class phpbb_db_migration
|
|||
{
|
||||
var $db;
|
||||
var $db_tools;
|
||||
var $table_prefix;
|
||||
|
||||
var $phpbb_root_path;
|
||||
var $php_ext;
|
||||
|
||||
var $errors;
|
||||
|
||||
/**
|
||||
* Migration constructor
|
||||
*
|
||||
* @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 $phpbb_root_path
|
||||
* @param string $php_ext
|
||||
*/
|
||||
function phpbb_db_migration(&$db, &$db_tools)
|
||||
function phpbb_db_migration(&$db, &$db_tools, $table_prefix, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$this->db = &$db;
|
||||
$this->db_tools = &$db_tools;
|
||||
$this->table_prefix = $table_prefix;
|
||||
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
$this->errors = array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,10 +86,39 @@ class phpbb_db_migration
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds a column to a database table
|
||||
* Wrapper for running queries to generate user feedback on updates
|
||||
*/
|
||||
function db_column_add($table_name, $column_name, $column_data)
|
||||
function sql_query($sql)
|
||||
{
|
||||
$this->db_tools->sql_column_add($table_name, $column_name, $column_data);
|
||||
if (defined('DEBUG_EXTRA'))
|
||||
{
|
||||
echo "<br />\n{$sql}\n<br />";
|
||||
}
|
||||
|
||||
$db->sql_return_on_error(true);
|
||||
|
||||
if ($sql === 'begin')
|
||||
{
|
||||
$result = $db->sql_transaction('begin');
|
||||
}
|
||||
else if ($sql === 'commit')
|
||||
{
|
||||
$result = $db->sql_transaction('commit');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $db->sql_query($sql);
|
||||
if ($db->sql_error_triggered)
|
||||
{
|
||||
$this->errors[] = array(
|
||||
'sql' => $db->sql_error_sql,
|
||||
'code' => $db->sql_error_returned,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$db->sql_return_on_error(false);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -32,7 +32,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
|||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->db_tools = new phpbb_db_tools($this->db);
|
||||
$this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE);
|
||||
$this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, 'phpbb_', MIGRATIONS_TABLE, 'phpBB/', '.php');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
|
|
Loading…
Add table
Reference in a new issue