示例#1
0
 /**
  * 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
文件: Job.php 项目: stefansl/convertx
 /**
  * Find the internal and external target tables (tmp versions)
  *
  * @param $intPid
  * @return array
  */
 public static function findTargetTables($intPid)
 {
     $objJob = JobModel::findByPk($intPid);
     $arrTargets = Helper::arrayOnly($objJob->targetTables);
     $objSteps = StepModel::findBy(array('tl_convertx_step.pid=?', 'tl_convertx_step.published=?', 'tl_convertx_step.action=?'), array($intPid, 1, 'converter'));
     if (!$objSteps) {
         return $arrTargets;
     }
     while ($objSteps->next()) {
         $objConverter = ConverterModel::findByPk($objSteps->converter);
         switch ($objConverter->targetType) {
             case 'InternalTable':
                 // table names for internal data
                 $arrTargets[] = 'cvx_' . $objConverter->targetTable;
                 break;
             default:
                 // tmp tables for external data get a name based on the converter id
                 $arrTargets[] = 'cvx_' . $objConverter->id;
                 break;
         }
     }
     return array_unique($arrTargets);
 }
示例#3
0
 /**
  * Get possible subjobs
  *
  * @param $objRow
  * @return array
  */
 public function getJobs($objRow)
 {
     $return = array();
     $objJobs = JobModel::findAll();
     while ($objJobs->next()) {
         if ($objJobs->id != $objRow->activeRecord->pid) {
             $return[$objJobs->id] = $objJobs->title;
         }
     }
     return $return;
 }
示例#4
0
 /**
  * Finalize the table
  *
  * @param $strTarget
  * @param $objRun
  * @return bool
  */
 public static function finalize($strTarget, $objRun)
 {
     $objConverter = ConverterModel::findOneBy('targetTable', $strTarget);
     $objJob = JobModel::findByPk($objRun->pid);
     // maybe there are tables not bound on a converter
     if (!$objConverter) {
         // do not finalize on simulation
         if ($objRun->simulation) {
             // drop tmp table
             $Database = Database::getInstance();
             $Database->prepare("DROP TABLE IF EXISTS cvx_" . $strTarget)->execute();
             return true;
         }
         // -----------------------------------------
         // replace the original table
         return self::replaceByWorkingTable('cvx_' . $strTarget, $objRun->begin, $objJob->keepVersions, $objRun->simulation);
     }
     // do not finalize on simulation
     if ($objRun->simulation) {
         // drop tmp table
         $Database = Database::getInstance();
         $Database->prepare("DROP TABLE IF EXISTS cvx_" . $objConverter->targetTable)->execute();
         return true;
     }
     // -----------------------------------------
     // replace the original table
     return self::replaceByWorkingTable('cvx_' . $objConverter->targetTable, $objRun->begin, $objJob->keepVersions, $objRun->sim);
 }
示例#5
0
文件: Run.php 项目: stefansl/convertx
 /**
  * Delete older logs, keep defined versions
  *
  * @param $objRun
  */
 public static function deleteLogs($objRun)
 {
     // get job data
     $objJob = JobModel::findByPk($objRun->pid);
     $objRuns = RunModel::findBy('pid', $objRun->pid, array('order' => 'end DESC', 'offset' => $objJob->keepLogs));
     // delete older logs
     if ($objRuns) {
         Database::getInstance()->prepare("DELETE FROM tl_convertx_run WHERE id IN (" . implode(',', $objRuns->fetchEach('id')) . ")")->execute();
         Database::getInstance()->prepare("DELETE FROM tl_convertx_log WHERE pid IN (" . implode(',', $objRuns->fetchEach('id')) . ")")->execute();
     }
 }