clear() public method

This is useful if you wish to write some output while a progress bar is running. Call display() to show the progress bar again.
public clear ( )
Ejemplo n.º 1
0
 private function cleanProgressbar()
 {
     if ($this->progress !== null && $this->progress->getStartTime() !== null) {
         $this->progress->clear();
         $this->output->writeln("");
     }
 }
Ejemplo n.º 2
0
 private function cleanProgressbar()
 {
     if ($this->progress !== null && $this->progress->getStartTime() !== null && $this->progress->getProgress() !== $this->progress->getMaxSteps() && $this->progresseBar === true) {
         $this->progress->clear();
         $this->output->write("\r");
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!Loader::includeModule('search')) {
         throw new BitrixException('Search module is not installed');
     }
     $searchResult = array();
     $bar = new ProgressBar($output, 0);
     do {
         $bar->display();
         $searchResult = \CSearch::ReIndexAll($input->getOption('full'), static::UPDATE_TIME, $searchResult);
         $bar->advance();
         $bar->clear();
         if (is_array($searchResult) && $searchResult['MODULE'] == 'main') {
             list(, $path) = explode("|", $searchResult["ID"], 2);
             $output->writeln("\r       " . $path, OutputInterface::VERBOSITY_VERBOSE);
         }
     } while (is_array($searchResult));
     $bar->finish();
     $bar->clear();
     $output->write("\r");
     if (ModuleManager::isModuleInstalled('socialnetwork')) {
         $output->writeln('<info>The Social Network module needs to be reindexed using the Social Network component in the public section of site.</info>');
     }
     $output->writeln(sprintf('<info>Reindexed</info> %d element%s.', $searchResult, $searchResult > 1 ? 's' : ''));
     return 0;
 }
 public function end()
 {
     if (!$this->verbose) {
         return;
     }
     $this->progressBar->clear();
     $this->progressBar->finish();
 }
Ejemplo n.º 5
0
 /**
  * @return bool
  */
 public function hideProgressIndicator()
 {
     $result = $this->progressBarDisplayed;
     if ($this->progressIndicatorRunning && $this->progressBarDisplayed) {
         $this->progressBar->clear();
         // Hack: progress indicator does not reset cursor to beginning of line on 'clear'
         $this->output->write("\r");
         $this->progressBarDisplayed = false;
     }
     return $result;
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fileIterator = new File_Iterator_Facade();
     $files = $input->getArgument('target');
     $files = $fileIterator->getFilesAsArray($files, '.php');
     $extractor = new Extractor();
     $results = [];
     $progress = new ProgressBar($output, count($files));
     foreach ($files as $file) {
         $results[$file] = $extractor->file($file);
         $progress->advance();
     }
     $progress->clear();
     $namespaces = [];
     foreach ($results as $file => $result) {
         foreach ($result as $dependency) {
             $namespaces[$dependency][] = $file;
         }
     }
     ksort($namespaces);
     $output->writeln('');
     // line break (due to the progress bar not completely clearing out)
     if ($input->getOption('why')) {
         foreach ($namespaces as $namespace => $files) {
             $output->writeln($namespace);
             foreach ($files as $file) {
                 $output->writeln("\t" . $file);
             }
         }
     } else {
         foreach (array_keys($namespaces) as $namespace) {
             $output->writeln($namespace);
         }
     }
 }
 /**
  * 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>');
 }
 /**
  * @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();
     }
 }
Ejemplo n.º 9
0
 protected function importCardsJsonFile(\SplFileInfo $fileinfo, $locale)
 {
     $cardsData = $this->getDataFromFile($fileinfo);
     $progress = new ProgressBar($this->output, count($cardsData));
     $progress->start();
     foreach ($cardsData as $cardData) {
         $progress->advance();
         $this->updateEntityFromData($locale, 'AppBundle\\Entity\\Card', $cardData, ['code', 'name'], ['flavor', 'traits', 'text']);
     }
     $progress->finish();
     $progress->clear();
     $this->output->write("\n");
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Design pattern detector by Jean-François Lépine <https://twitter.com/Halleck45>');
     $output->writeln('');
     $finder = new Finder($input->getOption('extensions'), $input->getOption('excluded-dirs'));
     $files = $finder->find($input->getArgument('path'));
     if (0 == sizeof($files, COUNT_NORMAL)) {
         throw new \LogicException('No file found');
     }
     //
     // 1. Extracting classes
     $output->writeln('<info>Extracting classes</info>');
     $progress = new ProgressBar($output);
     $progress->start(sizeof($files, COUNT_NORMAL));
     $collection = array();
     $tokenizer = new Tokenizer(new CacheMemory());
     $extractor = new Extractor($tokenizer);
     $nbClasses = 0;
     foreach ($files as $k => $filename) {
         $progress->advance();
         $collection[] = $classes = $extractor->extract($filename);
         $nbClasses += sizeof($classes->getClasses());
     }
     $progress->clear();
     $progress->finish();
     // inform user
     $output->writeln('');
     $output->writeln('');
     $output->writeln(sprintf("<info>Found %d classes</info>", $nbClasses));
     //
     // 2. Extracting patterns
     $output->writeln('<info>Extracting design patterns</info>');
     $patterns = array();
     foreach ($collection as $oop) {
         $classes = $oop->getClasses();
         $resolver = new PatternResolver($classes);
         foreach ($classes as $class) {
             $resolvedClass = new ResolvedClass($class);
             $resolver->resolve($resolvedClass);
             if ($resolvedClass->getPatterns()) {
                 $patterns = array_merge($patterns, $resolvedClass->getPatterns());
             }
         }
     }
     // inform user
     $output->writeln(sprintf("<info>Found %d design patterns</info>", sizeof($patterns)));
     $output->writeln();
     foreach ($patterns as $pattern) {
         $output->writeln(sprintf("\t<info>[%s]</info> %s", $pattern->getName(), $pattern->describe()));
     }
 }
 /**
  * Builds a loggerClosure to be called from inside the Provider to update the command
  * line.
  *
  * @param OutputInterface $output
  * @param string          $action
  * @param string          $index
  * @param string          $type
  *
  * @return callable
  */
 public function build(OutputInterface $output, $action, $index, $type)
 {
     if (!class_exists('Symfony\\Component\\Console\\Helper\\ProgressBar') || !is_callable(array('Symfony\\Component\\Console\\Helper\\ProgressBar', 'getProgress'))) {
         return $this->buildLegacy($output, $action, $index, $type);
     }
     $progress = null;
     return function ($increment, $totalObjects, $message = null) use(&$progress, $output, $action, $index, $type) {
         if (null === $progress) {
             $progress = new ProgressBar($output, $totalObjects);
             $progress->start();
         }
         if (null !== $message) {
             $progress->clear();
             $output->writeln(sprintf('<info>%s</info> <error>%s</error>', $action, $message));
             $progress->display();
         }
         $progress->setMessage(sprintf('<info>%s</info> <comment>%s/%s</comment>', $action, $index, $type));
         $progress->advance($increment);
     };
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function set_task_count($task_count, $restart = false)
 {
     parent::set_task_count($task_count, $restart);
     if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
         if ($this->progress_bar !== null) {
             // Symfony's ProgressBar is immutable regarding task_count, so delete the old and create a new one.
             $this->progress_bar->clear();
         } else {
             $this->io->newLine(2);
         }
         $this->progress_bar = $this->io->createProgressBar($task_count);
         $this->progress_bar->setFormat("    %current:3s%/%max:-3s% %bar%  %percent:3s%%\n" . "             %message%\n");
         $this->progress_bar->setBarWidth(60);
         if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
             $this->progress_bar->setEmptyBarCharacter('░');
             // light shade character \u2591
             $this->progress_bar->setProgressCharacter('');
             $this->progress_bar->setBarCharacter('▓');
             // dark shade character \u2593
         }
         $this->progress_bar->setMessage('');
         $this->progress_bar->start();
     }
 }
Ejemplo n.º 13
0
 /**
  * Wait for a single activity to complete, and display the log continuously.
  *
  * @param Activity        $activity
  * @param OutputInterface $output
  * @param string          $success
  * @param string          $failure
  *
  * @return bool
  *   True if the activity succeeded, false otherwise.
  */
 public static function waitAndLog(Activity $activity, OutputInterface $output, $success = null, $failure = null)
 {
     $output->writeln('Waiting for the activity <info>' . $activity->id . '</info> (' . $activity->getDescription() . "):");
     // Initialize a progress bar which will show elapsed time and the
     // activity's state.
     $bar = new ProgressBar($output);
     $bar->setPlaceholderFormatterDefinition('state', function () use($activity) {
         return self::formatState($activity->state);
     });
     $bar->setFormat("  [%bar%] %elapsed:6s% (%state%)");
     $bar->start();
     // Wait for the activity to complete.
     $activity->wait(function () use($bar) {
         $bar->advance();
     }, function ($log) use($output, $bar) {
         // Clear the progress bar and ensure the current line is flushed.
         $bar->clear();
         $output->write($output->isDecorated() ? "\n" : "\n");
         // Display the new log output, with an indent.
         $output->write(preg_replace('/^/m', '    ', $log));
         // Display the progress bar again.
         $bar->advance();
     });
     $bar->finish();
     $output->writeln('');
     // Display the success or failure messages.
     switch ($activity['result']) {
         case Activity::RESULT_SUCCESS:
             $output->writeln($success ?: "Activity <info>{$activity->id}</info> succeeded");
             return true;
         case Activity::RESULT_FAILURE:
             $output->writeln($failure ?: "Activity <error>{$activity->id}</error> failed");
             return false;
     }
     return false;
 }
 /**
  * For given $contentId in $versionNo updates fields of $fieldTypeIdentifier type.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \Symfony\Component\Console\Helper\ProgressBar $progress
  * @param int|string $contentId
  * @param int $versionNo
  * @param string $fieldTypeIdentifier
  * @param boolean $dryRun
  */
 protected function updateField(OutputInterface $output, ProgressBar $progress, $contentId, $versionNo, $fieldTypeIdentifier, $dryRun)
 {
     $container = $this->getContainer();
     /** @var \eZ\Publish\SPI\FieldType\FieldType $fieldType */
     /** @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter $converter */
     /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway $gateway */
     /** @var \eZ\Publish\SPI\Persistence\Content\Handler $contentHandler */
     /** @var \eZ\Publish\API\Repository\ContentService $contentService */
     /** @var \eZ\Publish\API\Repository\ContentTypeService $contentTypeService */
     $fieldType = $container->get("ezpublish.fieldType.{$fieldTypeIdentifier}");
     $converter = $container->get("ezpublish.fieldType.{$fieldTypeIdentifier}.converter");
     $gateway = $container->get("ezpublish.persistence.legacy.content.gateway");
     $contentHandler = $container->get("ezpublish.spi.persistence.legacy.content.handler");
     $contentService = $container->get("ezpublish.api.service.content");
     $contentTypeService = $container->get("ezpublish.api.service.content_type");
     $content = $contentService->loadContent($contentId, null, $versionNo);
     $spiContent = $contentHandler->load($contentId, $versionNo);
     $contentType = $contentTypeService->loadContentType($content->contentInfo->contentTypeId);
     foreach ($content->getFields() as $field) {
         $fieldDefinition = $contentType->getFieldDefinition($field->fieldDefIdentifier);
         // Match API field by field type
         if ($fieldDefinition->fieldTypeIdentifier != $fieldTypeIdentifier) {
             continue;
         }
         foreach ($spiContent->fields as $spiField) {
             // Match SPI field with API field by ID
             if ($spiField->id != $field->id) {
                 continue;
             }
             // Cast API field value to persistence value
             $persistenceValue = $fieldType->toPersistenceValue($field->value);
             if ($persistenceValue->sortKey == $spiField->value->sortKey) {
                 // Assume stored value is correct
                 break;
             }
             if (!$dryRun) {
                 // Create and fill Legacy Storage field value
                 $storageValue = new StorageFieldValue();
                 $converter->toStorageValue($persistenceValue, $storageValue);
                 $gateway->updateField($spiField, $storageValue);
             }
             $progress->clear();
             $output->write("\r");
             $output->writeln("Updated Content " . $content->id . ", version " . $content->versionInfo->versionNo . ", field " . $spiField->id . ": '" . $spiField->value->sortKey . "' => '" . $persistenceValue->sortKey . "'");
             $output->write("\r");
             $progress->display();
             // Continue outer loop
             break;
         }
     }
 }
Ejemplo n.º 15
0
 public function testMultilineFormat()
 {
     $bar = new ProgressBar($output = $this->getOutputStream(), 3);
     $bar->setFormat("%bar%\nfoobar");
     $bar->start();
     $bar->advance();
     $bar->clear();
     $bar->finish();
     rewind($output->getStream());
     $this->assertEquals($this->generateOutput(">---------------------------\nfoobar") . $this->generateOutput("=========>------------------\nfoobar                      ") . $this->generateOutput("                            \n                            ") . $this->generateOutput("============================\nfoobar                      "), stream_get_contents($output->getStream()));
 }
Ejemplo n.º 16
0
 /**
  * Parse files within a wrapper.
  *
  * @param AbstractWrapper $wrapper
  * @param string          $prefix
  *
  * @return mixed
  */
 protected function parseFiles($wrapper, $prefix)
 {
     $this->verbose($prefix . 'Fetching files ...');
     $time = microtime(true);
     $fileAmount = count($wrapper->getAllFileNames());
     $this->verbose(sprintf("\r" . $prefix . "Collected %d files in %0.2f seconds.", $fileAmount, microtime(true) - $time));
     $this->verbose($prefix . 'Parsing ' . $fileAmount . ' files ');
     $this->debug('  in ' . $wrapper->getBasePath());
     $time = microtime(true);
     $progress = new ProgressBar($this->getOutput(), $fileAmount);
     $progress->setFormat('%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s% RAM');
     $dataTree = [];
     foreach ($wrapper->getDataTree() as $tree) {
         $dataTree = $wrapper->mergeTrees($dataTree, $tree);
         $progress->advance();
     }
     $progress->clear();
     $this->verbose(sprintf($prefix . "Parsed %d files in %0.2f seconds.", $fileAmount, microtime(true) - $time));
     return $dataTree;
 }
Ejemplo n.º 17
0
 /**
  * @inheritdoc
  */
 public function execute(ResultCollection $collection, ResultCollection $aggregatedResults)
 {
     $files = $this->finder->find($this->path);
     if (0 == sizeof($files, COUNT_NORMAL)) {
         throw new \LogicException('No file found');
     }
     $progress = new ProgressBar($this->output);
     $progress->start(sizeof($files, COUNT_NORMAL));
     // tools
     $classMap = new ClassMap();
     $tokenizer = new Tokenizer();
     $syntaxChecker = new SyntaxChecker();
     $fileAnalyzer = new FileAnalyzer($this->output, $this->withOOP, new Extractor($tokenizer), new \Hal\Metrics\Complexity\Text\Halstead\Halstead($tokenizer, new \Hal\Component\Token\TokenType()), new \Hal\Metrics\Complexity\Text\Length\Loc($tokenizer), new \Hal\Metrics\Design\Component\MaintainabilityIndex\MaintainabilityIndex(), new \Hal\Metrics\Complexity\Component\McCabe\McCabe($tokenizer), new \Hal\Metrics\Complexity\Component\Myer\Myer($tokenizer), $classMap);
     foreach ($files as $k => $filename) {
         $progress->advance();
         // Integrity
         if (!$syntaxChecker->isCorrect($filename)) {
             $this->output->writeln(sprintf('<error>file %s is not valid and has been skipped</error>', $filename));
             unset($files[$k]);
             continue;
         }
         // Analyze
         try {
             $resultSet = $fileAnalyzer->execute($filename);
         } catch (\Exception $e) {
             throw new \Exception(sprintf("a '%s' exception occured analyzing file %s\nMessage: %s", get_class($e), $filename, $e->getMessage()) . sprintf("\n------------\nStack:\n%s", $e->getTraceAsString()) . sprintf("\n------------\nDo not hesitate to report a bug: https://github.com/Halleck45/PhpMetrics/issues"), 0, $e->getPrevious());
         }
         $collection->push($resultSet);
     }
     $progress->clear();
     $progress->finish();
     if ($this->withOOP) {
         // COUPLING (should be done after parsing files)
         $this->output->write(str_pad("\rAnalyzing coupling. This will take few minutes...", 80, " "));
         $couplingAnalyzer = new CouplingAnalyzer($classMap, $collection);
         $couplingAnalyzer->execute($files);
         // LCOM (should be done after parsing files)
         $this->output->write(str_pad("\rLack of cohesion of method (lcom). This will take few minutes...", 80, " "));
         $lcomAnalyzer = new LcomAnalyzer($classMap, $collection);
         $lcomAnalyzer->execute($files);
         // Card and Agresti (should be done after parsing files)
         $this->output->write(str_pad("\rAnalyzing System complexity. This will take few minutes...", 80, " "));
         $lcomAnalyzer = new CardAndAgrestiAnalyzer($classMap, $collection);
         $lcomAnalyzer->execute($files);
     }
 }
 /**
  * @param ProgressBar $progressHelper
  */
 private function iterateFiles(ProgressBar $progressHelper)
 {
     foreach ($this->getFinder()->getIterator() as $file) {
         /** @var \Symfony\Component\Finder\SplFileInfo $file */
         if (OutputInterface::VERBOSITY_VERBOSE <= $this->getOutput()->getVerbosity()) {
             $progressHelper->clear();
             $this->getOutput()->writeln("\r" . $file->getRealPath());
             $progressHelper->display();
         }
         $this->getAnalyzer()->analyze($file);
         $progressHelper->advance();
     }
 }
Ejemplo n.º 19
0
 /**
  * Downloads $url to $save_path and displays progress in the terminal.
  *
  * @param $url
  * @param $save_path
  * @param $filename
  */
 protected function downloadFileWithProgress($url, $save_path, $filename)
 {
     $headers = get_headers($url, 1);
     $dl_progress = isset($headers['Content-Length']);
     $remote_file = fopen($url, 'rb');
     $local_file = fopen($save_path, 'wb');
     if ($remote_file && $local_file) {
         if ($dl_progress) {
             $progress = new ProgressBar($this->output, (int) $headers['Content-Length'][1]);
             $progress->setFormat("    [%bar%] %percent:3s%%");
         } else {
             $progress = new ProgressBar($this->output);
             $progress->setFormat("    [%bar%] %current%");
         }
         $progress->setRedrawFrequency(1000);
         $this->output->writeln("  - Downloading <info>{$filename}</info>");
         $progress->start();
         while (!feof($remote_file)) {
             fwrite($local_file, fread($remote_file, 1024), 1024);
             $progress->advance(1024);
         }
         $progress->finish();
         $progress->clear();
         $this->output->write("\r");
         if ($this->output->isVerbose()) {
             $file_size = (int) $headers['Content-Length'] / 1024 / 1024;
             $this->output->writeln("    <comment>Success - downloaded {$file_size} MB</comment>");
         } else {
             $this->output->writeln("    <comment>Success!</comment>");
         }
     } else {
         $this->output->writeln("<error>Couldn't open either the remote file or the local file.</error>");
     }
     fclose($remote_file);
     fclose($local_file);
 }
Ejemplo n.º 20
0
 /**
  * Stream downloading
  *
  * @param $notification_code
  * @param $severity
  * @param $message
  * @param $message_code
  * @param $bytes_transferred
  * @param $bytes_max
  */
 public function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max)
 {
     static $filesize = null;
     static $progress = null;
     switch ($notification_code) {
         case STREAM_NOTIFY_AUTH_REQUIRED:
         case STREAM_NOTIFY_AUTH_RESULT:
             break;
         case STREAM_NOTIFY_CONNECT:
             if (!$progress) {
                 $this->output->writeln(sprintf("<info>Downloading</info>"));
             }
             break;
         case STREAM_NOTIFY_FILE_SIZE_IS:
             $filesize = $bytes_max;
             $progress = new ProgressBar($this->output);
             $progress->start($filesize / 100);
             break;
         case STREAM_NOTIFY_PROGRESS:
             if ($bytes_transferred > 0) {
                 if (!isset($filesize)) {
                     $this->output->writeln(sprintf("<info>Unknown file size.. %2d kb done..</info>", $bytes_transferred / 1024));
                 } else {
                     $progress->setProgress($bytes_transferred / 100);
                 }
             }
             break;
         case STREAM_NOTIFY_COMPLETED:
         case STREAM_NOTIFY_FAILURE:
             if ($progress) {
                 $progress->clear();
                 $progress->finish();
             }
             break;
     }
 }
Ejemplo n.º 21
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $startTime = microtime(true);
     $targetDirectory = getcwd();
     $tag = $this->config->get('tag');
     $against = $this->config->get('against') ?: 'HEAD';
     $includeBefore = $this->config->get('include-before');
     $excludeBefore = $this->config->get('exclude-before');
     $includeAfter = $this->config->get('include-after');
     $excludeAfter = $this->config->get('exclude-after');
     $client = new Client();
     $repository = $client->getRepository($targetDirectory);
     if ($tag === null) {
         $tag = $this->findLatestTag($repository);
     } else {
         $tag = $this->findTag($repository, $tag);
     }
     if ($tag === null) {
         $output->writeln('<error>No tags to suggest against</error>');
         return;
     }
     $output->writeln('<info>Testing ' . $against . ' against tag: ' . $tag . '</info>');
     $finder = new Finder();
     $sourceFilter = new SourceFilter();
     $beforeScanner = new Scanner();
     $afterScanner = new Scanner();
     $modifiedFiles = $repository->getModifiedFiles($tag, $against);
     $modifiedFiles = array_filter($modifiedFiles, function ($modifiedFile) {
         return substr($modifiedFile, -4) === '.php';
     });
     $initialBranch = $repository->getCurrentBranch();
     if (!$this->config->get('allow-detached') && !$initialBranch) {
         $output->writeln('<error>You are on a detached HEAD, aborting.</error>');
         $output->writeln('<info>If you still wish to run against a detached HEAD, use --allow-detached.</info>');
         return -1;
     }
     // Start with the against commit
     $repository->checkout($against . ' --');
     $sourceAfter = $finder->findFromString($targetDirectory, $includeAfter, $excludeAfter);
     $sourceAfterMatchedCount = count($sourceAfter);
     $sourceAfter = $sourceFilter->filter($sourceAfter, $modifiedFiles);
     $progress = new ProgressBar($output, count($sourceAfter));
     foreach ($sourceAfter as $file) {
         $afterScanner->scan($file);
         $progress->advance();
     }
     $progress->clear();
     // Finish with the tag commit
     $repository->checkout($tag . ' --');
     $sourceBefore = $finder->findFromString($targetDirectory, $includeBefore, $excludeBefore);
     $sourceBeforeMatchedCount = count($sourceBefore);
     $sourceBefore = $sourceFilter->filter($sourceBefore, $modifiedFiles);
     $progress = new ProgressBar($output, count($sourceBefore));
     foreach ($sourceBefore as $file) {
         $beforeScanner->scan($file);
         $progress->advance();
     }
     $progress->clear();
     // Reset repository to initial branch
     if ($initialBranch) {
         $repository->checkout($initialBranch);
     }
     $registryBefore = $beforeScanner->getRegistry();
     $registryAfter = $afterScanner->getRegistry();
     $analyzer = new Analyzer();
     $report = $analyzer->analyze($registryBefore, $registryAfter);
     $tag = new SemanticVersion($tag);
     $newTag = new SemanticVersion($tag);
     $suggestedLevel = $report->getSuggestedLevel();
     if ($suggestedLevel !== Level::NONE) {
         if ($newTag->getPrerelease()) {
             $newTag->inc('prerelease');
         } else {
             if ($newTag->getMajor() < 1 && $suggestedLevel === Level::MAJOR) {
                 $newTag->inc('minor');
             } else {
                 $newTag->inc(strtolower(Level::toString($suggestedLevel)));
             }
         }
     }
     $output->writeln('');
     $output->writeln('<info>Initial semantic version: ' . $tag . '</info>');
     $output->writeln('<info>Suggested semantic version: ' . $newTag . '</info>');
     if ($this->config->get('details')) {
         $reporter = new Reporter($report);
         $reporter->output($output);
     }
     $duration = microtime(true) - $startTime;
     $output->writeln('');
     $output->writeln('[Scanned files] Before: ' . count($sourceBefore) . ' (' . $sourceBeforeMatchedCount . ' unfiltered), After: ' . count($sourceAfter) . ' (' . $sourceAfterMatchedCount . '  unfiltered)');
     $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB');
 }
 /**
  * Search for dependencies in this package.
  *
  * @param PackageInterface $package  The package to search in.
  * @param string           $type     One of "prod" or "dev".
  * @param array|Link[]     $requires The require links.
  *
  * @return void
  */
 private function searchInRequires(PackageInterface $package, $type, array $requires)
 {
     if (isset($requires[$this->packageName])) {
         $link = $requires[$this->packageName];
         $constraint = $link->getPrettyConstraint();
         $section = $package->getPrettyString();
         $message = sprintf('<comment>%s</comment> %s %s', 'dev' == $type ? 'require-dev' : 'require', $this->packageName, $constraint);
         $this->progress->clear();
         // Hack to get the cursor on the line beginning
         $this->output->write("\n");
         $this->output->writeln($this->formatter->formatSection($section, $message));
         $this->progress->display();
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $startTime = microtime(true);
     $targetDirectory = getcwd();
     $commitBefore = $input->getArgument('before');
     $commitAfter = $input->getArgument('after');
     $includeBefore = $input->getOption('include-before');
     $excludeBefore = $input->getOption('exclude-before');
     $includeAfter = $input->getOption('include-after');
     $excludeAfter = $input->getOption('exclude-after');
     $finder = new Finder();
     $sourceFilter = new SourceFilter();
     $beforeScanner = new Scanner();
     $afterScanner = new Scanner();
     $client = new Client();
     $repository = $client->getRepository($targetDirectory);
     $modifiedFiles = $repository->getModifiedFiles($commitBefore, $commitAfter);
     $modifiedFiles = array_filter($modifiedFiles, function ($modifiedFile) {
         return substr($modifiedFile, -4) === '.php';
     });
     $initialBranch = $repository->getCurrentBranch();
     $repository->checkout($commitBefore . ' --');
     $sourceBefore = $finder->findFromString($targetDirectory, $includeBefore, $excludeBefore);
     $sourceBeforeMatchedCount = count($sourceBefore);
     $sourceBefore = $sourceFilter->filter($sourceBefore, $modifiedFiles);
     $progress = new ProgressBar($output, count($sourceBefore));
     foreach ($sourceBefore as $file) {
         $beforeScanner->scan($file);
         $progress->advance();
     }
     $progress->clear();
     $repository->checkout($commitAfter . ' --');
     $sourceAfter = $finder->findFromString($targetDirectory, $includeAfter, $excludeAfter);
     $sourceAfterMatchedCount = count($sourceAfter);
     $sourceAfter = $sourceFilter->filter($sourceAfter, $modifiedFiles);
     $progress = new ProgressBar($output, count($sourceAfter));
     foreach ($sourceAfter as $file) {
         $afterScanner->scan($file);
         $progress->advance();
     }
     $progress->clear();
     if ($initialBranch) {
         $repository->checkout($initialBranch);
     }
     $progress->clear();
     $registryBefore = $beforeScanner->getRegistry();
     $registryAfter = $afterScanner->getRegistry();
     $analyzer = new Analyzer();
     $report = $analyzer->analyze($registryBefore, $registryAfter);
     $reporter = new Reporter($report);
     $reporter->setFullPath(true);
     $reporter->output($output);
     $toJson = $input->getOption('to-json');
     if ($toJson) {
         $commitBeforeHash = $repository->getCommit($commitBefore)->getHash();
         $commitAfterHash = $repository->getCommit($commitAfter)->getHash();
         $jsonReporter = new JsonReporter($report, $toJson, $commitBeforeHash, $commitAfterHash);
         $jsonReporter->output();
     }
     $duration = microtime(true) - $startTime;
     $output->writeln('');
     $output->writeln('[Scanned files] Before: ' . count($sourceBefore) . ' (' . $sourceBeforeMatchedCount . ' unfiltered), After: ' . count($sourceAfter) . ' (' . $sourceAfterMatchedCount . ' unfiltered)');
     $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB');
 }
 /**
  * @param OutputInterface $output
  * @param ItemId[] $itemIds
  * @param bool $force
  */
 private function executeForItemIds(OutputInterface $output, array $itemIds, $force)
 {
     $itemLookup = $this->wikibaseFactory->newItemLookup();
     $processedItemIdStrings = $this->getProcessedItemIdStrings();
     $loopCounter = 0;
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     foreach ($itemIds as $itemId) {
         $loopCounter++;
         $itemIdString = $itemId->getSerialization();
         $output->writeln('----------------------------------------------------');
         if ($loopCounter % 10 != 0) {
             $processedItemIdStrings = $this->getProcessedItemIdStrings();
         }
         if (!$force && in_array($itemId->getSerialization(), $processedItemIdStrings)) {
             $output->writeln($formatter->formatSection($itemIdString, 'Already processed'));
             continue;
         }
         try {
             $output->writeln($formatter->formatSection($itemIdString, 'Loading Item'));
             $item = $itemLookup->getItemForId($itemId);
         } catch (ItemLookupException $e) {
             $output->writeln($formatter->formatSection($itemIdString, 'Failed to load item (exception)', 'error'));
             continue;
         }
         if ($item === null) {
             $output->writeln($formatter->formatSection($itemIdString, 'Failed to load item (null)', 'error'));
             continue;
         }
         // Get the item types..
         $types = array();
         foreach ($item->getStatements()->getByPropertyId(new PropertyId('P31'))->toArray() as $instanceStatement) {
             $mainSnak = $instanceStatement->getMainSnak();
             if ($mainSnak instanceof PropertyValueSnak) {
                 /** @var EntityIdValue $instanceItemIdValue */
                 $instanceItemIdValue = $mainSnak->getDataValue();
                 $idSerialization = $instanceItemIdValue->getEntityId()->getSerialization();
                 if (array_key_exists($idSerialization, $this->instanceMap)) {
                     $types[] = $this->instanceMap[$idSerialization];
                 }
             }
         }
         if (empty($types)) {
             $output->writeln($formatter->formatSection($itemIdString, 'Didn\\t find any useful instance of statements', 'comment'));
             continue;
         }
         // Note: only load Wikipedias
         $siteLinkList = DataModelUtils::getSitelinksWiteSiteIdSuffix($item->getSiteLinkList(), 'wiki');
         $output->writeln($formatter->formatSection($itemIdString, $siteLinkList->count() . ' Wikipedia pages to request'));
         $parseProgressBar = new ProgressBar($output, $siteLinkList->count());
         $parseProgressBar->display();
         /** @var PromiseInterface[] $parsePromises */
         $parsePromises = array();
         foreach ($siteLinkList->getIterator() as $siteLink) {
             $siteId = $siteLink->getSiteId();
             $pageName = $item->getSiteLinkList()->getBySiteId($siteId)->getPageName();
             $sourceMwFactory = $this->wmFactoryFactory->getFactory($siteId);
             $sourceParser = $sourceMwFactory->newParser();
             $pageIdentifier = new PageIdentifier(new Title($pageName));
             $parsePromises[$siteId] = $sourceParser->parsePageAsync($pageIdentifier);
             $parseProgressBar->advance();
         }
         $links = array();
         foreach ($parsePromises as $siteId => $promise) {
             try {
                 $parseResult = $promise->wait();
                 if (array_key_exists('externallinks', $parseResult)) {
                     foreach ($parseResult['externallinks'] as $externalLink) {
                         // Ignore archive.org links
                         if (strstr($externalLink, 'archive.org') === false) {
                             $links[] = $this->normalizeExternalLink($externalLink);
                         }
                     }
                 }
             } catch (Exception $e) {
                 $parseProgressBar->clear();
                 $output->writeln($formatter->formatSection($itemIdString, $e->getMessage(), 'error'));
                 $parseProgressBar->display();
                 // Ignore failed requests
             }
         }
         $parseProgressBar->finish();
         $output->writeln('');
         $links = array_unique($links);
         shuffle($links);
         /** @var Request[] $linkRequests */
         $linkRequests = array();
         foreach ($links as $link) {
             $linkRequests[] = new Request('GET', $link, array('allow_redirects' => array('track_redirects' => true), 'connect_timeout' => 3.14, 'timeout' => 10));
         }
         $output->writeln($formatter->formatSection($itemIdString, count($linkRequests) . ' External links to (download, action)'));
         if (empty($linkRequests)) {
             continue;
         }
         // Make a bunch of requests and act on the responses
         $referencesAddedToItem = 0;
         $externalLinkProgressBar = new ProgressBar($output, count($linkRequests) * 2);
         $externalLinkProgressBar->display();
         $pool = new Pool($this->externalLinkClient, $linkRequests, array('fulfilled' => function ($response) use($externalLinkProgressBar, $item, $types, $referencesAddedToItem, $output) {
             $externalLinkProgressBar->advance();
             // 1st advance point
             if ($response instanceof ResponseInterface) {
                 $link = $response->getHeaderLine('X-GUZZLE-EFFECTIVE-URL');
                 $html = $response->getBody();
                 $referencesAddedFromLink = 0;
                 foreach ($this->microDataExtractor->extract($html) as $microData) {
                     foreach ($types as $type) {
                         if ($microData->hasType($type) && array_key_exists($type, $this->referencerMap)) {
                             foreach ($this->referencerMap[$type] as $referencer) {
                                 /** @var Referencer $referencer */
                                 $addedReferences = $referencer->addReferences($microData, $item, $link);
                                 $referencesAddedToItem += $addedReferences;
                                 $referencesAddedFromLink += $addedReferences;
                             }
                         }
                     }
                 }
                 if ($referencesAddedFromLink > 0) {
                     $externalLinkProgressBar->clear();
                     $output->write("\r");
                     $output->writeln($referencesAddedFromLink . ' reference(s) added from ' . urldecode($link));
                     $externalLinkProgressBar->display();
                 }
             }
             $externalLinkProgressBar->advance();
             // 2nd advance point
         }, 'rejected' => function () use($externalLinkProgressBar) {
             // TODO add this to some kind of verbose log?
             $externalLinkProgressBar->advance();
             // 1st advance point
         }));
         $pool->promise()->wait();
         $externalLinkProgressBar->finish();
         $output->writeln('');
         $output->writeln($formatter->formatSection($itemIdString, $referencesAddedToItem . ' References added'));
         $this->markIdAsProcessed($itemId);
     }
 }
Ejemplo n.º 25
0
 /**
  * Log warning while progress bar is shown.
  *
  * @param \Symfony\Component\Console\Helper\ProgressBar $progress
  * @param $message
  */
 protected function logWarning(ProgressBar $progress, $message)
 {
     $progress->clear();
     $this->logger->warning($message);
     $progress->display();
 }
 /**
  * Fixes always available flag on fields of Content $contentId in $versionNo.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \Symfony\Component\Console\Helper\ProgressBar $progress
  * @param int $contentId
  * @param int $versionNo
  * @param int $mainLanguageId
  * @param bool $dryRun
  */
 protected function updateAlwaysAvailableFlag(OutputInterface $output, ProgressBar $progress, $contentId, $versionNo, $mainLanguageId, $dryRun)
 {
     if ($dryRun) {
         goto output;
     }
     /** @var \eZ\Publish\Core\Persistence\Database\DatabaseHandler $databaseHandler */
     $databaseHandler = $this->getContainer()->get('ezpublish.connection');
     // Remove always available flag from all fields not in main language
     /** @var $query \eZ\Publish\Core\Persistence\Database\UpdateQuery */
     $query = $databaseHandler->createUpdateQuery();
     $query->update($databaseHandler->quoteTable('ezcontentobject_attribute'))->set($databaseHandler->quoteColumn('language_id'), $query->expr->bitAnd($databaseHandler->quoteColumn('language_id'), -2))->where($query->expr->lAnd($query->expr->eq($databaseHandler->quoteColumn('contentobject_id'), $query->bindValue($contentId, null, PDO::PARAM_INT)), $query->expr->eq($databaseHandler->quoteColumn('version'), $query->bindValue($versionNo, null, PDO::PARAM_INT)), $query->expr->eq($query->expr->bitAnd($databaseHandler->quoteColumn('language_id'), $query->bindValue($mainLanguageId, null, PDO::PARAM_INT)), $query->bindValue(0, null, PDO::PARAM_INT))))->prepare()->execute();
     // Set always available flag on fields in main language
     $query = $databaseHandler->createUpdateQuery();
     $query->update($databaseHandler->quoteTable('ezcontentobject_attribute'))->set($databaseHandler->quoteColumn('language_id'), $query->expr->bitOr($databaseHandler->quoteColumn('language_id'), 1))->where($query->expr->lAnd($query->expr->eq($databaseHandler->quoteColumn('contentobject_id'), $query->bindValue($contentId, null, PDO::PARAM_INT)), $query->expr->eq($databaseHandler->quoteColumn('version'), $query->bindValue($versionNo, null, PDO::PARAM_INT)), $query->expr->gt($query->expr->bitAnd($databaseHandler->quoteColumn('language_id'), $query->bindValue($mainLanguageId, null, PDO::PARAM_INT)), $query->bindValue(0, null, PDO::PARAM_INT))))->prepare()->execute();
     output:
     $progress->clear();
     $output->write("\r");
     $output->writeln("Updated fields for Content '{$contentId}' in version '{$versionNo}'");
     $output->write("\r");
     $progress->display();
 }
 /**
  * Log warning while progress helper is running.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \Symfony\Component\Console\Helper\ProgressBar $progress
  * @param $message
  */
 private function logWarning(OutputInterface $output, ProgressBar $progress, $message)
 {
     $progress->clear();
     $this->logger->warning($message);
     $progress->display();
 }
Ejemplo n.º 28
0
                     $phpExcel->getActiveSheet()->setCellValue('A' . $i, $book['title']);
                     $phpExcel->getActiveSheet()->setCellValue('B' . $i, $book['authors']);
                     $phpExcel->getActiveSheet()->setCellValue('C' . $i, $book['publisher']);
                     $phpExcel->getActiveSheet()->setCellValue('D' . $i, $book['description']);
                     $phpExcel->getActiveSheet()->setCellValue('E' . $i, $book['pageCount']);
                     $phpExcel->getActiveSheet()->setCellValue('F' . $i, $book['imageLink']);
                     $i++;
                 } catch (BookNotFoundException $e) {
                     $app['monolog']->addError($e->getMessage());
                 } catch (ApiException $e) {
                     $app['monolog']->addError($e->getMessage());
                 }
                 $progress->advance();
             }
             $progress->setMessage('<comment>Search ready</comment>');
             $progress->clear();
             $progress->display();
             $progress->finish();
             $output->writeln('');
             $output->writeln("<info>Saving data in {$target}</info>");
             $phpExcel->setActiveSheetIndex(0);
             $writer = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
             $writer->save($target);
             $output->writeln("<info>Data saved in {$target}</info>");
             break;
         default:
             $output->writeln('<error>Unrecognized API</error>');
             break;
     }
 } else {
     $output->writeln('<error>The target file ' . $source . ' does not exist</error>');
 /**
  * Executes all prepared batches of requests.
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return array
  */
 protected function executeBatches(InputInterface $input, OutputInterface $output)
 {
     $totalResult = array();
     if (!$this->_options['silent']) {
         $output->writeln('<info>Found ' . count($this->_batches) . ' sets to process.</info>');
     }
     $setCount = count($this->_batches);
     $bi = 1;
     // batch number
     foreach ($this->_batches as $set) {
         // sitemaps
         $meta = $set['metadata'];
         $batchesCount = count($set['requests']);
         $setResults = array();
         if (!$this->_options['silent']) {
             $progress = new ProgressBar($output, $batchesCount);
             $progress->setFormat('<info> %message% </info>' . PHP_EOL . '%current%/%max% [%bar%] <comment> %percent:3s%% - %elapsed:6s%/%estimated:-6s% </comment>');
             $progress->setMessage('Now executing batch: ' . $bi . '/' . $setCount);
             $progress->start();
         }
         foreach ($set['requests'] as $batch) {
             // the batches of requests, singular or plural
             $batchResult = array();
             foreach ($batch as $request) {
                 $response = $this->simpleCurl($request);
                 $response['comparison_key'] = strtr($response['url'], array(rtrim($this->_options['compare-url'], "/") => '', rtrim($this->_options['current-url'], "/") => ''));
                 array_push($batchResult, $response);
             }
             array_push($setResults, $batchResult);
             if (!$this->_options['silent']) {
                 $progress->clear();
                 $progress->setMessage($this->parseStatusMessage($batchResult));
                 $progress->display();
                 $progress->advance();
             }
         }
         if (!$this->_options['silent']) {
             $progress->setMessage('Task is finished');
             $progress->finish();
         }
         array_push($totalResult, $setResults);
         $bi++;
     }
     return $totalResult;
 }
Ejemplo n.º 30
0
 /**
  * Installation modules.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param array $modules
  * @throws BitrixException
  * @throws \LogicException
  * @throws ModuleException
  */
 protected function configureModules(InputInterface $input, OutputInterface $output, array $modules)
 {
     $app = $this->getApplication();
     if ($app->getConfiguration()) {
         $app->addCommands(ModuleCommand::getCommands());
         if ($app->getBitrixStatus() != \Notamedia\ConsoleJedi\Application\Application::BITRIX_STATUS_COMPLETE) {
             throw new BitrixException('Bitrix core is not available');
         }
     } else {
         throw new BitrixException('No configuration loaded');
     }
     if (!is_array($modules)) {
         throw new \LogicException('Incorrect modules configuration');
     }
     if (!count($modules)) {
         return;
     }
     $bar = new ProgressBar($output, count($modules));
     $bar->setRedrawFrequency(1);
     $bar->setFormat('verbose');
     foreach ($modules as $moduleName) {
         $message = "\r" . '   module:load ' . $moduleName . ': ';
         try {
             if (isset($bar)) {
                 $bar->setMessage($message);
                 $bar->display();
             }
             (new Module($moduleName))->load()->register();
             $bar->clear();
             $output->writeln($message . '<info>ok</info>');
         } catch (ModuleInstallException $e) {
             $bar->clear();
             $output->writeln($e->getMessage(), OutputInterface::VERBOSITY_VERBOSE);
             $output->writeln($message . '<comment>not registered</comment> (install it in admin panel)');
         } catch (ModuleException $e) {
             $bar->clear();
             $output->writeln($e->getMessage(), OutputInterface::VERBOSITY_VERBOSE);
             $output->writeln($message . '<error>FAILED</error>');
         }
         $bar->advance();
     }
     $bar->finish();
     $bar->clear();
     $output->write("\r");
 }