diff options
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/avatar/driver/local.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/console/application.php | 80 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/cache/purge.php | 1 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/cron/cron_list.php | 90 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/cron/run.php | 176 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/db/migrate.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/cron/manager.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/beta4.php | 33 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/extensions_version_check_force_unstable.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/extension/finder.php | 81 | ||||
-rw-r--r-- | phpBB/phpbb/extension/manager.php | 21 | ||||
-rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 30 | ||||
-rw-r--r-- | phpBB/phpbb/log/log.php | 105 | ||||
-rw-r--r-- | phpBB/phpbb/log/log_interface.php | 12 | ||||
-rw-r--r-- | phpBB/phpbb/log/null.php | 7 |
15 files changed, 598 insertions, 68 deletions
diff --git a/phpBB/phpbb/avatar/driver/local.php b/phpBB/phpbb/avatar/driver/local.php index 00e519e3f2..f3acf7cb2c 100644 --- a/phpBB/phpbb/avatar/driver/local.php +++ b/phpBB/phpbb/avatar/driver/local.php @@ -36,7 +36,7 @@ class local extends \phpbb\avatar\driver\driver public function prepare_form($request, $template, $user, $row, &$error) { $avatar_list = $this->get_avatar_list($user); - $category = $request->variable('avatar_local_cat', ''); + $category = $request->variable('avatar_local_cat', key($avatar_list)); foreach ($avatar_list as $cat => $null) { @@ -131,7 +131,7 @@ class local extends \phpbb\avatar\driver\driver } return array( - 'avatar' => ($category != $user->lang['MAIN']) ? $category . '/' . $file : $file, + 'avatar' => ($category != $user->lang['NO_AVATAR_CATEGORY']) ? $category . '/' . $file : $file, 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'], ); @@ -179,9 +179,9 @@ class local extends \phpbb\avatar\driver\driver { $dims = array(0, 0); } - $cat = ($path == $file_path) ? $user->lang['MAIN'] : str_replace("$path/", '', $file_path); + $cat = ($path == $file_path) ? $user->lang['NO_AVATAR_CATEGORY'] : str_replace("$path/", '', $file_path); $avatar_list[$cat][$image] = array( - 'file' => ($cat != $user->lang['MAIN']) ? rawurlencode($cat) . '/' . rawurlencode($image) : rawurlencode($image), + 'file' => ($cat != $user->lang['NO_AVATAR_CATEGORY']) ? rawurlencode($cat) . '/' . rawurlencode($image) : rawurlencode($image), 'filename' => rawurlencode($image), 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), 'width' => $dims[0], diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index da2bfbb49a..b1f0635913 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,15 +13,93 @@ namespace phpbb\console; +use Symfony\Component\Console\Shell; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\TaggedContainerInterface; class application extends \Symfony\Component\Console\Application { - function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') + /** + * @var bool Indicates whether or not we are in a shell + */ + protected $in_shell = false; + + /** + * @var \phpbb\user User object + */ + protected $user; + + /** + * @param string $name The name of the application + * @param string $version The version of the application + * @param \phpbb\user $user The user which runs the application (used for translation) + */ + public function __construct($name, $version, \phpbb\user $user) + { + parent::__construct($name, $version); + + $this->user = $user; + } + + /** + * Gets the help message. + * + * It's a hack of the default help message to display the --shell + * option only for the application and not for all the commands. + * + * @return string A help message. + */ + public function getHelp() + { + // If we are already in a shell + // we do not want to have the --shell option available + if ($this->in_shell) + { + return parent::getHelp(); + } + + $this->getDefinition()->addOption(new InputOption( + '--shell', + '-s', + InputOption::VALUE_NONE, + $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL') + )); + + return parent::getHelp(); + } + + /** + * Register a set of commands from the container + * + * @param TaggedContainerInterface $container The container + * @param string $tag The tag used to register the commands + */ + public function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') { foreach($container->findTaggedServiceIds($tag) as $id => $void) { $this->add($container->get($id)); } } + + /** + * {@inheritdoc} + */ + public function doRun(InputInterface $input, OutputInterface $output) + { + // Run a shell if the --shell (or -s) option is set and if no command name is specified + // Also, we do not want to have the --shell option available if we are already in a shell + if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s'))) + { + $shell = new Shell($this); + $this->in_shell = true; + $shell->run(); + + return 0; + } + + return parent::doRun($input, $output); + } } diff --git a/phpBB/phpbb/console/command/cache/purge.php b/phpBB/phpbb/console/command/cache/purge.php index 1e2adaeb4d..50953185a4 100644 --- a/phpBB/phpbb/console/command/cache/purge.php +++ b/phpBB/phpbb/console/command/cache/purge.php @@ -43,7 +43,6 @@ class purge extends \phpbb\console\command\command $this->log = $log; $this->user = $user; $this->config = $config; - $this->user->add_lang(array('acp/common')); parent::__construct(); } diff --git a/phpBB/phpbb/console/command/cron/cron_list.php b/phpBB/phpbb/console/command/cron/cron_list.php new file mode 100644 index 0000000000..9db6a23947 --- /dev/null +++ b/phpBB/phpbb/console/command/cron/cron_list.php @@ -0,0 +1,90 @@ +<?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; + +class cron_list extends \phpbb\console\command\command +{ + /** @var \phpbb\cron\manager */ + protected $cron_manager; + + /** @var \phpbb\user */ + protected $user; + + public function __construct(\phpbb\cron\manager $cron_manager, \phpbb\user $user) + { + $this->cron_manager = $cron_manager; + $this->user = $user; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('cron:list') + ->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_LIST')) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $tasks = $this->cron_manager->get_tasks(); + + if (empty($tasks)) + { + $output->writeln($this->user->lang('CRON_NO_TASKS')); + return; + } + + $ready_tasks = array(); + $not_ready_tasks = array(); + foreach ($tasks as $task) + { + if ($task->is_ready()) + { + $ready_tasks[] = $task; + } + else + { + $not_ready_tasks[] = $task; + } + } + + if (!empty($ready_tasks)) + { + $output->writeln('<info>' . $this->user->lang('TASKS_READY') . '</info>'); + $this->print_tasks_names($ready_tasks, $output); + } + + if (!empty($ready_tasks) && !empty($not_ready_tasks)) + { + $output->writeln(''); + } + + if (!empty($not_ready_tasks)) + { + $output->writeln('<info>' . $this->user->lang('TASKS_NOT_READY') . '</info>'); + $this->print_tasks_names($not_ready_tasks, $output); + } + } + + protected function print_tasks_names(array $tasks, OutputInterface $output) + { + foreach ($tasks as $task) + { + $output->writeln($task->get_name()); + } + } +} diff --git a/phpBB/phpbb/console/command/cron/run.php b/phpBB/phpbb/console/command/cron/run.php new file mode 100644 index 0000000000..1029a2e085 --- /dev/null +++ b/phpBB/phpbb/console/command/cron/run.php @@ -0,0 +1,176 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited +* @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\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +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; + + /** @var \phpbb\user */ + protected $user; + + /** + * Construct method + * + * @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. + * @param \phobb\user $user The user object (used to get language information) + */ + public function __construct(\phpbb\cron\manager $cron_manager, \phpbb\lock\db $lock_db, \phpbb\user $user) + { + $this->cron_manager = $cron_manager; + $this->lock_db = $lock_db; + $this->user = $user; + parent::__construct(); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('cron:run') + ->setDescription($this->user->lang('CLI_DESCRIPTION_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 + { + $output->writeln('<error>' . $this->user->lang('CRON_LOCK_ERROR') . '</error>'); + return 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 + { + $output->writeln('<error>' . $this->user->lang('CRON_NO_SUCH_TASK', $task_name) . '</error>'); + return 2; + } + } +} diff --git a/phpBB/phpbb/console/command/db/migrate.php b/phpBB/phpbb/console/command/db/migrate.php index 0f74664095..2abeaf5268 100644 --- a/phpBB/phpbb/console/command/db/migrate.php +++ b/phpBB/phpbb/console/command/db/migrate.php @@ -43,7 +43,7 @@ class migrate extends \phpbb\console\command\command $this->cache = $cache; $this->log = $log; $this->user = $user; - $this->user->add_lang(array('common', 'acp/common', 'install', 'migrator')); + $this->user->add_lang(array('common', 'install', 'migrator')); parent::__construct(); } diff --git a/phpBB/phpbb/cron/manager.php b/phpBB/phpbb/cron/manager.php index 1eb8edf033..f04f063228 100644 --- a/phpBB/phpbb/cron/manager.php +++ b/phpBB/phpbb/cron/manager.php @@ -122,6 +122,16 @@ class manager } /** + * Find all tasks and return them. + * + * @return array List of all tasks. + */ + public function get_tasks() + { + return $this->tasks; + } + + /** * Wraps a task inside an instance of \phpbb\cron\task\wrapper. * * @param \phpbb\cron\task\task $task The task. diff --git a/phpBB/phpbb/db/migration/data/v310/beta4.php b/phpBB/phpbb/db/migration/data/v310/beta4.php new file mode 100644 index 0000000000..3e91d95178 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/beta4.php @@ -0,0 +1,33 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v310; + +class beta4 extends \phpbb\db\migration\migration +{ + static public function depends_on() + { + return array( + '\phpbb\db\migration\data\v310\beta3', + '\phpbb\db\migration\data\v310\extensions_version_check_force_unstable', + '\phpbb\db\migration\data\v310\reset_missing_captcha_plugin', + ); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.1.0-b4')), + ); + } +} diff --git a/phpBB/phpbb/db/migration/data/v310/extensions_version_check_force_unstable.php b/phpBB/phpbb/db/migration/data/v310/extensions_version_check_force_unstable.php index 5941c3aa54..1d6276f484 100644 --- a/phpBB/phpbb/db/migration/data/v310/extensions_version_check_force_unstable.php +++ b/phpBB/phpbb/db/migration/data/v310/extensions_version_check_force_unstable.php @@ -1,9 +1,13 @@ <?php /** * -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* 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. * */ diff --git a/phpBB/phpbb/extension/finder.php b/phpBB/phpbb/extension/finder.php index 71a5542b67..6f2408094e 100644 --- a/phpBB/phpbb/extension/finder.php +++ b/phpBB/phpbb/extension/finder.php @@ -465,6 +465,10 @@ class finder } else if ($directory && $directory[0] === '/') { + if (!$is_dir) + { + $path .= substr($directory, 1); + } $directory_pattern = '^' . preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR, '#'); } else @@ -477,45 +481,56 @@ class finder } $directory_pattern = '#' . $directory_pattern . '#'; - $iterator = new \RecursiveIteratorIterator( - new \phpbb\recursive_dot_prefix_filter_iterator( - new \RecursiveDirectoryIterator( - $path, - \FilesystemIterator::SKIP_DOTS - ) - ), - \RecursiveIteratorIterator::SELF_FIRST - ); - - foreach ($iterator as $file_info) + if (is_dir($path)) { - $filename = $file_info->getFilename(); - - if ($file_info->isDir() == $is_dir) + $iterator = new \RecursiveIteratorIterator( + new \phpbb\recursive_dot_prefix_filter_iterator( + new \RecursiveDirectoryIterator( + $path, + \FilesystemIterator::SKIP_DOTS + ) + ), + \RecursiveIteratorIterator::SELF_FIRST + ); + + foreach ($iterator as $file_info) { - if ($is_dir) + $filename = $file_info->getFilename(); + + if ($file_info->isDir() == $is_dir) { - $relative_path = $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR . basename($filename) . DIRECTORY_SEPARATOR; - if ($relative_path[0] !== DIRECTORY_SEPARATOR) + if ($is_dir) { - $relative_path = DIRECTORY_SEPARATOR . $relative_path; + $relative_path = $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR . basename($filename) . DIRECTORY_SEPARATOR; + if ($relative_path[0] !== DIRECTORY_SEPARATOR) + { + $relative_path = DIRECTORY_SEPARATOR . $relative_path; + } + } + else + { + $relative_path = $iterator->getInnerIterator()->getSubPathname(); + if ($directory && $directory[0] === '/') + { + $relative_path = str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR . $relative_path; + } + else + { + $relative_path = DIRECTORY_SEPARATOR . $relative_path; + } } - } - else - { - $relative_path = DIRECTORY_SEPARATOR . $iterator->getInnerIterator()->getSubPathname(); - } - if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) && - (!$prefix || substr($filename, 0, strlen($prefix)) === $prefix) && - (!$directory || preg_match($directory_pattern, $relative_path))) - { - $files[] = array( - 'named_path' => str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)), - 'ext_name' => $ext_name, - 'path' => str_replace(array(DIRECTORY_SEPARATOR, $this->phpbb_root_path), array('/', ''), $file_info->getPath()) . '/', - 'filename' => $filename, - ); + if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) && + (!$prefix || substr($filename, 0, strlen($prefix)) === $prefix) && + (!$directory || preg_match($directory_pattern, $relative_path))) + { + $files[] = array( + 'named_path' => str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)), + 'ext_name' => $ext_name, + 'path' => str_replace(array(DIRECTORY_SEPARATOR, $this->phpbb_root_path), array('/', ''), $file_info->getPath()) . '/', + 'filename' => $filename, + ); + } } } } diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 0bfec23573..cd7289e085 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -26,6 +26,7 @@ class manager protected $db; protected $config; protected $cache; + protected $user; protected $php_ext; protected $extensions; protected $extension_table; @@ -37,25 +38,27 @@ class manager * * @param ContainerInterface $container A container * @param \phpbb\db\driver\driver_interface $db A database connection - * @param \phpbb\config\config $config \phpbb\config\config + * @param \phpbb\config\config $config Config object * @param \phpbb\filesystem $filesystem + * @param \phpbb\user $user User object * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. - * @param string $php_ext php file extension + * @param string $php_ext php file extension, defaults to php * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, \phpbb\user $user, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext') { + $this->cache = $cache; + $this->cache_name = $cache_name; + $this->config = $config; $this->container = $container; - $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; - $this->config = $config; - $this->cache = $cache; + $this->extension_table = $extension_table; $this->filesystem = $filesystem; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $this->extension_table = $extension_table; - $this->cache_name = $cache_name; + $this->user = $user; $this->extensions = ($this->cache) ? $this->cache->get($this->cache_name) : false; @@ -150,7 +153,7 @@ class manager */ public function create_extension_metadata_manager($name, \phpbb\template\template $template) { - return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->phpbb_root_path); + return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->user, $this->phpbb_root_path); } /** diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 047f0ca54c..5c4e8fbf00 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -37,6 +37,12 @@ class metadata_manager protected $template; /** + * phpBB User instance + * @var \phpbb\user + */ + protected $user; + + /** * phpBB root path * @var string */ @@ -65,15 +71,17 @@ class metadata_manager * * @param string $ext_name Name (including vendor) of the extension * @param \phpbb\config\config $config phpBB Config instance - * @param \phpbb\extension\manager $extension_manager An instance of the phpBBb extension manager - * @param \phpbb\template\template $template phpBB Template instance + * @param \phpbb\extension\manager $extension_manager An instance of the phpBB extension manager + * @param \phpbb\template\template $template phpBB Template instance + * @param \phpbb\user $user User instance * @param string $phpbb_root_path Path to the phpbb includes directory. */ - public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, $phpbb_root_path) + public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, \phpbb\user $user, $phpbb_root_path) { $this->config = $config; $this->extension_manager = $extension_manager; $this->template = $template; + $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->ext_name = $ext_name; @@ -141,7 +149,7 @@ class metadata_manager if (!file_exists($this->metadata_file)) { - throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file); + throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file)); } } @@ -154,18 +162,18 @@ class metadata_manager { if (!file_exists($this->metadata_file)) { - throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file); + throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file)); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - throw new \phpbb\extension\exception('file_get_contents failed on ' . $this->metadata_file); + throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file)); } if (($metadata = json_decode($file_contents, true)) === null) { - throw new \phpbb\extension\exception('json_decode failed on ' . $this->metadata_file); + throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file)); } $this->metadata = $metadata; @@ -224,12 +232,12 @@ class metadata_manager { if (!isset($this->metadata[$name])) { - throw new \phpbb\extension\exception("Required meta field '$name' has not been set."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', $name)); } if (!preg_match($fields[$name], $this->metadata[$name])) { - throw new \phpbb\extension\exception("Meta field '$name' is invalid."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_INVALID', $name)); } } break; @@ -247,14 +255,14 @@ class metadata_manager { if (empty($this->metadata['authors'])) { - throw new \phpbb\extension\exception("Required meta field 'authors' has not been set."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'authors')); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - throw new \phpbb\extension\exception("Required meta field 'author name' has not been set."); + throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'author name')); } } diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index d83fa90a8e..10efe5fd1c 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -332,6 +332,99 @@ class log implements \phpbb\log\log_interface } /** + * {@inheritDoc} + */ + public function delete($mode, $conditions = array()) + { + switch ($mode) + { + case 'admin': + $log_type = LOG_ADMIN; + break; + + case 'mod': + $log_type = LOG_MOD; + break; + + case 'user': + $log_type = LOG_USERS; + break; + + case 'users': + $log_type = LOG_USERS; + break; + + case 'critical': + $log_type = LOG_CRITICAL; + break; + + default: + $log_type = false; + } + + /** + * Allows to modify log data before we delete it from the database + * + * NOTE: if sql_ary does not contain a log_type value, the entry will + * not be deleted in the database. So ensure to set it, if needed. + * + * @event core.delete_log + * @var string mode Mode of the entry we log + * @var string log_type Type ID of the log (should be different than false) + * @var array conditions An array of conditions, 3 different forms are accepted + * 1) <key> => <value> transformed into 'AND <key> = <value>' (value should be an integer) + * 2) <key> => array(<operator>, <value>) transformed into 'AND <key> <operator> <value>' (values can't be an array) + * 3) <key> => array('IN' => array(<values>)) transformed into 'AND <key> IN <values>' + * A special field, keywords, can also be defined. In this case only the log entries that have the keywords in log_operation or log_data will be deleted. + * @since 3.1.0-b4 + */ + $vars = array( + 'mode', + 'log_type', + 'conditions', + ); + extract($this->dispatcher->trigger_event('core.delete_log', compact($vars))); + + if ($log_type === false) + { + return; + } + + $sql_where = 'WHERE log_type = ' . $log_type; + + if (isset($conditions['keywords'])) + { + $sql_where .= $this->generate_sql_keyword($conditions['keywords'], ''); + + unset($conditions['keywords']); + } + + foreach ($conditions as $field => $field_value) + { + $sql_where .= ' AND '; + + if (is_array($field_value) && sizeof($field_value) == 2 && !is_array($field_value[1])) + { + $sql_where .= $field . ' ' . $field_value[0] . ' ' . $field_value[1]; + } + else if (is_array($field_value) && isset($field_value['IN']) && is_array($field_value['IN'])) + { + $sql_where .= $this->db->sql_in_set($field, $field_value['IN']); + } + else + { + $sql_where .= $field . ' = ' . $field_value; + } + } + + $sql = 'DELETE FROM ' . LOG_TABLE . " + $sql_where"; + $this->db->sql_query($sql); + + $this->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CLEAR_' . strtoupper($mode)); + } + + /** * Grab the logs from the database * * {@inheritDoc} @@ -638,11 +731,13 @@ class log implements \phpbb\log\log_interface /** * Generates a sql condition for the specified keywords * - * @param string $keywords The keywords the user specified to search for + * @param string $keywords The keywords the user specified to search for + * @param string $table_alias The alias of the logs' table ('l.' by default) + * @param string $statement_operator The operator used to prefix the statement ('AND' by default) * * @return string Returns the SQL condition searching for the keywords */ - protected function generate_sql_keyword($keywords) + protected function generate_sql_keyword($keywords, $table_alias = 'l.', $statement_operator = 'AND') { // Use no preg_quote for $keywords because this would lead to sole // backslashes being added. We also use an OR connection here for @@ -687,12 +782,12 @@ class log implements \phpbb\log\log_interface } } - $sql_keywords = 'AND ('; + $sql_keywords = ' ' . $statement_operator . ' ('; if (!empty($operations)) { - $sql_keywords .= $this->db->sql_in_set('l.log_operation', $operations) . ' OR '; + $sql_keywords .= $this->db->sql_in_set($table_alias . 'log_operation', $operations) . ' OR '; } - $sql_lower = $this->db->sql_lower_text('l.log_data'); + $sql_lower = $this->db->sql_lower_text($table_alias . 'log_data'); $sql_keywords .= " $sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; } diff --git a/phpBB/phpbb/log/log_interface.php b/phpBB/phpbb/log/log_interface.php index 2a44ebecb6..5932f722aa 100644 --- a/phpBB/phpbb/log/log_interface.php +++ b/phpBB/phpbb/log/log_interface.php @@ -69,6 +69,18 @@ interface log_interface public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()); /** + * Delete entries in the logs + * + * @param string $mode The mode defines which log_type is used and from which log the entries are deleted + * @param array $conditions An array of conditions, 3 different forms are accepted + * 1) <key> => <value> transformed into 'AND <key> = <value>' (value should be an integer) + * 2) <key> => array(<operator>, <value>) transformed into 'AND <key> <operator> <value>' (values can't be an array) + * 3) <key> => array('IN' => array(<values>)) transformed into 'AND <key> IN <values>' + * A special field, keywords, can also be defined. In this case only the log entries that have the keywords in log_operation or log_data will be deleted. + */ + public function delete($mode, $conditions = array()); + + /** * Grab the logs from the database * * @param string $mode The mode defines which log_type is used and ifrom which log the entry is retrieved diff --git a/phpBB/phpbb/log/null.php b/phpBB/phpbb/log/null.php index 7b11cc9e21..baa78895ea 100644 --- a/phpBB/phpbb/log/null.php +++ b/phpBB/phpbb/log/null.php @@ -51,6 +51,13 @@ class null implements log_interface /** * {@inheritdoc} */ + public function delete($mode, $conditions = array()) + { + } + + /** + * {@inheritdoc} + */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { return array(); |