1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

[ticket/12692] Fix tests and update style

PHPBB3-12692
This commit is contained in:
Tristan Darricau
2015-07-08 16:58:45 +02:00
parent e3e293f5a6
commit 618065ec16
5 changed files with 134 additions and 78 deletions

View File

@@ -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('<info>' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE') . '</info>');
$io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
return 0;
}
@@ -86,11 +91,36 @@ 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 = $this->getHelper('progress');
$progress->start($output, $nb_missing_thumbnails);
$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" .
" %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_DELETING'));
$progress->start();
$thumbnail_deleted = array();
$return = 0;
@@ -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('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
}
$return = 1;
$progress->setMessage('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
}
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;
}

View File

@@ -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('<info>' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE') . '</info>');
$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('<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" .
" %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('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
}
$progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
}
}
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;
}

View File

@@ -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('<comment>' . $this->user->lang('CLI_THUMBNAIL_DELETING') . '</comment>');
$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('<comment>' . $this->user->lang('CLI_THUMBNAIL_GENERATING') . '</comment>');
$input_create = new ArrayInput($parameters);
$return = $this->getApplication()->run($input_create, $output);
}