コード例 #1
0
ファイル: cron.php プロジェクト: stefansl/convertx
 /**
  * Run the controller
  */
 public function run()
 {
     $tmp = explode('?', Environment::get('request'));
     $strAction = ampersand($tmp[0]);
     $objStatus = (object) null;
     System::loadLanguageFile('tl_convertx_job');
     // only run with token and maybe restricted to certain IPs
     $ipOk = count($GLOBALS['convertx']['allowIPs']) == 0 || count($GLOBALS['convertx']['allowIPs']) > 0 && in_array(Environment::get('ip'), $GLOBALS['convertx']['allowIPs']) ? true : false;
     if (!$ipOk || !Input::get('token') && !Input::get('REQUEST_TOKEN')) {
         die($GLOBALS['TL_LANG']['tl_convertx_job']['no_cron_access']);
     }
     // get the job
     if (Input::get('token')) {
         $objJob = JobModel::findOneBy('token', Input::get('token'));
         if (!$objJob) {
             die($GLOBALS['TL_LANG']['tl_convertx_job']['cron_failed']);
         }
         // start a run
         $this->redirect($strAction . '?run=init&id=' . $objJob->id . '&REQUEST_TOKEN=' . REQUEST_TOKEN);
     }
     // we need a run
     if (!Input::get('run')) {
         die($GLOBALS['TL_LANG']['tl_convertx_job']['cron_failed']);
     }
     // do the convertx run
     $objRun = new Run();
     $arrRun = $objRun->doRun(Input::get('run'), 0);
     foreach ($arrRun as $k => $v) {
         $objStatus->{$k} = $v;
     }
     // success
     if ($objStatus->complete) {
         echo '<!DOCTYPE html>
             <head>
             <meta charset="utf-8">
             <title>CONVERTX CRON</title>
             </head>
             <body>
             <h1>' . $GLOBALS['TL_LANG']['tl_convertx_job']['cron_success'] . '</h1>
             ' . $objStatus->content . '
             </body>
             </html>';
         die;
     }
     // next step
     $strAction .= '?key=runjob&run=' . ($objStatus->subjob ? 'init&jumpToRun=' . $objStatus->jumpToRun . '&rootRun=' . $objStatus->rootRun . '&id=' : '') . $objStatus->id . ($objStatus->final ? '&final=1' : '') . '&REQUEST_TOKEN=';
     $this->redirect($strAction . REQUEST_TOKEN);
 }
コード例 #2
0
ファイル: Run.php プロジェクト: stefansl/convertx
 /**
  * Generate module
  *
  * @return string
  */
 protected function compile()
 {
     $this->import('BackendUser', 'User');
     // prepare template
     $this->Template = new BackendTemplate($this->strTemplate);
     $this->Template->back_href = $this->getReferer(true);
     $this->Template->back_title = specialchars($GLOBALS['TL_LANG']['MSC']['backBT']);
     $this->Template->back_button = $GLOBALS['TL_LANG']['MSC']['backBT'];
     $this->Template->action = ampersand($this->Environment->request);
     // -----------------------------------------
     // confirm job run first
     if (!Input::get('run')) {
         $objJob = Job::findJob(Input::get('id'));
         // job not found
         if ($objJob->error) {
             $this->Template->abort = true;
             $this->Template->running = false;
             $this->Template->complete = false;
             $this->Template->title = $objJob->title;
             $this->Template->error = $objJob->error;
             $this->Template->submit = $GLOBALS['TL_LANG']['tl_convertx_job']['end'];
             return $this->Template->parse();
         }
         // show confirmation form
         $this->Template->id = $objJob->id;
         $this->Template->title = sprintf($GLOBALS['TL_LANG']['tl_convertx_job']['jobTitle'], $objJob->id, $objJob->title);
         $this->Template->content = $GLOBALS['TL_LANG']['tl_convertx_job']['runNotice'];
         $this->Template->submit = $GLOBALS['TL_LANG']['tl_convertx_job']['start'];
         $this->Template->isSimulation = $GLOBALS['TL_LANG']['tl_convertx_job']['simNotice'];
         return $this->Template->parse();
     }
     $objRun = new ConvertXRun();
     $arrRun = $objRun->doRun(Input::get('run'), $this->User->id);
     foreach ($arrRun as $k => $v) {
         $this->Template->{$k} = $v;
     }
     return $this->Template->parse();
 }