protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('remove-before')) { $this->get('library.indexation')->deleteIndexes(); foreach (\LibraryDocumentCollectionPeer::doSelect(new \Criteria()) as $documentCollection) { $this->get('library.documentCollection')->map($this->get('library.documentCollection')->export($documentCollection)); } } $vocabularyService = $this->get('library.vocabulary'); foreach ($this->get('library.documentCollection')->getList() as $documentCollection) { $documents = $documentCollection->getLibraryDocuments(); if (count($documents)) { $output->writeln($documentCollection->getName() . ':'); $progress = new ProgressBar($output, count($documents)); $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%'); foreach ($documents as $document) { $elasticaDocument = $this->get('library.indexation')->getDocument($document->getId()); if (false !== $elasticaDocument && !$input->getOption('update-image')) { $this->get('library.indexation')->refreshDocument($document, $vocabularyService, false); } else { $this->get('library.indexation')->refreshDocument($document, $vocabularyService, !$input->getOption('ignore-image')); } $progress->advance(); } $progress->finish(); $output->writeln("\n"); } } }
$this->message = $message; } $command = sprintf("%d %s\n", $percent, $message); fwrite($this->pipe, $command); } /** * Close progress bar window */ public function finish() { pclose($this->pipe); } } /** * Sample Usage */ $bar = new ProgressBar("ProgressBar.php Test"); for ($percent = 0; $percent < 25; $percent++) { usleep(150000); // .15 sec $bar->update($percent, "Test Starting..."); } for ($percent = 25; $percent < 100; $percent++) { usleep(20000); // .02 sec $bar->update($percent, "Test Finishing..."); } usleep(500000); // .5 sec $bar->finish();
} } unset($levels, $date_min, $date_max, $i, $row, $created, $level, $parent_id); print ProgressBar::finish(); print "DONE\r\n\n"; } } // Generate articles. if ($numbers['articles']) { ProgressBar::start($numbers['articles']); ProgressBar::setMessage('Adding articles...'); $date_min = new DateTime('-3 years'); $date_max = new DateTime(); for ($i = 0; $i < $numbers['articles']; $i++) { $row = Library\ObjectManager::getInstance()->getObject('com:articles.model.articles')->getItem(); $row->title = $generator->words(pick_random(range(1, 5))); $row->introtext = $generator->sentences(pick_random(range(1, 3))); $row->fulltext = $generator->sentences(pick_random(range(0, 5))); $row->published = (int) (rand(0, 20) > 0); $row->categories_category_id = pick_random($categories['articles']); $created = new DateTime('@' . rand($date_min->format('U'), $date_max->format('U'))); $row->created_on = $created->format('Y-m-d H:i:s'); $row->created_by = pick_random($users); $row->save(); print ProgressBar::next(); } unset($date_min, $date_max, $i, $row, $created); print ProgressBar::finish(); print "DONE\r\n\n"; } exit(0);