Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
settxtfile.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Update file text which comes from transformation engine
9  *
10  * @author Anakeen 2007
11  * @version $Id: settxtfile.php,v 1.13 2007/12/12 15:22:36 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Doc.php");
20 include_once ("FDL/Class.TaskRequest.php");
21 include_once ("WHAT/Class.TEClient.php");
22 /**
23  * Modify the attrid_txt attribute
24  * @param Action &$action current action
25  * @global docid Http var : document identificator to modify
26  * @global attrid Http var : the id of attribute to modify
27  * @global index Http var : the range in case of array
28  * @global tid Http var : task identificator
29  *
30  */
31 function settxtfile(&$action)
32 {
33  $docid = GetHttpVars("docid");
34  $attrid = GetHttpVars("attrid");
35  $index = GetHttpVars("index", -1);
36  $tid = GetHttpVars("tid");
37  $dbaccess = $action->GetParam("FREEDOM_DB");
38 
39  if (!$tid) $$err = _("no task identificator found");
40  else {
41  $ot = new TransformationEngine($action->getParam("TE_HOST") , $action->getParam("TE_PORT"));
42 
43  $err = $ot->getInfo($tid, $info);
44  if ($err == "") {
45  $tr = new TaskRequest($dbaccess, $tid);
46  if ($tr->isAffected()) {
47  $tr->delete(); // no need now
48  $outfile = $info["outfile"];
49  $status = $info["status"];
50  $sem = fopen(getTmpDir() . "/fdl$docid.lck", "a+");
51 
52  if (flock($sem, LOCK_EX)) {
53  //fwrite($sem,'fdl'.posix_getpid().":lock\n");
55  if (!$doc->isAffected()) $err = sprintf(_("cannot see unknow reference %s") , $docid);
56  if ($err == "") {
57 
58  if (($status == 'D') && ($outfile != '')) {
59  $filename = uniqid(getTmpDir() . "/txt-" . $doc->id . '-');
60  $err = $ot->getTransformation($tid, $filename);
61  //$err=$ot->getAndLeaveTransformation($tid,$filename);
62  if ($err == "") {
63  $at = $attrid . '_txt';
64  if (file_exists($filename) && $info['status'] == 'D') {
65  if ($index == - 1) {
66  $doc->$at = file_get_contents($filename);
67  } else {
68  if ($doc->AffectColumn(array(
69  $at
70  ))) {
71  $doc->$at = sep_replace($doc->$at, $index, str_replace("\n", " ", file_get_contents($filename)));
72  }
73  }
74  $av = $attrid . '_vec';
75  $doc->fields[$av] = $av;
76  $doc->$av = '';
77 
78  $doc->fulltext = '';
79  $doc->fields[$at] = $at;
80  $doc->fields['fulltext'] = 'fulltext';
81  $err = $doc->modify(true, array(
82  'fulltext',
83  $at,
84  $av
85  ) , true);
86  $doc->AddComment(sprintf(_("text conversion done for file %s") , $doc->vault_filename($attrid, false, $index)) , HISTO_NOTICE);
87  if (($err == "") && ($doc->locked == - 1)) {
88  // propagation in case of auto revision
89  $idl = $doc->latestId();
90  $ldoc = new_Doc($dbaccess, $idl);
91  if ($doc->getValue($attrid) == $ldoc->getValue($attrid)) {
92  $ldoc->$at = $doc->$at;
93  $ldoc->$av = '';
94  $ldoc->fulltext = '';
95  $ldoc->fields[$at] = $at;
96  $ldoc->fields[$av] = $av;
97  $ldoc->fields['fulltext'] = 'fulltext';
98  $err = $ldoc->modify(true, array(
99  'fulltext',
100  $at,
101  $av
102  ) , true);
103  }
104  }
105  } else {
106  $err = sprintf(_("output file [%s] not found") , $filename);
107  }
108  @unlink($filename);
109  }
110  } else {
111  $err = sprintf(_("task %s is not done correctly") , $tid);
112  }
113  if ($err != "") $doc->AddComment(sprintf(_("conversion failed for %s: ") . $err, $doc->vault_filename($attrid, false, $index)) , HISTO_NOTICE);
114  } else {
115  $err = sprintf(_("document [%s] not found") , $docid);
116  }
117  //fwrite($sem,posix_getpid().":unlock\n");
118  fclose($sem);
119  } else {
120  $err = sprintf(_("semaphore block") , $docid);
121  }
122  } else {
123  $err = sprintf(_("task %s is not recorded") , $tid);
124  }
125  }
126  }
127 
128  if ($err != '') $action->lay->template = $err;
129  else $action->lay->template = "OK : " . sprintf(_("doc %d indexed") , $docid);
130 }
131 ?>
← centre documentaire © anakeen - published under CC License - Dynacase