Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
fdl_execute.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Execute Freedom Processes
8  *
9  * @author Anakeen
10  * @version $Id: fdl_execute.php,v 1.6 2008/10/02 15:42:43 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 // refreah for a classname
17 // use this only if you have changed title attributes
18 include_once ("FDL/Lib.Attr.php");
19 include_once ("FDL/Class.DocFam.php");
20 
21 global $action;
22 
24 $appl->Set("FDL", $core);
25 
26 $dbaccess = $appl->dbaccess;
27 if ($dbaccess == "") {
28  print "Database not found : appl->dbaccess";
29  exit;
30 }
31 
32 $usage = new ApiUsage();
33 $usage->setDefinitionText("Execute Dynacase Processes");
34 $docid = $usage->addOptionalParameter("docid", "special docid", null, 0);
35 $comment = base64_decode($usage->addOptionalParameter("comment", "additionnal comment", null, ""));
36 $usage->verify();
37 
38 if (($docid == 0) && (!is_numeric($docid))) $docid = getFamIdFromName($dbaccess, $docid);
39 
40 if ($docid > 0) {
42  /**
43  * @var \Dcp\Family\EXEC $doc
44  */
45  if ($doc->locked == - 1) { // it is revised document
46  $doc = new_Doc($dbaccess, $doc->getLatestId());
47  }
48 
49  $doc->setValue("exec_status", "progressing");
50  $doc->setValue("exec_statusdate", $doc->getTimeDate());
51  $doc->modify(true, array(
52  "exec_status",
53  "exec_statusdate"
54  ) , true);
55  $cmd = $doc->bgCommand($action->user->id == 1);
56  $f = uniqid(getTmpDir() . "/fexe");
57  $fout = "$f.out";
58  $ferr = "$f.err";
59  $cmd.= ">$fout 2>$ferr";
60  $m1 = microtime();
61  system($cmd, $statut);
62  $m2 = microtime_diff(microtime() , $m1);
63  $ms = gmstrftime("%H:%M:%S", $m2);
64 
65  if (file_exists($fout)) {
66  $doc->setValue("exec_detail", file_get_contents($fout));
67  unlink($fout);
68  }
69  if (file_exists($ferr)) {
70  $doc->setValue("exec_detaillog", file_get_contents($ferr));
71  unlink($ferr);
72  }
73 
74  $doc->clearValue("exec_nextdate");
75  $doc->setValue("exec_elapsed", $ms);
76  $doc->setValue("exec_date", date("d/m/Y H:i "));
77  $doc->clearValue("exec_status");
78  $doc->clearValue("exec_statusdate");
79  $doc->setValue("exec_state", (($statut == 0) ? "OK" : $statut));
80  $puserid = $doc->getRawValue("exec_iduser"); // default exec user
81  $doc->setValue("exec_iduser", $doc->getExecUserID());
82  $doc->refresh();
83  $err = $doc->modify();
84  if ($err == "") {
85  if ($comment != "") $doc->addHistoryEntry($comment);
86  $err = $doc->revise(sprintf(_("execution by %s done %s") , $doc->getTitle($doc->getExecUserID()) , $statut));
87  if ($err == "") {
88  $doc->clearValue("exec_elapsed");
89  $doc->clearValue("exec_detail");
90  $doc->clearValue("exec_detaillog");
91  $doc->clearValue("exec_date");
92  $doc->clearValue("exec_state");
93  $doc->setValue("exec_iduser", $puserid);
94  $doc->refresh();
95  $err = $doc->modify();
96  }
97  } else {
98  $doc->addHistoryEntry($err, HISTO_ERROR);
99  }
100 
101  if ($err != "") exit(1);
102 }
$dbaccess
Definition: fdl_execute.php:26
$comment
Definition: fdl_execute.php:35
$appl
Definition: fdl_execute.php:23
foreach($argv as $arg) $cmd
const HISTO_ERROR
global $action
Definition: fdl_execute.php:18
microtime_diff($a, $b)
Definition: Lib.Common.php:302
getFamIdFromName($dbaccess, $name)
print
Definition: checklist.php:49
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
switch($command) exit
Definition: checkVault.php:46
new_Doc($dbaccess, $id= '', $latest=false)
if($dbaccess=="") $usage
Definition: fdl_execute.php:32
if($file) if($subject==""&&$file) if($subject=="") $err
$docid
Definition: fdl_execute.php:34
Verify arguments for wsh programs.
$core
Definition: chgpasswd.php:33
← centre documentaire © anakeen