/** * 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>'); }
/** * Simple method for listing output * one column * * @param string $header * @param array $items * @param OutputInterface $output */ public static function renderList($header, $items, $output) { $output->writeln('<fg=yellow;options=underscore>' . ucfirst($header) . "</>\n"); if (count($items) > 0) { foreach ($items as $item) { $output->writeln(" - {$item}"); } } $output->writeln("\n" . self::tint('(' . count($items) . ' in set)', 'comment')); }
protected function execute(InputInterface $input, OutputInterface $output) { $date = $input->getArgument("expiredDate"); $checkDate = $date instanceof \DateTime ? $date : new \DateTime($date); $checkDate->setTime(0, 0, 0); $em = $this->getContainer()->get('doctrine')->getEntityManager(); $entities = $em->getRepository('BraemCRMBundle:Lead')->deleteExpiredLeads($checkDate); if ($entities) { $count = count($entities); foreach ($entities as $entity) { $em->remove($entity); $output->writeln('Removed lead #' . $entity->getId()); } $em->flush(); $output->writeln($count . ' leads were successfully removing'); } else { $output->writeln('Nothing to remove'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $time_start = $this->microtime_float(); $output->writeln('<comment>START delete process</comment>'); if ($input->getOption('account')) { $output->writeln('<info>Safe accounts delete using ID</info>'); $ids = explode(",", $input->getOption('account')); foreach ($ids as $accountId) { $helper = new ImportAccountsHelper($this->getContainer()->get('doctrine')->getEntityManager()); $deleteResult = $helper->deleteAccount($accountId); $output->writeln($deleteResult); } } if ($input->getOption('file')) { $output->writeln('<info>Safe accounts delete using file: ' . $input->getOption('file') . '</info>'); $file = $input->getOption('file'); $parser = new AccountParser($file); $helper = new ImportAccountsHelper($this->getContainer()->get('doctrine')->getEntityManager()); while (count($accounts = $parser->getData()) > 0) { foreach ($accounts as $account) { $accountId = $account[1]; $deleteResult = $helper->deleteAccount($accountId); $output->writeln($deleteResult); } } } $time_end = $this->microtime_float(); $time = $time_end - $time_start; $output->writeln('<comment>END import process(' . $time . ' sec)</comment>'); }
/** * Stop * * @param OutputInterface $output * * @return void */ protected function stop(OutputInterface $output) { if (!file_exists($this->pidfile)) { $output->writeln('<error>PID file not found</error>'); } else { $output->writeln('Stopping daemon ... '); $pid = file_get_contents($this->pidfile); posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); $output->writeln('Daemon stopped with PID ' . $pid); unlink($this->pidfile); } }
/** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * @return null */ public function log($level, $message, array $context = array()) { $line = sprintf('<%s>[%s]</%s> %s', $level, $level, $level, strtr($message, $context)); $this->output->writeln($line); }