diff --git a/phpBB/phpbb/db/doctrine/connection_parameter_factory.php b/phpBB/phpbb/db/doctrine/connection_parameter_factory.php
index 740c4b82b7..90e41061fc 100644
--- a/phpBB/phpbb/db/doctrine/connection_parameter_factory.php
+++ b/phpBB/phpbb/db/doctrine/connection_parameter_factory.php
@@ -149,6 +149,7 @@ class connection_parameter_factory
$enrichment_tags = [
'pdo_mysql' => [
'charset' => 'UTF8',
+ 'platform' => new mysql_platform(),
],
'oci8' => [
'charset' => 'UTF8',
diff --git a/phpBB/phpbb/db/doctrine/mysql_platform.php b/phpBB/phpbb/db/doctrine/mysql_platform.php
new file mode 100644
index 0000000000..8a2090b6d9
--- /dev/null
+++ b/phpBB/phpbb/db/doctrine/mysql_platform.php
@@ -0,0 +1,62 @@
+
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\doctrine;
+
+use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
+use Doctrine\DBAL\Schema\TableDiff;
+
+/**
+ * MySQL specific schema handling.
+ *
+ * While adding auto_increment column to MySQL, it must be indexed.
+ * If it's indexed as primary key, it should be declared as NOT NULL
+ * because MySQL primary key columns cannot be NULL.
+ */
+class mysql_platform extends AbstractMySQLPlatform
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function getAlterTableSQL(TableDiff $diff)
+ {
+ $sql = parent::getAlterTableSQL($diff);
+ $table = $diff->getOldTable();
+ $columns = $diff->getAddedColumns();
+
+ foreach ($columns as $column)
+ {
+ $column_name = $column->getName();
+ if (!empty($column->getAutoincrement()) && $table)
+ {
+ foreach ($sql as $i => $query)
+ {
+ if (stripos($query, "add $column_name"))
+ {
+ if (!$table->getPrimaryKey())
+ {
+ $sql[$i] = str_replace(' DEFAULT NULL', '', $sql[$i]);
+ $sql[$i] .= ' PRIMARY KEY';
+ }
+ else
+ {
+ $sql[$i] .= ", ADD KEY ($column_name)";
+ }
+ }
+ }
+ }
+ }
+
+ return $sql;
+ }
+}
diff --git a/phpBB/phpbb/db/doctrine/postgresql_platform.php b/phpBB/phpbb/db/doctrine/postgresql_platform.php
index ea637b4203..d67b2439b2 100644
--- a/phpBB/phpbb/db/doctrine/postgresql_platform.php
+++ b/phpBB/phpbb/db/doctrine/postgresql_platform.php
@@ -14,10 +14,10 @@
namespace phpbb\db\doctrine;
use Doctrine\DBAL\Platforms\AbstractPlatform;
-use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
-use Doctrine\DBAL\Schema\Index;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
+use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\SmallIntType;
@@ -31,7 +31,7 @@ use Doctrine\DBAL\Types\Type;
* to stay compatible with the existing DB we have to change its
* naming and not ours.
*/
-class postgresql_platform extends PostgreSQL94Platform
+class postgresql_platform extends PostgreSQLPlatform
{
/**
* {@inheritdoc}
@@ -78,6 +78,36 @@ class postgresql_platform extends PostgreSQL94Platform
return AbstractPlatform::getDefaultValueDeclarationSQL($column);
}
+ /**
+ * {@inheritDoc}
+ */
+ public function getAlterTableSQL(TableDiff $diff)
+ {
+ $sql = parent::getAlterTableSQL($diff);
+ $table_name = $diff->getOldTable()->getName();
+ $columns = $diff->getAddedColumns();
+ $post_sql = $sequence_sql = [];
+
+ foreach ($columns as $column)
+ {
+ $column_name = $column->getName();
+ if (!empty($column->getAutoincrement()))
+ {
+ $sequence = new Sequence($this->getIdentitySequenceName($table_name, $column_name));
+ $sequence_sql[] = $this->getCreateSequenceSQL($sequence);
+ $post_sql[] = 'ALTER SEQUENCE ' . $sequence->getName() . ' OWNED BY ' . $table_name . '.' . $column_name;
+ }
+ }
+ $sql = array_merge($sequence_sql, $sql, $post_sql);
+
+ foreach ($sql as $i => $query)
+ {
+ $sql[$i] = str_replace('{{placeholder_sequence}}', "nextval('{$table_name}_seq')", $query);
+ }
+
+ return $sql;
+ }
+
/**
* {@inheritDoc}
*/
@@ -157,31 +187,19 @@ class postgresql_platform extends PostgreSQL94Platform
{
// If we have a primary or a unique index, we need to drop the constraint
// instead of the index itself or postgreSQL will reject the query.
- if ($index instanceof Index)
+ if (is_string($index) && $table !== null && $index === $this->tableName($table) . '_pkey')
{
- if ($index->isPrimary())
- {
- if ($table instanceof Table)
- {
- $table = $table->getQuotedName($this);
- }
- else if (!is_string($table))
- {
- throw new \InvalidArgumentException(
- __METHOD__ . '() expects $table parameter to be string or ' . Table::class . '.'
- );
- }
-
- return 'ALTER TABLE '.$table.' DROP CONSTRAINT '.$index->getQuotedName($this);
- }
- }
- else if (! is_string($index))
- {
- throw new \InvalidArgumentException(
- __METHOD__ . '() expects $index parameter to be string or ' . Index::class . '.'
- );
+ return $this->getDropConstraintSQL($index, $this->tableName($table));
}
return parent::getDropIndexSQL($index, $table);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ private function tableName($table)
+ {
+ return $table instanceof Table ? $table->getName() : (string) $table;
+ }
}
diff --git a/phpBB/phpbb/db/migration/data/v400/remove_jabber.php b/phpBB/phpbb/db/migration/data/v400/remove_jabber.php
index 12759f5f47..17bf49d753 100644
--- a/phpBB/phpbb/db/migration/data/v400/remove_jabber.php
+++ b/phpBB/phpbb/db/migration/data/v400/remove_jabber.php
@@ -34,7 +34,15 @@ class remove_jabber extends migration
$this->table_prefix . 'users' => [
'user_jabber',
],
- ]
+ ],
+ 'add_columns' => [
+ $this->table_prefix . 'user_notifications' => [
+ 'id' => ['ULINT', null, 'auto_increment'],
+ ],
+ ],
+ 'add_primary_keys' => [
+ $this->table_prefix . 'user_notifications' => ['id'],
+ ],
];
}
@@ -45,7 +53,12 @@ class remove_jabber extends migration
$this->table_prefix . 'users' => [
'user_jabber' => ['VCHAR_UNI', ''],
],
- ]
+ ],
+ 'drop_columns' => [
+ $this->table_prefix . 'user_notifications' => [
+ 'id',
+ ],
+ ],
];
}
@@ -105,11 +118,22 @@ class remove_jabber extends migration
{
$limit = 1000;
- $sql = 'UPDATE ' . $this->tables['user_notifications'] . '
- SET ' . $this->db->sql_build_array('UPDATE', ['method' => 'notification.method.email']) . "
- WHERE method = 'notification.method.jabber'";
- $this->db->sql_query_limit($sql, $limit, $start ?: 0);
+ $sql = 'SELECT id FROM ' . $this->tables['user_notifications'] . "
+ WHERE method = 'notification.method.jabber'
+ ORDER BY id ASC";
+ $result = $this->db->sql_query_limit($sql, $limit, $start ?: 0);
+ $rowset = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+ $ids_array = array_column($rowset, 'id');
- return $this->db->sql_affectedrows() < $limit ? true : $start + $limit;
+ if (count($ids_array))
+ {
+ $sql = 'UPDATE ' . $this->tables['user_notifications'] . '
+ SET ' . $this->db->sql_build_array('UPDATE', ['method' => 'notification.method.email']) . '
+ WHERE ' . $this->db->sql_in_set('id', $ids_array);
+ $this->db->sql_query($sql);
+ }
+
+ return count($ids_array) < $limit ? true : $start + $limit;
}
}
diff --git a/phpBB/phpbb/db/migration/schema_generator.php b/phpBB/phpbb/db/migration/schema_generator.php
index 90cfddbe5a..1153f4c67e 100644
--- a/phpBB/phpbb/db/migration/schema_generator.php
+++ b/phpBB/phpbb/db/migration/schema_generator.php
@@ -185,6 +185,7 @@ class schema_generator
'drop_columns' => 'COLUMNS',
'change_columns' => 'COLUMNS',
'add_index' => 'KEYS',
+ 'add_primary_keys' => 'PRIMARY_KEY',
'add_unique_index' => 'KEYS',
'drop_keys' => 'KEYS',
'rename_index' => 'KEYS',
diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php
index 2aeec109a4..8e35d49d03 100644
--- a/phpBB/phpbb/db/migration/tool/module.php
+++ b/phpBB/phpbb/db/migration/tool/module.php
@@ -377,7 +377,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
{
if (!$this->exists($class, $parent, $module, true))
{
- return;
+ throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $module);
}
$parent_sql = '';
diff --git a/phpBB/phpbb/db/tools/doctrine.php b/phpBB/phpbb/db/tools/doctrine.php
index 043252b4c5..87628d440e 100644
--- a/phpBB/phpbb/db/tools/doctrine.php
+++ b/phpBB/phpbb/db/tools/doctrine.php
@@ -96,7 +96,7 @@ class doctrine implements tools_interface
*/
protected function get_schema(): Schema
{
- return $this->get_schema_manager()->createSchema();
+ return $this->get_schema_manager()->introspectSchema();
}
/**
@@ -300,36 +300,6 @@ class doctrine implements tools_interface
*/
public function sql_column_remove(string $table_name, string $column_name)
{
- // Check if this column is part of a primary key. If yes, remove the primary key.
- $primary_key_indexes = $this->get_filtered_index_list($table_name, false);
-
- $primary_key_indexes = array_filter($primary_key_indexes, function($index) use ($column_name) {
- $index_columns = array_map('strtolower', $index->getUnquotedColumns());
- return in_array($column_name, $index_columns, true) && $index->isPrimary();
- });
-
- if (count($primary_key_indexes))
- {
- // For PostgreSQL, drop primary index first to avoid "Dependent objects still exist" error
- if (stripos($this->get_schema_manager()->getDatabasePlatform()->getname(), 'postgresql') !== false)
- {
- $this->get_schema_manager()->dropIndex('"primary"', $table_name);
- }
-
- $ret = $this->alter_schema(
- function (Schema $schema) use ($table_name, $column_name): void
- {
- $table = $schema->getTable($table_name);
- $table->dropPrimaryKey();
- }
- );
-
- if ($ret !== true)
- {
- return $ret;
- }
- }
-
return $this->alter_schema(
function (Schema $schema) use ($table_name, $column_name): void
{
@@ -398,7 +368,7 @@ class doctrine implements tools_interface
return $this->alter_schema(
function (Schema $schema) use ($table_name, $column): void
{
- $this->schema_create_primary_key($schema, $column, $table_name);
+ $this->schema_create_primary_key($schema, $table_name, $column);
}
);
}
@@ -410,7 +380,7 @@ class doctrine implements tools_interface
{
try
{
- $this->connection->executeQuery($this->get_schema_manager()->getDatabasePlatform()->getTruncateTableSQL($table_name));
+ $this->connection->executeQuery($this->connection->getDatabasePlatform()->getTruncateTableSQL($table_name));
}
catch (Exception $e)
{
@@ -515,7 +485,7 @@ class doctrine implements tools_interface
$comparator = new comparator();
$schemaDiff = $comparator->compareSchemas($current_schema, $new_schema);
- $queries = $schemaDiff->toSql($this->get_schema_manager()->getDatabasePlatform());
+ $queries = $schemaDiff->toSql($this->connection->getDatabasePlatform());
if ($this->return_statements)
{
@@ -527,7 +497,6 @@ class doctrine implements tools_interface
// executeQuery() must be used here because $query might return a result set, for instance REPAIR does
$this->connection->executeQuery($query);
}
-
return true;
}
@@ -659,7 +628,7 @@ class doctrine implements tools_interface
$table = $schema->createTable($table_name);
$short_table_name = table_helper::generate_shortname(self::remove_prefix($table_name, $this->table_prefix));
- $dbms_name = $this->get_schema_manager()->getDatabasePlatform()->getName();
+ $dbms_name = $this->connection->getDatabasePlatform()->getName();
foreach ($table_data['COLUMNS'] as $column_name => $column_data)
{
@@ -758,7 +727,7 @@ class doctrine implements tools_interface
return false;
}
- $dbms_name = $this->get_schema_manager()->getDatabasePlatform()->getName();
+ $dbms_name = $this->connection->getDatabasePlatform()->getName();
list($type, $options) = table_helper::convert_column_data($column_data, $dbms_name);
$table->addColumn($column_name, $type, $options);
@@ -790,7 +759,7 @@ class doctrine implements tools_interface
return;
}
- $dbms_name = $this->get_schema_manager()->getDatabasePlatform()->getName();
+ $dbms_name = $this->connection->getDatabasePlatform()->getName();
list($type, $options) = table_helper::convert_column_data($column_data, $dbms_name);
$options['type'] = Type::getType($type);
@@ -990,16 +959,16 @@ class doctrine implements tools_interface
/**
* Creates primary key for a table
*
- * @param $column
* @param Schema $schema
* @param string $table_name
+ * @param array|string $column_name
* @param bool $safe_check
*
* @throws SchemaException
*/
- protected function schema_create_primary_key(Schema $schema, $column, string $table_name, bool $safe_check = false): void
+ protected function schema_create_primary_key(Schema $schema, string $table_name, array|string $column_name, bool $safe_check = false): void
{
- $columns = (is_array($column)) ? $column : [$column];
+ $columns = (is_array($column_name)) ? $column_name : [$column_name];
$table = $schema->getTable($table_name);
$table->dropPrimaryKey();
$table->setPrimaryKey($columns);
diff --git a/tests/dbal/migration/schema_add_autoincrement.php b/tests/dbal/migration/schema_add_autoincrement.php
new file mode 100644
index 0000000000..4e3ecff183
--- /dev/null
+++ b/tests/dbal/migration/schema_add_autoincrement.php
@@ -0,0 +1,43 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class schema_add_autoincrement extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return [
+ 'add_tables' => [
+ $this->table_prefix . 'noid' => [
+ 'COLUMNS' => [
+ 'text' => ['VCHAR:50', ''],
+ ],
+ ],
+ ],
+
+ 'add_columns' => [
+ $this->table_prefix . 'noid' => [
+ 'id' => ['UINT:3', null, 'auto_increment'],
+ ],
+ ],
+ ];
+ }
+
+ function revert_schema()
+ {
+ return [
+ 'drop_tables' => [
+ $this->table_prefix . 'noid',
+ ],
+ ];
+ }
+}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index f4b80fc5e9..284c52a07c 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -25,6 +25,7 @@ require_once __DIR__ . '/migration/fail.php';
require_once __DIR__ . '/migration/installed.php';
require_once __DIR__ . '/migration/schema.php';
require_once __DIR__ . '/migration/schema_index.php';
+require_once __DIR__ . '/migration/schema_add_autoincrement.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
@@ -502,4 +503,24 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
}
}
}
+
+ public function test_add_autoincrement_column()
+ {
+ $this->migrator->set_migrations(['schema_add_autoincrement']);
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->db_tools->sql_table_exists('phpbb_noid'));
+ $this->assertTrue($this->db_tools->sql_column_exists('phpbb_noid', 'id'));
+
+ while ($this->migrator->migration_state('schema_add_autoincrement'))
+ {
+ $this->migrator->revert('schema_add_autoincrement');
+ }
+
+ $this->assertFalse($this->db_tools->sql_table_exists('phpbb_noid'));
+ }
}
diff --git a/tests/migrations/fixtures/migration_remove_jabber.xml b/tests/migrations/fixtures/migration_remove_jabber.xml
new file mode 100644
index 0000000000..e263cdafcf
--- /dev/null
+++ b/tests/migrations/fixtures/migration_remove_jabber.xml
@@ -0,0 +1,284 @@
+
+
+
+ migration_name
+ migration_depends_on
+ migration_schema_done
+ migration_data_done
+ migration_data_state
+ migration_start_time
+ migration_end_time
+
+
+ config_name
+ config_value
+
+ jab_enable
+ 1
+
+
+ jab_host
+
+
+
+ jab_package_size
+ 0
+
+
+ jab_password
+
+
+
+ jab_port
+
+
+
+ jab_use_ssl
+
+
+
+ jab_username
+ user
+
+
+ jab_verify_peer
+ 0
+
+
+ jab_verify_peer_name
+ 0
+
+
+ jab_allow_self_signed
+ 0
+
+
+
+ module_id
+ module_enabled
+ module_display
+ module_basename
+ module_class
+ parent_id
+ left_id
+ right_id
+ module_langname
+ module_mode
+ module_auth
+
+ 1
+ 1
+ 1
+
+ acp
+ 0
+ 1
+ 76
+ ACP_CAT_GENERAL
+
+
+
+
+ 4
+ 1
+ 1
+
+ acp
+ 1
+ 48
+ 59
+ ACP_CLIENT_COMMUNICATION
+
+
+
+
+ 75
+ 1
+ 1
+ acp_jabber
+ acp
+ 4
+ 53
+ 54
+ ACP_JABBER_SETTINGS
+ settings
+ acl_a_jabber
+
+
+
+ auth_option_id
+ auth_option
+ is_global
+ is_local
+ founder_only
+
+ 70
+ a_jabber
+ 1
+ 0
+ 0
+
+
+ 121
+ u_sendim
+ 1
+ 0
+ 0
+
+
+
+ group_id
+ forum_id
+ auth_option_id
+ auth_role_id
+ auth_setting
+
+
+ role_id
+ auth_option_id
+ auth_setting
+
+ 4
+ 70
+ 1
+
+
+ 5
+ 121
+ 1
+
+
+ 6
+ 121
+ 1
+
+
+
+ user_id
+ forum_id
+ auth_option_id
+ auth_role_id
+ auth_setting
+
+
+ id
+ item_type
+ item_id
+ user_id
+ method
+ notify
+
+ 1
+ notification.type.post
+ 0
+ 2
+ notification.method.jabber
+ 1
+
+
+ 2
+ notification.type.post
+ 0
+ 3
+ notification.method.jabber
+ 1
+
+
+ 3
+ notification.type.post
+ 0
+ 4
+ notification.method.jabber
+ 1
+
+
+ 4
+ notification.type.post
+ 0
+ 5
+ notification.method.jabber
+ 1
+
+
+ 5
+ notification.type.post
+ 0
+ 6
+ notification.method.jabber
+ 1
+
+
+ 6
+ notification.type.post
+ 0
+ 7
+ notification.method.jabber
+ 1
+
+
+ 7
+ notification.type.post
+ 0
+ 8
+ notification.method.jabber
+ 1
+
+
+ 8
+ notification.type.forum
+ 0
+ 2
+ notification.method.jabber
+ 1
+
+
+ 9
+ notification.type.forum
+ 0
+ 3
+ notification.method.jabber
+ 1
+
+
+ 10
+ notification.type.forum
+ 0
+ 4
+ notification.method.jabber
+ 1
+
+
+ 11
+ notification.type.forum
+ 0
+ 5
+ notification.method.jabber
+ 1
+
+
+ 12
+ notification.type.forum
+ 0
+ 6
+ notification.method.jabber
+ 1
+
+
+ 13
+ notification.type.forum
+ 0
+ 7
+ notification.method.jabber
+ 1
+
+
+ 14
+ notification.type.forum
+ 0
+ 8
+ notification.method.jabber
+ 1
+
+
+
+
diff --git a/tests/migrations/migration_test_base.php b/tests/migrations/migration_test_base.php
new file mode 100644
index 0000000000..62148a6654
--- /dev/null
+++ b/tests/migrations/migration_test_base.php
@@ -0,0 +1,151 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+abstract class phpbb_migration_test_base extends phpbb_database_test_case
+{
+ /** @var \phpbb\db\driver\driver_interface */
+ protected $db;
+
+ /** @var \Doctrine\DBAL\Connection */
+ protected $doctrine_db;
+
+ /** @var \phpbb\db\tools\tools_interface */
+ protected $db_tools;
+
+ /** @var \phpbb\db\migrator */
+ protected $migrator;
+
+ /** @var \phpbb\config\config */
+ protected $config;
+
+ /** @var \phpbb\extension\manager */
+ protected $extension_manager;
+
+ /** @var string */
+ protected $fixture;
+
+ /** @var string */
+ protected $migration_class;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(__DIR__ . $this->fixture);
+ }
+
+ protected function setUp(): void
+ {
+ global $cache, $db, $phpbb_log, $phpbb_root_path, $phpEx, $skip_add_log, $table_prefix, $user;
+
+ parent::setUp();
+
+ // Disable the logs
+ $skip_add_log = true;
+
+ $db = $this->db = $this->new_dbal();
+ $this->doctrine_db = $this->new_doctrine_dbal();
+ $factory = new \phpbb\db\tools\factory();
+ $this->db_tools = $factory->get($this->doctrine_db);
+ $this->db_tools->set_table_prefix($table_prefix);
+ $this->cache = new phpbb_mock_cache();
+ $this->auth = new \phpbb\auth\auth();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $this->config = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config');
+ $this->config->initialise($this->cache);
+ $cache = $this->cache_service = new \phpbb\cache\service($this->cache, $this->config, $this->db, $phpbb_dispatcher, $phpbb_root_path, $phpEx);
+
+
+ $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
+ $lang = new \phpbb\language\language($lang_loader);
+ $user = $this->user = new \phpbb\user($lang, '\phpbb\datetime');
+
+ $phpbb_log = new \phpbb\log\log($this->db, $this->user, $this->auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ $container = new phpbb_mock_container_builder();
+ $container->set('event_dispatcher', $phpbb_dispatcher);
+
+ $finder_factory = $this->createMock('\phpbb\finder\factory');
+ $this->extension_manager = new \phpbb\extension\manager(
+ $container,
+ $this->db,
+ $this->config,
+ $finder_factory,
+ 'phpbb_ext',
+ __DIR__ . '/../../phpBB/',
+ null
+ );
+
+ $module_manager = new \phpbb\module\module_manager($this->cache, $this->db, $this->extension_manager, 'phpbb_modules', $phpbb_root_path, $phpEx);
+
+ $this->tools = array(
+ 'config' => new \phpbb\db\migration\tool\config($this->config),
+ 'config_text' => new \phpbb\db\migration\tool\config_text(new \phpbb\config\db_text($this->db, 'phpbb_config_text')),
+ 'module' => new \phpbb\db\migration\tool\module($this->db, $this->user, $module_manager, 'phpbb_modules'),
+ 'permission' => new \phpbb\db\migration\tool\permission($this->db, $this->cache_service, $this->auth, $phpbb_root_path, $phpEx),
+ );
+
+ $this->migrator = new \phpbb\db\migrator(
+ $container,
+ $this->config,
+ $this->db,
+ $this->db_tools,
+ 'phpbb_migrations',
+ __DIR__ . '/../../phpBB/',
+ 'php',
+ 'phpbb_',
+ self::get_core_tables(),
+ $this->tools,
+ new \phpbb\db\migration\helper()
+ );
+ $container->set('migrator', $this->migrator);
+
+ $migration = $this->migrator->get_migration($this->migration_class);
+ $depends = $migration->depends_on();
+ $this->migrator->populate_migrations($depends);
+
+ $this->migrator->set_migrations([$this->migration_class]);
+ }
+
+ protected function apply_migration()
+ {
+ while (!$this->migrator->finished())
+ {
+ try
+ {
+ $this->migrator->update();
+ }
+ catch (\phpbb\db\migration\exception $e)
+ {
+ $this->fail('Applying migration error: ' . $e->__toString());
+ }
+ }
+
+ return $this->migrator->finished();
+ }
+
+ protected function revert_migration()
+ {
+ while ($this->migrator->migration_state($this->migration_class) !== false)
+ {
+ try
+ {
+ $this->migrator->revert($this->migration_class);
+ }
+ catch (\phpbb\db\migration\exception $e)
+ {
+ $this->fail('Reverting migration error: ' . $e->__toString());
+ }
+ }
+
+ return !$this->migrator->migration_state($this->migration_class);
+ }
+}
diff --git a/tests/migrations/remove_jabber_migration_test.php b/tests/migrations/remove_jabber_migration_test.php
new file mode 100644
index 0000000000..e80a5cbbaa
--- /dev/null
+++ b/tests/migrations/remove_jabber_migration_test.php
@@ -0,0 +1,76 @@
+
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once __DIR__ . '/migration_test_base.php';
+
+class phpbb_migrations_remove_jabber_migration_test extends phpbb_migration_test_base
+{
+
+ protected $migration_class = '\phpbb\db\migration\data\v400\remove_jabber';
+ protected $fixture = '/fixtures/migration_remove_jabber.xml';
+
+ public function test_remove_jabber_migration()
+ {
+ $sql = "SELECT id FROM phpbb_user_notifications
+ WHERE method = 'notification.method.jabber'";
+ $result = $this->db->sql_query($sql);
+ $rowset = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+ $this->assertEquals(14, count($rowset));
+
+ $sql = "SELECT config_name FROM phpbb_config
+ WHERE config_name = 'jab_enable'";
+ $this->assertNotFalse($this->db->sql_query($sql));
+
+ $this->assertTrue($this->tools['permission']->exists('a_jabber'));
+ $this->assertTrue($this->tools['permission']->exists('u_sendim'));
+ $this->assertTrue($this->tools['module']->exists('acp', 'ACP_CLIENT_COMMUNICATION', 'ACP_JABBER_SETTINGS'));
+
+ $this->apply_migration();
+
+ $sql = "SELECT id FROM phpbb_user_notifications
+ WHERE method = 'notification.method.jabber'";
+ $this->db->sql_query($sql);
+ $this->assertFalse($this->db->sql_fetchfield('id'));
+
+ $sql = "SELECT id FROM phpbb_user_notifications
+ WHERE method = 'notification.method.email'";
+ $result = $this->db->sql_query($sql);
+ $rowset = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+ $this->assertEquals(14, count($rowset));
+
+ $sql = "SELECT config_name FROM phpbb_config
+ WHERE config_name = 'jab_enable'";
+ $this->db->sql_query($sql);
+ $this->assertFalse($this->db->sql_fetchfield('config_name'));
+
+ $this->assertFalse($this->tools['permission']->exists('a_jabber'));
+ $this->assertFalse($this->tools['permission']->exists('u_sendim'));
+ $this->assertFalse($this->tools['module']->exists('acp', 'ACP_CLIENT_COMMUNICATION', 'ACP_JABBER_SETTINGS'));
+
+ $this->revert_migration();
+
+ $sql = "SELECT config_name FROM phpbb_config
+ WHERE config_name = 'jab_enable'";
+ $this->db->sql_query($sql);
+ $this->assertEquals('jab_enable', $this->db->sql_fetchfield('config_name'));
+
+ $this->assertTrue($this->tools['permission']->exists('a_jabber'));
+ $this->assertTrue($this->tools['permission']->exists('u_sendim'));
+ $this->assertTrue($this->tools['module']->exists('acp', 'ACP_CLIENT_COMMUNICATION', 'ACP_JABBER_SETTINGS'));
+
+ // Apply migration back
+ $this->apply_migration();
+ }
+}
diff --git a/tests/notification/fixtures/email_notification.type.post.xml b/tests/notification/fixtures/email_notification.type.post.xml
index 6d064141b7..7a4a7191eb 100644
--- a/tests/notification/fixtures/email_notification.type.post.xml
+++ b/tests/notification/fixtures/email_notification.type.post.xml
@@ -164,12 +164,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.post
0
2
@@ -177,6 +179,7 @@
1
+ 2
notification.type.post
0
3
@@ -184,6 +187,7 @@
1
+ 3
notification.type.post
0
4
@@ -191,6 +195,7 @@
1
+ 4
notification.type.post
0
5
@@ -198,6 +203,7 @@
1
+ 5
notification.type.post
0
6
@@ -205,6 +211,7 @@
1
+ 6
notification.type.post
0
7
@@ -212,6 +219,7 @@
1
+ 7
notification.type.post
0
8
@@ -219,6 +227,7 @@
1
+ 8
notification.type.forum
0
2
@@ -226,6 +235,7 @@
1
+ 9
notification.type.forum
0
3
@@ -233,6 +243,7 @@
1
+ 10
notification.type.forum
0
4
@@ -240,6 +251,7 @@
1
+ 11
notification.type.forum
0
5
@@ -247,6 +259,7 @@
1
+ 12
notification.type.forum
0
6
@@ -254,6 +267,7 @@
1
+ 13
notification.type.forum
0
7
@@ -261,6 +275,7 @@
1
+ 14
notification.type.forum
0
8
diff --git a/tests/notification/fixtures/submit_post_notification.type.bookmark.xml b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
index b6163e9ed0..1e6b6a19ca 100644
--- a/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
@@ -119,12 +119,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.bookmark
0
2
@@ -132,6 +134,7 @@
1
+ 2
notification.type.bookmark
0
3
@@ -139,6 +142,7 @@
1
+ 3
notification.type.bookmark
0
4
@@ -146,6 +150,7 @@
1
+ 4
notification.type.bookmark
0
5
@@ -153,6 +158,7 @@
1
+ 5
notification.type.bookmark
0
6
@@ -160,6 +166,7 @@
0
+ 6
notification.type.bookmark
0
3
diff --git a/tests/notification/fixtures/submit_post_notification.type.forum.xml b/tests/notification/fixtures/submit_post_notification.type.forum.xml
index b8df34bedc..c12c878604 100644
--- a/tests/notification/fixtures/submit_post_notification.type.forum.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.forum.xml
@@ -155,12 +155,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.post
0
2
@@ -168,6 +170,7 @@
1
+ 2
notification.type.post
0
3
@@ -175,6 +178,7 @@
1
+ 3
notification.type.post
0
4
@@ -182,6 +186,7 @@
1
+ 4
notification.type.post
0
5
@@ -189,6 +194,7 @@
1
+ 5
notification.type.post
0
6
@@ -196,6 +202,7 @@
1
+ 6
notification.type.post
0
7
@@ -203,6 +210,7 @@
1
+ 7
notification.type.post
0
8
@@ -210,6 +218,7 @@
1
+ 8
notification.type.forum
0
2
@@ -217,6 +226,7 @@
1
+ 9
notification.type.forum
0
3
@@ -224,6 +234,7 @@
1
+ 10
notification.type.forum
0
4
@@ -231,6 +242,7 @@
1
+ 11
notification.type.forum
0
5
@@ -238,6 +250,7 @@
1
+ 12
notification.type.forum
0
6
@@ -245,6 +258,7 @@
1
+ 13
notification.type.forum
0
7
@@ -252,6 +266,7 @@
1
+ 14
notification.type.forum
0
8
diff --git a/tests/notification/fixtures/submit_post_notification.type.mention.xml b/tests/notification/fixtures/submit_post_notification.type.mention.xml
index 86ae1fd037..7faf22c401 100644
--- a/tests/notification/fixtures/submit_post_notification.type.mention.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.mention.xml
@@ -136,12 +136,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.mention
0
2
@@ -149,6 +151,7 @@
1
+ 2
notification.type.mention
0
3
@@ -156,6 +159,7 @@
1
+ 3
notification.type.mention
0
4
@@ -163,6 +167,7 @@
1
+ 4
notification.type.mention
0
5
@@ -170,6 +175,7 @@
1
+ 5
notification.type.mention
0
6
@@ -177,6 +183,7 @@
0
+ 6
notification.type.mention
0
8
diff --git a/tests/notification/fixtures/submit_post_notification.type.post.xml b/tests/notification/fixtures/submit_post_notification.type.post.xml
index 75bfb03e89..7d760cd1eb 100644
--- a/tests/notification/fixtures/submit_post_notification.type.post.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.post.xml
@@ -155,12 +155,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.post
0
2
@@ -168,6 +170,7 @@
1
+ 2
notification.type.post
0
3
@@ -175,6 +178,7 @@
1
+ 3
notification.type.post
0
4
@@ -182,6 +186,7 @@
1
+ 4
notification.type.post
0
5
@@ -189,6 +194,7 @@
1
+ 5
notification.type.post
0
6
@@ -196,6 +202,7 @@
1
+ 6
notification.type.post
0
7
@@ -203,6 +210,7 @@
1
+ 7
notification.type.post
0
8
@@ -210,6 +218,7 @@
1
+ 8
notification.type.forum
0
2
@@ -217,6 +226,7 @@
1
+ 9
notification.type.forum
0
3
@@ -224,6 +234,7 @@
1
+ 10
notification.type.forum
0
4
@@ -231,6 +242,7 @@
1
+ 11
notification.type.forum
0
5
@@ -238,6 +250,7 @@
1
+ 12
notification.type.forum
0
6
@@ -245,6 +258,7 @@
1
+ 13
notification.type.forum
0
7
@@ -252,6 +266,7 @@
1
+ 14
notification.type.forum
0
8
diff --git a/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
index 12e73b0ff2..fe0a99bdc5 100644
--- a/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
@@ -103,12 +103,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.needs_approval
0
2
@@ -116,6 +118,7 @@
1
+ 2
notification.type.needs_approval
0
3
@@ -123,6 +126,7 @@
1
+ 3
notification.type.needs_approval
0
4
@@ -130,6 +134,7 @@
1
+ 4
notification.type.needs_approval
0
5
@@ -137,6 +142,7 @@
1
+ 5
notification.type.needs_approval
0
6
@@ -144,6 +150,7 @@
1
+ 6
notification.type.needs_approval
0
7
@@ -151,6 +158,7 @@
0
+ 7
notification.type.needs_approval
0
9
diff --git a/tests/notification/fixtures/submit_post_notification.type.quote.xml b/tests/notification/fixtures/submit_post_notification.type.quote.xml
index 9f4ba91475..8fe85d0db3 100644
--- a/tests/notification/fixtures/submit_post_notification.type.quote.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.quote.xml
@@ -91,12 +91,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.quote
0
2
@@ -104,6 +106,7 @@
1
+ 2
notification.type.quote
0
3
@@ -111,6 +114,7 @@
1
+ 3
notification.type.quote
0
4
@@ -118,6 +122,7 @@
1
+ 4
notification.type.quote
0
5
@@ -125,6 +130,7 @@
1
+ 5
notification.type.quote
0
6
diff --git a/tests/notification/fixtures/submit_post_notification.type.topic.xml b/tests/notification/fixtures/submit_post_notification.type.topic.xml
index 1f96ed2ee7..eebab64e6b 100644
--- a/tests/notification/fixtures/submit_post_notification.type.topic.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.topic.xml
@@ -99,12 +99,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.topic
0
2
@@ -112,6 +114,7 @@
1
+ 2
notification.type.topic
0
6
@@ -119,6 +122,7 @@
1
+ 3
notification.type.topic
0
7
@@ -126,6 +130,7 @@
1
+ 4
notification.type.topic
0
8
diff --git a/tests/notification/fixtures/webpush_notification.type.post.xml b/tests/notification/fixtures/webpush_notification.type.post.xml
index d59d5b92c4..89c5354030 100644
--- a/tests/notification/fixtures/webpush_notification.type.post.xml
+++ b/tests/notification/fixtures/webpush_notification.type.post.xml
@@ -185,12 +185,14 @@
+ id
item_type
item_id
user_id
method
notify
+ 1
notification.type.post
0
2
@@ -198,6 +200,7 @@
1
+ 2
notification.type.post
0
3
@@ -205,6 +208,7 @@
1
+ 3
notification.type.post
0
4
@@ -212,6 +216,7 @@
1
+ 4
notification.type.post
0
5
@@ -219,6 +224,7 @@
1
+ 5
notification.type.post
0
6
@@ -226,6 +232,7 @@
1
+ 6
notification.type.post
0
7
@@ -233,6 +240,7 @@
1
+ 7
notification.type.post
0
8
@@ -240,6 +248,7 @@
1
+ 8
notification.type.forum
0
2
@@ -247,6 +256,7 @@
1
+ 9
notification.type.forum
0
3
@@ -254,6 +264,7 @@
1
+ 10
notification.type.forum
0
4
@@ -261,6 +272,7 @@
1
+ 11
notification.type.forum
0
5
@@ -268,6 +280,7 @@
1
+ 12
notification.type.forum
0
6
@@ -275,6 +288,7 @@
1
+ 13
notification.type.forum
0
7
@@ -282,6 +296,7 @@
1
+ 14
notification.type.forum
0
8