progressAdvance() public method

public progressAdvance ( $step = 1 )
Esempio n. 1
0
 private function removeIssues(InputInterface $input)
 {
     $this->refreshJournal($input);
     $journalIssues = $this->em->getRepository('OjsJournalBundle:Issue')->findBy(['journal' => $this->journal]);
     $this->io->progressStart(count($journalIssues));
     foreach ($journalIssues as $issue) {
         $this->io->progressAdvance();
         $this->em->remove($issue);
     }
     $this->em->flush();
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io->title($this->getDescription());
     $this->io->progressStart(count($this->allJournals));
     $counter = 1;
     foreach ($this->allJournals as $journal) {
         $this->normalizeSetting($journal);
         $this->io->progressAdvance(1);
         $counter = $counter + 1;
         if ($counter % 50 == 0) {
             $this->em->flush();
         }
     }
     $this->em->flush();
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io->title($this->getDescription());
     $this->io->progressStart(count($this->getJournals()));
     $counter = 1;
     foreach ($this->getJournals() as $journal) {
         $this->addTranslation($journal);
         $this->io->progressAdvance(1);
         $counter = $counter + 1;
         if ($counter % 50 == 0) {
             $this->em->flush();
         }
     }
     $this->em->flush();
     $this->io->success('All process finished');
 }
Esempio n. 4
0
 /**
  * @param Journal $journal
  * @return bool|null
  */
 private function normalizeLastIssuesByJournal(Journal $journal)
 {
     $this->io->newLine();
     $this->io->text('normalizing last issue for ' . $journal->getTitle());
     $this->io->progressAdvance();
     $findLastIssue = $this->em->getRepository('OjsJournalBundle:Issue')->findOneBy(['journal' => $journal, 'lastIssue' => true]);
     if ($findLastIssue) {
         return true;
     }
     /** @var Issue|null $getLogicalLastIssue */
     $getLogicalLastIssue = $this->em->getRepository('OjsJournalBundle:Issue')->getLastIssueByJournal($journal);
     if ($getLogicalLastIssue == null) {
         return null;
     }
     $getLogicalLastIssue->setLastIssue(true);
     $this->em->flush();
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io->title($this->getDescription());
     $this->io->progressStart(count($this->getAnnouncements()));
     $counter = 1;
     foreach ($this->getAnnouncements() as $announcement) {
         if (!$this->haveTranslation($announcement['id'])) {
             $this->addTranslation($announcement);
             $this->io->progressAdvance(1);
             $counter = $counter + 1;
             if ($counter % 50 == 0) {
                 $this->em->flush();
             }
         }
     }
     $this->em->flush();
     $this->io->success('All process finished');
 }
 /**
  * @{inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->application = $this->getApplication()->getApplication();
     $this->fixtureLoader = $this->getContainer()->get('demo.website_loader');
     $this->dataRepository = $this->getBundle()->getBaseDirectory() . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR;
     $output = new SymfonyStyle($input, $output);
     $output->title('BackBee Demonstration Website Importer');
     $output->progressStart(3);
     $lines = $this->loadFixtures();
     $output->progressAdvance();
     $output->note('✓ Updated BackBee Application');
     $website = $this->updateWebsite();
     $output->progressAdvance();
     $output->note(sprintf('✓ Updated Domain to ``%s`` with label ``%s``', $website['domain'], $website['label']));
     $this->importAssets();
     $output->progressAdvance();
     $output->note('✓ Imported pictures assets');
     $output->newline();
     $output->success('Website loaded with success.');
 }
Esempio n. 7
0
 private function installAssets(SymfonyStyle $io)
 {
     $io->section("Installing assets...");
     $input = $this->getEnvsInput('prod');
     $commands = array('assets:install', 'assetic:dump');
     $io->progressStart(count($commands));
     foreach ($commands as $command) {
         $cmdOutput = new BufferedOutput();
         $returnCode = $this->getApplication()->find($command)->run($input, $cmdOutput);
         if ($returnCode !== 0) {
             $io->newLine(2);
             $io->error("{$command} failed. Run it separately to find out why.");
             return;
         }
         $io->progressAdvance();
     }
     $io->progressFinish();
 }
Esempio n. 8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $io->title('Slack import');
     $io->comment('Requesting slack history…');
     $om = $this->container->get('doctrine')->getManager();
     $slack = $this->container->get('slack.api');
     $args = ['channel' => $slack->findChannelId($this->container->getParameter('slack_web_channel')), 'count' => 1000];
     try {
         $latest = $om->getRepository(ProcessedSlackMessage::class)->findMostRecent();
         $args['oldest'] = $latest->getDate()->format('U.u');
     } catch (NoResultException $e) {
     }
     $response = $slack->request('channels.history', $args);
     $messages = json_decode($response)->messages;
     $io->progressStart(count($messages));
     foreach ($messages as $message) {
         $io->progressAdvance();
         if (!(new AndX(new IsSlackMessage(), new IsHumanMessage()))->isSatisfiedBy($message)) {
             continue;
         }
         try {
             $url = $this->container->get('parser.slack_message')->parseUrl($message->text);
             $tags = $this->container->get('parser.slack_message')->parseTags($message->text);
             $watchLink = $this->container->get('extractor.watch_link_metadata')->extract($url, $tags);
             $watchLink->setCreatedAt((new \DateTime())->setTimestamp($message->ts));
             $processedMessage = new ProcessedSlackMessage($watchLink->getCreatedAt());
             $om->persist($processedMessage);
             $om->persist($watchLink);
             // Flush required at each round for tags unicity
             $om->flush();
         } catch (\InvalidArgumentException $e) {
             $this->container->get('logger')->addNotice('Unable to insert watchlink', ['exception' => $e, 'message' => $message->text]);
         } catch (\Exception $e) {
             $this->container->get('logger')->addError('Unknow exception', ['exception' => $e, 'message' => $message->text]);
         }
     }
     $io->progressFinish();
     $io->comment('Flush links…');
     $io->comment('Done.');
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $finder = new Finder();
     $finder->in(sys_get_temp_dir())->ignoreUnreadableDirs()->sortByType();
     $fs = new Filesystem();
     $files = $finder->name("backup_*");
     if (count($files) == 0) {
         $io->success('No olders backups removed');
         return;
     }
     $io->progressStart(count($files));
     foreach ($files as $file) {
         if ($fs->exists($file->getRealpath())) {
             $fs->remove($file->getRealpath());
         }
         sleep(1);
         $io->progressAdvance();
     }
     $io->progressFinish();
 }
 private function normalizePeriods()
 {
     $this->io->newLine();
     $this->io->text('normalizing periods');
     $this->getContainer()->getParameter('locale');
     $this->io->progressStart();
     $periods = $this->em->getRepository('OjsJournalBundle:Period')->findAll();
     foreach ($periods as $period) {
         $getTranslation = $this->em->getRepository('OjsJournalBundle:PeriodTranslation')->findOneBy(['translatable' => $period, 'locale' => $this->locale]);
         if (!$getTranslation) {
             $this->io->progressAdvance();
             $newPeriodTranslation = new PeriodTranslation();
             $newPeriodTranslation->setTranslatable($period);
             $newPeriodTranslation->setLocale($this->locale);
             $newPeriodTranslation->setPeriod('-');
             $this->em->persist($newPeriodTranslation);
         }
     }
     $this->em->flush();
     $this->io->newLine();
 }
Esempio n. 11
0
 private function createServerManagers()
 {
     /** @var Discord $discord */
     /* @var ObjectManager $manager */
     $discord = $this->getContainer()->get('discord');
     $manager = $this->getContainer()->get('default_manager');
     $repo = $manager->getRepository($this->getContainer()->getParameter('server_class'));
     /** @var Collection $servers */
     $servers = $discord->guilds;
     $ids = [];
     foreach ($discord->guilds as $guild) {
         $ids[] = $guild->id;
     }
     $dbServers = $repo->findBy(['identifier' => $ids]);
     $this->output->text('Creating server managers for ' . $servers->count() . ' servers.');
     $this->output->progressStart($servers->count());
     /** @var ServerManagerFactory $factory */
     $factory = $this->getContainer()->get('factory.server_manager');
     foreach ($discord->guilds as $server) {
         $dbServer = $this->findDbServer($dbServers, $server);
         try {
             $this->serverManagers[] = $factory->create($server, $dbServer);
         } catch (\Exception $e) {
             $this->output->progressFinish();
             $this->logError($e->getMessage());
             exit(0);
         }
         $this->output->progressAdvance();
     }
     $this->output->progressFinish();
     $delay = $this->getContainer()->getParameter('database_save_delay');
     if ($delay !== false) {
         $this->getContainer()->get('default_manager')->flush();
         $discord->loop->addPeriodicTimer($delay, function () {
             $this->output->note('Saving current UoW to database.');
             $this->getContainer()->get('default_manager')->flush();
         });
     }
 }
 /**
  * @return array
  */
 private function doGenerate()
 {
     $numberOfChars = count($this->possibleChars) - 1;
     $codesList = [];
     $this->io->progressStart($this->numberOfCodesToGenerate);
     for ($i = 0; $i < $this->numberOfCodesToGenerate; $i++) {
         do {
             $code = '';
             for ($j = 0; $j < $this->codeLength; $j++) {
                 $code .= $this->possibleChars[rand(0, $numberOfChars)];
             }
         } while (isset($codesList[$code]));
         $codesList[$code] = $code;
         $this->io->progressAdvance();
         if ($this->sleepTime) {
             usleep($this->sleepTime);
         }
     }
     $this->io->progressFinish();
     if ($this->sort) {
         sort($codesList);
     }
     return array_unique($codesList);
 }
Esempio n. 13
0
 /**
  * Search for open jobs and executes them
  * then show a report about the done job.
  */
 protected function executeJobs()
 {
     // Get the Jobs to be processed.
     $jobsInQueue = $this->em->getRepository('CampaignChainCoreBundle:Job')->getOpenJobsForScheduler($this->scheduler);
     if (empty($jobsInQueue)) {
         return;
     }
     $this->io->section('Executing jobs now:');
     $this->logger->info('Executing {counter} jobs now:', ['counter' => count($jobsInQueue)]);
     $this->io->progressStart(count($jobsInQueue));
     foreach ($jobsInQueue as $jobInQueue) {
         // Execute job.
         $this->executeJob($jobInQueue);
         $this->io->progressAdvance();
     }
     // ensure that the progress bar is at 100%
     $this->io->progressFinish();
     $this->em->clear();
     // Get the processed jobs.
     $jobsProcessed = $this->em->getRepository('CampaignChainCoreBundle:Job')->getProcessedJobsForScheduler($this->scheduler);
     if (empty($jobsProcessed)) {
         return;
     }
     // Display the results of the execution.
     $tableHeader = ['Job ID', 'Operation ID', 'Process ID', 'Job Name', 'Job Start Date', 'Job End Date', 'Duration', 'Status', 'Message'];
     $outputTableRows = [];
     foreach ($jobsProcessed as $jobProcessed) {
         $startDate = null;
         $endDate = null;
         if ($jobProcessed->getStartDate()) {
             $startDate = $jobProcessed->getStartDate()->format('Y-m-d H:i:s');
         }
         if ($jobProcessed->getEndDate()) {
             $endDate = $jobProcessed->getEndDate()->format('Y-m-d H:i:s');
         }
         $jobData = [$jobProcessed->getId(), $jobProcessed->getActionId(), $jobProcessed->getPid(), $jobProcessed->getName(), $startDate, $endDate, $jobProcessed->getDuration() . ' ms', $jobProcessed->getStatus(), $jobProcessed->getMessage()];
         $outputTableRows[] = $jobData;
         if (Job::STATUS_ERROR === $jobProcessed->getStatus()) {
             $context = array_combine($tableHeader, $jobData);
             $this->logger->error($jobProcessed->getMessage(), $context);
         }
     }
     $this->io->text('Results of executed actions:');
     $this->io->table($tableHeader, $outputTableRows);
 }
Esempio n. 14
0
 /**
  * @param QueryRequest $query
  * @param SymfonyStyle $io
  * @param DateTime $date
  * @throws \QCharts\CoreBundle\Exception\WriteReadException
  */
 protected function updateQuery(QueryRequest $query, SymfonyStyle $io, DateTime $date)
 {
     $modes = QueryUpdateCommand::getModes();
     $dateFormat = SnapshotService::FILE_DATE_FORMAT;
     /** @var SnapshotService $snapshotService */
     $snapshotService = $this->getContainer()->get("qcharts.core.snapshot_service");
     /** @var QueryRepository $qrRepo */
     $qrRepo = $this->getContainer()->get("qcharts.query_repo");
     $cron = CronExpression::factory($query->getCronExpression());
     $queryDate = $query->getConfig()->getFetchedOn()->format($dateFormat);
     $io->newLine();
     $io->section("QCharts checking: '{$query->getTitle()}' with date: {$queryDate}");
     if ($cron->isDue($date)) {
         //update it!
         $duration = $snapshotService->updateSnapshot($query);
         $io->newLine(1);
         $io->note("QCharts updating:");
         $io->table(['Title', 'CronExpression', 'Last fetch', 'Mode', 'Query execution time'], [[$query->getTitle(), $query->getCronExpression(), $query->getConfig()->getFetchedOn()->format($dateFormat), $modes[$query->getConfig()->getIsCached()], "{$duration} secs."]]);
         $qrRepo->setUpdatedOn($query, $date);
     }
     $io->success("QCharts '{$query->getTitle()}' is up to date, next run: {$cron->getNextRunDate()->format($dateFormat)}");
     $io->progressAdvance(1);
     $io->newLine(2);
 }
Esempio n. 15
-1
    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     *
     * @return void
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->io->title($this->getDescription());
        $totalAuthorCount = $this->getAuthorCount();
        $this->io->progressStart($totalAuthorCount);
        $rsm = new ResultSetMapping();
        for ($count = 0; $count <= $totalAuthorCount; $count += self::STEP) {
            $sql = <<<SQL
        UPDATE author
        SET user_id = users.id
        FROM users
        WHERE author.email = users.email
        AND author.id > ?
        and author.id < ?
        and author.user_id is null
SQL;
            $query = $this->em->createNativeQuery($sql, $rsm);
            $query->setParameter(1, $count);
            $query->setParameter(2, $count + self::STEP);
            $query->getResult();
            if (self::STEP > $totalAuthorCount) {
                $this->io->progressFinish();
            } else {
                $this->io->progressAdvance(self::STEP);
            }
        }
        $this->io->newLine(2);
        $this->io->success('All process finished');
    }