28 AddWarningMsg(sprintf(_(
"Error : need edit privilege to execute")));
73 $fu =
getTDoc($this->dbaccess, $fuid);
74 $wuid = $fu[
"us_whatid"];
75 $this->execuserid = $fuid;
80 $cmd.=
" --userid=$wuid";
81 if (!$bgapi)
$cmd.= sprintf(
" --app=%s --action=%s", escapeshellarg($bgapp) , escapeshellarg($bgact));
82 else $cmd.= sprintf(
" --api=%s", escapeshellarg($bgapi));
84 foreach ($tp as $k => $v) {
85 $b = sprintf(
" --%s=%s", escapeshellarg($v[
"exec_idvar"]) , escapeshellarg($v[
"exec_valuevar"]));
96 return $this->execuserid;
106 $nday = intval($this->
getRawValue(
"exec_periodday", 0));
107 $nhour = intval($this->
getRawValue(
"exec_periodhour", 0));
108 $nmin = intval($this->
getRawValue(
"exec_periodmin", 0));
109 if (($nday + $nhour + $nmin) > 0) {
110 $ndh = $this->
getDate($nday, $nhour, $nmin);
123 $td =
getTDoc($this->dbaccess, $pid);
124 $ndh =
getv($td,
"exec_date");
144 public function executeNow()
149 $status = $this->bgExecute(_(
"dynacase cron try execute"));
154 $del->clearValue(
"exec_status");
155 $del->clearValue(
"exec_handnextdate");
156 $err = $del->store();
159 print sprintf(
"Execute %s [%d] (%s) : %s\n", $del->title, $del->id, $del->getRawValue(
"exec_handnextdate") ,
$err);
161 print sprintf(
"Error executing %s [%d] (%s) : %s (%s)\n", $del->title, $del->id, $del->getRawValue(
"exec_handnextdate") ,
$err,
$status);
176 $time_start = microtime(
true);
179 $time_end = microtime(
true);
180 $time = $time_end - $time_start;
182 AddWarningMsg(sprintf(_(
"Process %s [%d] executed") , $this->title, $this->
id));
183 $action->log->
info(sprintf(_(
"Process %s [%d] executed in %.03f seconds") , $this->title, $this->
id, $time));
185 AddWarningMsg(sprintf(_(
"Error : Process %s [%d]: status %d") , $this->title, $this->
id,
$status));
186 $action->log->
error(sprintf(_(
"Error : Process %s [%d]: status %d in %.03f seconds") , $this->title, $this->
id,
$status, $time));
197 if (
$doc->locked == - 1) {
201 $doc->setValue(
"exec_status",
"progressing");
202 $doc->setValue(
"exec_statusdate",
$doc->getTimeDate());
203 $doc->modify(
true, array(
207 $cmd =
$doc->bgCommand($action->user->id == 1);
211 $cmd.=
">$fout 2>$ferr";
213 system(
$cmd, $statut);
215 $ms = gmstrftime(
"%H:%M:%S", $m2);
217 if (file_exists($fout)) {
218 $doc->setValue(
"exec_detail", file_get_contents($fout));
221 if (file_exists($ferr)) {
222 $doc->setValue(
"exec_detaillog", file_get_contents($ferr));
226 $doc->clearValue(
"exec_nextdate");
227 $doc->setValue(
"exec_elapsed", $ms);
228 $doc->setValue(
"exec_date", date(
"d/m/Y H:i "));
229 $doc->clearValue(
"exec_status");
230 $doc->clearValue(
"exec_statusdate");
231 $doc->setValue(
"exec_state", (($statut == 0) ?
"OK" : $statut));
232 $puserid =
$doc->getRawValue(
"exec_iduser");
233 $doc->setValue(
"exec_iduser",
$doc->getExecUserID());
238 $err =
$doc->revise(sprintf(_(
"execution by %s done %s") ,
$doc->getTitle(
$doc->getExecUserID()) , $statut));
240 $doc->clearValue(
"exec_elapsed");
241 $doc->clearValue(
"exec_detail");
242 $doc->clearValue(
"exec_detaillog");
243 $doc->clearValue(
"exec_date");
244 $doc->clearValue(
"exec_state");
245 $doc->setValue(
"exec_iduser", $puserid);
253 if (
$err !=
"")
return 1;
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
static getDate($daydelta=0, $dayhour="", $daymin="", $getlocale=false)
getLatestId($fixed=false, $forcequery=false)
canEdit($verifyDomain=true)
bgCommand($masteruserid=false)
getArrayRawValues($idAttr, $index=-1)
modify($nopost=false, $sfields="", $nopre=false)
foreach($argv as $arg) $cmd
setValue($attrid, $value, $index=-1, &$kvalue=null)
getWshCmd($nice=false, $userid=0, $sudo=false)
revision(Action &$action)
_execute(\Action &$action, $comment= '')
new_Doc($dbaccess, $id= '', $latest=false)
setMaxExecutionTimeTo($limit)
if($file) if($subject==""&&$file) if($subject=="") $err
getRawValue($idAttr, $def="")
control($aclname, $strict=false)