Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
insertfile.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Insert rendering file which comes from transformation engine
8  *
9  * @author Anakeen
10  * @version $Id: insertfile.php,v 1.8 2007/12/10 09:15:03 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
18 include_once ("FDL/Class.TaskRequest.php");
19 include_once ("Lib.FileMime.php");
20 /**
21  * Modify the attrid_txt attribute
22  * @param Action &$action current action
23  * @global docid string Http var : document identifier to modify
24  * @global attrid string Http var : the id of attribute to modify
25  * @global index int Http var : the range in case of array
26  * @global tid string Http var : task identifier
27  *
28  */
29 function insertfile(&$action)
30 {
31  $vidin = GetHttpVars("vidin");
32  $vidout = GetHttpVars("vidout");
33  $tid = GetHttpVars("tid");
34  $name = GetHttpVars("name");
35  $docid = GetHttpVars("docid");
36  $dbaccess = $action->dbaccess;
37 
38  if (!$tid) $err = _("no task identifier found");
39  else {
40  $filename = tempnam(getTmpDir() , 'txt-');
41  if ($filename === false) {
42  $err = sprintf(_("Error creating temporary file in '%s'.") , getTmpDir());
43  } else {
45  if ($err == "") {
46 
47  $outfile = $info["outfile"];
48  $status = $info["status"];
49  $infoin = new VaultFileInfo();
50  $infoout = new VaultFileInfo();
51 
52  if (($status == 'D') && ($outfile != '')) {
53 
55  $vf->Retrieve($vidin, $infoin);
56  $vf->Retrieve($vidout, $infoout);
57  $vf->Save($filename, false, $vidout);
58  $err = $vf->Retrieve($vidout, $infoout); // relaod for mime
59  $ext = getExtension($infoout->mime_s);
60  if ($ext == "") $ext = $infoout->teng_lname;
61  // print_r($infoout);
62  // print_r($ext);
63  if ($name != "") {
64  $newname = $name;
65  } else {
66  $pp = strrpos($infoin->name, '.');
67  $newname = substr($infoin->name, 0, $pp) . '.' . $ext;
68  }
69 
70  $vf->Rename($vidout, $newname);
71  $vf->storage->teng_state = \Dcp\TransformationEngine\Client::status_done;
72  $vf->storage->modify();
73  } else {
75  $vf->Retrieve($vidin, $infoin);
76  $vf->Retrieve($vidout, $infoout);
77 
78  $filename2 = tempnam(getTmpDir() , 'txt-');
79  if ($filename2 === false) {
80  $err = sprintf(_("Error creating temporary file in '%s'.") , getTmpDir());
81  } else {
82  $error = sprintf(_("Conversion as %s has failed ") , $infoout->teng_lname);
83  $error.= "\n== " . _("See below information about conversion") . "==\n" . print_r($info, true);
84  file_put_contents($filename2, $error);
85  //$vf->rename($vidout,"toto.txt");
86  $vf->Retrieve($vidout, $infoout);
87  $err = $vf->Save($filename2, false, $vidout);
88  $basename = _("conversion error") . ".txt";
89  $vf->Rename($vidout, $basename);
90  $vf->storage->teng_state = \Dcp\TransformationEngine\Client::error_convert;
91  $vf->storage->modify();
92  if ($docid) {
93  $doc = new_doc($dbaccess, $docid);
94  if ($doc->isAlive()) {
95  $doc->addHistoryEntry(sprintf(_("convert file %s as %s failed") , $infoin->name, $infoout->teng_lname) , HISTO_ERROR);
96  }
97  }
98  unlink($filename2);
99  }
100  }
101  }
102  unlink($filename);
103  }
104  }
105  if ($err != '') $action->lay->template = htmlspecialchars($err, ENT_QUOTES);
106  else $action->lay->template = htmlspecialchars("OK : " . sprintf(_("vid %s stored") , $vidout) , ENT_QUOTES);
107  $action->lay->noparse = true;
108 }
109 /**
110  * return filename where is stored produced file
111  * need to delete after use it
112  * @param $tid string
113  * @param $filename string
114  * @param $info array
115  * @return string
116  */
118 {
119  global $action;
120  $dbaccess = $action->dbaccess;
121  $ot = new \Dcp\TransformationEngine\Client($action->getParam("TE_HOST") , $action->getParam("TE_PORT"));
122 
123  $err = $ot->getInfo($tid, $info);
124  if ($err == "") {
125  $tr = new TaskRequest($dbaccess, $tid);
126  if ($tr->isAffected()) {
127  $outfile = $info["outfile"];
128  $status = $info["status"];
129 
130  if (($status == 'D') && ($outfile != '')) {
131  $err = $ot->getTransformation($tid, $filename);
132  //$err=$ot->getAndLeaveTransformation($tid,$filename); // to debug
133 
134  }
135  } else {
136  $err = sprintf(_("task %s is not recorded") , $tid);
137  }
138  }
139  return $err;
140 }
$status
Definition: index.php:30
global $action
newFreeVaultFile($dbaccess)
Definition: Lib.Util.php:17
$filename
const HISTO_ERROR
$docid
Definition: cleanFamily.php:13
$outfile
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
$vf
Definition: geticon.php:28
$dbaccess
Definition: checkVault.php:17
$info
Definition: geticon.php:30
getTEFile($tid, $filename, &$info)
Definition: insertfile.php:117
insertfile(&$action)
Definition: insertfile.php:29
getExtension($smime)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen