createProgressBar() public method

public createProgressBar ( $max )
Esempio n. 1
0
 /**
  * Create a styled progress bar
  *
  * @param  integer $max Max value for the progress bar
  * @return \Symfony\Component\Console\Helper\ProgressBar
  */
 protected function create_progress_bar($max)
 {
     $progress = $this->io->createProgressBar($max);
     if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
         $progress->setFormat('<info>[%percent:3s%%]</info> %message%');
         $progress->setOverwrite(false);
     } else {
         if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
             $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
             $progress->setOverwrite(false);
         } else {
             $this->io->newLine(2);
             $progress->setFormat("    %current:s%/%max:s% %bar%  %percent:3s%%\n" . "        %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n");
             $progress->setBarWidth(60);
         }
     }
     if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
         $progress->setEmptyBarCharacter('░');
         // light shade character \u2591
         $progress->setProgressCharacter('');
         $progress->setBarCharacter('▓');
         // dark shade character \u2593
     }
     return $progress;
 }
Esempio n. 2
0
 /**
  * Reparse all text handled by given reparser within given range
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param string $name Reparser name
  * @return null
  */
 protected function reparse(InputInterface $input, OutputInterface $output, $name)
 {
     $reparser = $this->reparsers[$name];
     if ($input->getOption('dry-run')) {
         $reparser->disable_save();
     } else {
         $reparser->enable_save();
     }
     // Start at range-max if specified or at the highest ID otherwise
     $max = is_null($input->getOption('range-max')) ? $reparser->get_max_id() : $input->getOption('range-max');
     $min = $input->getOption('range-min');
     $size = $input->getOption('range-size');
     if ($max === 0) {
         return;
     }
     $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max));
     $progress = $this->io->createProgressBar($max);
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
         $progress->setFormat('<info>[%percent:3s%%]</info> %message%');
         $progress->setOverwrite(false);
     } else {
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
             $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
             $progress->setOverwrite(false);
         } else {
             $this->io->newLine(2);
             $progress->setFormat("    %current:s%/%max:s% %bar%  %percent:3s%%\n" . "        %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n");
             $progress->setBarWidth(60);
         }
     }
     $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', str_replace('text_reparser.', '', $name)));
     if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
         $progress->setEmptyBarCharacter('░');
         // light shade character \u2591
         $progress->setProgressCharacter('');
         $progress->setBarCharacter('▓');
         // dark shade character \u2593
     }
     $progress->start();
     // Start from $max and decrement $current by $size until we reach $min
     $current = $max;
     while ($current >= $min) {
         $start = max($min, $current + 1 - $size);
         $end = max($min, $current);
         $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $start, $end));
         $reparser->reparse_range($start, $end);
         $current = $start - 1;
         $progress->setProgress($max + 1 - $start);
     }
     $progress->finish();
     $this->io->newLine(2);
 }
Esempio n. 3
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->dispatcher = $this->getContainer()->get('event_dispatcher');
     $this->output = new SymfonyStyle($input, $output);
     $this->dispatcher->dispatch(BotEvent::START, BotEvent::create('START'));
     $this->output->title((new \DateTime())->format('Y-m-d H:i:s') . 'Starting ' . $this->getContainer()->getParameter('name'));
     $this->updateModules();
     $this->fillIgnoredRepository();
     /** @var Discord $discord */
     $discord = $this->getContainer()->get('discord');
     $this->dispatcher->dispatch(BotEvent::PREPARE, BotEvent::create('PREPARE'));
     $discord->on('error', [$this, 'logError']);
     $servers = 0;
     $progress = null;
     $this->output->note('Loading up servers. Please wait.');
     $progress = $this->output->createProgressBar($this->getTotalServers());
     $discord->on('available', function () use(&$servers, $progress) {
         $servers++;
         $this->updateServerFile($servers);
         if ($progress !== null) {
             $progress->advance();
         }
     });
     $discord->on('ready', function () use($discord, &$servers, $progress) {
         $this->dispatcher->dispatch(BotEvent::READY_START, BotEvent::create('READY_START'));
         $this->updateServerFile($servers);
         if ($progress !== null) {
             $progress->finish();
             $this->output->newLine(2);
         }
         $this->getContainer()->get('listener.discord')->listen();
         $this->output->success('Bot is ready!');
         $this->createServerManagers();
         $status = $this->getContainer()->getParameter('status');
         $this->output->note('Setting status to: ' . $status['name']);
         $discord->updatePresence($discord->factory(Game::class, $status), false);
         $this->dispatcher->dispatch(BotEvent::READY_FINISH, BotEvent::create('READY_FINISH'));
     });
     try {
         $discord->run();
     } catch (ContextErrorException $e) {
     }
 }
Esempio n. 4
0
 /**
  * @phpcsSuppress SlevomatCodingStandard.Typehints.TypeHintDeclaration.missingParameterTypeHint
  * @param int $max
  */
 public function createProgressBar($max = 0) : ProgressBar
 {
     $this->progressBar = parent::createProgressBar($max);
     return $this->progressBar;
 }
Esempio n. 5
0
 public function createProgressBar($max = 0)
 {
     $progress = $this->interactive->createProgressBar($max);
     $progress->setBarWidth(Cli::getConsoleWidth() - 12 - strlen($max) * 2);
     return $progress;
 }
Esempio n. 6
0
    /**
     * Executes the command thumbnail:generate.
     *
     * Generate a thumbnail for all attachments which need one and don't have it yet.
     *
     * @param InputInterface $input The input stream used to get the argument and verboe option.
     * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
     *
     * @return int 0.
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->section($this->user->lang('CLI_THUMBNAIL_GENERATING'));
        $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
        $this->db->sql_freeresult($result);
        if ($nb_missing_thumbnails === 0) {
            $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
            return 0;
        }
        $extensions = $this->cache->obtain_attach_extensions(true);
        $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        if (!function_exists('create_thumbnail')) {
            require $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
        }
        $progress = $io->createProgressBar($nb_missing_thumbnails);
        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
            $progress->setFormat('<info>[%percent:3s%%]</info> %message%');
            $progress->setOverwrite(false);
        } else {
            if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
                $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
                $progress->setOverwrite(false);
            } else {
                $io->newLine(2);
                $progress->setFormat("    %current:s%/%max:s% %bar%  %percent:3s%%\n" . "                         %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)) {
            if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE) {
                $source = $this->phpbb_root_path . 'files/' . $row['physical_filename'];
                $destination = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
                if (create_thumbnail($source, $destination, $row['mimetype'])) {
                    $thumbnail_created[] = (int) $row['attach_id'];
                    if (count($thumbnail_created) === 250) {
                        $this->commit_changes($thumbnail_created);
                        $thumbnail_created = array();
                    }
                    $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
                } else {
                    $progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
                }
            }
            $progress->advance();
        }
        $this->db->sql_freeresult($result);
        if (!empty($thumbnail_created)) {
            $this->commit_changes($thumbnail_created);
        }
        $progress->finish();
        $io->newLine(2);
        $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE'));
        return 0;
    }
Esempio n. 7
0
    /**
     * Executes the command thumbnail:delete.
     *
     * Deletes all existing thumbnails and updates the database accordingly.
     *
     * @param InputInterface $input The input stream used to get the argument and verbose option.
     * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
     *
     * @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted.
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->section($this->user->lang('CLI_THUMBNAIL_DELETING'));
        $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 1';
        $result = $this->db->sql_query($sql);
        $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
        $this->db->sql_freeresult($result);
        if ($nb_missing_thumbnails === 0) {
            $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
            return 0;
        }
        $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 1';
        $result = $this->db->sql_query($sql);
        $progress = $io->createProgressBar($nb_missing_thumbnails);
        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
            $progress->setFormat('<info>[%percent:3s%%]</info> %message%');
            $progress->setOverwrite(false);
        } else {
            if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
                $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
                $progress->setOverwrite(false);
            } else {
                $io->newLine(2);
                $progress->setFormat("    %current:s%/%max:s% %bar%  %percent:3s%%\n" . "                         %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;
        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 (sizeof($thumbnail_deleted) === 250) {
                    $this->commit_changes($thumbnail_deleted);
                    $thumbnail_deleted = array();
                }
                $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
            } else {
                $return = 1;
                $progress->setMessage('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
            }
            $progress->advance();
        }
        $this->db->sql_freeresult($result);
        if (!empty($thumbnail_deleted)) {
            $this->commit_changes($thumbnail_deleted);
        }
        $progress->finish();
        $io->newLine(2);
        $io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE'));
        return $return;
    }