From 98ab5478e6a74b4325f002c1a5daae9d6dbe80e1 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 12 Jun 2014 14:20:58 +0200 Subject: [ticket/12692] Add a console command to manage the thumbnails PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 111 +++++++++++++++++ phpBB/phpbb/console/command/thumbnail/generate.php | 133 +++++++++++++++++++++ phpBB/phpbb/console/command/thumbnail/recreate.php | 84 +++++++++++++ 3 files changed, 328 insertions(+) create mode 100644 phpBB/phpbb/console/command/thumbnail/delete.php create mode 100644 phpBB/phpbb/console/command/thumbnail/generate.php create mode 100644 phpBB/phpbb/console/command/thumbnail/recreate.php (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php new file mode 100644 index 0000000000..81f1baf1db --- /dev/null +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -0,0 +1,111 @@ + +* @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 delete extends \phpbb\console\command\command +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\user */ + protected $user; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * Constructor + * + * @param \phpbb\db\driver\driver_interface $db Database connection + * @param \phpbb\user $user The user object (used to get language information) + * @param string $phpbb_root_path Root path + */ + public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path) + { + $this->db = $db; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + parent::__construct(); + } + + /** + * 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. + * + * @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) + { + $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype + FROM ' . ATTACHMENTS_TABLE . ' + WHERE thumbnail = 1'; + $result = $this->db->sql_query($sql); + + $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 ($input->getOption('verbose')) + { + $output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); + } + } + else + { + if ($input->getOption('verbose')) + { + $return = 1; + $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + } + } + } + $this->db->sql_freeresult($result); + + if (sizeof($thumbnail_deleted)) + { + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET thumbnail = 0 + WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted); + $this->db->sql_query($sql); + } + + return $return; + } +} diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php new file mode 100644 index 0000000000..dcf60e4fe2 --- /dev/null +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -0,0 +1,133 @@ + +* @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; + +class generate extends \phpbb\console\command\command +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\user */ + protected $user; + + /** @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\db\driver\driver_interface $db Database connection + * @param \phpbb\user $user The user object (used to get language information) + * @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\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->user = $user; + $this->cache = $cache; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + parent::__construct(); + } + + /** + * 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. + * + * @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) + { + $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); + } + + $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'])) + { + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + } + } + else + { + $thumbnail_created[] = $row['attach_id']; + if ($input->getOption('verbose')) + { + $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); + } + } + } + } + $this->db->sql_freeresult($result); + + if (sizeof($thumbnail_created)) + { + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET thumbnail = 1 + WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created); + $this->db->sql_query($sql); + } + + return 0; + } +} diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php new file mode 100644 index 0000000000..569642f2a4 --- /dev/null +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -0,0 +1,84 @@ + +* @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 +{ + /** @var \phpbb\user */ + protected $user; + + /** + * Constructor + * + * @param \phpbb\user $user The user object (used to get language information) + */ + public function __construct(\phpbb\user $user) + { + $this->user = $user; + parent::__construct(); + } + + /** + * 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. + * + * @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['-v'] = 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; + } +} -- cgit v1.2.1 From 074dfdbdfea364cc2796d69c4d27535ab19fdac7 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 13 Jun 2014 15:46:09 +0200 Subject: [ticket/12692] Update doc blocks PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 4 +++- phpBB/phpbb/console/command/thumbnail/generate.php | 2 ++ phpBB/phpbb/console/command/thumbnail/recreate.php | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 81f1baf1db..707c05ffea 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -61,7 +61,9 @@ class delete extends \phpbb\console\command\command /** * Executes the command thumbnail:delete. * - * @param InputInterface $input The input stream used to get the argument and verboe option. + * Delete all the existing thumbnails (and update the database in consequences). + * + * @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. diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index dcf60e4fe2..bbe6677650 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -74,6 +74,8 @@ class generate extends \phpbb\console\command\command /** * 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. * diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 569642f2a4..71c5d90654 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -48,6 +48,8 @@ class recreate extends \phpbb\console\command\command /** * 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. * -- cgit v1.2.1 From 3a0883e93ebd542c1cf67203b4c17456d8308426 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 13 Jun 2014 21:43:44 +0200 Subject: [ticket/12692] Use !empty() instead of sizeof() PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 2 +- phpBB/phpbb/console/command/thumbnail/generate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 707c05ffea..ba6fdf7ce6 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -100,7 +100,7 @@ class delete extends \phpbb\console\command\command } $this->db->sql_freeresult($result); - if (sizeof($thumbnail_deleted)) + if (!empty($thumbnail_deleted)) { $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET thumbnail = 0 diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index bbe6677650..ac9d18d933 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -122,7 +122,7 @@ class generate extends \phpbb\console\command\command } $this->db->sql_freeresult($result); - if (sizeof($thumbnail_created)) + if (!empty($thumbnail_created)) { $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET thumbnail = 1 -- cgit v1.2.1 From 3924428050d4225c073876bd0e22cf4e9f54138e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 13 Jun 2014 21:47:35 +0200 Subject: [ticket/12692] Use strict comparison in thumbnail:recreate PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/recreate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 71c5d90654..69ea67e410 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -71,7 +71,7 @@ class recreate extends \phpbb\console\command\command $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); - if ($return == 0) + if ($return === 0) { $parameters['command'] = 'thumbnail:generate'; -- cgit v1.2.1 From ed0e1590800e00b19115ad1712e75f33d3080a5e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:13:34 +0200 Subject: [ticket/12692] Fix coding style PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 2 +- phpBB/phpbb/console/command/thumbnail/recreate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index ba6fdf7ce6..52a6c424e6 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; -class delete extends \phpbb\console\command\command +class delete extends \phpbb\console\command\command { /** @var \phpbb\db\driver\driver_interface */ protected $db; diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 69ea67e410..dd10da9106 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -16,7 +16,7 @@ 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 +class recreate extends \phpbb\console\command\command { /** @var \phpbb\user */ protected $user; -- cgit v1.2.1 From 3f0fa70e3afb0ce2dbca72bd74b17c93a2756e02 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:14:26 +0200 Subject: [ticket/12692] Update comments PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 52a6c424e6..82a53727ab 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -61,7 +61,7 @@ class delete extends \phpbb\console\command\command /** * Executes the command thumbnail:delete. * - * Delete all the existing thumbnails (and update the database in consequences). + * 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. -- cgit v1.2.1 From 6b5fdc730fe1b73bab9ecfe748009bc90d1950f3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:16:28 +0200 Subject: [ticket/12692] Remove a not and swap the blocks in the corresponding if PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/generate.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index ac9d18d933..1cfb2159d9 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -103,19 +103,19 @@ class generate extends \phpbb\console\command\command $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'])) + if (create_thumbnail($source, $destination, $row['mimetype'])) { + $thumbnail_created[] = $row['attach_id']; if ($input->getOption('verbose')) { - $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); } } else { - $thumbnail_created[] = $row['attach_id']; if ($input->getOption('verbose')) { - $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); + $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } } -- cgit v1.2.1 From c96cc2cb05de05c9599ca27241e903ea6fada3a3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:17:26 +0200 Subject: [ticket/12692] Cast the ids to int PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/generate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 1cfb2159d9..1070b7b37a 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -105,7 +105,7 @@ class generate extends \phpbb\console\command\command if (create_thumbnail($source, $destination, $row['mimetype'])) { - $thumbnail_created[] = $row['attach_id']; + $thumbnail_created[] = (int) $row['attach_id']; if ($input->getOption('verbose')) { $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); -- cgit v1.2.1 From 54be6b1f622cf394f3cb2c7eb5f2c27072018baa Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:24:45 +0200 Subject: [ticket/12692] Update the database regularly PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 25 ++++++++++++++++++---- phpBB/phpbb/console/command/thumbnail/generate.php | 25 ++++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 82a53727ab..7c66011d5c 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -84,6 +84,13 @@ class delete extends \phpbb\console\command\command if (@unlink($thumbnail_path)) { $thumbnail_deleted[] = $row['attach_id']; + + if (sizeof($thumbnail_deleted) === 250) + { + $this->commit_changes($thumbnail_deleted); + $thumbnail_deleted = array(); + } + if ($input->getOption('verbose')) { $output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); @@ -102,12 +109,22 @@ class delete extends \phpbb\console\command\command if (!empty($thumbnail_deleted)) { - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET thumbnail = 0 - WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted); - $this->db->sql_query($sql); + $this->commit_changes($thumbnail_deleted); } 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); + } } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 1070b7b37a..c27d91d4d5 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -106,6 +106,13 @@ class generate extends \phpbb\console\command\command if (create_thumbnail($source, $destination, $row['mimetype'])) { $thumbnail_created[] = (int) $row['attach_id']; + + if (sizeof($thumbnail_created) === 250) + { + $this->commit_changes($thumbnail_created); + $thumbnail_created = array(); + } + if ($input->getOption('verbose')) { $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); @@ -124,12 +131,22 @@ class generate extends \phpbb\console\command\command if (!empty($thumbnail_created)) { - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET thumbnail = 1 - WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created); - $this->db->sql_query($sql); + $this->commit_changes($thumbnail_created); } 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); + } } -- cgit v1.2.1 From 487fea8cfffe872e888ebcc3e1f5538b72bcaec1 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 22 Jul 2014 16:24:40 +0200 Subject: [ticket/12692] Move the language strings to cli.php PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 16 +++++++--------- phpBB/phpbb/console/command/thumbnail/generate.php | 19 ++++++++++--------- phpBB/phpbb/console/command/thumbnail/recreate.php | 14 -------------- 3 files changed, 17 insertions(+), 32 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 7c66011d5c..b60ea5238f 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -13,17 +13,15 @@ namespace phpbb\console\command\thumbnail; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; class delete extends \phpbb\console\command\command { - /** @var \phpbb\db\driver\driver_interface */ + /** + * @var \phpbb\db\driver\driver_interface + */ protected $db; - /** @var \phpbb\user */ - protected $user; - /** * phpBB root path * @var string @@ -33,16 +31,16 @@ class delete extends \phpbb\console\command\command /** * Constructor * - * @param \phpbb\db\driver\driver_interface $db Database connection * @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\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path) + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_root_path) { $this->db = $db; - $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; - parent::__construct(); + + parent::__construct($user); } /** diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index c27d91d4d5..640d971b5d 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -17,13 +17,14 @@ use Symfony\Component\Console\Output\OutputInterface; class generate extends \phpbb\console\command\command { - /** @var \phpbb\db\driver\driver_interface */ + /** + * @var \phpbb\db\driver\driver_interface + */ protected $db; - /** @var \phpbb\user */ - protected $user; - - /** @var \phpbb\cache\service */ + /** + * @var \phpbb\cache\service + */ protected $cache; /** @@ -42,20 +43,20 @@ class generate extends \phpbb\console\command\command /** * Constructor * - * @param \phpbb\db\driver\driver_interface $db Database connection * @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\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext) + 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->user = $user; $this->cache = $cache; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - parent::__construct(); + + parent::__construct($user); } /** diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index dd10da9106..624e4e507f 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -18,20 +18,6 @@ use Symfony\Component\Console\Output\OutputInterface; class recreate extends \phpbb\console\command\command { - /** @var \phpbb\user */ - protected $user; - - /** - * Constructor - * - * @param \phpbb\user $user The user object (used to get language information) - */ - public function __construct(\phpbb\user $user) - { - $this->user = $user; - parent::__construct(); - } - /** * Sets the command name and description * -- cgit v1.2.1 From 24e39545ae77a78fb1f5350b4fe5658c924ad75c Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 15:18:08 +0200 Subject: [ticket/12692] Add output PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 30 ++++++++++++++++++++++ phpBB/phpbb/console/command/thumbnail/generate.php | 30 ++++++++++++++++++++++ phpBB/phpbb/console/command/thumbnail/recreate.php | 3 +++ 3 files changed, 63 insertions(+) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index b60ea5238f..b57fcc681f 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -68,11 +68,31 @@ class delete extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails + FROM ' . ATTACHMENTS_TABLE . ' + WHERE thumbnail = 1'; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; + if ($nb_missing_thumbnails === 0) + { + $output->writeln('' . $this->user->lang('NO_THUMBNAIL_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); + if (!$input->getOption('verbose')) + { + $progress = $this->getHelper('progress'); + $progress->start($output, $nb_missing_thumbnails); + } + $thumbnail_deleted = array(); $return = 0; while ($row = $this->db->sql_fetchrow($result)) @@ -102,6 +122,11 @@ class delete extends \phpbb\console\command\command $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } + + if (!$input->getOption('verbose')) + { + $progress->advance(); + } } $this->db->sql_freeresult($result); @@ -110,6 +135,11 @@ class delete extends \phpbb\console\command\command $this->commit_changes($thumbnail_deleted); } + if (!$input->getOption('verbose')) + { + $progress->finish(); + } + return $return; } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 640d971b5d..068bd0ff94 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -84,6 +84,20 @@ class generate extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails + FROM ' . ATTACHMENTS_TABLE . ' + WHERE thumbnail = 0'; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; + if ($nb_missing_thumbnails === 0) + { + $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_GENERATE') . ''); + return 0; + } + $extensions = $this->cache->obtain_attach_extensions(true); $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype @@ -96,6 +110,12 @@ class generate extends \phpbb\console\command\command require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); } + if (!$input->getOption('verbose')) + { + $progress = $this->getHelper('progress'); + $progress->start($output, $nb_missing_thumbnails); + } + $thumbnail_created = array(); while ($row = $this->db->sql_fetchrow($result)) { @@ -127,6 +147,11 @@ class generate extends \phpbb\console\command\command } } } + + if (!$input->getOption('verbose')) + { + $progress->advance(); + } } $this->db->sql_freeresult($result); @@ -135,6 +160,11 @@ class generate extends \phpbb\console\command\command $this->commit_changes($thumbnail_created); } + if (!$input->getOption('verbose')) + { + $progress->finish(); + } + return 0; } diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 624e4e507f..ec093161af 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -54,6 +54,7 @@ class recreate extends \phpbb\console\command\command $this->getApplication()->setAutoExit(false); + $output->writeln('' . $this->user->lang('THUMBNAIL_DELETING') . ''); $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); @@ -61,6 +62,8 @@ class recreate extends \phpbb\console\command\command { $parameters['command'] = 'thumbnail:generate'; + $output->writeln(''); + $output->writeln('' . $this->user->lang('THUMBNAIL_GENERATING') . ''); $input_create = new ArrayInput($parameters); $return = $this->getApplication()->run($input_create, $output); } -- cgit v1.2.1 From 0f789f4d5ac39f056569544eb1fad3545d80e9d3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 16:23:12 +0200 Subject: [ticket/12692] Fix languages files PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 3 +-- phpBB/phpbb/console/command/thumbnail/generate.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index b57fcc681f..3a60271fc2 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -72,10 +72,9 @@ class delete extends \phpbb\console\command\command FROM ' . ATTACHMENTS_TABLE . ' WHERE thumbnail = 1'; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails'); $this->db->sql_freeresult($result); - $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; if ($nb_missing_thumbnails === 0) { $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_DELETE') . ''); diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 068bd0ff94..d7530881f1 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -88,10 +88,9 @@ class generate extends \phpbb\console\command\command FROM ' . ATTACHMENTS_TABLE . ' WHERE thumbnail = 0'; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails'); $this->db->sql_freeresult($result); - $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; if ($nb_missing_thumbnails === 0) { $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_GENERATE') . ''); -- cgit v1.2.1 From e3e293f5a6b38bb85f57841756a362e26b09088b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 30 Aug 2014 18:17:23 +0200 Subject: [ticket/12692] Cleanup language file PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 6 +++--- phpBB/phpbb/console/command/thumbnail/generate.php | 6 +++--- phpBB/phpbb/console/command/thumbnail/recreate.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 3a60271fc2..fb63f7c510 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -77,7 +77,7 @@ class delete extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_DELETE') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE') . ''); return 0; } @@ -110,7 +110,7 @@ class delete extends \phpbb\console\command\command if ($input->getOption('verbose')) { - $output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); + $output->writeln($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); } } else @@ -118,7 +118,7 @@ class delete extends \phpbb\console\command\command if ($input->getOption('verbose')) { $return = 1; - $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index d7530881f1..0f4a40bd9f 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -93,7 +93,7 @@ class generate extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_GENERATE') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE') . ''); return 0; } @@ -135,14 +135,14 @@ class generate extends \phpbb\console\command\command if ($input->getOption('verbose')) { - $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); + $output->writeln($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); } } else { if ($input->getOption('verbose')) { - $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } } diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index ec093161af..5d3edbd699 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -54,7 +54,7 @@ class recreate extends \phpbb\console\command\command $this->getApplication()->setAutoExit(false); - $output->writeln('' . $this->user->lang('THUMBNAIL_DELETING') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_DELETING') . ''); $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); @@ -63,7 +63,7 @@ class recreate extends \phpbb\console\command\command $parameters['command'] = 'thumbnail:generate'; $output->writeln(''); - $output->writeln('' . $this->user->lang('THUMBNAIL_GENERATING') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_GENERATING') . ''); $input_create = new ArrayInput($parameters); $return = $this->getApplication()->run($input_create, $output); } -- cgit v1.2.1 From 618065ec16030f1d142667473ee2ff42cd80e72b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 8 Jul 2015 16:58:45 +0200 Subject: [ticket/12692] Fix tests and update style PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 63 ++++++++++++++------- phpBB/phpbb/console/command/thumbnail/generate.php | 64 +++++++++++++++------- phpBB/phpbb/console/command/thumbnail/recreate.php | 5 +- 3 files changed, 86 insertions(+), 46 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index fb63f7c510..e8e4cf568e 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -14,6 +14,7 @@ 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 { @@ -68,6 +69,10 @@ class delete extends \phpbb\console\command\command */ 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'; @@ -77,7 +82,7 @@ class delete extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE') . ''); + $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE')); return 0; } @@ -86,12 +91,37 @@ class delete extends \phpbb\console\command\command WHERE thumbnail = 1'; $result = $this->db->sql_query($sql); - if (!$input->getOption('verbose')) + $progress = $io->createProgressBar($nb_missing_thumbnails); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) { - $progress = $this->getHelper('progress'); - $progress->start($output, $nb_missing_thumbnails); + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 } + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING')); + + $progress->start(); + $thumbnail_deleted = array(); $return = 0; while ($row = $this->db->sql_fetchrow($result)) @@ -108,24 +138,15 @@ class delete extends \phpbb\console\command\command $thumbnail_deleted = array(); } - if ($input->getOption('verbose')) - { - $output->writeln($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); - } + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); } else { - if ($input->getOption('verbose')) - { - $return = 1; - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); - } + $return = 1; + $progress->setMessage('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } - if (!$input->getOption('verbose')) - { - $progress->advance(); - } + $progress->advance(); } $this->db->sql_freeresult($result); @@ -134,10 +155,10 @@ class delete extends \phpbb\console\command\command $this->commit_changes($thumbnail_deleted); } - if (!$input->getOption('verbose')) - { - $progress->finish(); - } + $progress->finish(); + + $io->newLine(2); + $io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE')); return $return; } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 0f4a40bd9f..e677db3a97 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -10,10 +10,12 @@ * 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 { @@ -84,6 +86,10 @@ class generate extends \phpbb\console\command\command */ 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'; @@ -93,7 +99,7 @@ class generate extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE') . ''); + $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE')); return 0; } @@ -109,11 +115,36 @@ class generate extends \phpbb\console\command\command require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); } - if (!$input->getOption('verbose')) + $progress = $io->createProgressBar($nb_missing_thumbnails); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { - $progress = $this->getHelper('progress'); - $progress->start($output, $nb_missing_thumbnails); + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); } + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %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 + } + + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING')); + + $progress->start(); $thumbnail_created = array(); while ($row = $this->db->sql_fetchrow($result)) @@ -127,30 +158,21 @@ class generate extends \phpbb\console\command\command { $thumbnail_created[] = (int) $row['attach_id']; - if (sizeof($thumbnail_created) === 250) + if (count($thumbnail_created) === 250) { $this->commit_changes($thumbnail_created); $thumbnail_created = array(); } - if ($input->getOption('verbose')) - { - $output->writeln($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); - } + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); } else { - if ($input->getOption('verbose')) - { - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); - } + $progress->setMessage('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } - if (!$input->getOption('verbose')) - { - $progress->advance(); - } + $progress->advance(); } $this->db->sql_freeresult($result); @@ -159,10 +181,10 @@ class generate extends \phpbb\console\command\command $this->commit_changes($thumbnail_created); } - if (!$input->getOption('verbose')) - { - $progress->finish(); - } + $progress->finish(); + + $io->newLine(2); + $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE')); return 0; } diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 5d3edbd699..382da290bf 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -49,12 +49,11 @@ class recreate extends \phpbb\console\command\command if ($input->getOption('verbose')) { - $parameters['-v'] = true; + $parameters['-' . str_repeat('v', $output->getVerbosity() - 1)] = true; } $this->getApplication()->setAutoExit(false); - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_DELETING') . ''); $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); @@ -62,8 +61,6 @@ class recreate extends \phpbb\console\command\command { $parameters['command'] = 'thumbnail:generate'; - $output->writeln(''); - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_GENERATING') . ''); $input_create = new ArrayInput($parameters); $return = $this->getApplication()->run($input_create, $output); } -- cgit v1.2.1 From d713ce94ff218c2464823cb23dae1007354c60f3 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 12 Apr 2016 10:56:23 -0700 Subject: [ticket/14569] Extract CLI progress bar creation to a method PHPBB3-14569 --- phpBB/phpbb/console/command/thumbnail/delete.php | 27 +--------------------- phpBB/phpbb/console/command/thumbnail/generate.php | 27 +--------------------- 2 files changed, 2 insertions(+), 52 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index e8e4cf568e..cfa9891fbc 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -91,32 +91,7 @@ class delete extends \phpbb\console\command\command WHERE thumbnail = 1'; $result = $this->db->sql_query($sql); - $progress = $io->createProgressBar($nb_missing_thumbnails); - if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); - $progress->setOverwrite(false); - } - else - { - $io->newLine(2); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %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 - } + $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output); $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING')); diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index e677db3a97..64f7555336 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -115,32 +115,7 @@ class generate extends \phpbb\console\command\command require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); } - $progress = $io->createProgressBar($nb_missing_thumbnails); - if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); - $progress->setOverwrite(false); - } - else - { - $io->newLine(2); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %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 - } + $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output); $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING')); -- cgit v1.2.1 From f8fbe3793680af1dae2db2829cfc84068831c52f Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 28 Jun 2017 00:58:03 +0700 Subject: [ticket/14972] replace all occurrences of sizeof() with the count() PHPBB3-14972 --- phpBB/phpbb/console/command/thumbnail/delete.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index cfa9891fbc..9f2ee822be 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -107,7 +107,7 @@ class delete extends \phpbb\console\command\command { $thumbnail_deleted[] = $row['attach_id']; - if (sizeof($thumbnail_deleted) === 250) + if (count($thumbnail_deleted) === 250) { $this->commit_changes($thumbnail_deleted); $thumbnail_deleted = array(); -- cgit v1.2.1 From 96491a70e8b61ba5700c78dd7b20fe9ca9a3b665 Mon Sep 17 00:00:00 2001 From: rubencm Date: Sat, 9 Feb 2019 12:16:47 +0000 Subject: [ticket/15965] Fix hardcoded directory PHPBB3-15965 --- phpBB/phpbb/console/command/thumbnail/delete.php | 11 +++++++++-- phpBB/phpbb/console/command/thumbnail/generate.php | 13 ++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command/thumbnail') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 9f2ee822be..7b95c20cf2 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -18,6 +18,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; class delete extends \phpbb\console\command\command { + /** + * @var \phpbb\config\config + */ + protected $config; + /** * @var \phpbb\db\driver\driver_interface */ @@ -32,12 +37,14 @@ class delete extends \phpbb\console\command\command /** * Constructor * + * @param \config\config $config The config * @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) + public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_root_path) { + $this->config = $config; $this->db = $db; $this->phpbb_root_path = $phpbb_root_path; @@ -101,7 +108,7 @@ class delete extends \phpbb\console\command\command $return = 0; while ($row = $this->db->sql_fetchrow($result)) { - $thumbnail_path = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename']; + $thumbnail_path = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename']; if (@unlink($thumbnail_path)) { diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 64f7555336..1f6582b17b 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -19,6 +19,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; class generate extends \phpbb\console\command\command { + /** + * @var \phpbb\config\config + */ + protected $config; + /** * @var \phpbb\db\driver\driver_interface */ @@ -45,14 +50,16 @@ class generate extends \phpbb\console\command\command /** * Constructor * + * @param \config\config $config The config * @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) + public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext) { + $this->config = $config; $this->db = $db; $this->cache = $cache; $this->phpbb_root_path = $phpbb_root_path; @@ -126,8 +133,8 @@ class generate extends \phpbb\console\command\command { 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']; + $source = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $row['physical_filename']; + $destination = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename']; if (create_thumbnail($source, $destination, $row['mimetype'])) { -- cgit v1.2.1