/** * {@inheritdoc} */ public function prepare() { $this->progress = new ProgressBar($this->output, $this->reader->count()); $this->progress->setFormat($this->verbosity); $this->progress->setRedrawFrequency($this->redrawFrequency); $this->progress->start(); }
/** * @param TaskEvent $event */ public function advanceProgress(TaskEvent $event) { $taskReflection = new ReflectionClass($event->getTask()); $taskName = $taskReflection->getShortName(); $this->progressBar->setFormat($this->progressFormat); $this->progressBar->setMessage($taskName); $this->progressBar->advance(); }
protected function startProgress($num = 2) { if (!$this->getOutput()) { throw new \Exception('Unable to find console output object.'); } $this->bar = new ProgressBar($this->getOutput(), $num); $this->bar->setFormat("%message%\n [%bar%] %percent:3s%% %elapsed% %memory:6s% "); $this->bar->start(); }
public function onStartedProviding(HasStartedProviding $event) { $this->output->writeln(sprintf('<info> - Running <comment>%s</comment> provider into <comment>%s/%s</comment></info>', get_class($event->getEntry()->getProvider()), $event->getEntry()->getIndex(), $event->getEntry()->getType())); $count = $event->getEntry()->getProvider()->count(); if (null !== $count) { $this->progressBar = new ProgressBar($this->output, $count); $this->progressBar->setFormat(self::PROGRESS_BAR_TEMPLATE); } }
/** * @return \Symfony\Component\Console\Helper\ProgressBar */ private function getProgressBar() { if ($this->progressBar === null) { $this->progressBar = new ProgressBar($this->output, $this->getFileCount()); $this->progressBar->setFormat("%message%\n%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%"); $this->output->writeln(''); } return $this->progressBar; }
/** * @param RunnerEvent $runnerEvent */ public function finishProgress(RunnerEvent $runnerEvent) { if ($this->progressBar->getProgress() != $this->progressBar->getMaxSteps()) { $this->progressBar->setFormat('<fg=red>%message%</fg=red>'); $this->progressBar->setMessage('Aborted ...'); } $this->progressBar->finish(); $this->output->writeln(''); }
/** * {@inheritdoc} */ public function start($count, $label = '') { $this->count = $count; $this->current = 0; if ($label) { $this->output->writeln($label); } $this->progress = new ProgressBar($this->output, $count); $this->progress->setFormat('very_verbose'); }
/** * @return int|null|void */ protected function serve() { $this->progress = new ProgressBar($this->output); $this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] %elapsed:6s% %memory:6s%'); Grav::instance()['config']->init(); $destination = $this->input->getArgument('destination') ? $this->input->getArgument('destination') : null; $log = JsonFile::instance(Grav::instance()['locator']->findResource("log://backup.log", true, true)); $backup = ZipBackup::backup($destination, [$this, 'output']); $log->content(['time' => time(), 'location' => $backup]); $log->save(); $this->output->writeln(''); $this->output->writeln(''); }
/** * @param $total * @param OutputInterface $output * @param callable $callback */ public function mainProgressBarAction($total, $output, callable $callback) { // Перенос строки $output->writeln("\n"); // Инициализируем прогресс бар $progress = new ProgressBar($output, $total); $progress->setFormat("<info>%message%\n Фильм %current% из %max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%</info>"); $progress->setMessage('Процесс запущен'); $progress->start(); // Инициализируем цикл и выполняем $progress->setMessage('В процессе...'); for ($i = 0; $i < $total; $i++) { // Задержка sleep(Config::DELAY_BETWEEN_REQUESTS); // Выполняем колбэк $callback(); // Передвигаем прогресс бар $progress->advance(); } // Завершаем прогресс бар $progress->setMessage('Процесс завершен'); $progress->finish(); // Перенос строки $output->writeln("\n"); }
/** * @param int $current * @param PhpFileInfo $file */ public function advance($current, PhpFileInfo $file) { if (!$this->verbose) { return; } if (1 === $current) { $format = '<info>%message%</info>' . "\n" . $this->label . ': <info>%current%</info>/<info>%max%</info>'; $this->progressBar->clear(); $this->progressBar->setFormat($format); } $message = $file->getRelativePathname(); $this->progressBar->setMessage($message); $this->progressBar->clear(); $this->progressBar->advance(); $this->progressBar->display(); }
/** * Run the command. * * @param InputInterface $input * @param OutputInterface $output * * @return void * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { $serviceName = $input->getArgument('service'); $service = $this->serviceManager->getService($serviceName); $hostProvider = $service->getHostProvider(); $this->getApplication()->find('listhosts')->run(new ArrayInput(['service' => $serviceName]), $output); $output->writeln(""); $progress = new ProgressBar($output, 5); $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%'); $progress->setMessage('Checking existing hosts'); $progress->start(); $currentHostCount = count($hostProvider->getHostsForService($service)); if ($service->maxHosts && $currentHostCount >= $service->maxHosts) { throw new Exception("There are already {$currentHostCount}/{$service->maxHosts} hosts for {$serviceName}."); } $newInstance = $currentHostCount + 1; $hostname = sprintf($service->hostnameTemplate, $newInstance); $host = $hostProvider->launch($hostname, $service->hostDefaults); $hostname = $host->getHostname(); // Just check it set the right name $progress->setMessage("Created host " . $hostname . " at " . $hostProvider->getName()); $progress->advance(); sleep(5); $progress->setMessage("Waiting for " . $hostname . " to be ready"); $progress->advance(); while (!$host->isReady()) { $lastState = $host->getState(); $progress->setMessage("Waiting for " . $hostname . " to be ready (Current sate: " . $lastState . ")"); $progress->display(); sleep(10); } if (!empty($service->testUrl)) { $progress->setMessage("Testing host's HTTP response"); $progress->advance(); do { $lastResponse = $host->testHttp($service->testUrl, $service->testUrlHeaders); $progress->setMessage("Testing host's HTTP response (Current response: {$lastResponse})"); $progress->display(); $lastResponse === 200 || sleep(5); } while ($lastResponse !== 200); } $dnsProvider = $service->getDnsProvider(); $recordData = []; foreach ($host->publicIps as $ip) { foreach ($service->dnsRecords as $domain => $domainRecords) { foreach ($domainRecords as $record => $recordSettings) { $data = ['domain' => $domain, 'type' => $ip->version === 6 ? 'AAAA' : 'A', 'name' => sprintf($record, $newInstance), 'value' => $ip->ip]; $recordData[] = $data + $recordSettings; } } } $progress->setMessage("Adding " . count($recordData) . " DNS records to " . $dnsProvider->getName()); $progress->advance(); $dnsProvider->addRecords($recordData); $progress->setMessage('Done!'); $progress->finish(); $output->writeln(""); $output->writeln(""); $this->getApplication()->find('listhosts')->run(new ArrayInput(['service' => $serviceName]), $output); }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $io->title('Exporting databases'); $io->section('Exporting all databases'); $strategies = $this->collectorDbStrategy->collectDatabasesStrategies(); $totalStrategies = count($strategies); $io->writeln($totalStrategies . ' strategie(s) found.'); $progressBar = new ProgressBar($output, $totalStrategies); $progressBar->setFormat(self::PROGRESS_BAR_FORMAT); $progressBar->setMessage('Beginning backuping'); $this->eventDispatcher->dispatch(Events::BACKUP_BEGINS, new BackupBeginsEvent($output)); $progressBar->start(); $reportContent = new \ArrayObject(); foreach ($strategies as $strategy) { $strategyIdentifier = $strategy->getIdentifier(); $setProgressBarMessage = function ($message) use($progressBar, $strategyIdentifier) { $message = "[{$strategyIdentifier}] {$message}"; $progressBar->setMessage($message); $progressBar->display(); }; $exportedFiles = $this->processorDatabaseDumper->dump($strategy, $setProgressBarMessage); $reportContent->append("Backuping of the database: {$strategyIdentifier}"); foreach ($exportedFiles as $file) { $filename = $file->getPath(); $reportContent->append("\t→ {$filename}"); } $progressBar->advance(); } $progressBar->finish(); $io->newLine(2); $io->section('Report'); $io->text($reportContent->getArrayCopy()); $this->eventDispatcher->dispatch(Events::BACKUP_ENDS, new BackupEndsEvent($output)); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->configuration = $this->getHelperSet()->get('configuration')->getConfiguration(); $this->entityManager = $this->getHelperSet()->get('em')->getEntityManager(); $this->questionHelper = $this->getHelperSet()->get('question'); if (!empty($this->configuration['assetsProcessing']['maxPixelSize']) && $this->configuration['assetsProcessing']['maxPixelSize'] > 0) { $this->downscaler = new DownscaleImageManager($this->entityManager, null, $this->configuration['assetsProcessing']['driver'], $this->configuration['assetsProcessing']['maxPixelSize']); $confirmation = new ConfirmationQuestion('<question>Are you sure to downscale all your image documents to ' . $this->configuration['assetsProcessing']['maxPixelSize'] . 'px?</question>', false); if ($this->questionHelper->ask($input, $output, $confirmation)) { $documents = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\Document')->findBy(['mimeType' => ['image/png', 'image/jpeg', 'image/gif', 'image/tiff'], 'raw' => false]); $progress = new ProgressBar($output, count($documents)); $progress->setFormat('verbose'); $progress->start(); foreach ($documents as $document) { $this->downscaler->processDocumentFromExistingRaw($document); $progress->advance(); } $progress->finish(); $text = PHP_EOL . '<info>Every documents have been downscaled, a raw version has been kept.</info>' . PHP_EOL; /* * Clear cache documents */ $assetsClearer = new AssetsClearer(); $assetsClearer->clear(); $text .= $assetsClearer->getOutput() . PHP_EOL; } } else { $text = '<info>Your configuration is not set for downscaling documents.</info>' . PHP_EOL; $text .= 'Add <info>assetsProcessing.maxPixelSize</info> parameter in your <info>config.yml</info> file.' . PHP_EOL; } $output->writeln($text); }
private function reindex(string $locale, OutputInterface $output) { $totalEntities = $this->repository->getTotalCount(); $iterations = $this->getIterations($totalEntities, $this->batchSize); $output->writeln(sprintf('<comment>Total entities:</comment> %s', $totalEntities)); $output->writeln(sprintf('<comment>Batch size:</comment> %s', $this->batchSize)); $output->writeln(sprintf('<comment>Iterations:</comment> %s', count($iterations))); $output->writeln(sprintf('<comment>Locale:</comment> %s', $locale)); $output->writeln('<info>Flushing index</info>'); $this->manager->flushIndex($locale); $progress = new ProgressBar($output, $totalEntities); $progress->setFormat('verbose'); $progress->setRedrawFrequency($this->batchSize); $progress->start(); foreach ($iterations as $iteration) { $entities = $this->getEntities($iteration); foreach ($entities as $entity) { $document = $this->type->createDocument($entity, $locale); $this->manager->addDocument($document); $progress->advance(); } } $progress->finish(); $output->writeln(''); $output->writeln('<info>Optimizing index</info>'); $this->manager->optimizeIndex($locale); }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var ImportAddressService $importAddressService */ $importAddressService = $this->getHelper('container')->getByType('StreetApi\\Services\\ImportAddressService'); $cityId = $input->getArgument('cityId'); $xmlFile = simplexml_load_file($importAddressService->getRootDir() . '/../adresy.xml'); if (!$xmlFile) { $output->writeln(PHP_EOL . '<error>Missing source file!</error>'); return 1; } try { $output->writeLn('<info>Start importing addresses</info>'); $totalCount = $xmlFile->count(); $output->writeln(PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL); $progressBar = new ProgressBar($output, $totalCount); $progressBar->setFormat('%message%' . PHP_EOL . '%bar% %percent:3s% %' . PHP_EOL . 'count: %current%/%max%' . PHP_EOL . 'time: %elapsed:6s%/%estimated:-6s%' . PHP_EOL); $progressBar->setBarCharacter('<info>■</info>'); $progressBar->setEmptyBarCharacter(' '); $progressBar->setProgressCharacter(''); $progressBar->setRedrawFrequency(ceil($totalCount / 100)); $progressBar->start(); $importAddressService->import($xmlFile, $progressBar, $cityId); $output->writeLn(PHP_EOL . '<info>Importing addresses finished</info>'); return 0; } catch (\Exception $e) { $output->writeLn('<error>' . $e->getMessage() . '</error>'); return 1; } }
/** * Run a terminal command * @param [array] $command [description] * @param [path] $directory [description] * @param OutputInterface $output [description] * @return [void] [description] */ private function runProcess($command, $directory, $output, $alias) { $output->writeln(''); if (is_array($command['line'])) { $commandLine = implode(' && ', $command['line']); } else { $commandLine = $command['line']; } $process = new Process($commandLine, $directory); $process->setTimeout(7600); $process->start(); if ($output->isVerbose()) { $process->wait(function ($type, $buffer) { echo $buffer; }); } else { $progress = new ProgressBar($output); $progress->setFormat("<comment>%message%</comment> [%bar%]"); $progress->setMessage($command['title']); $progress->start(); $progress->setRedrawFrequency(10000); while ($process->isRunning()) { $progress->advance(); } $progress->finish(); $progress->clear(); } $output->writeln(''); $output->write('<comment>' . $command['title'] . ' </comment><info>√ done</info>'); }
protected function execute(InputInterface $input, OutputInterface $output) { $constraintDescriber = new \RestSpec\Output\ConstraintDescriber(); $consoleOutput = new \RestSpec\Output\ConsoleOutput($output, $constraintDescriber); $validator = new \RestSpec\Validator\Rest(); $loader = new \RestSpec\Loader(); $loader->run(); try { $useCaseFilter = $input->getArgument('filter'); $api = $input->getOption('api'); $restSpec = Spec\Rest::getInstance(); $restSpecValidator = new \RestSpec\Spec\Validator(); $restSpecValidator->validate($restSpec); $progressBar = new ProgressBar($output); $progressBar->setFormat('Testing your API specs. Already tested: %current% use cases [%bar%]'); $progressBar->start(); $validator->progress(function ($useCases) use($output, $progressBar) { $progressBar->advance(); }); $report = $validator->validate($restSpec, $api, $useCaseFilter); $progressBar->finish(); $output->write($report->dumpAsConsoleText($api, $useCaseFilter)); if ($report->getTotalUseCases() === 0 || $report->getUseCasesFailedCount() > 0) { exit(1); } else { exit(0); } } catch (\Exception $e) { $log = join("\n", $validator->getLog()); $consoleOutput->getOutput()->writeln(sprintf("\n<error>Whoops! Some unexpected error occured. Validation log dump:\n\n%s\n\nThe exception type is: %s, and a message is following:</error>", $log, get_class($e))); $consoleOutput->errorHandler($e, 2); } }
protected function execute(InputInterface $input, OutputInterface $output) { $indexName = $input->getOption('index'); $batchSize = $input->getOption('batch_size'); $indexManager = $this->getIndexManager($indexName); $totalDocuments = $indexManager->getTotalEntities(); $iterations = $this->getIterations($totalDocuments, $batchSize); $output->writeln(sprintf('<info>Reindexing</info> "%s"', $indexName)); $output->writeln(sprintf('<comment>Total documents:</comment> %s', $totalDocuments)); $output->writeln(sprintf('<comment>Batch size:</comment> %s', $batchSize)); $output->writeln(sprintf('<comment>Iterations:</comment> %s', $iterations)); $progress = new ProgressBar($output, $totalDocuments); $progress->setFormat('verbose'); $progress->setRedrawFrequency($batchSize); $progress->start(); $indexManager->purgeIndex(); for ($i = 0; $i < $iterations; $i++) { $criteria = new Criteria(); $criteria->setMaxResults($batchSize); $criteria->setFirstResult($i * $batchSize); $collection = $indexManager->getEntitiesCollection($criteria); $collection->map(function (EntityInterface $entity) use($indexManager, $progress) { $indexManager->addEntity($entity); $progress->advance(); }); } $progress->finish(); $output->writeln(''); $output->writeln(sprintf('<info>Optimizing "%s"</info>', $indexName)); $indexManager->optimizeIndex(); }
/** * (non-PHPdoc) * * @see \Symfony\Component\Console\Command\Command::execute() */ public function execute(InputInterface $input, OutputInterface $output) { $document = $this->getDocument($input->getArgument('document')); $items = $document->getElement(); $directory = sprintf($input->getArgument('elementOutput'), $document->getFileInfo()->getBasename('.dtd')); $namespace = sprintf($input->getArgument('elementNamespace'), $document->getFileInfo()->getBasename('.dtd')); $parentClass = $input->getArgument('elementParentClass'); $description = str_replace("\\", " ", $namespace); if (!file_exists($directory)) { mkdir($directory, 0777, true); } $progressBar = new ProgressBar($output, $items->count()); $progressBar->setFormat('verbose'); foreach ($items as $item) { $name = sprintf("%sElement", Source::camelCase($item->getName())); $filename = sprintf("%s/%s.php", $directory, $name); $classDescription = sprintf("%s %s", $description, $name); $datetime = new \DateTime(); $properties = array((new PropertyGenerator("name", $item->getName()))->setDocBlock(new DocBlockGenerator(sprintf("%s Name", $classDescription), "", array(new Tag("var", "string")))), (new PropertyGenerator("value", $item->getValue()))->setDocBlock(new DocBlockGenerator(sprintf("%s Value", $classDescription), "", array(new Tag("var", "string"))))); $docblock = new DocBlockGenerator($classDescription, "", array(new Tag("author", "ITC Generator " . $datetime->format("d.m.Y h:m:s")), new Tag("copyright", "LGPL"))); $fileGenerator = new FileGenerator(); $fileGenerator->setClass(new ClassGenerator($name, $namespace, null, $parentClass, array(), $properties, array(), $docblock)); file_put_contents($filename, $fileGenerator->generate()); $progressBar->advance(); } $progressBar->finish(); }
/** * Download */ protected function download(OutputInterface &$output, $from, $to) { $output->writeln('Download ' . $from); $progress = new ProgressBar($output); $progress->setFormat('normal_nomax'); $step = 0; $ctx = stream_context_create(array(), array('notification' => function ($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) use($output, $progress, &$step) { switch ($notification_code) { case STREAM_NOTIFY_FILE_SIZE_IS: $progress->start(100); break; case STREAM_NOTIFY_PROGRESS: $newStep = round($bytes_transferred / $bytes_max * 100); if ($newStep > $step) { $step = $newStep; $progress->setProgress($step); } break; } })); $file = file_get_contents($from, false, $ctx); $progress->finish(); file_put_contents($to, $file); $output->writeln(''); return $to; }
/** * Wait for multiple activities to complete. * * @param Activity[] $activities * @param OutputInterface $output */ public static function waitMultiple(array $activities, OutputInterface $output) { $count = count($activities); if ($count <= 0) { return; } $complete = 0; $output->writeln("Waiting..."); $bar = new ProgressBar($output); $bar->start($count); $bar->setFormat('verbose'); while ($complete < $count) { sleep(1); foreach ($activities as $activity) { if (!$activity->isComplete()) { $activity->refresh(); } else { $complete++; } } $bar->setProgress($complete); } $bar->finish(); $output->writeln(''); }
/** * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code * * @throws \LogicException When this abstract method is not implemented * * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { /* @var $em \Doctrine\ORM\EntityManager */ $em = $this->getContainer()->get('doctrine.orm.' . $this->getContainer()->getParameter('geonames.entity_manager')); $connection = $em->getConnection(); $quote = function ($value) use($connection) { return $connection->quote($value); }; // Disable SQL logger $connection->getConfiguration()->setSQLLogger(null); $output->writeln('<info>> Start update Geonames alternate names list</info>'); $file = $this->download($output, 'http://download.geonames.org/export/dump/alternateNames.zip', $this->getTempDir('/alternateNames.zip')); $output->writeln('Clear Geonames alternate names table'); $connection->query('SET FOREIGN_KEY_CHECKS=0'); $connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSql('timiki_geonames_alternate_names')); $connection->query('SET FOREIGN_KEY_CHECKS=1'); $output->writeln('Load new Geonames alternate names list to table...wait'); $output->writeln('Processing downloaded data...'); // Prepare $handler = fopen('zip://' . $file . '#alternateNames.txt', 'r'); $count = 0; while (!feof($handler)) { fgets($handler); $count++; } // rewind fclose($handler); $handler = fopen('zip://' . $file . '#alternateNames.txt', 'r'); $progress = new ProgressBar($output); $progress->setFormat('normal_nomax'); $step = 0; $sql = ''; $progress->start($count); // Output one line until end-of-file while (!feof($handler)) { $step++; $line = fgets($handler); $explode = explode("\t", $line); if (count($explode) > 1) { $isoLanguage = array_key_exists(2, $explode) ? $explode[2] : null; $isHistoric = array_key_exists(7, $explode) ? $explode[7] : null; $isShortName = array_key_exists(5, $explode) ? $explode[5] : null; // Not load not valid data if (!empty($isoLanguage) && $isoLanguage !== 'link' && $isoLanguage !== 'post' && $isoLanguage !== 'iata' && $isoLanguage !== 'icao' && $isoLanguage !== 'faac' && $isoLanguage !== 'fr_1793' && $isoLanguage !== 'abbr' && $isHistoric !== 1 && $isShortName !== 1) { $sql .= $connection->createQueryBuilder()->insert('timiki_geonames_alternate_names')->values(['alternate_name_id' => $quote(array_key_exists(0, $explode) ? $explode[0] : null), 'geoname_id' => $quote(array_key_exists(1, $explode) ? $explode[1] : null), 'iso_language' => $quote(array_key_exists(2, $explode) ? $explode[2] : null), 'alternate_name' => $quote(array_key_exists(3, $explode) ? $explode[3] : null), 'is_preferred_name' => $quote(array_key_exists(4, $explode) ? $explode[4] : null), 'is_short_name' => $quote(array_key_exists(5, $explode) ? $explode[5] : null), 'is_colloquial' => $quote(array_key_exists(6, $explode) ? $explode[6] : null), 'is_historic' => $quote(array_key_exists(7, $explode) ? $explode[7] : null)])->getSQL() . ';'; if ($step % 1000 === 0) { $progress->setProgress($step); $connection->exec($sql); $sql = ''; } } } } $progress->setProgress($step); $connection->exec($sql); fclose($handler); $output->writeln(''); $output->writeln('Done!'); }
/** * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code * * @throws \LogicException When this abstract method is not implemented * * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { /* @var $em \Doctrine\ORM\EntityManager */ $em = $this->getContainer()->get('doctrine.orm.' . $this->getContainer()->getParameter('geonames.entity_manager')); $connection = $em->getConnection(); $population = $this->getContainer()->getParameter('geonames.cities_population'); $quote = function ($value) use($connection) { return $connection->quote($value); }; // Disable SQL logger $connection->getConfiguration()->setSQLLogger(null); $output->writeln('<info>> Start update Geonames list</info>'); if (!in_array($population, [1000, 5000, 15000])) { $output->writeln('<error>False population value set in config "geonames.cities_population". Value must be one of 1000|5000|15000</error>'); } else { $fileName = 'cities' . $population . '.zip'; $file = $this->download($output, 'http://download.geonames.org/export/dump/' . $fileName, $this->getTempDir('/' . $fileName)); $output->writeln('Clear Geonames table'); $connection->query('SET FOREIGN_KEY_CHECKS=0'); $connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSql('timiki_geonames')); $connection->query('SET FOREIGN_KEY_CHECKS=1'); $output->writeln('Load new Geonames list to table...wait'); $output->writeln('Processing downloaded data...'); // Prepare $handler = fopen('zip://' . $file . '#cities' . $population . '.txt', 'r'); $count = 0; while (!feof($handler)) { fgets($handler); $count++; } // rewind fclose($handler); $handler = fopen('zip://' . $file . '#cities' . $population . '.txt', 'r'); $progress = new ProgressBar($output); $progress->setFormat('normal_nomax'); $step = 0; $sql = ''; $progress->start($count); // Load to db while (!feof($handler)) { $step++; $line = fgets($handler); $explode = explode("\t", $line); if (count($explode) > 1) { $sql .= $connection->createQueryBuilder()->insert('timiki_geonames')->values(['geoname_id' => $quote(array_key_exists(0, $explode) ? $explode[0] : null), 'name' => $quote(array_key_exists(1, $explode) ? $explode[1] : null), 'ascii_name' => $quote(array_key_exists(2, $explode) ? $explode[2] : null), 'alternate_names' => $quote(array_key_exists(3, $explode) ? $explode[3] : null), 'latitude' => $quote(array_key_exists(4, $explode) ? $explode[4] : null), 'longitude' => $quote(array_key_exists(5, $explode) ? $explode[5] : null), 'feature_class' => $quote(array_key_exists(6, $explode) ? $explode[6] : null), 'feature_code' => $quote(array_key_exists(7, $explode) ? $explode[7] : null), 'country_code' => $quote(array_key_exists(8, $explode) ? $explode[8] : null), 'cc2' => $quote(array_key_exists(9, $explode) ? $explode[9] : null), 'admin1_code' => $quote(array_key_exists(10, $explode) ? $explode[10] : null), 'admin2_code' => $quote(array_key_exists(11, $explode) ? $explode[11] : null), 'admin3_code' => $quote(array_key_exists(12, $explode) ? $explode[12] : null), 'admin4_code' => $quote(array_key_exists(13, $explode) ? $explode[13] : null), 'population' => $quote(array_key_exists(14, $explode) ? $explode[14] : 0), 'elevation' => $quote(array_key_exists(15, $explode) ? $explode[15] : 0), 'dem' => $quote(array_key_exists(16, $explode) ? $explode[16] : 0), 'timezone' => $quote(array_key_exists(17, $explode) ? $explode[17] : null), 'modification_date' => $quote(array_key_exists(18, $explode) ? $explode[18] : null)])->getSQL() . ';'; if ($step % 1000 === 0) { $progress->setProgress($step); $connection->exec($sql); $sql = ''; } } } $progress->setProgress($step); $connection->exec($sql); fclose($handler); $output->writeln(''); $output->writeln('Done!'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $startTime = microtime(true); $output->writeln("phplint {$this->getApplication()->getVersion()}"); $output->writeln(''); $phpBinary = PHP_BINARY; $path = $input->getArgument('path'); $exclude = $input->getOption('exclude'); $extensions = $input->getOption('extensions'); $procLimit = $input->getOption('jobs'); // $failOnFirst = $input->getOption('fail-on-first'); if ($extensions) { $extensions = explode(',', $extensions); } else { $extensions = array('php'); } $linter = new Linter($path, $exclude, $extensions); if ($procLimit) { $linter->setProcessLimit($procLimit); } $files = $linter->getFiles(); $fileCount = count($files); $progress = new ProgressBar($output, $fileCount); $progress->setBarWidth(50); $progress->setMessage('', 'overview'); $progress->setFormat(" %overview%\n %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%"); $progress->start(); $linter->setProcessCallback(function ($status, $filename) use($progress) { /* $overview = $progress->getMessage('overview'); if ($status == 'ok') { $overview .= '.'; } elseif ($status == 'error') { $overview .= 'F'; // exit(1); } $progress->setMessage($overview, 'overview'); */ $progress->advance(); }); $result = $linter->lint($files); $progress->finish(); $output->writeln(''); $testTime = microtime(true) - $startTime; $code = 0; $errCount = count($result); $out = "<info>Checked {$fileCount} files in " . round($testTime, 1) . " seconds</info>"; if ($errCount > 0) { $out .= "<info> and found syntax errors in </info><error>{$errCount}</error><info> files.</info>"; $out .= "\n" . json_encode($result, JSON_PRETTY_PRINT); $code = 1; } else { $out .= '<info> a no syntax error were deteced.'; } $output->writeln($out . PHP_EOL); return $code; }
/** * @param integer $number */ public function progress($number) { $progress = new ProgressBar($this->output, $number); $progress->setFormat(ProgressHelper::FORMAT_VERBOSE); $progress->start(); $this->progress = $progress; return $progress; }
/** * Progress bar define * * @param \Symfony\Component\Console\Output\OutputInterface $output * @param int $finish * @param string $format * @return \Symfony\Component\Console\Helper\ProgressBar */ public function getProgress(OutputInterface $output, $finish = 100, $format = 'normal') { $progress = new ProgressBar($output, $finish); $progress->setProgressCharacter('ϟ'); $progress->setFormat($format); $progress->setBarCharacter('<comment>=</comment>'); return $progress; }
/** * @param OutputInterface $output * @return ProgressBar */ protected function createProgressBar(OutputInterface $output) { $progress = new ProgressBar($output); $progress->setBarCharacter('<comment>=</comment>'); $progress->setProgressCharacter('|'); $progress->setFormat(self::PROGRESS_BAR_MESSAGE_FORMAT); return $progress; }
protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->get('config'); $client = $this->get('client'); $type = $input->getOption('type'); if (empty($type)) { $type = $config->get('default_type'); } $filter = sprintf('%s is null', self::UNSUBSCRIBE_ATTRIBUTE); if (!empty($input->getArgument('filter'))) { $filter .= ' AND (' . $input->getArgument('filter') . ')'; } // Total count records with unsubscribe attribute value empty / null. $total_count = $this->getEntityCount($type, $filter); $output->writeln(sprintf('<info>Found %d records where "%s"</info>', $total_count, $filter)); // Confirm update. $question = new ConfirmationQuestion(sprintf('Update these %d records? [y/n] ', $total_count), false); $helper = $this->getHelper('question'); if (!$helper->ask($input, $output, $question)) { exit(0); } $progress = new ProgressBar($output, $total_count); $progress->setFormat(" %current%/%max% [%bar%] %percent:3s%% \n%message%"); $updateParams = array('type_name' => $type, 'attributes' => array(self::UNSUBSCRIBE_ATTRIBUTE => '')); $succeed = 0; $failed = 0; $offset = 0; $records = $this->retrieveRecords($this->getQueryParams($offset, $type, $filter)); if (empty($records)) { $output->write('No records to update.'); exit(0); } $progress->setMessage('Retrieving records...'); $progress->start(); while (!empty($records)) { foreach ($records as $record) { $updateParams['attributes'][self::UNSUBSCRIBE_ATTRIBUTE] = sha1($record['uuid'] . $record['created']); $progress->setMessage(sprintf('Update record with id %s', $record['id'])); $result = $client->api('entity')->updateById($record['id'], $updateParams); if ('ok' === strtolower($result['stat'])) { $succeed++; } else { $failed++; } $progress->advance(); } $offset += sizeof($records); $progress->setMessage('Retrieving records...'); $records = $this->retrieveRecords($this->getQueryParams($offset, $type, $filter)); } if ($failed > 0) { $progress->setMessage(sprintf('<info>%d</info> records are successfully updated, but<error>%d</error> records are failed to update. Please try run this command again.', $succeed, $failed)); } else { $progress->setMessage(sprintf('<info>%d</info> records are successfully updated.', $succeed)); } $progress->finish(); exit($failed > 0 ? 1 : 0); }
private function getNotificationCallback($filename) { $notificationCallback = function ($notification_code, $severity, $message, $messageCode, $bytesTransferred, $bytesMax) use($filename) { switch ($notification_code) { case STREAM_NOTIFY_FILE_SIZE_IS: $this->progress = new ProgressBar($this->output, $bytesMax); $this->progress->setFormat('%message% %final_report%' . "\n" . '%percent:3s%% of %photo_size% [%bar%] %downloaded_bytes% eta %estimated:6s%'); $this->progress->setMessage($filename); $this->progress->setMessage('', 'final_report'); $this->progress->start(); break; case STREAM_NOTIFY_PROGRESS: $this->progress->setCurrent($bytesTransferred); break; } }; return $notificationCallback; }
/** * @param ProgressEvent $event * @param string $label */ protected function onProgress($event, $label) { if (0 === $event->getProcessed()) { $format = $label . ': <comment>loading %max% files</comment>'; $this->progressBar->setFormat($format); $this->progressBar->start($event->getTotalNumber()); } elseif ($event->getProcessed() == $event->getTotalNumber()) { $this->progressBar->finish(); $this->output->writeln(''); } else { if (1 === $event->getProcessed()) { $format = $label . ': <info>%current%/%max%</info>'; $this->progressBar->clear(); $this->progressBar->setFormat($format); } $this->progressBar->advance(); } }