aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2015-01-20 23:32:36 +0100
committerJoas Schilling <nickvergessen@gmx.de>2015-01-20 23:32:36 +0100
commitb566686b5161e699f8376b0463960a9ffb3812b6 (patch)
tree9392b221794a7bac17102b20f64f33fa009c31c2
parentc71e8ffb29e0b3774395b9fbfa3b3faff0095413 (diff)
parenta5fae1b1f09358f8a24ff32fc5192395cd314244 (diff)
downloadforums-b566686b5161e699f8376b0463960a9ffb3812b6.tar
forums-b566686b5161e699f8376b0463960a9ffb3812b6.tar.gz
forums-b566686b5161e699f8376b0463960a9ffb3812b6.tar.bz2
forums-b566686b5161e699f8376b0463960a9ffb3812b6.tar.xz
forums-b566686b5161e699f8376b0463960a9ffb3812b6.zip
Merge branch 'develop-ascraeus' into develop
Conflicts: phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php phpBB/phpbb/db/migration/profilefield_base_migration.php phpBB/phpbb/db/migrator.php
-rw-r--r--phpBB/config/default/container/services_db.yml1
-rw-r--r--phpBB/phpbb/db/migration/container_aware_migration.php36
-rw-r--r--phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php9
-rw-r--r--phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php20
-rw-r--r--phpBB/phpbb/db/migration/profilefield_base_migration.php6
-rw-r--r--phpBB/phpbb/db/migrator.php52
-rw-r--r--phpBB/phpbb/event/dispatcher.php35
-rw-r--r--phpBB/phpbb/event/dispatcher_interface.php10
-rw-r--r--tests/dbal/migrator_test.php8
-rw-r--r--tests/extension/manager_test.php4
-rw-r--r--tests/extension/metadata_manager_test.php3
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php4
12 files changed, 156 insertions, 32 deletions
diff --git a/phpBB/config/default/container/services_db.yml b/phpBB/config/default/container/services_db.yml
index 77a1b59d22..ce08785c65 100644
--- a/phpBB/config/default/container/services_db.yml
+++ b/phpBB/config/default/container/services_db.yml
@@ -18,6 +18,7 @@ services:
migrator:
class: phpbb\db\migrator
arguments:
+ - @service_container
- @config
- @dbal.conn
- @dbal.tools
diff --git a/phpBB/phpbb/db/migration/container_aware_migration.php b/phpBB/phpbb/db/migration/container_aware_migration.php
new file mode 100644
index 0000000000..3b4b49b04b
--- /dev/null
+++ b/phpBB/phpbb/db/migration/container_aware_migration.php
@@ -0,0 +1,36 @@
+<?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.
+*
+*/
+
+namespace phpbb\db\migration;
+
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+* Abstract base class for container aware database migrations.
+*/
+abstract class container_aware_migration extends migration implements ContainerAwareInterface
+{
+ /**
+ * @var ContainerInterface
+ */
+ protected $container;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setContainer(ContainerInterface $container = null)
+ {
+ $this->container = $container;
+ }
+}
diff --git a/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php
index 20543463ab..c2a3ce5940 100644
--- a/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php
+++ b/phpBB/phpbb/db/migration/data/v30x/release_3_0_5_rc1.php
@@ -13,7 +13,9 @@
namespace phpbb\db\migration\data\v30x;
-class release_3_0_5_rc1 extends \phpbb\db\migration\migration
+use phpbb\db\migration\container_aware_migration;
+
+class release_3_0_5_rc1 extends container_aware_migration
{
public function effectively_installed()
{
@@ -55,10 +57,9 @@ class release_3_0_5_rc1 extends \phpbb\db\migration\migration
public function hash_old_passwords()
{
- global $phpbb_container;
-
/* @var $passwords_manager \phpbb\passwords\manager */
- $passwords_manager = $phpbb_container->get('passwords.manager');
+ $passwords_manager = $this->container->get('passwords.manager');
+
$sql = 'SELECT user_id, user_password
FROM ' . $this->table_prefix . 'users
WHERE user_pass_convert = 1';
diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php
index 58845b88ec..85b90da5fa 100644
--- a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php
+++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php
@@ -13,12 +13,14 @@
namespace phpbb\db\migration\data\v310;
+use phpbb\db\migration\container_aware_migration;
+
/**
* Migration to convert the Soft Delete MOD for 3.0
*
* https://www.phpbb.com/customise/db/mod/soft_delete/
*/
-class soft_delete_mod_convert extends \phpbb\db\migration\migration
+class soft_delete_mod_convert extends container_aware_migration
{
static public function depends_on()
{
@@ -115,19 +117,11 @@ class soft_delete_mod_convert extends \phpbb\db\migration\migration
}
}
+ /**
+ * @return \phpbb\content_visibility
+ */
protected function get_content_visibility()
{
- return new \phpbb\content_visibility(
- new \phpbb\auth\auth(),
- $this->config,
- $this->db,
- new \phpbb\user('\phpbb\datetime'),
- $this->phpbb_root_path,
- $this->php_ext,
- $this->table_prefix . 'forums',
- $this->table_prefix . 'posts',
- $this->table_prefix . 'topics',
- $this->table_prefix . 'users'
- );
+ return $this->container->get('content.visibility');
}
}
diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php
index bc3d2e9ee5..3f26a4998c 100644
--- a/phpBB/phpbb/db/migration/profilefield_base_migration.php
+++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php
@@ -13,7 +13,7 @@
namespace phpbb\db\migration;
-abstract class profilefield_base_migration extends \phpbb\db\migration\migration
+abstract class profilefield_base_migration extends container_aware_migration
{
protected $profilefield_name;
@@ -237,10 +237,8 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration
if ($profile_row === null)
{
- global $phpbb_container;
-
/* @var $manager \phpbb\profilefields\manager */
- $manager = $phpbb_container->get('profilefields.manager');
+ $manager = $this->container->get('profilefields.manager');
$profile_row = $manager->build_insert_sql_array(array());
}
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php
index bb79c0dd68..6902913c64 100644
--- a/phpBB/phpbb/db/migrator.php
+++ b/phpBB/phpbb/db/migrator.php
@@ -13,11 +13,19 @@
namespace phpbb\db;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
/**
* The migrator is responsible for applying new migrations in the correct order.
*/
class migrator
{
+ /**
+ * @var ContainerInterface
+ */
+ protected $container;
+
/** @var \phpbb\config\config */
protected $config;
@@ -77,15 +85,16 @@ class migrator
/**
* The output handler. A null handler is configured by default.
*
- * @var migrator_output_handler
+ * @var migrator_output_handler_interface
*/
public $output_handler;
/**
* Constructor of the database migrator
*/
- public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools\tools_interface $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools, \phpbb\db\migration\helper $helper)
+ public function __construct(ContainerInterface $container, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools\tools_interface $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools, \phpbb\db\migration\helper $helper)
{
+ $this->container = $container;
$this->config = $config;
$this->db = $db;
$this->db_tools = $db_tools;
@@ -172,6 +181,18 @@ class migrator
*/
public function update()
{
+ $this->container->get('dispatcher')->disable();
+ $this->update_do();
+ $this->container->get('dispatcher')->enable();
+ }
+
+ /**
+ * Effectively runs a single update step from the next migration to be applied.
+ *
+ * @return null
+ */
+ protected function update_do()
+ {
foreach ($this->migrations as $name)
{
if (!isset($this->migration_state[$name]) ||
@@ -317,7 +338,7 @@ class migrator
catch (\phpbb\db\migration\exception $e)
{
// Revert the schema changes
- $this->revert($name);
+ $this->revert_do($name);
// Rethrow exception
throw $e;
@@ -337,10 +358,22 @@ class migrator
* check if revert() needs to be called again use the migration_state() method.
*
* @param string $migration String migration name to revert (including any that depend on this migration)
- * @return null
*/
public function revert($migration)
{
+ $this->container->get('dispatcher')->disable();
+ $this->revert_do($migration);
+ $this->container->get('dispatcher')->enable();
+ }
+
+ /**
+ * Effectively runs a single revert step from the last migration installed
+ *
+ * @param string $migration String migration name to revert (including any that depend on this migration)
+ * @return null
+ */
+ protected function revert_do($migration)
+ {
if (!isset($this->migration_state[$migration]))
{
// Not installed
@@ -351,7 +384,7 @@ class migrator
{
if (!empty($state['migration_depends_on']) && in_array($migration, $state['migration_depends_on']))
{
- $this->revert($name);
+ $this->revert_do($name);
}
}
@@ -742,7 +775,14 @@ class migrator
*/
protected function get_migration($name)
{
- return new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
+ $migration = new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
+
+ if ($migration instanceof ContainerAwareInterface)
+ {
+ $migration->setContainer($this->container);
+ }
+
+ return $migration;
}
/**
diff --git a/phpBB/phpbb/event/dispatcher.php b/phpBB/phpbb/event/dispatcher.php
index 9a786022c2..1c4abeb108 100644
--- a/phpBB/phpbb/event/dispatcher.php
+++ b/phpBB/phpbb/event/dispatcher.php
@@ -14,6 +14,7 @@
namespace phpbb\event;
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
+use Symfony\Component\EventDispatcher\Event;
/**
* Extension of the Symfony2 EventDispatcher
@@ -32,6 +33,11 @@ use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
class dispatcher extends ContainerAwareEventDispatcher implements dispatcher_interface
{
/**
+ * @var bool
+ */
+ protected $disabled = false;
+
+ /**
* {@inheritdoc}
*/
public function trigger_event($eventName, $data = array())
@@ -40,4 +46,33 @@ class dispatcher extends ContainerAwareEventDispatcher implements dispatcher_int
$this->dispatch($eventName, $event);
return $event->get_data_filtered(array_keys($data));
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function dispatch($eventName, Event $event = null)
+ {
+ if ($this->disabled)
+ {
+ return $event;
+ }
+
+ return parent::dispatch($eventName, $event);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function disable()
+ {
+ $this->disabled = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function enable()
+ {
+ $this->disabled = false;
+ }
}
diff --git a/phpBB/phpbb/event/dispatcher_interface.php b/phpBB/phpbb/event/dispatcher_interface.php
index 50a3ef9101..c66aa98260 100644
--- a/phpBB/phpbb/event/dispatcher_interface.php
+++ b/phpBB/phpbb/event/dispatcher_interface.php
@@ -37,4 +37,14 @@ interface dispatcher_interface extends \Symfony\Component\EventDispatcher\EventD
* @return mixed
*/
public function trigger_event($eventName, $data = array());
+
+ /**
+ * Disable the event dispatcher.
+ */
+ public function disable();
+
+ /**
+ * Enable the event dispatcher.
+ */
+ public function enable();
}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index e4fb442818..9b8383fc88 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -46,7 +46,10 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
new \phpbb\db\migration\tool\config($this->config),
);
+ $container = new phpbb_mock_container_builder();
+
$this->migrator = new \phpbb\db\migrator(
+ $container,
$this->config,
$this->db,
$this->db_tools,
@@ -57,9 +60,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$tools,
new \phpbb\db\migration\helper()
);
-
- $container = new phpbb_mock_container_builder();
- $container->set('migrator', $migrator);
+ $container->set('migrator', $this->migrator);
+ $container->set('dispatcher', new phpbb_mock_event_dispatcher());
$user = new \phpbb\user('\phpbb\datetime');
$this->extension_manager = new \phpbb\extension\manager(
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index ab93edd939..c737d33f95 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -156,7 +156,10 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$table_prefix = 'phpbb_';
$user = new \phpbb\user('\phpbb\user');
+ $container = new phpbb_mock_container_builder();
+
$migrator = new \phpbb\db\migrator(
+ $container,
$config,
$db,
$db_tools,
@@ -167,7 +170,6 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
array(),
new \phpbb\db\migration\helper()
);
- $container = new phpbb_mock_container_builder();
$container->set('migrator', $migrator);
return new \phpbb\extension\manager(
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
index 2d6df3a3f3..bd7acf12f9 100644
--- a/tests/extension/metadata_manager_test.php
+++ b/tests/extension/metadata_manager_test.php
@@ -77,7 +77,10 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)));
$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
+ $container = new phpbb_mock_container_builder();
+
$this->migrator = new \phpbb\db\migrator(
+ $container,
$this->config,
$this->db,
$this->db_tools,
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 0ea6c5b7cb..5960956444 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -232,7 +232,9 @@ class phpbb_functional_test_case extends phpbb_test_case
$db = $this->get_db();
$db_tools = new \phpbb\db\tools\tools($db);
+ $container = new phpbb_mock_container_builder();
$migrator = new \phpbb\db\migrator(
+ $container,
$config,
$db,
$db_tools,
@@ -243,8 +245,8 @@ class phpbb_functional_test_case extends phpbb_test_case
array(),
new \phpbb\db\migration\helper()
);
- $container = new phpbb_mock_container_builder();
$container->set('migrator', $migrator);
+ $container->set('dispatcher', new phpbb_mock_event_dispatcher());
$user = new \phpbb\user('\phpbb\datetime');
$extension_manager = new \phpbb\extension\manager(