Beispiel #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $task_id = $this->param['taskid'];
     $alloc_act = $this->param['alloc_act'];
     $job_id = $this->param['job_id'];
     $date_type = $this->param['type'];
     $from_date = $this->param['from_date'];
     $to_date = $this->param['to_date'];
     $email = $this->param['email'];
     $_REQUEST["act"] = $alloc_act;
     if ($date_type == "day") {
         $date = date('Y-m-d');
         $from_date = date('Y-m-d', strtotime($date . ' -1 day')) . "";
         $to_date = $from_date;
     }
     $this->fff();
     if (!($job_id > 0) && !($runner_id > 0)) {
         $this->_log("Unknown job or runner to run allocation", 1);
         if ($task_id > 0) {
             $this->finalizeTask($task_id, 3, $this->log, $email);
         }
         exit;
     }
     if ($job_id) {
         $tmp = AllocJob::where(['ID' => $job_id])->select('DAY_BY_DAY')->first();
         $daybyday = $tmp['DAY_BY_DAY'];
         if ($daybyday == 1) {
             $ds = explode("-", $from_date);
             $d1 = "{$ds['2']}-{$ds['0']}-{$ds['1']}";
             $ds = explode("-", $to_date);
             $d2 = "{$ds['2']}-{$ds['0']}-{$ds['1']}";
             while (strtotime($d1) <= strtotime($d2)) {
                 $ds = explode("-", $d1);
                 $dd = "{$ds['1']}/{$ds['2']}/{$ds['0']}";
                 $this->exec_job($job_id, $dd, $dd);
                 $d1 = date("Y-m-d", strtotime("+1 day", strtotime($d1)));
             }
         } else {
             $this->exec_job($job_id, $from_date, $to_date);
         }
     } else {
         if ($runner_id) {
             $tmp = DB::table('alloc_runner AS b')->join(' alloc_job AS a', 'a.id', '=', 'b.job_id')->where(['b.id' => $job_id])->select('a.DAY_BY_DAY')->first();
             $daybyday = $tmp->DAY_BY_DAY;
             if ($daybyday == 1) {
                 $d1 = toDateString($from_date);
                 $d2 = toDateString($to_date);
                 while (strtotime($d1) <= strtotime($d2)) {
                     $ds = explode("-", $d1);
                     $dd = "{$ds['1']}/{$ds['2']}/{$ds['0']}";
                     $this->exec_runner($runner_id, $dd, $dd);
                     $d1 = date("Y-m-d", strtotime("+1 day", strtotime($d1)));
                 }
             } else {
                 $this->exec_runner($runner_id, $from_date, $to_date);
             }
         }
     }
     $this->_log("Finish." . ($this->error_count > 0 ? " <font color='red'>({$this->error_count} error)</font>" : " (no error)"), 2);
     if (isset($task_id) > 0) {
         $this->finalizeTask($task_id, $this->error_count > 0 ? 3 : 1, $this->log, $email);
         if ($this->log) {
             if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                 try {
                     $mailFrom = env('MAIL_USERNAME');
                     $data = ['content' => strip_tags($this->log)];
                     $subjectName = ($this->error_count > 0 ? "[ERROR] " : "") . "Automatic allocation task's log";
                     $ret = Mail::send('front.sendmail', $data, function ($message) use($email, $subjectName, $mailFrom) {
                         $message->from($mailFrom, 'Your Application');
                         $message->to($email)->subject($subjectName);
                     });
                 } catch (\Exception $e) {
                     \Log::info($e->getMessage());
                 }
             }
         }
     } else {
         \Log::info($this->log);
     }
 }
Beispiel #2
0
    }
}
if ($insert_values) {
    $sSQL = "insert into INT_TAG_MAPPING(OBJECT_TYPE, {$_REQUEST['fields_list']}) values {$insert_values}";
    $sSQL = str_replace("''", "null", $sSQL);
    $result = mysql_query($sSQL) or die("fail: " . $sSQL . "-> error:" . mysql_error());
}
$ids_delete = "";
foreach ($ids as $xID) {
    if ($xID) {
        $c = $_REQUEST["TAG_ID{$xID}"];
        if ($c) {
            $sSet = "";
            foreach ($fields_list as $fcomp) {
                if ($fcomp == 'BEGIN_DATE' || $fcomp == 'END_DATE') {
                    $_REQUEST["{$fcomp}{$xID}"] = toDateString($_REQUEST["{$fcomp}{$xID}"]);
                }
                $sSet .= ($sSet == "" ? "" : ",") . "`{$fcomp}`='" . $_REQUEST["{$fcomp}{$xID}"] . "'";
            }
            if ($sSet) {
                $sSQL = "UPDATE INT_TAG_MAPPING SET {$sSet} where id='{$xID}';";
                $sSQL = str_replace("''", "null", $sSQL);
                $result = mysql_query($sSQL) or die("fail: " . $sSQL . "-> error:" . mysql_error());
            }
        } else {
            $ids_delete .= ($ids_delete == "" ? "" : ",") . $xID;
        }
    }
}
if ($ids_delete) {
    $sSQL = "delete from INT_TAG_MAPPING where id in ({$ids_delete});";