mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-06 06:25:04 +02:00
[ticket/13489] Disable the event dispatcher in the migrator
PHPBB3-13489
This commit is contained in:
parent
a415a4ec2b
commit
c99ed64473
@ -13,11 +13,19 @@
|
|||||||
|
|
||||||
namespace phpbb\db;
|
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.
|
* The migrator is responsible for applying new migrations in the correct order.
|
||||||
*/
|
*/
|
||||||
class migrator
|
class migrator
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var ContainerInterface
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
/** @var \phpbb\config\config */
|
/** @var \phpbb\config\config */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
@ -77,15 +85,16 @@ class migrator
|
|||||||
/**
|
/**
|
||||||
* The output handler. A null handler is configured by default.
|
* The output handler. A null handler is configured by default.
|
||||||
*
|
*
|
||||||
* @var migrator_output_handler
|
* @var migrator_output_handler_interface
|
||||||
*/
|
*/
|
||||||
public $output_handler;
|
public $output_handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the database migrator
|
* Constructor of the database migrator
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools $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 $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools, \phpbb\db\migration\helper $helper)
|
||||||
{
|
{
|
||||||
|
$this->container = $container;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->db_tools = $db_tools;
|
$this->db_tools = $db_tools;
|
||||||
@ -171,6 +180,18 @@ class migrator
|
|||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function update()
|
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)
|
foreach ($this->migrations as $name)
|
||||||
{
|
{
|
||||||
@ -317,7 +338,7 @@ class migrator
|
|||||||
catch (\phpbb\db\migration\exception $e)
|
catch (\phpbb\db\migration\exception $e)
|
||||||
{
|
{
|
||||||
// Revert the schema changes
|
// Revert the schema changes
|
||||||
$this->revert($name);
|
$this->revert_do($name);
|
||||||
|
|
||||||
// Rethrow exception
|
// Rethrow exception
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -337,9 +358,21 @@ class migrator
|
|||||||
* check if revert() needs to be called again use the migration_state() method.
|
* 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)
|
* @param string $migration String migration name to revert (including any that depend on this migration)
|
||||||
* @return null
|
|
||||||
*/
|
*/
|
||||||
public function revert($migration)
|
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]))
|
if (!isset($this->migration_state[$migration]))
|
||||||
{
|
{
|
||||||
@ -351,7 +384,7 @@ class migrator
|
|||||||
{
|
{
|
||||||
if (!empty($state['migration_depends_on']) && in_array($migration, $state['migration_depends_on']))
|
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)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
namespace phpbb\event;
|
namespace phpbb\event;
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
||||||
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of the Symfony2 EventDispatcher
|
* Extension of the Symfony2 EventDispatcher
|
||||||
@ -31,6 +32,11 @@ use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
|||||||
*/
|
*/
|
||||||
class dispatcher extends ContainerAwareEventDispatcher implements dispatcher_interface
|
class dispatcher extends ContainerAwareEventDispatcher implements dispatcher_interface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $disabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -40,4 +46,33 @@ class dispatcher extends ContainerAwareEventDispatcher implements dispatcher_int
|
|||||||
$this->dispatch($eventName, $event);
|
$this->dispatch($eventName, $event);
|
||||||
return $event->get_data_filtered(array_keys($data));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,4 +37,14 @@ interface dispatcher_interface extends \Symfony\Component\EventDispatcher\EventD
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function trigger_event($eventName, $data = array());
|
public function trigger_event($eventName, $data = array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the event dispatcher.
|
||||||
|
*/
|
||||||
|
public function disable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the event dispatcher.
|
||||||
|
*/
|
||||||
|
public function enable();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user