PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,91 @@
<?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\console\command\cache;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class purge extends \phpbb\console\command\command
{
/** @var \phpbb\cache\driver\driver_interface */
protected $cache;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\auth\auth */
protected $auth;
/** @var \phpbb\log\log_interface */
protected $log;
/** @var \phpbb\config\config */
protected $config;
/**
* Constructor
*
* @param \phpbb\user $user User instance
* @param \phpbb\cache\driver\driver_interface $cache Cache instance
* @param \phpbb\db\driver\driver_interface $db Database connection
* @param \phpbb\auth\auth $auth Auth instance
* @param \phpbb\log\log_interface $log Logger instance
* @param \phpbb\config\config $config Config instance
*/
public function __construct(\phpbb\user $user, \phpbb\cache\driver\driver_interface $cache, \phpbb\db\driver\driver_interface $db, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\config\config $config)
{
$this->cache = $cache;
$this->db = $db;
$this->auth = $auth;
$this->log = $log;
$this->config = $config;
parent::__construct($user);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('cache:purge')
->setDescription($this->user->lang('PURGE_CACHE'))
;
}
/**
* Executes the command cache:purge.
*
* Purge the cache (including permissions) and increment the asset_version number
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->config->increment('assets_version', 1);
$this->cache->purge();
// Clear permissions
$this->auth->acl_clear_prefetch();
phpbb_cache_moderators($this->db, $this->cache, $this->auth);
$this->log->add('admin', ANONYMOUS, '', 'LOG_PURGE_CACHE', time(), array());
$io = new SymfonyStyle($input, $output);
$io->success($this->user->lang('PURGE_CACHE_SUCCESS'));
}
}

View File

@ -0,0 +1,76 @@
<?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\console\command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
abstract class command extends \Symfony\Component\Console\Command\Command
{
/** @var \phpbb\user */
protected $user;
/**
* Constructor
*
* @param \phpbb\user $user User instance (mostly for translation)
*/
public function __construct(\phpbb\user $user)
{
$this->user = $user;
parent::__construct();
}
/**
* Create a styled progress bar
*
* @param int $max Max value for the progress bar
* @param SymfonyStyle $io Symfony style output decorator
* @param OutputInterface $output The output stream, used to print messages
* @param bool $message Should we display message output under the progress bar?
* @return ProgressBar
*/
public function create_progress_bar($max, SymfonyStyle $io, OutputInterface $output, $message = false)
{
$progress = $io->createProgressBar($max);
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE)
{
$progress->setFormat('<info>[%percent:3s%%]</info> %message%');
$progress->setOverwrite(false);
}
else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE)
{
$progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
$progress->setOverwrite(false);
}
else
{
$io->newLine(2);
$progress->setFormat(
" %current:s%/%max:s% %bar% %percent:3s%%\n" .
" " . ($message ? '%message%' : ' ') . " %elapsed:6s%/%estimated:-6s% %memory:6s%\n");
$progress->setBarWidth(60);
}
if (!defined('PHP_WINDOWS_VERSION_BUILD'))
{
$progress->setEmptyBarCharacter('░'); // light shade character \u2591
$progress->setProgressCharacter('');
$progress->setBarCharacter('▓'); // dark shade character \u2593
}
return $progress;
}
}

View File

@ -0,0 +1,26 @@
<?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\console\command\config;
abstract class command extends \phpbb\console\command\command
{
/** @var \phpbb\config\config */
protected $config;
public function __construct(\phpbb\user $user, \phpbb\config\config $config)
{
$this->config = $config;
parent::__construct($user);
}
}

View File

@ -0,0 +1,66 @@
<?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\console\command\config;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class delete extends command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:delete')
->setDescription($this->user->lang('CLI_DESCRIPTION_DELETE_CONFIG'))
->addArgument(
'key',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_OPTION_NAME')
)
;
}
/**
* Executes the command config:delete.
*
* Removes a configuration option
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return void
* @see \phpbb\config\config::delete()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$key = $input->getArgument('key');
if (isset($this->config[$key]))
{
$this->config->delete($key);
$io->success($this->user->lang('CLI_CONFIG_DELETE_SUCCESS', $key));
}
else
{
$io->error($this->user->lang('CLI_CONFIG_NOT_EXISTS', $key));
}
}
}

View File

@ -0,0 +1,75 @@
<?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\console\command\config;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class get extends command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:get')
->setDescription($this->user->lang('CLI_DESCRIPTION_GET_CONFIG'))
->addArgument(
'key',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_OPTION_NAME')
)
->addOption(
'no-newline',
null,
InputOption::VALUE_NONE,
$this->user->lang('CLI_CONFIG_PRINT_WITHOUT_NEWLINE')
)
;
}
/**
* Executes the command config:get.
*
* Retrieves a configuration value.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return void
* @see \phpbb\config\config::offsetGet()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$key = $input->getArgument('key');
if (isset($this->config[$key]) && $input->getOption('no-newline'))
{
$output->write($this->config[$key]);
}
else if (isset($this->config[$key]))
{
$output->writeln($this->config[$key]);
}
else
{
$io->error($this->user->lang('CLI_CONFIG_NOT_EXISTS', $key));
}
}
}

View File

@ -0,0 +1,73 @@
<?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\console\command\config;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class increment extends command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:increment')
->setDescription($this->user->lang('CLI_DESCRIPTION_INCREMENT_CONFIG'))
->addArgument(
'key',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_OPTION_NAME')
)
->addArgument(
'increment',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_INCREMENT_BY')
)
->addOption(
'dynamic',
'd',
InputOption::VALUE_NONE,
$this->user->lang('CLI_CONFIG_CANNOT_CACHED')
)
;
}
/**
* Executes the command config:increment.
*
* Increments an integer configuration value.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return void
* @see \phpbb\config\config::increment()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$key = $input->getArgument('key');
$increment = $input->getArgument('increment');
$use_cache = !$input->getOption('dynamic');
$this->config->increment($key, $increment, $use_cache);
$io->success($this->user->lang('CLI_CONFIG_INCREMENT_SUCCESS', $key));
}
}

View File

@ -0,0 +1,73 @@
<?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\console\command\config;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class set extends command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:set')
->setDescription($this->user->lang('CLI_DESCRIPTION_SET_CONFIG'))
->addArgument(
'key',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_OPTION_NAME')
)
->addArgument(
'value',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_NEW')
)
->addOption(
'dynamic',
'd',
InputOption::VALUE_NONE,
$this->user->lang('CLI_CONFIG_CANNOT_CACHED')
)
;
}
/**
* Executes the command config:set.
*
* Sets a configuration option's value.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return void
* @see \phpbb\config\config::set()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$key = $input->getArgument('key');
$value = $input->getArgument('value');
$use_cache = !$input->getOption('dynamic');
$this->config->set($key, $value, $use_cache);
$io->success($this->user->lang('CLI_CONFIG_SET_SUCCESS', $key));
}
}

View File

@ -0,0 +1,87 @@
<?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\console\command\config;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class set_atomic extends command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:set-atomic')
->setDescription($this->user->lang('CLI_DESCRIPTION_SET_ATOMIC_CONFIG'))
->addArgument(
'key',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_OPTION_NAME')
)
->addArgument(
'old',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_CURRENT')
)
->addArgument(
'new',
InputArgument::REQUIRED,
$this->user->lang('CLI_CONFIG_NEW')
)
->addOption(
'dynamic',
'd',
InputOption::VALUE_NONE,
$this->user->lang('CLI_CONFIG_CANNOT_CACHED')
)
;
}
/**
* Executes the command config:set-atomic.
*
* Sets a configuration option's value only if the old_value matches the
* current configuration value or the configuration value does not exist yet.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return bool True if the value was changed, false otherwise.
* @see \phpbb\config\config::set_atomic()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$key = $input->getArgument('key');
$old_value = $input->getArgument('old');
$new_value = $input->getArgument('new');
$use_cache = !$input->getOption('dynamic');
if ($this->config->set_atomic($key, $old_value, $new_value, $use_cache))
{
$io->success($this->user->lang('CLI_CONFIG_SET_SUCCESS', $key));
return 0;
}
else
{
$io->error($this->user->lang('CLI_CONFIG_SET_FAILURE', $key));
return 1;
}
}
}

View File

@ -0,0 +1,94 @@
<?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\console\command\cron;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class cron_list extends \phpbb\console\command\command
{
/** @var \phpbb\cron\manager */
protected $cron_manager;
/**
* Constructor
*
* @param \phpbb\user $user User instance
* @param \phpbb\cron\manager $cron_manager Cron manager
*/
public function __construct(\phpbb\user $user, \phpbb\cron\manager $cron_manager)
{
$this->cron_manager = $cron_manager;
parent::__construct($user);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('cron:list')
->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_LIST'))
;
}
/**
* Executes the command cron:list.
*
* Prints a list of ready and unready cron jobs.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$tasks = $this->cron_manager->get_tasks();
if (empty($tasks))
{
$io->error($this->user->lang('CRON_NO_TASKS'));
return;
}
$ready_tasks = $not_ready_tasks = array();
foreach ($tasks as $task)
{
if ($task->is_ready())
{
$ready_tasks[] = $task->get_name();
}
else
{
$not_ready_tasks[] = $task->get_name();
}
}
if (!empty($ready_tasks))
{
$io->title($this->user->lang('TASKS_READY'));
$io->listing($ready_tasks);
}
if (!empty($not_ready_tasks))
{
$io->title($this->user->lang('TASKS_NOT_READY'));
$io->listing($not_ready_tasks);
}
}
}

View File

@ -0,0 +1,171 @@
<?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\console\command\cron;
use phpbb\exception\runtime_exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
class run extends \phpbb\console\command\command
{
/** @var \phpbb\cron\manager */
protected $cron_manager;
/** @var \phpbb\lock\db */
protected $lock_db;
/**
* Construct method
*
* @param \phpbb\user $user The user object (used to get language information)
* @param \phpbb\cron\manager $cron_manager The cron manager containing
* the cron tasks to be executed.
* @param \phpbb\lock\db $lock_db The lock for accessing database.
*/
public function __construct(\phpbb\user $user, \phpbb\cron\manager $cron_manager, \phpbb\lock\db $lock_db)
{
$this->cron_manager = $cron_manager;
$this->lock_db = $lock_db;
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('cron:run')
->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_RUN'))
->setHelp($this->user->lang('CLI_HELP_CRON_RUN'))
->addArgument('name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1'))
;
}
/**
* Executes the command cron:run.
*
* Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks.
* If the cron lock can not be obtained, an error message is printed
* and the exit status is set to 1.
* If the verbose option is specified, each start of a task is printed.
* Otherwise there is no output.
* If an argument is given to the command, only the task whose name matches the
* argument will be started. If verbose option is specified,
* an info message containing the name of the task is printed.
* If no task matches the argument given, an error message is printed
* and the exit status is set to 2.
*
* @param InputInterface $input The input stream used to get the argument and verboe option.
* @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
*
* @return int 0 if all is ok, 1 if a lock error occured and 2 if no task matching the argument was found.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->lock_db->acquire())
{
$task_name = $input->getArgument('name');
if ($task_name)
{
$exit_status = $this->run_one($input, $output, $task_name);
}
else
{
$exit_status = $this->run_all($input, $output);
}
$this->lock_db->release();
return $exit_status;
}
else
{
throw new runtime_exception('CRON_LOCK_ERROR', array(), null, 1);
}
}
/**
* Executes all ready cron tasks.
*
* If verbose mode is set, an info message will be printed if there is no task to
* be run, or else for each starting task.
*
* @see execute
* @param InputInterface $input The input stream used to get the argument and verbose option.
* @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
* @return int 0
*/
protected function run_all(InputInterface $input, OutputInterface $output)
{
$run_tasks = $this->cron_manager->find_all_ready_tasks();
if ($run_tasks)
{
foreach ($run_tasks as $task)
{
if ($input->getOption('verbose'))
{
$output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task->get_name()) . '</info>');
}
$task->run();
}
}
else
{
if ($input->getOption('verbose'))
{
$output->writeln('<info>' . $this->user->lang('CRON_NO_TASK') . '</info>');
}
}
return 0;
}
/**
* Executes a given cron task, if it is ready.
*
* If there is a task whose name matches $task_name, it is run and 0 is returned.
* and if verbose mode is set, print an info message with the name of the task.
* If there is no task matching $task_name, the function prints an error message
* and returns with status 2.
*
* @see execute
* @param string $task_name The name of the task that should be run.
* @param InputInterface $input The input stream used to get the argument and verbose option.
* @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
* @return int 0 if all is well, 2 if no task matches $task_name.
*/
protected function run_one(InputInterface $input, OutputInterface $output, $task_name)
{
$task = $this->cron_manager->find_task($task_name);
if ($task)
{
if ($input->getOption('verbose'))
{
$output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task_name) . '</info>');
}
$task->run();
return 0;
}
else
{
throw new runtime_exception('CRON_NO_SUCH_TASK', array( $task_name), null, 2);
}
}
}

View File

@ -0,0 +1,69 @@
<?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\console\command\db;
use phpbb\db\output_handler\migrator_output_handler_interface;
use phpbb\user;
use Symfony\Component\Console\Output\OutputInterface;
class console_migrator_output_handler implements migrator_output_handler_interface
{
/**
* User object.
*
* @var user
*/
private $user;
/**
* Console output object.
*
* @var OutputInterface
*/
private $output;
/**
* Constructor
*
* @param user $user User object
* @param OutputInterface $output Console output object
*/
public function __construct(user $user, OutputInterface $output)
{
$this->user = $user;
$this->output = $output;
}
/**
* {@inheritdoc}
*/
public function write($message, $verbosity)
{
if ($verbosity <= $this->output->getVerbosity())
{
$translated_message = call_user_func_array(array($this->user, 'lang'), $message);
if ($verbosity === migrator_output_handler_interface::VERBOSITY_NORMAL)
{
$translated_message = '<info>' . $translated_message . '</info>';
}
else if ($verbosity === migrator_output_handler_interface::VERBOSITY_VERBOSE)
{
$translated_message = '<comment>' . $translated_message . '</comment>';
}
$this->output->writeln($translated_message);
}
}
}

View File

@ -0,0 +1,81 @@
<?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\console\command\db;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class list_command extends \phpbb\console\command\db\migration_command
{
protected function configure()
{
$this
->setName('db:list')
->setDescription($this->user->lang('CLI_DESCRIPTION_DB_LIST'))
->addOption(
'available',
'u',
InputOption::VALUE_NONE,
$this->user->lang('CLI_MIGRATIONS_ONLY_AVAILABLE')
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$show_installed = !$input->getOption('available');
$installed = $available = array();
foreach ($this->load_migrations() as $name)
{
if ($this->migrator->migration_state($name) !== false)
{
$installed[] = $name;
}
else
{
$available[] = $name;
}
}
if ($show_installed)
{
$io->section($this->user->lang('CLI_MIGRATIONS_INSTALLED'));
if (!empty($installed))
{
$io->listing($installed);
}
else
{
$io->text($this->user->lang('CLI_MIGRATIONS_EMPTY'));
$io->newLine();
}
}
$io->section($this->user->lang('CLI_MIGRATIONS_AVAILABLE'));
if (!empty($available))
{
$io->listing($available);
}
else
{
$io->text($this->user->lang('CLI_MIGRATIONS_EMPTY'));
$io->newLine();
}
}
}

View File

@ -0,0 +1,86 @@
<?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\console\command\db;
use phpbb\db\output_handler\log_wrapper_migrator_output_handler;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class migrate extends \phpbb\console\command\db\migration_command
{
/** @var \phpbb\log\log */
protected $log;
/** @var string phpBB root path */
protected $phpbb_root_path;
/** @var \phpbb\filesystem\filesystem_interface */
protected $filesystem;
/** @var \phpbb\language\language */
protected $language;
public function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path)
{
$this->language = $language;
$this->log = $log;
$this->filesystem = $filesystem;
$this->phpbb_root_path = $phpbb_root_path;
parent::__construct($user, $migrator, $extension_manager, $config, $cache);
$this->language->add_lang(array('common', 'install', 'migrator'));
}
protected function configure()
{
$this
->setName('db:migrate')
->setDescription($this->language->lang('CLI_DESCRIPTION_DB_MIGRATE'))
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem));
$this->migrator->create_migrations_table();
$this->cache->purge();
$this->load_migrations();
$orig_version = $this->config['version'];
while (!$this->migrator->finished())
{
try
{
$this->migrator->update();
}
catch (\phpbb\db\migration\exception $e)
{
$io->error($e->getLocalisedMessage($this->user));
$this->finalise_update();
return 1;
}
}
if ($orig_version != $this->config['version'])
{
$this->log->add('admin', ANONYMOUS, '', 'LOG_UPDATE_DATABASE', time(), array($orig_version, $this->config['version']));
}
$this->finalise_update();
$io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL'));
}
}

View File

@ -0,0 +1,56 @@
<?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\console\command\db;
abstract class migration_command 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;
public function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache)
{
$this->migrator = $migrator;
$this->extension_manager = $extension_manager;
$this->config = $config;
$this->cache = $cache;
parent::__construct($user);
}
protected function load_migrations()
{
$migrations = $this->extension_manager
->get_finder()
->core_path('phpbb/db/migration/data/')
->extension_directory('/migrations')
->get_classes();
$this->migrator->set_migrations($migrations);
return $this->migrator->get_migrations();
}
protected function finalise_update()
{
$this->cache->purge();
$this->config->increment('assets_version', 1);
}
}

View File

@ -0,0 +1,74 @@
<?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\console\command\db;
use phpbb\db\output_handler\log_wrapper_migrator_output_handler;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class revert extends \phpbb\console\command\db\migrate
{
protected function configure()
{
$this
->setName('db:revert')
->setDescription($this->language->lang('CLI_DESCRIPTION_DB_REVERT'))
->addArgument(
'name',
InputArgument::REQUIRED,
$this->language->lang('CLI_MIGRATION_NAME')
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$name = str_replace('/', '\\', $input->getArgument('name'));
$this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem));
$this->cache->purge();
if (!in_array($name, $this->load_migrations()))
{
$io->error($this->language->lang('MIGRATION_NOT_VALID', $name));
return 1;
}
else if ($this->migrator->migration_state($name) === false)
{
$io->error($this->language->lang('MIGRATION_NOT_INSTALLED', $name));
return 1;
}
try
{
while ($this->migrator->migration_state($name) !== false)
{
$this->migrator->revert($name);
}
}
catch (\phpbb\db\migration\exception $e)
{
$io->error($e->getLocalisedMessage($this->user));
$this->finalise_update();
return 1;
}
$this->finalise_update();
$io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL'));
}
}

View File

@ -0,0 +1,64 @@
<?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\console\command\dev;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class migration_tips extends \phpbb\console\command\command
{
/** @var \phpbb\extension\manager */
protected $extension_manager;
public function __construct(\phpbb\user $user, \phpbb\extension\manager $extension_manager)
{
$this->extension_manager = $extension_manager;
parent::__construct($user);
}
protected function configure()
{
$this
->setName('dev:migration-tips')
->setDescription($this->user->lang('CLI_DESCRIPTION_FIND_MIGRATIONS'))
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$migrations = $this->extension_manager->get_finder()
->set_extensions(array())
->core_path('phpbb/db/migration/data/')
->get_classes();
$tips = $migrations;
foreach ($migrations as $migration_class)
{
foreach ($migration_class::depends_on() as $dependency)
{
$tips_key = array_search($dependency, $tips);
if ($tips_key !== false)
{
unset($tips[$tips_key]);
}
}
}
$output->writeln("\t\tarray(");
foreach ($tips as $migration)
{
$output->writeln("\t\t\t'{$migration}',");
}
$output->writeln("\t\t);");
}
}

View File

@ -0,0 +1,30 @@
<?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\console\command\extension;
abstract class command extends \phpbb\console\command\command
{
/** @var \phpbb\extension\manager */
protected $manager;
/** @var \phpbb\log\log */
protected $log;
public function __construct(\phpbb\user $user, \phpbb\extension\manager $manager, \phpbb\log\log $log)
{
$this->manager = $manager;
$this->log = $log;
parent::__construct($user);
}
}

View File

@ -0,0 +1,62 @@
<?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\console\command\extension;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class disable extends command
{
protected function configure()
{
$this
->setName('extension:disable')
->setDescription($this->user->lang('CLI_DESCRIPTION_DISABLE_EXTENSION'))
->addArgument(
'extension-name',
InputArgument::REQUIRED,
$this->user->lang('CLI_EXTENSION_NAME')
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$name = $input->getArgument('extension-name');
if (!$this->manager->is_enabled($name))
{
$io->error($this->user->lang('CLI_EXTENSION_DISABLED', $name));
return 2;
}
$this->manager->disable($name);
$this->manager->load_extensions();
if ($this->manager->is_enabled($name))
{
$io->error($this->user->lang('CLI_EXTENSION_DISABLE_FAILURE', $name));
return 1;
}
else
{
$this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_DISABLE', time(), array($name));
$io->success($this->user->lang('CLI_EXTENSION_DISABLE_SUCCESS', $name));
return 0;
}
}
}

View File

@ -0,0 +1,76 @@
<?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\console\command\extension;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class enable extends command
{
protected function configure()
{
$this
->setName('extension:enable')
->setDescription($this->user->lang('CLI_DESCRIPTION_ENABLE_EXTENSION'))
->addArgument(
'extension-name',
InputArgument::REQUIRED,
$this->user->lang('CLI_EXTENSION_NAME')
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$name = $input->getArgument('extension-name');
if (!$this->manager->is_available($name))
{
$io->error($this->user->lang('CLI_EXTENSION_NOT_EXIST', $name));
return 1;
}
$extension = $this->manager->get_extension($name);
if (!$extension->is_enableable())
{
$io->error($this->user->lang('CLI_EXTENSION_NOT_ENABLEABLE', $name));
return 1;
}
if ($this->manager->is_enabled($name))
{
$io->error($this->user->lang('CLI_EXTENSION_ENABLED', $name));
return 1;
}
$this->manager->enable($name);
$this->manager->load_extensions();
if ($this->manager->is_enabled($name))
{
$this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_ENABLE', time(), array($name));
$io->success($this->user->lang('CLI_EXTENSION_ENABLE_SUCCESS', $name));
return 0;
}
else
{
$io->error($this->user->lang('CLI_EXTENSION_ENABLE_FAILURE', $name));
return 1;
}
}
}

View File

@ -0,0 +1,55 @@
<?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\console\command\extension;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class purge extends command
{
protected function configure()
{
$this
->setName('extension:purge')
->setDescription($this->user->lang('CLI_DESCRIPTION_PURGE_EXTENSION'))
->addArgument(
'extension-name',
InputArgument::REQUIRED,
$this->user->lang('CLI_EXTENSION_NAME')
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$name = $input->getArgument('extension-name');
$this->manager->purge($name);
$this->manager->load_extensions();
if ($this->manager->is_enabled($name))
{
$io->error($this->user->lang('CLI_EXTENSION_PURGE_FAILURE', $name));
return 1;
}
else
{
$this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_PURGE', time(), array($name));
$io->success($this->user->lang('CLI_EXTENSION_PURGE_SUCCESS', $name));
return 0;
}
}
}

View File

@ -0,0 +1,54 @@
<?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\console\command\extension;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class show extends command
{
protected function configure()
{
$this
->setName('extension:show')
->setDescription($this->user->lang('CLI_DESCRIPTION_LIST_EXTENSIONS'))
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$this->manager->load_extensions();
$all = array_keys($this->manager->all_available());
if (empty($all))
{
$io->note($this->user->lang('CLI_EXTENSION_NOT_FOUND'));
return 3;
}
$enabled = array_keys($this->manager->all_enabled());
$io->section($this->user->lang('CLI_EXTENSIONS_ENABLED'));
$io->listing($enabled);
$disabled = array_keys($this->manager->all_disabled());
$io->section($this->user->lang('CLI_EXTENSIONS_DISABLED'));
$io->listing($disabled);
$purged = array_diff($all, $enabled, $disabled);
$io->section($this->user->lang('CLI_EXTENSIONS_AVAILABLE'));
$io->listing($purged);
}
}

View File

@ -0,0 +1,137 @@
<?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\console\command\fixup;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class fix_left_right_ids extends \phpbb\console\command\command
{
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\cache\driver\driver_interface */
protected $cache;
/**
* Constructor
*
* @param \phpbb\user $user User instance
* @param \phpbb\db\driver\driver_interface $db Database connection
* @param \phpbb\cache\driver\driver_interface $cache Cache instance
*/
public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache)
{
$this->user = $user;
$this->db = $db;
$this->cache = $cache;
parent::__construct($user);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('fixup:fix-left-right-ids')
->setDescription($this->user->lang('CLI_DESCRIPTION_FIX_LEFT_RIGHT_IDS'))
;
}
/**
* Executes the command fixup:fix-left-right-ids.
*
* Repairs the tree structure of the forums and modules.
* The code is mainly borrowed from Support toolkit for phpBB Olympus
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
// Fix Left/Right IDs for the modules table
$result = $this->db->sql_query('SELECT DISTINCT(module_class) FROM ' . MODULES_TABLE);
while ($row = $this->db->sql_fetchrow($result))
{
$i = 1;
$where = array("module_class = '" . $this->db->sql_escape($row['module_class']) . "'");
$this->fix_ids_tree($i, 'module_id', MODULES_TABLE, 0, $where);
}
$this->db->sql_freeresult($result);
// Fix the Left/Right IDs for the forums table
$i = 1;
$this->fix_ids_tree($i, 'forum_id', FORUMS_TABLE);
$this->cache->purge();
$io->success($this->user->lang('CLI_FIXUP_FIX_LEFT_RIGHT_IDS_SUCCESS'));
}
/**
* Item's tree structure rebuild helper
* The item is either forum or ACP/MCP/UCP module
*
* @param int $i Item id offset index
* @param string $field The key field to fix, forum_id|module_id
* @param string $table The table name to perform, FORUMS_TABLE|MODULES_TABLE
* @param int $parent_id Parent item id
* @param array $where Additional WHERE clause condition
*
* @return bool True on rebuild success, false otherwise
*/
protected function fix_ids_tree(&$i, $field, $table, $parent_id = 0, $where = array())
{
$changes_made = false;
$sql = 'SELECT * FROM ' . $table . '
WHERE parent_id = ' . (int) $parent_id .
((!empty($where)) ? ' AND ' . implode(' AND ', $where) : '') . '
ORDER BY left_id ASC';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
// Update the left_id for the item
if ($row['left_id'] != $i)
{
$this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('left_id' => $i)) . " WHERE $field = " . (int) $row[$field]);
$changes_made = true;
}
$i++;
// Go through children and update their left/right IDs
$changes_made = (($this->fix_ids_tree($i, $field, $table, $row[$field], $where)) || $changes_made) ? true : false;
// Update the right_id for the item
if ($row['right_id'] != $i)
{
$this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('right_id' => $i)) . " WHERE $field = " . (int) $row[$field]);
$changes_made = true;
}
$i++;
}
$this->db->sql_freeresult($result);
return $changes_made;
}
}

View File

@ -0,0 +1,76 @@
<?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\console\command\fixup;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class recalculate_email_hash extends \phpbb\console\command\command
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db)
{
$this->db = $db;
parent::__construct($user);
}
protected function configure()
{
$this
->setName('fixup:recalculate-email-hash')
->setDescription($this->user->lang('CLI_DESCRIPTION_RECALCULATE_EMAIL_HASH'))
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$sql = 'SELECT user_id, user_email, user_email_hash
FROM ' . USERS_TABLE . '
WHERE user_type <> ' . USER_IGNORE . "
AND user_email <> ''";
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$user_email_hash = phpbb_email_hash($row['user_email']);
if ($user_email_hash !== $row['user_email_hash'])
{
$sql_ary = array(
'user_email_hash' => $user_email_hash,
);
$sql = 'UPDATE ' . USERS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . (int) $row['user_id'];
$this->db->sql_query($sql);
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG)
{
$io->table(
array('user_id', 'user_email', 'user_email_hash'),
array(array($row['user_id'], $row['user_email'], $user_email_hash))
);
}
}
}
$this->db->sql_freeresult($result);
$io->success($this->user->lang('CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS'));
}
}

View File

@ -0,0 +1,117 @@
<?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\console\command\fixup;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressBar;
class update_hashes extends \phpbb\console\command\command
{
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\passwords\manager */
protected $passwords_manager;
/** @var string Default hashing type */
protected $default_type;
/**
* Update_hashes constructor
*
* @param \phpbb\config\config $config
* @param \phpbb\user $user
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\passwords\manager $passwords_manager
* @param array $hashing_algorithms Hashing driver
* service collection
* @param array $defaults Default password types
*/
public function __construct(\phpbb\config\config $config, \phpbb\user $user,
\phpbb\db\driver\driver_interface $db, \phpbb\passwords\manager $passwords_manager,
$hashing_algorithms, $defaults)
{
$this->config = $config;
$this->db = $db;
$this->passwords_manager = $passwords_manager;
foreach ($defaults as $type)
{
if ($hashing_algorithms[$type]->is_supported())
{
$this->default_type = $type;
break;
}
}
parent::__construct($user);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('fixup:update-hashes')
->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_HASH_BCRYPT'))
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// Get count to be able to display progress
$sql = 'SELECT COUNT(user_id) AS count
FROM ' . USERS_TABLE . '
WHERE user_password ' . $this->db->sql_like_expression('$H$' . $this->db->get_any_char()) . '
OR user_password ' . $this->db->sql_like_expression('$CP$' . $this->db->get_any_char());
$result = $this->db->sql_query($sql);
$total_update_passwords = $this->db->sql_fetchfield('count');
$this->db->sql_freeresult($result);
// Create progress bar
$progress_bar = new ProgressBar($output, $total_update_passwords);
$progress_bar->start();
$sql = 'SELECT user_id, user_password
FROM ' . USERS_TABLE . '
WHERE user_password ' . $this->db->sql_like_expression('$H$' . $this->db->get_any_char()) . '
OR user_password ' . $this->db->sql_like_expression('$CP$' . $this->db->get_any_char());
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$new_hash = $this->passwords_manager->hash($row['user_password'], array($this->default_type));
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_password = '" . $this->db->sql_escape($new_hash) . "'
WHERE user_id = " . (int) $row['user_id'];
$this->db->sql_query($sql);
$progress_bar->advance();
}
$this->config->set('update_hashes_last_cron', time());
$progress_bar->finish();
$output->writeln('<info>' . $this->user->lang('CLI_FIXUP_UPDATE_HASH_BCRYPT_SUCCESS') . '</info>');
}
}

View File

@ -0,0 +1,72 @@
<?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\console\command\reparser;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class list_all extends \phpbb\console\command\command
{
/**
* @var string[] Names of the reparser services
*/
protected $reparser_names;
/**
* Constructor
*
* @param \phpbb\user $user
* @param \phpbb\di\service_collection $reparsers
*/
public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers)
{
parent::__construct($user);
$this->reparser_names = array();
foreach ($reparsers as $reparser)
{
// Store the names without the "text_reparser." prefix
$this->reparser_names[] = $reparser->get_name();
}
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('reparser:list')
->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_LIST'))
;
}
/**
* Executes the command reparser:list
*
* @param InputInterface $input
* @param OutputInterface $output
* @return integer
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->section($this->user->lang('CLI_DESCRIPTION_REPARSER_AVAILABLE'));
$io->listing($this->reparser_names);
return 0;
}
}

View File

@ -0,0 +1,242 @@
<?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\console\command\reparser;
use phpbb\exception\runtime_exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class reparse extends \phpbb\console\command\command
{
/**
* @var InputInterface
*/
protected $input;
/**
* @var SymfonyStyle
*/
protected $io;
/**
* @var OutputInterface
*/
protected $output;
/**
* @var \phpbb\lock\db
*/
protected $reparse_lock;
/**
* @var \phpbb\textreparser\manager
*/
protected $reparser_manager;
/**
* @var \phpbb\di\service_collection
*/
protected $reparsers;
/**
* @var array The reparser's last $current ID as values
*/
protected $resume_data;
/**
* Constructor
*
* @param \phpbb\user $user
* @param \phpbb\lock\db $reparse_lock
* @param \phpbb\textreparser\manager $reparser_manager
* @param \phpbb\di\service_collection $reparsers
*/
public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers)
{
require_once __DIR__ . '/../../../../includes/functions_content.php';
$this->reparse_lock = $reparse_lock;
$this->reparser_manager = $reparser_manager;
$this->reparsers = $reparsers;
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('reparser:reparse')
->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE'))
->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1'))
->addOption(
'dry-run',
null,
InputOption::VALUE_NONE,
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN')
)
->addOption(
'resume',
null,
InputOption::VALUE_NONE,
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RESUME')
)
->addOption(
'range-min',
null,
InputOption::VALUE_REQUIRED,
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'),
1
)
->addOption(
'range-max',
null,
InputOption::VALUE_REQUIRED,
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MAX')
)
->addOption(
'range-size',
null,
InputOption::VALUE_REQUIRED,
$this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE'),
100
);
;
}
/**
* Executes the command reparser:reparse
*
* @param InputInterface $input
* @param OutputInterface $output
* @return integer
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
$this->io = new SymfonyStyle($input, $output);
if (!$this->reparse_lock->acquire())
{
throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1);
}
$name = $input->getArgument('reparser-name');
if ($name)
{
$name = $this->reparser_manager->find_reparser($name);
$this->reparse($name);
}
else
{
foreach ($this->reparsers as $name => $service)
{
$this->reparse($name);
}
}
$this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS'));
$this->reparse_lock->release();
return 0;
}
/**
* Get an option value, adjusted for given reparser
*
* Will use the last saved value if --resume is set and the option was not specified
* on the command line
*
* @param string $option_name Option name
* @return integer
*/
protected function get_option($option_name)
{
// Return the option from the resume_data if applicable
if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name))
{
return $this->resume_data[$option_name];
}
return $this->input->getOption($option_name);
}
/**
* Reparse all text handled by given reparser within given range
*
* @param string $name Reparser service name
*/
protected function reparse($name)
{
$reparser = $this->reparsers[$name];
$this->resume_data = $this->reparser_manager->get_resume_data($name);
if ($this->input->getOption('dry-run'))
{
$reparser->disable_save();
}
else
{
$reparser->enable_save();
}
// Start at range-max if specified or at the highest ID otherwise
$max = $this->get_option('range-max');
$min = $this->get_option('range-min');
$size = $this->get_option('range-size');
// range-max has no default value, it must be computed for each reparser
if ($max === null)
{
$max = $reparser->get_max_id();
}
if ($max < $min)
{
return;
}
$this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $min, $max));
$progress = $this->create_progress_bar($max, $this->io, $this->output, true);
$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', $reparser->get_name()));
$progress->start();
// Start from $max and decrement $current by $size until we reach $min
$current = $max;
while ($current >= $min)
{
$start = max($min, $current + 1 - $size);
$end = max($min, $current);
$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end));
$reparser->reparse_range($start, $end);
$current = $start - 1;
$progress->setProgress($max + 1 - $start);
$this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run'));
}
$progress->finish();
$this->io->newLine(2);
}
}

View File

@ -0,0 +1,153 @@
<?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\console\command\thumbnail;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class delete extends \phpbb\console\command\command
{
/**
* @var \phpbb\db\driver\driver_interface
*/
protected $db;
/**
* phpBB root path
* @var string
*/
protected $phpbb_root_path;
/**
* Constructor
*
* @param \phpbb\user $user The user object (used to get language information)
* @param \phpbb\db\driver\driver_interface $db Database connection
* @param string $phpbb_root_path Root path
*/
public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_root_path)
{
$this->db = $db;
$this->phpbb_root_path = $phpbb_root_path;
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('thumbnail:delete')
->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_DELETE'))
;
}
/**
* Executes the command thumbnail:delete.
*
* Deletes all existing thumbnails and updates the database accordingly.
*
* @param InputInterface $input The input stream used to get the argument and verbose option.
* @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
*
* @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->section($this->user->lang('CLI_THUMBNAIL_DELETING'));
$sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
FROM ' . ATTACHMENTS_TABLE . '
WHERE thumbnail = 1';
$result = $this->db->sql_query($sql);
$nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
$this->db->sql_freeresult($result);
if ($nb_missing_thumbnails === 0)
{
$io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
return 0;
}
$sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
FROM ' . ATTACHMENTS_TABLE . '
WHERE thumbnail = 1';
$result = $this->db->sql_query($sql);
$progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING'));
$progress->start();
$thumbnail_deleted = array();
$return = 0;
while ($row = $this->db->sql_fetchrow($result))
{
$thumbnail_path = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
if (@unlink($thumbnail_path))
{
$thumbnail_deleted[] = $row['attach_id'];
if (count($thumbnail_deleted) === 250)
{
$this->commit_changes($thumbnail_deleted);
$thumbnail_deleted = array();
}
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
}
else
{
$return = 1;
$progress->setMessage('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
}
$progress->advance();
}
$this->db->sql_freeresult($result);
if (!empty($thumbnail_deleted))
{
$this->commit_changes($thumbnail_deleted);
}
$progress->finish();
$io->newLine(2);
$io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE'));
return $return;
}
/**
* Commits the changes to the database
*
* @param array $thumbnail_deleted
*/
protected function commit_changes(array $thumbnail_deleted)
{
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
SET thumbnail = 0
WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted);
$this->db->sql_query($sql);
}
}

View File

@ -0,0 +1,179 @@
<?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\console\command\thumbnail;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class generate extends \phpbb\console\command\command
{
/**
* @var \phpbb\db\driver\driver_interface
*/
protected $db;
/**
* @var \phpbb\cache\service
*/
protected $cache;
/**
* phpBB root path
* @var string
*/
protected $phpbb_root_path;
/**
* PHP extension.
*
* @var string
*/
protected $php_ext;
/**
* Constructor
*
* @param \phpbb\user $user The user object (used to get language information)
* @param \phpbb\db\driver\driver_interface $db Database connection
* @param \phpbb\cache\service $cache The cache service
* @param string $phpbb_root_path Root path
* @param string $php_ext PHP extension
*/
public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext)
{
$this->db = $db;
$this->cache = $cache;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('thumbnail:generate')
->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_GENERATE'))
;
}
/**
* Executes the command thumbnail:generate.
*
* Generate a thumbnail for all attachments which need one and don't have it yet.
*
* @param InputInterface $input The input stream used to get the argument and verboe option.
* @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
*
* @return int 0.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->section($this->user->lang('CLI_THUMBNAIL_GENERATING'));
$sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
FROM ' . ATTACHMENTS_TABLE . '
WHERE thumbnail = 0';
$result = $this->db->sql_query($sql);
$nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
$this->db->sql_freeresult($result);
if ($nb_missing_thumbnails === 0)
{
$io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
return 0;
}
$extensions = $this->cache->obtain_attach_extensions(true);
$sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
FROM ' . ATTACHMENTS_TABLE . '
WHERE thumbnail = 0';
$result = $this->db->sql_query($sql);
if (!function_exists('create_thumbnail'))
{
require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext);
}
$progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING'));
$progress->start();
$thumbnail_created = array();
while ($row = $this->db->sql_fetchrow($result))
{
if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE)
{
$source = $this->phpbb_root_path . 'files/' . $row['physical_filename'];
$destination = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
if (create_thumbnail($source, $destination, $row['mimetype']))
{
$thumbnail_created[] = (int) $row['attach_id'];
if (count($thumbnail_created) === 250)
{
$this->commit_changes($thumbnail_created);
$thumbnail_created = array();
}
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
}
else
{
$progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
}
}
$progress->advance();
}
$this->db->sql_freeresult($result);
if (!empty($thumbnail_created))
{
$this->commit_changes($thumbnail_created);
}
$progress->finish();
$io->newLine(2);
$io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE'));
return 0;
}
/**
* Commits the changes to the database
*
* @param array $thumbnail_created
*/
protected function commit_changes(array $thumbnail_created)
{
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
SET thumbnail = 1
WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created);
$this->db->sql_query($sql);
}
}

View File

@ -0,0 +1,72 @@
<?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\console\command\thumbnail;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;
class recreate extends \phpbb\console\command\command
{
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('thumbnail:recreate')
->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_RECREATE'))
;
}
/**
* Executes the command thumbnail:recreate.
*
* This command is a "macro" to execute thumbnail:delete and then thumbnail:generate.
*
* @param InputInterface $input The input stream used to get the argument and verboe option.
* @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
*
* @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$parameters = array(
'command' => 'thumbnail:delete'
);
if ($input->getOption('verbose'))
{
$parameters['-' . str_repeat('v', $output->getVerbosity() - 1)] = true;
}
$this->getApplication()->setAutoExit(false);
$input_delete = new ArrayInput($parameters);
$return = $this->getApplication()->run($input_delete, $output);
if ($return === 0)
{
$parameters['command'] = 'thumbnail:generate';
$input_create = new ArrayInput($parameters);
$return = $this->getApplication()->run($input_create, $output);
}
$this->getApplication()->setAutoExit(true);
return $return;
}
}

View File

@ -0,0 +1,331 @@
<?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\console\command\update;
use phpbb\config\config;
use phpbb\exception\exception_interface;
use phpbb\language\language;
use phpbb\user;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerInterface;
class check extends \phpbb\console\command\command
{
/** @var \phpbb\config\config */
protected $config;
/** @var \Symfony\Component\DependencyInjection\ContainerBuilder */
protected $phpbb_container;
/**
* @var language
*/
private $language;
/**
* Construct method
*/
public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language)
{
$this->config = $config;
$this->phpbb_container = $phpbb_container;
$this->language = $language;
$this->language->add_lang(array('acp/common', 'acp/extensions'));
parent::__construct($user);
}
/**
* Configures the service.
*
* Sets the name and description of the command.
*
* @return null
*/
protected function configure()
{
$this
->setName('update:check')
->setDescription($this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK'))
->addArgument('ext-name', InputArgument::OPTIONAL, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1'))
->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY'))
->addOption('cache', 'c', InputOption::VALUE_NONE, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE'))
;
}
/**
* Executes the command.
*
* Checks if an update is available.
* If at least one is available, a message is printed and if verbose mode is set the list of possible updates is printed.
* If their is none, nothing is printed unless verbose mode is set.
*
* @param InputInterface $input Input stream, used to get the options.
* @param OutputInterface $output Output stream, used to print messages.
* @return int 0 if the board is up to date, 1 if it is not and 2 if an error occured.
* @throws \RuntimeException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$recheck = true;
if ($input->getOption('cache'))
{
$recheck = false;
}
$stability = null;
if ($input->getOption('stability'))
{
$stability = $input->getOption('stability');
if (!($stability == 'stable') && !($stability == 'unstable'))
{
$io->error($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability));
return 3;
}
}
$ext_name = $input->getArgument('ext-name');
if ($ext_name != null)
{
if ($ext_name == 'all')
{
return $this->check_all_ext($io, $stability, $recheck);
}
else
{
return $this->check_ext($input, $io, $stability, $recheck, $ext_name);
}
}
else
{
return $this->check_core($input, $io, $stability, $recheck);
}
}
/**
* Check if a given extension is up to date
*
* @param InputInterface $input Input stream, used to get the options.
* @param SymfonyStyle $io IO handler, for formatted and unified IO
* @param string $stability Force a given stability
* @param bool $recheck Disallow the use of the cache
* @param string $ext_name The extension name
* @return int
*/
protected function check_ext(InputInterface $input, SymfonyStyle $io, $stability, $recheck, $ext_name)
{
try
{
$ext_manager = $this->phpbb_container->get('ext.manager');
$md_manager = $ext_manager->create_extension_metadata_manager($ext_name);
$updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability);
$metadata = $md_manager->get_metadata('all');
if ($input->getOption('verbose'))
{
$io->title($md_manager->get_metadata('display-name'));
$io->note($this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']);
}
if (!empty($updates_available))
{
if ($input->getOption('verbose'))
{
$io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name']));
$this->display_versions($io, $updates_available);
}
return 1;
}
else
{
if ($input->getOption('verbose'))
{
$io->success($this->language->lang('UPDATE_NOT_NEEDED'));
}
return 0;
}
}
catch (\RuntimeException $e)
{
$io->error($this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name));
return 1;
}
}
/**
* Check if the core is up to date
*
* @param InputInterface $input Input stream, used to get the options.
* @param SymfonyStyle $io IO handler, for formatted and unified IO
* @param string $stability Force a given stability
* @param bool $recheck Disallow the use of the cache
* @return int
*/
protected function check_core(InputInterface $input, SymfonyStyle $io, $stability, $recheck)
{
$version_helper = $this->phpbb_container->get('version_helper');
$version_helper->force_stability($stability);
$updates_available = $version_helper->get_suggested_updates($recheck);
if ($input->getOption('verbose'))
{
$io->title('phpBB core');
$io->note( $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']);
}
if (!empty($updates_available))
{
$io->caution($this->language->lang('UPDATE_NEEDED'));
if ($input->getOption('verbose'))
{
$this->display_versions($io, $updates_available);
}
return 1;
}
else
{
if ($input->getOption('verbose'))
{
$io->success($this->language->lang('UPDATE_NOT_NEEDED'));
}
return 0;
}
}
/**
* Check if all the available extensions are up to date
*
* @param SymfonyStyle $io IO handler, for formatted and unified IO
* @param bool $recheck Disallow the use of the cache
* @return int
*/
protected function check_all_ext(SymfonyStyle $io, $stability, $recheck)
{
/** @var \phpbb\extension\manager $ext_manager */
$ext_manager = $this->phpbb_container->get('ext.manager');
$rows = [];
foreach ($ext_manager->all_available() as $ext_name => $ext_path)
{
$row = [];
$row[] = sprintf("<info>%s</info>", $ext_name);
$md_manager = $ext_manager->create_extension_metadata_manager($ext_name);
try
{
$metadata = $md_manager->get_metadata('all');
if (isset($metadata['extra']['version-check']))
{
try {
$updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability);
if (!empty($updates_available))
{
$versions = array_map(function($entry)
{
return $entry['current'];
}, $updates_available);
$row[] = sprintf("<comment>%s</comment>", $metadata['version']);
$row[] = implode(', ', $versions);
}
else
{
$row[] = sprintf("<info>%s</info>", $metadata['version']);
$row[] = '';
}
} catch (\RuntimeException $e) {
$row[] = $metadata['version'];
$row[] = '';
}
}
else
{
$row[] = $metadata['version'];
$row[] = '';
}
}
catch (exception_interface $e)
{
$exception_message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
$row[] = '<error>' . $exception_message . '</error>';
}
catch (\RuntimeException $e)
{
$row[] = '<error>' . $e->getMessage() . '</error>';
}
$rows[] = $row;
}
$io->table([
$this->language->lang('EXTENSION_NAME'),
$this->language->lang('CURRENT_VERSION'),
$this->language->lang('LATEST_VERSION'),
], $rows);
return 0;
}
/**
* Display the details of the available updates
*
* @param SymfonyStyle $io IO handler, for formatted and unified IO
* @param array $updates_available The list of the available updates
*/
protected function display_versions(SymfonyStyle $io, $updates_available)
{
$io->section($this->language->lang('UPDATES_AVAILABLE'));
$rows = [];
foreach ($updates_available as $version_data)
{
$row = ['', '', ''];
$row[0] = $version_data['current'];
if (isset($version_data['announcement']))
{
$row[1] = $version_data['announcement'];
}
if (isset($version_data['download']))
{
$row[2] = $version_data['download'];
}
$rows[] = $row;
}
$io->table([
$this->language->lang('VERSION'),
$this->language->lang('ANNOUNCEMENT_TOPIC'),
$this->language->lang('DOWNLOAD_LATEST'),
], $rows);
}
}

View File

@ -0,0 +1,218 @@
<?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\console\command\user;
use phpbb\config\config;
use phpbb\console\command\command;
use phpbb\db\driver\driver_interface;
use phpbb\language\language;
use phpbb\log\log_interface;
use phpbb\notification\manager;
use phpbb\user;
use phpbb\user_loader;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class activate extends command
{
/** @var driver_interface */
protected $db;
/** @var config */
protected $config;
/** @var language */
protected $language;
/** @var log_interface */
protected $log;
/** @var manager */
protected $notifications;
/** @var user_loader */
protected $user_loader;
/**
* phpBB root path
*
* @var string
*/
protected $phpbb_root_path;
/**
* PHP extension.
*
* @var string
*/
protected $php_ext;
/**
* Construct method
*
* @param user $user
* @param driver_interface $db
* @param config $config
* @param language $language
* @param log_interface $log
* @param manager $notifications
* @param user_loader $user_loader
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(user $user, driver_interface $db, config $config, language $language, log_interface $log, manager $notifications, user_loader $user_loader, $phpbb_root_path, $php_ext)
{
$this->db = $db;
$this->config = $config;
$this->language = $language;
$this->log = $log;
$this->notifications = $notifications;
$this->user_loader = $user_loader;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->language->add_lang('acp/users');
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('user:activate')
->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE'))
->setHelp($this->language->lang('CLI_HELP_USER_ACTIVATE'))
->addArgument(
'username',
InputArgument::REQUIRED,
$this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_USERNAME')
)
->addOption(
'deactivate',
'd',
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_DEACTIVATE')
)
->addOption(
'send-email',
null,
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_NOTIFY')
)
;
}
/**
* Executes the command user:activate
*
* Activate (or deactivate) a user account
*
* @param InputInterface $input The input stream used to get the options
* @param OutputInterface $output The output stream, used to print messages
*
* @return int 0 if all is well, 1 if any errors occurred
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$name = $input->getArgument('username');
$mode = ($input->getOption('deactivate')) ? 'deactivate' : 'activate';
$user_id = $this->user_loader->load_user_by_username($name);
$user_row = $this->user_loader->get_user($user_id);
if ($user_row['user_id'] == ANONYMOUS)
{
$io->error($this->language->lang('NO_USER'));
return 1;
}
// Check if the user is already active (or inactive)
if ($mode == 'activate' && $user_row['user_type'] != USER_INACTIVE)
{
$io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_ACTIVE'));
return 1;
}
else if ($mode == 'deactivate' && $user_row['user_type'] == USER_INACTIVE)
{
$io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_INACTIVE'));
return 1;
}
// Activate the user account
if (!function_exists('user_active_flip'))
{
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
user_active_flip($mode, $user_row['user_id']);
// Notify the user upon activation
if ($mode == 'activate' && $this->config['require_activation'] == USER_ACTIVATION_ADMIN)
{
$this->send_notification($user_row, $input);
}
// Log and display the result
$msg = ($mode == 'activate') ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
$log = ($mode == 'activate') ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
$this->log->add('admin', ANONYMOUS, '', $log, false, array($user_row['username']));
$this->log->add('user', ANONYMOUS, '', $log . '_USER', false, array(
'reportee_id' => $user_row['user_id']
));
$io->success($this->language->lang($msg));
return 0;
}
/**
* Send account activation notification to user
*
* @param array $user_row The user data array
* @param InputInterface $input The input stream used to get the options
* @return null
*/
protected function send_notification($user_row, InputInterface $input)
{
$this->notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
if ($input->getOption('send-email'))
{
if (!class_exists('messenger'))
{
require($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
}
$messenger = new \messenger(false);
$messenger->template('admin_welcome_activated', $user_row['user_lang']);
$messenger->set_addresses($user_row);
$messenger->anti_abuse_headers($this->config, $this->user);
$messenger->assign_vars(array(
'USERNAME' => htmlspecialchars_decode($user_row['username']))
);
$messenger->send(NOTIFY_EMAIL);
}
}
}

View File

@ -0,0 +1,334 @@
<?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\console\command\user;
use phpbb\config\config;
use phpbb\console\command\command;
use phpbb\db\driver\driver_interface;
use phpbb\exception\runtime_exception;
use phpbb\language\language;
use phpbb\passwords\manager;
use phpbb\user;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
class add extends command
{
/** @var array Array of interactively acquired options */
protected $data;
/** @var driver_interface */
protected $db;
/** @var config */
protected $config;
/** @var language */
protected $language;
/** @var manager */
protected $password_manager;
/**
* phpBB root path
*
* @var string
*/
protected $phpbb_root_path;
/**
* PHP extension.
*
* @var string
*/
protected $php_ext;
/**
* Construct method
*
* @param user $user
* @param driver_interface $db
* @param config $config
* @param language $language
* @param manager $password_manager
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(user $user, driver_interface $db, config $config, language $language, manager $password_manager, $phpbb_root_path, $php_ext)
{
$this->db = $db;
$this->config = $config;
$this->language = $language;
$this->password_manager = $password_manager;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->language->add_lang('ucp');
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('user:add')
->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ADD'))
->setHelp($this->language->lang('CLI_HELP_USER_ADD'))
->addOption(
'username',
'U',
InputOption::VALUE_REQUIRED,
$this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME')
)
->addOption(
'password',
'P',
InputOption::VALUE_REQUIRED,
$this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD')
)
->addOption(
'email',
'E',
InputOption::VALUE_REQUIRED,
$this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL')
)
->addOption(
'send-email',
null,
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_NOTIFY')
)
;
}
/**
* Executes the command user:add
*
* Adds a new user to the database. If options are not provided, it will ask for the username, password and email.
* User is added to the registered user group. Language and timezone default to $config settings.
*
* @param InputInterface $input The input stream used to get the options
* @param OutputInterface $output The output stream, used to print messages
*
* @return int 0 if all is well, 1 if any errors occurred
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
try
{
$this->validate_user_data();
$group_id = $this->get_group_id();
}
catch (runtime_exception $e)
{
$io->error($e->getMessage());
return 1;
}
$user_row = array(
'username' => $this->data['username'],
'user_password' => $this->password_manager->hash($this->data['new_password']),
'user_email' => $this->data['email'],
'group_id' => $group_id,
'user_timezone' => $this->config['board_timezone'],
'user_lang' => $this->config['default_lang'],
'user_type' => USER_NORMAL,
'user_regdate' => time(),
);
$user_id = (int) user_add($user_row);
if (!$user_id)
{
$io->error($this->language->lang('AUTH_NO_PROFILE_CREATED'));
return 1;
}
if ($input->getOption('send-email') && $this->config['email_enable'])
{
$this->send_activation_email($user_id);
}
$io->success($this->language->lang('CLI_USER_ADD_SUCCESS', $this->data['username']));
return 0;
}
/**
* Interacts with the user.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
$this->data = array(
'username' => $input->getOption('username'),
'new_password' => $input->getOption('password'),
'email' => $input->getOption('email'),
);
if (!$this->data['username'])
{
$question = new Question($this->ask_user('USERNAME'));
$this->data['username'] = $helper->ask($input, $output, $question);
}
if (!$this->data['new_password'])
{
$question = new Question($this->ask_user('PASSWORD'));
$question->setValidator(function ($value) use ($helper, $input, $output) {
$question = new Question($this->ask_user('CONFIRM_PASSWORD'));
$question->setHidden(true);
if ($helper->ask($input, $output, $question) != $value)
{
throw new runtime_exception($this->language->lang('NEW_PASSWORD_ERROR'));
}
return $value;
});
$question->setHidden(true);
$question->setMaxAttempts(5);
$this->data['new_password'] = $helper->ask($input, $output, $question);
}
if (!$this->data['email'])
{
$question = new Question($this->ask_user('EMAIL_ADDRESS'));
$this->data['email'] = $helper->ask($input, $output, $question);
}
}
/**
* Validate the submitted user data
*
* @throws runtime_exception if any data fails validation
* @return null
*/
protected function validate_user_data()
{
if (!function_exists('validate_data'))
{
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
$error = validate_data($this->data, array(
'username' => array(
array('string', false, $this->config['min_name_chars'], $this->config['max_name_chars']),
array('username', '')),
'new_password' => array(
array('string', false, $this->config['min_pass_chars'], $this->config['max_pass_chars']),
array('password')),
'email' => array(
array('string', false, 6, 60),
array('user_email')),
));
if ($error)
{
throw new runtime_exception(implode("\n", array_map(array($this->language, 'lang'), $error)));
}
}
/**
* Get the group id
*
* Go and find in the database the group_id corresponding to 'REGISTERED'
*
* @throws runtime_exception if the group id does not exist in database.
* @return null
*/
protected function get_group_id()
{
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'
AND group_type = " . GROUP_SPECIAL;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row || !$row['group_id'])
{
throw new runtime_exception($this->language->lang('NO_GROUP'));
}
return $row['group_id'];
}
/**
* Send account activation email
*
* @param int $user_id The new user's id
* @return null
*/
protected function send_activation_email($user_id)
{
switch ($this->config['require_activation'])
{
case USER_ACTIVATION_SELF:
$email_template = 'user_welcome_inactive';
$user_actkey = gen_rand_string(mt_rand(6, 10));
break;
case USER_ACTIVATION_ADMIN:
$email_template = 'admin_welcome_inactive';
$user_actkey = gen_rand_string(mt_rand(6, 10));
break;
default:
$email_template = 'user_welcome';
$user_actkey = '';
break;
}
if (!class_exists('messenger'))
{
require($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
}
$messenger = new \messenger(false);
$messenger->template($email_template, $this->user->lang_name);
$messenger->to($this->data['email'], $this->data['username']);
$messenger->anti_abuse_headers($this->config, $this->user);
$messenger->assign_vars(array(
'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])),
'USERNAME' => htmlspecialchars_decode($this->data['username']),
'PASSWORD' => htmlspecialchars_decode($this->data['new_password']),
'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey")
);
$messenger->send(NOTIFY_EMAIL);
}
/**
* Helper to translate questions to the user
*
* @param string $key The language key
* @return string The language key translated with a colon and space appended
*/
protected function ask_user($key)
{
return $this->language->lang($key) . $this->language->lang('COLON') . ' ';
}
}

View File

@ -0,0 +1,170 @@
<?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\console\command\user;
use phpbb\console\command\command;
use phpbb\db\driver\driver_interface;
use phpbb\language\language;
use phpbb\log\log_interface;
use phpbb\user;
use phpbb\user_loader;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
class delete extends command
{
/** @var driver_interface */
protected $db;
/** @var language */
protected $language;
/** @var log_interface */
protected $log;
/** @var user_loader */
protected $user_loader;
/**
* phpBB root path
*
* @var string
*/
protected $phpbb_root_path;
/**
* PHP extension.
*
* @var string
*/
protected $php_ext;
/**
* Construct method
*
* @param user $user
* @param driver_interface $db
* @param language $language
* @param log_interface $log
* @param user_loader $user_loader
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(user $user, driver_interface $db, language $language, log_interface $log, user_loader $user_loader, $phpbb_root_path, $php_ext)
{
$this->db = $db;
$this->language = $language;
$this->log = $log;
$this->user_loader = $user_loader;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->language->add_lang('acp/users');
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('user:delete')
->setDescription($this->language->lang('CLI_DESCRIPTION_USER_DELETE'))
->addArgument(
'username',
InputArgument::REQUIRED,
$this->language->lang('CLI_DESCRIPTION_USER_DELETE_USERNAME')
)
->addOption(
'delete-posts',
null,
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_USER_DELETE_OPTION_POSTS')
)
;
}
/**
* Executes the command user:delete
*
* Deletes a user from the database. An option to delete the user's posts
* is available, by default posts will be retained.
*
* @param InputInterface $input The input stream used to get the options
* @param OutputInterface $output The output stream, used to print messages
*
* @return int 0 if all is well, 1 if any errors occurred
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('username');
$mode = ($input->getOption('delete-posts')) ? 'remove' : 'retain';
if ($name)
{
$io = new SymfonyStyle($input, $output);
$user_id = $this->user_loader->load_user_by_username($name);
$user_row = $this->user_loader->get_user($user_id);
if ($user_row['user_id'] == ANONYMOUS)
{
$io->error($this->language->lang('NO_USER'));
return 1;
}
if (!function_exists('user_delete'))
{
require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
user_delete($mode, $user_row['user_id'], $user_row['username']);
$this->log->add('admin', ANONYMOUS, '', 'LOG_USER_DELETED', false, array($user_row['username']));
$io->success($this->language->lang('USER_DELETED'));
}
return 0;
}
/**
* Interacts with the user.
* Confirm they really want to delete the account...last chance!
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion(
$this->language->lang('CLI_USER_DELETE_CONFIRM', $input->getArgument('username')),
false
);
if (!$helper->ask($input, $output, $question))
{
$input->setArgument('username', false);
}
}
}

View File

@ -0,0 +1,158 @@
<?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\console\command\user;
use phpbb\console\command\command;
use phpbb\db\driver\driver_interface;
use phpbb\language\language;
use phpbb\user;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class reclean extends command
{
/** @var driver_interface */
protected $db;
/** @var language */
protected $language;
/** @var int A count of the number of re-cleaned user names */
protected $processed;
/** @var ProgressBar */
protected $progress;
/**
* Construct method
*
* @param user $user
* @param driver_interface $db
* @param language $language
*/
public function __construct(user $user, driver_interface $db, language $language)
{
$this->db = $db;
$this->language = $language;
parent::__construct($user);
}
/**
* Sets the command name and description
*
* @return null
*/
protected function configure()
{
$this
->setName('user:reclean')
->setDescription($this->language->lang('CLI_DESCRIPTION_USER_RECLEAN'))
->setHelp($this->language->lang('CLI_HELP_USER_RECLEAN'))
;
}
/**
* Executes the command user:reclean
*
* Cleans user names that are unclean.
*
* @param InputInterface $input The input stream used to get the options
* @param OutputInterface $output The output stream, used to print messages
*
* @return int 0 if all is well, 1 if any errors occurred
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->section($this->language->lang('CLI_USER_RECLEAN_START'));
$this->processed = 0;
$this->progress = $this->create_progress_bar($this->get_count(), $io, $output);
$this->progress->setMessage($this->language->lang('CLI_USER_RECLEAN_START'));
$this->progress->start();
$stage = 0;
while ($stage !== true)
{
$stage = $this->reclean_usernames($stage);
}
$this->progress->finish();
$io->newLine(2);
$io->success($this->language->lang('CLI_USER_RECLEAN_DONE', $this->processed));
return 0;
}
/**
* Re-clean user names
* Only user names that are unclean will be re-cleaned
*
* @param int $start An offset index
* @return bool|int Return the next offset index or true if all records have been processed.
*/
protected function reclean_usernames($start = 0)
{
$limit = 500;
$i = 0;
$this->db->sql_transaction('begin');
$sql = 'SELECT user_id, username, username_clean FROM ' . USERS_TABLE;
$result = $this->db->sql_query_limit($sql, $limit, $start);
while ($row = $this->db->sql_fetchrow($result))
{
$i++;
$username_clean = $this->db->sql_escape(utf8_clean_string($row['username']));
if ($username_clean != $row['username_clean'])
{
$sql = 'UPDATE ' . USERS_TABLE . "
SET username_clean = '$username_clean'
WHERE user_id = {$row['user_id']}";
$this->db->sql_query($sql);
$this->processed++;
}
$this->progress->advance();
}
$this->db->sql_freeresult($result);
$this->db->sql_transaction('commit');
return ($i < $limit) ? true : $start + $i;
}
/**
* Get the count of users in the database
*
* @return int
*/
protected function get_count()
{
$sql = 'SELECT COUNT(user_id) AS count FROM ' . USERS_TABLE;
$result = $this->db->sql_query($sql);
$count = (int) $this->db->sql_fetchfield('count');
$this->db->sql_freeresult($result);
return $count;
}
}