mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
Merge branch '3.2.x'
This commit is contained in:
commit
5338b7a361
4 changed files with 141 additions and 2 deletions
|
@ -503,11 +503,14 @@ class migrator
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->migration_state as $name => $state)
|
foreach ($this->migrations as $name)
|
||||||
{
|
{
|
||||||
if (!empty($state['migration_depends_on']) && in_array($migration, $state['migration_depends_on']))
|
$state = $this->migration_state($name);
|
||||||
|
|
||||||
|
if ($state && in_array($migration, $state['migration_depends_on']) && ($state['migration_schema_done'] || $state['migration_data_done']))
|
||||||
{
|
{
|
||||||
$this->revert_do($name);
|
$this->revert_do($name);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
tests/dbal/migration/revert_table.php
Normal file
39
tests/dbal/migration/revert_table.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_dbal_migration_revert_table extends \phpbb\db\migration\migration
|
||||||
|
{
|
||||||
|
function update_schema()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'add_tables' => array(
|
||||||
|
'phpbb_foobar' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'module_id' => array('UINT:3', NULL, 'auto_increment'),
|
||||||
|
'bar_column' => array('UINT', 1),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => 'module_id',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function revert_schema()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'drop_tables' => array(
|
||||||
|
'phpbb_foobar',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
52
tests/dbal/migration/revert_table_with_dependency.php
Normal file
52
tests/dbal/migration/revert_table_with_dependency.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_dbal_migration_revert_table_with_dependency extends \phpbb\db\migration\migration
|
||||||
|
{
|
||||||
|
static public function depends_on()
|
||||||
|
{
|
||||||
|
return array('phpbb_dbal_migration_revert_table');
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_schema()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'add_columns' => array(
|
||||||
|
'phpbb_foobar' => array(
|
||||||
|
'baz_column' => array('UINT', 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'drop_columns' => array(
|
||||||
|
'phpbb_foobar' => array(
|
||||||
|
'bar_column',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function revert_schema()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'add_columns' => array(
|
||||||
|
'phpbb_foobar' => array(
|
||||||
|
'bar_column' => array('UINT', 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'drop_columns' => array(
|
||||||
|
'phpbb_foobar' => array(
|
||||||
|
'baz_column',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,16 +19,26 @@ require_once dirname(__FILE__) . '/migration/if_params.php';
|
||||||
require_once dirname(__FILE__) . '/migration/recall_params.php';
|
require_once dirname(__FILE__) . '/migration/recall_params.php';
|
||||||
require_once dirname(__FILE__) . '/migration/revert.php';
|
require_once dirname(__FILE__) . '/migration/revert.php';
|
||||||
require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
|
require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
|
||||||
|
require_once dirname(__FILE__) . '/migration/revert_table.php';
|
||||||
|
require_once dirname(__FILE__) . '/migration/revert_table_with_dependency.php';
|
||||||
require_once dirname(__FILE__) . '/migration/fail.php';
|
require_once dirname(__FILE__) . '/migration/fail.php';
|
||||||
require_once dirname(__FILE__) . '/migration/installed.php';
|
require_once dirname(__FILE__) . '/migration/installed.php';
|
||||||
require_once dirname(__FILE__) . '/migration/schema.php';
|
require_once dirname(__FILE__) . '/migration/schema.php';
|
||||||
|
|
||||||
class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
|
/** @var \phpbb\db\driver\driver_interface */
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
|
/** @var \phpbb\db\tools\tools_interface */
|
||||||
protected $db_tools;
|
protected $db_tools;
|
||||||
|
|
||||||
|
/** @var \phpbb\db\migrator */
|
||||||
protected $migrator;
|
protected $migrator;
|
||||||
|
|
||||||
|
/** @var \phpbb\config\config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
|
||||||
|
@ -290,6 +300,41 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||||
$this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again');
|
$this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_revert_table()
|
||||||
|
{
|
||||||
|
// Make sure there are no other migrations in the db, this could cause issues
|
||||||
|
$this->db->sql_query("DELETE FROM phpbb_migrations");
|
||||||
|
$this->migrator->load_migration_state();
|
||||||
|
|
||||||
|
$this->migrator->set_migrations(array('phpbb_dbal_migration_revert_table', 'phpbb_dbal_migration_revert_table_with_dependency'));
|
||||||
|
|
||||||
|
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table'));
|
||||||
|
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table_with_dependency'));
|
||||||
|
|
||||||
|
// Install the migration first
|
||||||
|
while (!$this->migrator->finished())
|
||||||
|
{
|
||||||
|
$this->migrator->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_table') !== false);
|
||||||
|
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_table_with_dependency') !== false);
|
||||||
|
|
||||||
|
$this->assertTrue($this->db_tools->sql_column_exists('phpbb_foobar', 'baz_column'));
|
||||||
|
$this->assertFalse($this->db_tools->sql_column_exists('phpbb_foobar', 'bar_column'));
|
||||||
|
|
||||||
|
// Revert migrations
|
||||||
|
while ($this->migrator->migration_state('phpbb_dbal_migration_revert_table') !== false)
|
||||||
|
{
|
||||||
|
$this->migrator->revert('phpbb_dbal_migration_revert_table');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table'));
|
||||||
|
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table_with_dependency'));
|
||||||
|
|
||||||
|
$this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar'));
|
||||||
|
}
|
||||||
|
|
||||||
public function test_fail()
|
public function test_fail()
|
||||||
{
|
{
|
||||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_fail'));
|
$this->migrator->set_migrations(array('phpbb_dbal_migration_fail'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue