public function execute(Request $request, $count, OutputInterface $out) { $client = new \Elasticsearch\Client(['hosts' => [$request->getHost()]]); $response = new Response(); if ($this->clearCache) { $this->clearCache($client, $out); } $helper = new ProgressHelper(); $helper->start($out, $count); $start = microtime(true); for ($i = 0; $i < $count; $i++) { try { $response->addSuccess($client->search($request->getParameters())); } catch (\Exception $ex) { $response->addFailure(); var_dump($ex->getMessage()); exit; } $helper->advance(); } $helper->finish(); $response->setExternalTime(microtime(true) - $start); try { $response->setStats($client->indices()->stats([['index' => $request->getIndex()], 'groups' => [$request->getStatId()]])); } catch (\Exception $ex) { // nothing to do here } return $response; }
/** * Execute command * * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { $registry = PlayerRegistry::getDefaultPlayers(); $player1 = $input->getArgument('player-x'); $player2 = $input->getArgument('player-o'); $count = (int) $input->getOption('games'); $progress = new ProgressHelper(); $progress->start($output, $count); $stats = [PlayerInterface::SYMBOL_X => 0, PlayerInterface::SYMBOL_O => 0, 'Draw' => 0]; for ($i = 0; $i < $count; $i++) { $game = new Game(); $game->addPlayer($registry->get($player1, PlayerInterface::SYMBOL_X)); $game->addPlayer($registry->get($player2), PlayerInterface::SYMBOL_O); $winner = $game->autoPlay(); $stats[$winner ? $winner : 'Draw']++; $progress->advance(); } $progress->finish(); $output->writeln(''); $output->writeln('Winning statistics'); $table = new TableHelper(); $table->setHeaders([$player1, $player2, "Draw"]); $table->addRow(array_values($stats)); $table->render($output); }
protected function processGroup($group, $lines) { // Do nothing if there is no line if (empty($lines) || is_string($lines)) { return; } array_set($this->missing, $group, array()); $this->line("Processing {$group} group..."); $this->progress->start($this->output, count($lines, COUNT_RECURSIVE)); // Iterate over passed lines foreach ($lines as $line => $translation) { // Run recursive if translation is an array if (is_array($translation)) { $this->processGroup($group . '.' . $line, $line); } else { if ($this->manager->findLineCount($group, $line) == 0) { array_push($this->missing[$group], $line); } $this->progress->advance(); } } $this->line(" "); // Add line break to stop lines from joining if ($missing = array_get($this->missing, $group)) { foreach ($missing as $m) { if ($this->input->getOption('silent') or $confirm = $this->confirm("{$group}.{$m} is missing. Remove? [yes/no]")) { $this->manager->removeLine($group, $m); $this->info("Removed {$m} from {$group}"); } } } }
/** * Executes a raw import. * * @param Manager $manager * @param string $filename * @param OutputInterface $output * @param int $bulkSize */ protected function executeRawImport(Manager $manager, $filename, OutputInterface $output, $bulkSize) { $reader = $this->getReader($manager, $filename, false); if (class_exists('\\Symfony\\Component\\Console\\Helper\\ProgressBar')) { $progress = new ProgressBar($output, $reader->count()); $progress->setRedrawFrequency(100); $progress->start(); } else { $progress = new ProgressHelper(); $progress->setRedrawFrequency(100); $progress->start($output, $reader->count()); } foreach ($reader as $key => $document) { $data = $document['_source']; $data['_id'] = $document['_id']; $manager->getConnection()->bulk('index', $document['_type'], $data); if (($key + 1) % $bulkSize == 0) { $manager->commit(); } $progress->advance(); } if (($key + 1) % $bulkSize != 0) { $manager->commit(); } $progress->finish(); $output->writeln(''); }
/** * @param ProgressHelper $progress * @param OutputInterface $output * @param string $filename */ public function __construct(ProgressHelper $progress, OutputInterface $output, $filename) { $progress->setFormat(ProgressHelper::FORMAT_QUIET); $output = new ExportOutput($output, $filename, false); // reset old value $output->write('0%'); parent::__construct($progress, $output); }
public function testPercentNotHundredBeforeComplete() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream(), 200); $progress->display(); $progress->advance(199); $progress->advance(); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 0/200 [>---------------------------] 0%') . $this->generateOutput(' 199/200 [===========================>] 99%') . $this->generateOutput(' 200/200 [============================] 100%'), stream_get_contents($output->getStream())); }
public function testPercent() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream(), 50); $progress->display(); $progress->advance(); $progress->advance(); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 0/50 [>---------------------------] 0%') . $this->generateOutput(' 1/50 [>---------------------------] 2%') . $this->generateOutput(' 2/50 [=>--------------------------] 4%'), stream_get_contents($output->getStream())); }
/** * Copy & Paste Detection (CPD). * * @param Iterator|array $files List of files to process * @param integer $minLines Minimum number of identical lines * @param integer $minTokens Minimum number of identical tokens * @param boolean $fuzzy * @return CodeCloneMap Map of exact clones found in the list of files */ public function copyPasteDetection($files, $minLines = 5, $minTokens = 70, $fuzzy = false) { $result = new CodeCloneMap(); foreach ($files as $file) { $this->strategy->processFile($file, $minLines, $minTokens, $result, $fuzzy); if ($this->progressHelper !== null) { $this->progressHelper->advance(); } } return $result; }
public function run() { foreach ($this->processes as $process) { /** @var $process Process **/ $process->setIdleTimeout($this->idleTimeout); $process->setTimeout($this->timeout); $process->start(); $this->printTaskInfo($process->getCommandLine()); } $progress = new ProgressHelper(); $progress->setFormat(" <fg=white;bg=cyan;options=bold>[" . get_class($this) . "]</fg=white;bg=cyan;options=bold> Processes: %current%/%max% [%bar%] %percent%%"); $progress->start($this->getOutput(), count($this->processes)); $running = $this->processes; $progress->display(); $started = microtime(true); while (true) { foreach ($running as $k => $process) { try { $process->checkTimeout(); } catch (ProcessTimedOutException $e) { } if (!$process->isRunning()) { $progress->advance(); if ($this->isPrinted) { $this->getOutput()->writeln(""); $this->printTaskInfo("Output for <fg=white;bg=magenta> " . $process->getCommandLine() . " </fg=white;bg=magenta>"); $this->getOutput()->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW); if ($process->getErrorOutput()) { $this->getOutput()->writeln("<error>" . $process->getErrorOutput() . "</error>"); } } unset($running[$k]); } } if (empty($running)) { break; } usleep(1000); } $this->getOutput()->writeln(""); $taken = number_format(microtime(true) - $started, 2); $this->printTaskInfo(count($this->processes) . " processes ended in {$taken} s"); $errorMessage = ''; $exitCode = 0; foreach ($this->processes as $p) { if ($p->getExitCode() === 0) { continue; } $errorMessage .= "'" . $p->getCommandLine() . "' exited with code " . $p->getExitCode() . " \n"; $exitCode = max($exitCode, $p->getExitCode()); } return new Result($this, $exitCode, $errorMessage); }
/** * Prefix url of document with current resourcelocator prefix. * * @param IndexRebuildEvent $event */ public function onIndexRebuild(IndexRebuildEvent $event) { $output = $event->getOutput(); $filter = $event->getFilter(); $output->writeln('<info>Rebuilding content index</info>'); $typeMap = $this->baseMetadataFactory->getPhpcrTypeMap(); $phpcrTypes = []; foreach ($typeMap as $type) { $phpcrType = $type['phpcr_type']; if ($phpcrType !== 'sulu:path') { $phpcrTypes[] = sprintf('[jcr:mixinTypes] = "%s"', $phpcrType); } } $condition = implode(' or ', $phpcrTypes); // TODO: We cannot select all contents via. the parent type, see: https://github.com/jackalope/jackalope-doctrine-dbal/issues/217 $query = $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE ' . $condition); $count = []; $documents = $query->execute(); $progress = new ProgressHelper(); $progress->start($output, count($documents)); foreach ($documents as $document) { if ($document instanceof SecurityBehavior && !empty($document->getPermissions())) { $progress->advance(); continue; } $locales = $this->inspector->getLocales($document); foreach ($locales as $locale) { try { $this->documentManager->find($document->getUuid(), $locale); $documentClass = get_class($document); if ($filter && !preg_match('{' . $filter . '}', $documentClass)) { continue; } $this->searchManager->index($document, $locale); if (!isset($count[$documentClass])) { $count[$documentClass] = 0; } ++$count[$documentClass]; } catch (\Exception $e) { $output->writeln(sprintf('<error>Error indexing or de-indexing page (path: %s locale: %s)</error>: %s', $this->inspector->getPath($document), $locale, $e->getMessage())); } } $progress->advance(); } $output->writeln(''); foreach ($count as $className => $count) { if ($count == 0) { continue; } $output->writeln(sprintf('<comment>Content</comment>: %s <info>%s</info> indexed', $className, $count)); } }
/** * @param EventDispatcherInterface $dispatcher * @param ProgressHelper $progress * @param OutputInterface $output */ protected function setupProgressListeners(EventDispatcherInterface $dispatcher, ProgressHelper $progress, OutputInterface $output) { $dispatcher->addListener(IoEvents::PRE_EXPORT_FEED, function (ExportFeedEvent $event) use($progress, $output) { $output->writeln(sprintf('Exporting feed for <info>%s</info> to <info>%s</info>', $event->getType()->getName(), $event->getFile())); $progress->start($output, $event->getTotal()); }); $dispatcher->addListener(IoEvents::POST_EXPORT_ITEM, function () use($progress) { $progress->advance(1); }); $dispatcher->addListener(IoEvents::POST_EXPORT_FEED, function () use($progress) { $progress->finish(); }); }
/** * {@inheritdoc} */ public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null) { $this->familiesFile = $outputDir . '/' . self::FAMILIES_FILENAME; $this->delimiter = $config['delimiter']; $count = (int) $config['count']; $attributesCount = (int) $config['attributes_count'] - 1; $requirementsCount = (int) $config['requirements_count'] - 1; $this->identifierAttribute = $config['identifier_attribute']; $this->labelAttribute = $config['label_attribute']; $this->faker = Faker\Factory::create(); $families = []; for ($i = 0; $i < $count; $i++) { $family = []; $family['code'] = self::FAMILY_CODE_PREFIX . $i; foreach ($this->getLocalizedRandomLabels() as $localeCode => $label) { $family['label-' . $localeCode] = $label; } $family['attribute_as_label'] = $this->labelAttribute; $attributes = $this->faker->randomElements($this->getAttributeCodes(), $attributesCount); $attributes = array_unique(array_merge([$this->identifierAttribute, $this->labelAttribute], $attributes)); $family['attributes'] = implode(static::ATTRIBUTE_DELIMITER, $attributes); $requirements = []; foreach ($this->getChannels() as $channel) { $attributeReqs = $this->faker->randomElements($this->getAttributeCodes(), $requirementsCount); $attributeReqs = array_merge([$this->identifierAttribute], $attributeReqs); $family['requirements-' . $channel->getCode()] = implode(static::ATTRIBUTE_DELIMITER, $attributeReqs); } $families[$family['code']] = $family; $progress->advance(); } $this->families = $families; $headers = $this->getAllKeys($this->families); $this->writeCsvFile($this->families, $headers); return $this; }
/** * Display result information. */ public function finish() { $time = microtime(true) - $this->started; $this->progress->finish(); $this->output->writeln(sprintf('Execution time: <comment>%F</comment> seconds.', $this->time)); $this->output->writeln(sprintf('Total time: <comment>%F</comment> seconds.', $time)); $this->output->writeln(''); $style = new OutputFormatterStyle('black', 'yellow'); $this->output->getFormatter()->setStyle('skipped', $style); if ($this->incomplete->count() > 0) { $style = new OutputFormatterStyle('white', 'blue'); $this->output->getFormatter()->setStyle('incomplete', $style); $this->output->writeln('Incomplete tests:'); foreach ($this->incomplete as $i => $method) { $this->printMethod($i + 1, $method, 'incomplete'); } } if ($this->failed->count() > 0) { $this->output->writeln('Failed tests:'); foreach ($this->failed as $i => $method) { $this->printMethod($i + 1, $method, 'error'); } $this->fail(); } else { $this->success(); } }
/** * {@inheritdoc} */ public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null) { $this->attributeGroupsFile = $outputDir . '/' . static::ATTRIBUTE_GROUP_FILENAME; $count = (int) $config['count']; $this->faker = Faker\Factory::create(); $this->attributeGroups = []; for ($i = 0; $i < $count; $i++) { $attributeGroup = []; $attributeGroup['sortOrder'] = $this->faker->numberBetween(1, 10); $attributeGroup['labels'] = $this->getLocalizedRandomLabels(); $this->attributeGroups[self::ATTR_GROUP_CODE_PREFIX . $i] = $attributeGroup; $progress->advance(); } $this->writeYamlFile(['attribute_groups' => $this->attributeGroups], $this->attributeGroupsFile); return $this; }
private function addCustomVariables(Model $model, $numberOfVarsToAdd, OutputInterface $output) { for ($index = 0; $index < $numberOfVarsToAdd; $index++) { $indexAdded = $model->addCustomVariable(); $this->progress->advance(); $output->writeln(' <info>Added a variable in scope "' . $model->getScopeName() . '" having the index ' . $indexAdded . '</info>'); } }
/** * Prefix url of document with current resourcelocator prefix. * * @param IndexRebuildEvent $event */ public function onIndexRebuild(IndexRebuildEvent $event) { $output = $event->getOutput(); $purge = $event->getPurge(); $filter = $event->getFilter(); $output->writeln('<info>Rebuilding content index</info>'); // TODO: We cannot select all contents via. the parent type, see: https://github.com/jackalope/jackalope-doctrine-dbal/issues/217 $query = $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE [jcr:mixinTypes] = "sulu:page" or [jcr:mixinTypes] = "sulu:snippet"'); $count = []; if ($purge) { $this->purgeContentIndexes($output); } $documents = $query->execute(); $progress = new ProgressHelper(); $progress->start($output, count($documents)); foreach ($documents as $document) { $locales = $this->inspector->getLocales($document); foreach ($locales as $locale) { try { $this->documentManager->find($document->getUuid(), $locale); $documentClass = get_class($document); if ($filter && !preg_match('{' . $filter . '}', $documentClass)) { continue; } $this->searchManager->index($document, $locale); if (!isset($count[$documentClass])) { $count[$documentClass] = 0; } ++$count[$documentClass]; } catch (\Exception $e) { $output->writeln(sprintf('<error>Error indexing or de-indexing page (path: %s locale: %s)</error>: %s', $this->inspector->getPath($document), $locale, $e->getMessage())); } } $progress->advance(); } $output->writeln(''); foreach ($count as $className => $count) { if ($count == 0) { continue; } $output->writeln(sprintf('<comment>Content</comment>: %s <info>%s</info> indexed', $className, $count)); } }
/** * @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 ProgressHelper(); $progress->start($this->output, 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\MaintenabilityIndex\MaintenabilityIndex($tokenizer), 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 $resultSet = $fileAnalyzer->execute($filename); $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); } }
public function testCustomizations() { $progress = new ProgressHelper(); $progress->setBarWidth(10); $progress->setBarCharacter('_'); $progress->setEmptyBarCharacter(' '); $progress->setProgressCharacter('/'); $progress->setFormat(' %current%/%max% [%bar%] %percent%%'); $progress->start($output = $this->getOutputStream(), 10); $progress->advance(); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 1/10 [_/ ] 10%'), stream_get_contents($output->getStream())); }
protected function execute(InputInterface $input, OutputInterface $output) { $defaults = array(); if ($input->getOption('msgctxt')) { $defaults['msgctxt'] = $input->getOption('msgctxt'); } $this->pot = new Pot($input->getOption('base'), array(), $defaults); $files = $input->getArgument('files'); if (in_array('-', $files)) { $files = array_merge($files, explode("\n", stream_get_contents($this->stdin))); } $actualFiles = $this->findFiles($files); if (!$input->getOption('out')) { foreach ($actualFiles as $file) { $this->extractFile($file); } if ($input->getOption('header')) { $output->write(file_get_contents($input->getOption('header'))); } $output->write($this->pot->toString($input)); } else { $progress = new ProgressHelper(); $progress->start($output, 1 + count($actualFiles)); $progress->advance(); foreach ($actualFiles as $file) { $this->extractFile($file); $progress->advance(); } $content = ''; ## If header is supplied and if we're starting a new file. if ($input->getOption('header')) { if (!file_exists($input->getOption('out')) || !$input->getOption('append')) { $content .= file_get_contents($input->getOption('header')); } } $content .= $this->pot->toString($input); file_put_contents($input->getOption('out'), $content, $input->getOption('append') ? FILE_APPEND : NULL); $progress->finish(); } }
/** * {@inheritdoc} */ public function generate(array $amount, $outputDir, ProgressHelper $progress, array $options = null) { if (!empty($config['filename'])) { $this->outputFile = $outputDir . '/' . trim($config['filename']); } else { $this->outputFile = $outputDir . '/' . self::DEFAULT_FILENAME; } $this->delimiter = $options['delimiter'] != null ? $options['delimiter'] : self::DEFAULT_DELIMITER; $this->forcedValues = []; $this->faker = Faker\Factory::create(); $associations = []; for ($i = 0; $i < $amount; $i++) { $association = []; $association['code'] = $this->getRandomProduct($this->faker); $association['products'] = $this->getRandomProducts(); $association['association_type'] = $this->getRandomAssociationType(); $associations[] = $association; $progress->advance(); } $headers = $this->getAllKeys($products); $this->writeCsvFile($products, $headers); return $this; }
public function start($inputDir, $outputDir, OutputInterface $consoleOutput, ProgressHelper $progress) { $this->inputDir = $inputDir; $this->outputDir = $outputDir; self::$consoleOutput = $consoleOutput; $inputOutputMappings = $this->createInputOutputMappings(); $availableDataFiles = array(); $progress->start($consoleOutput, count($inputOutputMappings)); foreach ($inputOutputMappings as $textFile => $outputFiles) { $mappings = $this->readMappingsFromFile($textFile); $language = $this->getLanguageFromTextFile($textFile); $this->removeEmptyEnglishMappings($mappings, $language); $this->makeDataFallbackToEnglish($textFile, $mappings); $mappingForFiles = $this->splitMap($mappings, $outputFiles); foreach ($mappingForFiles as $outputFile => $value) { $this->writeMappingFile($language, $outputFile, $value); $this->addConfigurationMapping($availableDataFiles, $language, $outputFile); } $progress->advance(); } $this->writeConfigMap($availableDataFiles); $progress->finish(); }
/** * Exports es index to provided file. * * @param Manager $manager * @param string $filename * @param int $chunkSize * @param OutputInterface $output */ public function exportIndex(Manager $manager, $filename, $chunkSize, OutputInterface $output) { $types = $manager->getTypesMapping(); $repo = $manager->getRepository($types); $results = $this->getResults($repo, $chunkSize); if (class_exists('\\Symfony\\Component\\Console\\Helper\\ProgressBar')) { $progress = new ProgressBar($output, $results->getTotalCount()); $progress->setRedrawFrequency(100); $progress->start(); } else { $progress = new ProgressHelper(); $progress->setRedrawFrequency(100); $progress->start($output, $results->getTotalCount()); } $metadata = ['count' => $results->getTotalCount(), 'date' => date(\DateTime::ISO8601)]; $writer = $this->getWriter($this->getFilePath($filename), $metadata); foreach ($results as $data) { $writer->push(array_intersect_key($data, array_flip(['_id', '_type', '_source']))); $progress->advance(); } $writer->finalize(); $progress->finish(); $output->writeln(''); }
/** * Process list of time entries. * * @param $entries */ function processTimeEntries($entries) { $process = array(); $table = new Table($this->output); $table->setHeaders(array('Issue', 'Issue title', 'Description', 'Duration', 'Activity', 'Status')); $defaultActivity = $this->getDefaultRedmineActivity(); // Get the items to process. foreach ($entries as $entry) { $activity_type = $this->getRedmineActivityFromTogglEntry($entry); // Get issue number from description. if ($issue_id = $this->getIssueNumberFromTimeEntry($entry)) { // Check if the entry is already synced. if ($this->isTimeEntrySynced($entry)) { $table->addRow(array($issue_id, $this->getRedmineIssueTitle($issue_id, '<warning>Issue is not available anymore.</warning>'), $entry['description'], number_format($entry['duration'] / 60 / 60, 2), $activity_type ? $activity_type->name : '', '<info>SYNCED</info>')); } elseif (!$this->isIssueNumberValid($issue_id)) { $table->addRow(array($issue_id, '', $entry['description'], number_format($entry['duration'] / 60 / 60, 2), $activity_type ? $activity_type->name : '', '<error>Given issue not available.</error>')); } elseif ($activity_type || $defaultActivity) { $table->addRow(array($issue_id, $this->getRedmineIssueTitle($issue_id), $entry['description'], number_format($entry['duration'] / 60 / 60, 2), $activity_type ? $activity_type->name : sprintf('[ %s ]', $defaultActivity->name), '<comment>unsynced</comment>')); // Set item to be process. $process[] = array('issue' => $issue_id, 'entry' => $entry, 'activity' => $activity_type ? $activity_type : $defaultActivity); } else { $table->addRow(array($issue_id, $this->getRedmineIssueTitle($issue_id), $entry['description'], number_format($entry['duration'] / 60 / 60, 2), '', '<error>no activity</error>')); } } else { $table->addRow(array(' - ', '', $entry['description'], number_format($entry['duration'] / 60 / 60, 2), $activity_type->name, '<error>No Issue ID found</error>')); } } $table->render(); // Simply proceed if no items are to be processed. if (empty($process)) { $this->output->writeln('<info>All entries synced</info>'); return; } // Confirm before we really process. if (!$this->question->ask($this->input, $this->output, new ConfirmationQuestion(sprintf('<question> %d entries not synced. Process now? [y] </question>', count($process)), false))) { $this->output->writeln('<error>Sync aborted.</error>'); return; } // Process each item. $this->progress->start($this->output, count($process)); foreach ($process as $processData) { $this->syncTimeEntry($processData['entry'], $processData['issue'], $processData['activity']); $this->progress->advance(); } $this->progress->finish(); }
/** * {@inheritdoc} */ public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null) { $this->attributesFile = $outputDir . '/' . self::ATTRIBUTES_FILENAME; $this->delimiter = $config['delimiter']; $count = (int) $config['count']; $localizableProbability = (int) $config['localizable_probability']; $scopableProbability = (int) $config['scopable_probability']; $locScopableProbability = (int) $config['localizable_and_scopable_probability']; $identifier = $config['identifier_attribute']; $this->faker = Faker\Factory::create(); $this->attributes = []; $this->attributes[$identifier] = ['code' => $identifier, 'type' => 'pim_catalog_identifier', 'group' => $this->getRandomAttributeGroupCode()]; $forceAttributes = $config['force_attributes']; foreach ($forceAttributes as $forceAttribute) { list($code, $type) = explode('=', $forceAttribute); $this->attributes[trim($code)] = ['type' => trim($type), 'group' => $this->getRandomAttributeGroupCode()]; } for ($i = 0; $i < $count; $i++) { $attribute = []; $attribute['code'] = self::ATTRIBUTE_CODE_PREFIX . $i; $type = $this->getRandomAttributeType(); $attribute['type'] = $type; $attribute['group'] = $this->getRandomAttributeGroupCode(); foreach ($this->getLocalizedRandomLabels() as $localeCode => $label) { $attribute['label-' . $localeCode] = $label; } if ($this->faker->boolean($locScopableProbability)) { $attribute['localizable'] = 1; $attribute['scopable'] = 1; } else { $attribute['localizable'] = (int) $this->faker->boolean($localizableProbability); $attribute['scopable'] = (int) $this->faker->boolean($scopableProbability); } if ('pim_catalog_metric' === $type) { $attribute = array_merge($attribute, $this->getMetricProperties()); } if ('pim_catalog_image' === $type || 'pim_catalog_file' === $type) { $attribute = array_merge($attribute, $this->getMediaProperties()); } $this->attributes[$attribute['code']] = $attribute; $progress->advance(); } $headers = $this->getAllKeys($this->attributes); $this->writeCsvFile($this->attributes, $headers); return $this; }
/** * Run the tool * * @param int $prev_contrib Previous contrib that was resynced * @param ProgressHelper|null $progress * @return array */ public function run($prev_contrib = 0, $progress = null) { $defaults = $this->get_defaults(); $total = $this->get_total(); // Reset counts to 0 if ($this->start == 0) { $this->reset_counts($defaults); } $batch = $this->get_batch(); foreach ($batch as $row) { if ($prev_contrib != $row['contrib_id']) { $this->update_contrib($row); } $type_count = ''; // Does the type have a field in the authors table for storing the type total? if (isset($this->types->get($row['contrib_type'])->author_count)) { $count_name = $this->types->get($row['contrib_type'])->author_count; $type_count = ", {$count_name} = {$count_name} +1"; } // Update owner's count if ($prev_contrib != $row['contrib_id']) { $this->increase_author_count($type_count, $row['contrib_user_id']); } // Update coauthor's count if (isset($row['user_id'])) { $this->increase_author_count($type_count, $row['user_id']); } if ($progress) { $progress->advance(); } $prev_contrib = $row['contrib_id']; } $next_batch = $this->start + $this->limit; if ($next_batch >= $total) { $result = $this->get_result('RESYNC_CONTRIB_COUNT_COMPLETE', $total, false); } else { $result = $this->get_result($this->user->lang('TOOL_PROGRESS_TOTAL', $next_batch, $total), $total, $next_batch); } $result['prev_contrib'] = $prev_contrib; return $result; }
/** * @param Channel $channel * @param BufferedQueryResultIterator $entities * @param InputInterface $input * @param ProgressHelper $progress * * @return int */ protected function processChannel($channel, BufferedQueryResultIterator $entities, InputInterface $input, ProgressHelper $progress) { $count = 0; $identityFQCN = $channel->getCustomerIdentity(); $em = $this->getDoctrineHelper()->getEntityManager($identityFQCN); foreach ($entities as $k => $entity) { if ($input->isInteractive()) { $progress->advance(); } if ($this->getAnalyticBuilder()->build($entity)) { $count++; } if (($k + 1) % self::BATCH_SIZE === 0) { $em->flush(); $em->clear(); } } $em->flush(); $em->clear(); return $count; }
/** * Render a pattern and theme pair. * * @param Raincolor\Containers\Pattern $pattern * @param Raincolor\Containers\Pattern $theme * @return void */ protected function render($pattern, $theme) { // Get template array from pattern. $templates = $pattern->get('templates'); foreach ($templates as $template) { // Get the path to the pattern. $path = dirname($pattern->get('path')); // Load the template file from disk. $source = $this->file->load($path . '/' . $template->get('file')); // Create a new presenter. $presenter = new Presenter($source, $theme); // Get the resulting colour scheme. $scheme = $presenter->present(); // Build the file output path for the scheme. $output = $this->buildOutputPath($pattern, $template, $theme); // Write the file to disk. $this->file->write($output, $scheme); // Update progress. $this->progress->advance(); } }
/** * {@inheritdoc} */ public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null) { $this->tmpFile = tempnam(sys_get_temp_dir(), 'data-gene'); if (!empty($config['filename'])) { $this->outputFile = $outputDir . '/' . trim($config['filename']); } else { $this->outputFile = $outputDir . '/' . self::DEFAULT_FILENAME; } $count = (int) $config['count']; $nbAttrBase = (int) $config['filled_attributes_count']; $nbAttrDeviation = (int) $config['filled_attributes_standard_deviation']; $startIndex = (int) $config['start_index']; $categoriesCount = (int) $config['categories_count']; $mandatoryAttributes = $config['mandatory_attributes']; if (!is_array($mandatoryAttributes)) { $mandatoryAttributes = []; } $delimiter = $config['delimiter']; $this->delimiter = $delimiter != null ? $delimiter : self::DEFAULT_DELIMITER; if (isset($config['force_values'])) { $this->forcedValues = $config['force_values']; } else { $this->forcedValues = []; } $this->identifierCode = $this->attributeRepository->getIdentifierCode(); $this->faker = Faker\Factory::create(); for ($i = $startIndex; $i < $startIndex + $count; $i++) { $product = []; $product[$this->identifierCode] = self::IDENTIFIER_PREFIX . $i; $family = $this->getRandomFamily($this->faker); $product['family'] = $family->getCode(); if ($nbAttrBase > 0) { if ($nbAttrDeviation > 0) { $nbAttr = $this->faker->numberBetween($nbAttrBase - round($nbAttrDeviation / 2), $nbAttrBase + round($nbAttrDeviation / 2)); } else { $nbAttr = $nbAttrBase; } } $familyAttrCount = count($this->getAttributesFromFamily($family)); if (!isset($nbAttr) || $nbAttr > $familyAttrCount) { $nbAttr = $familyAttrCount; } $attributes = $this->getRandomAttributesFromFamily($family, $nbAttr); foreach ($attributes as $attribute) { $valueData = $this->generateValue($attribute); $product = array_merge($product, $valueData); } foreach ($mandatoryAttributes as $mandatoryAttribute) { if (isset($this->attributesByFamily[$family->getCode()][$mandatoryAttribute])) { $attribute = $this->attributesByFamily[$family->getCode()][$mandatoryAttribute]; $valueData = $this->generateValue($attribute); $product = array_merge($product, $valueData); } } $categories = $this->getRandomCategoryCodes($categoriesCount); $product[self::CATEGORY_FIELD] = implode(',', $categories); $this->bufferizeProduct($product); $progress->advance(); } $this->writeCsvFile(); unlink($this->tmpFile); return $this; }
public function testNonDecoratedOutput() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream(false)); $progress->advance(); rewind($output->getStream()); $this->assertEquals('', stream_get_contents($output->getStream())); }
<?php use Symfony\Component\Console\Helper\ProgressHelper; // create a new progress bar (50 units) $progress = new ProgressHelper($output, 50); // start and displays the progress bar $progress->start(); $i = 0; while ($i++ < 50) { // ... do some work // advance the progress bar 1 unit $progress->advance(); // you can also advance the progress bar by more than 1 unit // $progress->advance(3); } // ensure that the progress bar is at 100% $progress->finish();