mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-06 23:55:26 +02:00
Merge remote-tracking branch 'github-bantu/ticket/12473' into develop-ascraeus
* github-bantu/ticket/12473: [ticket/12473] Add console command for database migration. [ticket/12473] Add more compatibility to phpBB Console Application. [ticket/12473] Move compatibility globals out into its own file.
This commit is contained in:
commit
b73d0bdbd6
@ -22,6 +22,7 @@ require($phpbb_root_path . 'config.' . $phpEx);
|
|||||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||||
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||||
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
|
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
|
||||||
|
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
|
||||||
require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx);
|
require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx);
|
||||||
|
|
||||||
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
|
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
|
||||||
@ -30,6 +31,8 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/"
|
|||||||
$phpbb_class_loader_ext->register();
|
$phpbb_class_loader_ext->register();
|
||||||
|
|
||||||
$phpbb_container = phpbb_create_update_container($phpbb_root_path, $phpEx, "$phpbb_root_path/config");
|
$phpbb_container = phpbb_create_update_container($phpbb_root_path, $phpEx, "$phpbb_root_path/config");
|
||||||
|
$phpbb_container->get('request')->enable_super_globals();
|
||||||
|
require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx);
|
||||||
|
|
||||||
$application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION);
|
$application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION);
|
||||||
$application->register_container_commands($phpbb_container);
|
$application->register_container_commands($phpbb_container);
|
||||||
|
@ -96,34 +96,7 @@ $phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx);
|
|||||||
$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
|
$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
|
||||||
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
|
$phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver'));
|
||||||
|
|
||||||
// set up caching
|
require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx);
|
||||||
$cache = $phpbb_container->get('cache');
|
|
||||||
|
|
||||||
// Instantiate some basic classes
|
|
||||||
$phpbb_dispatcher = $phpbb_container->get('dispatcher');
|
|
||||||
$request = $phpbb_container->get('request');
|
|
||||||
$user = $phpbb_container->get('user');
|
|
||||||
$auth = $phpbb_container->get('auth');
|
|
||||||
$db = $phpbb_container->get('dbal.conn');
|
|
||||||
|
|
||||||
// make sure request_var uses this request instance
|
|
||||||
request_var('', 0, false, false, $request); // "dependency injection" for a function
|
|
||||||
|
|
||||||
// Grab global variables, re-cache if necessary
|
|
||||||
$config = $phpbb_container->get('config');
|
|
||||||
set_config(null, null, null, $config);
|
|
||||||
set_config_count(null, null, null, $config);
|
|
||||||
|
|
||||||
$phpbb_log = $phpbb_container->get('log');
|
|
||||||
$symfony_request = $phpbb_container->get('symfony_request');
|
|
||||||
$phpbb_filesystem = $phpbb_container->get('filesystem');
|
|
||||||
$phpbb_path_helper = $phpbb_container->get('path_helper');
|
|
||||||
|
|
||||||
// load extensions
|
|
||||||
$phpbb_extension_manager = $phpbb_container->get('ext.manager');
|
|
||||||
$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
|
|
||||||
|
|
||||||
$template = $phpbb_container->get('template');
|
|
||||||
|
|
||||||
// Add own hook handler
|
// Add own hook handler
|
||||||
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
||||||
|
@ -34,6 +34,18 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: console.command }
|
- { name: console.command }
|
||||||
|
|
||||||
|
console.command.db.migrate:
|
||||||
|
class: phpbb\console\command\db\migrate
|
||||||
|
arguments:
|
||||||
|
- @migrator
|
||||||
|
- @ext.manager
|
||||||
|
- @config
|
||||||
|
- @cache
|
||||||
|
- @log
|
||||||
|
- @user
|
||||||
|
tags:
|
||||||
|
- { name: console.command }
|
||||||
|
|
||||||
console.command.extension.disable:
|
console.command.extension.disable:
|
||||||
class: phpbb\console\command\extension\disable
|
class: phpbb\console\command\extension\disable
|
||||||
arguments:
|
arguments:
|
||||||
|
44
phpBB/includes/compatibility_globals.php
Normal file
44
phpBB/includes/compatibility_globals.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2014 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set up caching
|
||||||
|
$cache = $phpbb_container->get('cache');
|
||||||
|
|
||||||
|
// Instantiate some basic classes
|
||||||
|
$phpbb_dispatcher = $phpbb_container->get('dispatcher');
|
||||||
|
$request = $phpbb_container->get('request');
|
||||||
|
$user = $phpbb_container->get('user');
|
||||||
|
$auth = $phpbb_container->get('auth');
|
||||||
|
$db = $phpbb_container->get('dbal.conn');
|
||||||
|
|
||||||
|
// make sure request_var uses this request instance
|
||||||
|
request_var('', 0, false, false, $request); // "dependency injection" for a function
|
||||||
|
|
||||||
|
// Grab global variables, re-cache if necessary
|
||||||
|
$config = $phpbb_container->get('config');
|
||||||
|
set_config(null, null, null, $config);
|
||||||
|
set_config_count(null, null, null, $config);
|
||||||
|
|
||||||
|
$phpbb_log = $phpbb_container->get('log');
|
||||||
|
$symfony_request = $phpbb_container->get('symfony_request');
|
||||||
|
$phpbb_filesystem = $phpbb_container->get('filesystem');
|
||||||
|
$phpbb_path_helper = $phpbb_container->get('path_helper');
|
||||||
|
|
||||||
|
// load extensions
|
||||||
|
$phpbb_extension_manager = $phpbb_container->get('ext.manager');
|
||||||
|
$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader');
|
||||||
|
|
||||||
|
$template = $phpbb_container->get('template');
|
127
phpBB/phpbb/console/command/db/migrate.php
Normal file
127
phpBB/phpbb/console/command/db/migrate.php
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2014 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace phpbb\console\command\db;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
class migrate extends \phpbb\console\command\command
|
||||||
|
{
|
||||||
|
/** @var \phpbb\db\migrator */
|
||||||
|
protected $migrator;
|
||||||
|
|
||||||
|
/** @var \phpbb\extension\manager */
|
||||||
|
protected $extension_manager;
|
||||||
|
|
||||||
|
/** @var \phpbb\config\config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/** @var \phpbb\cache\service */
|
||||||
|
protected $cache;
|
||||||
|
|
||||||
|
/** @var \phpbb\log\log */
|
||||||
|
protected $log;
|
||||||
|
|
||||||
|
/** @var \phpbb\user */
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
function __construct(\phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\user $user)
|
||||||
|
{
|
||||||
|
$this->migrator = $migrator;
|
||||||
|
$this->extension_manager = $extension_manager;
|
||||||
|
$this->config = $config;
|
||||||
|
$this->cache = $cache;
|
||||||
|
$this->log = $log;
|
||||||
|
$this->user = $user;
|
||||||
|
$this->user->add_lang(array('common', 'acp/common', 'install', 'migrator'));
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('db:migrate')
|
||||||
|
->setDescription('Updates the database by applying migrations.')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->load_migrations();
|
||||||
|
$orig_version = $this->config['version'];
|
||||||
|
while (!$this->migrator->finished())
|
||||||
|
{
|
||||||
|
$migration_start_time = microtime(true);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->migrator->update();
|
||||||
|
}
|
||||||
|
catch (\phpbb\db\migration\exception $e)
|
||||||
|
{
|
||||||
|
$output->writeln($e->getLocalisedMessage($this->user));
|
||||||
|
$this->finalise_update();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$migration_stop_time = microtime(true) - $migration_start_time;
|
||||||
|
|
||||||
|
$state = array_merge(
|
||||||
|
array(
|
||||||
|
'migration_schema_done' => false,
|
||||||
|
'migration_data_done' => false,
|
||||||
|
),
|
||||||
|
$this->migrator->last_run_migration['state']
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($this->migrator->last_run_migration['effectively_installed']))
|
||||||
|
{
|
||||||
|
$msg = $this->user->lang('MIGRATION_EFFECTIVELY_INSTALLED', $this->migrator->last_run_migration['name']);
|
||||||
|
$output->writeln("<comment>$msg</comment>");
|
||||||
|
}
|
||||||
|
else if ($this->migrator->last_run_migration['task'] == 'process_data_step' && $state['migration_data_done'])
|
||||||
|
{
|
||||||
|
$msg = $this->user->lang('MIGRATION_DATA_DONE', $this->migrator->last_run_migration['name'], $migration_stop_time);
|
||||||
|
$output->writeln("<info>$msg</info>");
|
||||||
|
}
|
||||||
|
else if ($this->migrator->last_run_migration['task'] == 'process_data_step')
|
||||||
|
{
|
||||||
|
$output->writeln($this->user->lang('MIGRATION_DATA_IN_PROGRESS', $this->migrator->last_run_migration['name'], $migration_stop_time));
|
||||||
|
}
|
||||||
|
else if ($state['migration_schema_done'])
|
||||||
|
{
|
||||||
|
$msg = $this->user->lang('MIGRATION_SCHEMA_DONE', $this->migrator->last_run_migration['name'], $migration_stop_time);
|
||||||
|
$output->writeln("<info>$msg</info>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($orig_version != $this->config['version'])
|
||||||
|
{
|
||||||
|
$log->add('admin', 'LOG_UPDATE_DATABASE', $orig_version, $this->config['version']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->finalise_update();
|
||||||
|
$output->writeln($this->user->lang['DATABASE_UPDATE_COMPLETE']);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function load_migrations()
|
||||||
|
{
|
||||||
|
$migrations = $this->extension_manager
|
||||||
|
->get_finder()
|
||||||
|
->core_path('phpbb/db/migration/data/')
|
||||||
|
->get_classes();
|
||||||
|
$this->migrator->set_migrations($migrations);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function finalise_update()
|
||||||
|
{
|
||||||
|
$this->cache->purge();
|
||||||
|
$this->config->increment('assets_version', 1);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user