/**
  * execute api command
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $aData = array();
     // set colors and formats
     $oErrStyle = new OutputFormatterStyle('red', null, array('bold'));
     $oOkStyle = new OutputFormatterStyle('green', null, array('bold'));
     $oLogoStyle = new OutputFormatterStyle('cyan', null);
     $output->getFormatter()->setStyle('err', $oErrStyle);
     $output->getFormatter()->setStyle('ok', $oOkStyle);
     $output->getFormatter()->setStyle('sw', $oLogoStyle);
     // print logo
     $this->_printLogo($output);
     // Get active remote apps
     $aRemoteApps = RemoteAppQuery::create()->findByActivated(true);
     /** @var RemoteApp $oRemoteApp */
     $iCnt = 0;
     foreach ($aRemoteApps as $oRemoteApp) {
         // get cron string
         $aData[] = array($oRemoteApp->getId(), $oRemoteApp->getName(), $oRemoteApp->getLastRun()->format("d.m.Y H:i:s"));
         $iCnt++;
     }
     // get tablehelper for cli
     $oTable = $this->getHelper('table');
     $oTable->setHeaders(array('ID', 'Title', 'Lastrun'))->setRows($aData);
     $oTable->render($output);
     // green text
     $output->writeln("\n<fg=white;options=bold>     " . $iCnt . " Job(s) found</fg=white;options=bold>\n");
 }
Exemplo n.º 2
0
 /**
  * execute api command
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // define colors if verbose
     if ($input->hasOption('verbose')) {
         if ($input->getOption('verbose')) {
             $oErrStyle = new OutputFormatterStyle('red', null, array('bold'));
             $oOkStyle = new OutputFormatterStyle('green', null, array('bold'));
             $oLogoStyle = new OutputFormatterStyle('cyan', null);
             $output->getFormatter()->setStyle('err', $oErrStyle);
             $output->getFormatter()->setStyle('ok', $oOkStyle);
             $output->getFormatter()->setStyle('sw', $oLogoStyle);
         }
     }
     // define colors if verbose
     if ($input->hasOption('verbose')) {
         if ($input->getOption('verbose')) {
             $this->_printLogo($output);
         }
     }
     $bForce = false;
     $sAppId = $input->getOption('app');
     if ($input->hasOption('force')) {
         $bForce = $input->getOption('force');
     }
     // run command for single app?
     if (!$sAppId) {
         // Get active remote apps
         $aRemoteApps = RemoteAppQuery::create()->findByActivated(true);
     } else {
         $oRemoteApp = RemoteAppQuery::create()->findOneById($sAppId);
         $aRemoteApps = array($oRemoteApp);
     }
     $iCnt = 0;
     $iStarttime = microtime(true);
     // iterate through apps and run api call
     foreach ($aRemoteApps as $oRemoteApp) {
         // get cron string
         $sCron = $oRemoteApp->getCron();
         if (strlen($sCron) > 1) {
             // parse cronstring and check time
             $bRun = $this->_parseCrontab(date('d.m.Y H:i'), $oRemoteApp->getCron());
             if ($bRun || $bForce) {
                 if ($input->hasOption('verbose')) {
                     if ($input->getOption('verbose')) {
                         $output->write('     ' . date('d.m.Y H:i') . ' <comment>Job:</comment> <fg=magenta>' . $oRemoteApp->getName() . '</fg=magenta> <comment>runnning...</comment>');
                     }
                 }
                 // make api call
                 $aResponse = $this->_makeCall($oRemoteApp);
                 // save response to database
                 $this->_saveResponse($aResponse, $oRemoteApp);
                 // print status if verbose
                 if ($input->hasOption('verbose')) {
                     if ($input->getOption('verbose')) {
                         $output->write("\t\t" . $this->_getStatus($aResponse['status']) . "\n");
                     }
                 }
                 $iCnt++;
             } else {
                 // current app ignored because of cronsettings
                 if ($input->hasOption('verbose')) {
                     if ($input->getOption('verbose')) {
                         $output->write('     ' . date('d.m.Y H:i') . ' <fg=magenta>' . $oRemoteApp->getName() . "</fg=magenta> <comment>not running because of cron settings.</comment>\n");
                     }
                 }
             }
         }
     }
     // calculate elapsed time
     if ($input->hasOption('verbose')) {
         if ($input->getOption('verbose')) {
             $iEndtime = microtime(true);
             $iSeconds = round($iEndtime - $iStarttime);
             $iMinutes = round($iSeconds / 60);
             if ($iSeconds < 10) {
                 $iSeconds = '0' . $iSeconds;
             }
             $iHour = round($iMinutes / 60);
             if ($iMinutes < 10) {
                 $iMinutes = '0' . $iMinutes;
             }
             if ($iHour < 10) {
                 $iHour = '0' . $iHour;
             }
             // green text
             $output->writeln("\n<fg=white;options=bold>     " . $iCnt . ' Job(s) done in ' . $iHour . ':' . $iMinutes . ':' . $iSeconds . "</fg=white;options=bold>\n");
         }
     }
 }
 /**
  * Returns a new RemoteAppQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   RemoteAppQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return RemoteAppQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof RemoteAppQuery) {
         return $criteria;
     }
     $query = new RemoteAppQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Exemplo n.º 4
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(RemoteAppPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = RemoteAppQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * Get the associated RemoteApp object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return RemoteApp The associated RemoteApp object.
  * @throws PropelException
  */
 public function getRemoteApp(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aRemoteApp === null && $this->remote_app_id !== null && $doQuery) {
         $this->aRemoteApp = RemoteAppQuery::create()->findPk($this->remote_app_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aRemoteApp->addRemoteHistoryContaos($this);
            */
     }
     return $this->aRemoteApp;
 }
 /**
  * Shows last api-log entry
  *
  * @param $id
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function lastLogAction($id)
 {
     $oLog = ApiLogQuery::create()->findOneByRemoteAppId($id);
     $oRemoteApp = RemoteAppQuery::create()->findOneById($id);
     return $this->render('SlashworksAppBundle:RemoteApp:log.html.twig', array('oLog' => $oLog, 'remote_app' => $oRemoteApp));
 }
Exemplo n.º 7
0
 /**
  * Returns the number of related RemoteApp objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related RemoteApp objects.
  * @throws PropelException
  */
 public function countRemoteApps(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collRemoteAppsPartial && !$this->isNew();
     if (null === $this->collRemoteApps || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collRemoteApps) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getRemoteApps());
         }
         $query = RemoteAppQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByCustomer($this)->count($con);
     }
     return count($this->collRemoteApps);
 }