Core  3.2
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  * @package FDL
5 */
6 /**
7  * Update file text which comes from transformation engine
8  *
9  * @author Anakeen
10  * @version $Id: settxtfile.php,v 1.13 2007/12/12 15:22:36 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 /**
20  * Modify the attrid_txt attribute
21  * @param Action &$action current action
22  * @global docid string Http var : document identifier to modify
23  * @global attrid string Http var : the id of attribute to modify
24  * @global index int Http var : the range in case of array
25  * @global tid string Http var : task identifier
26  *
27  */
29 {
30  $docid = $action->getArgument("docid");
31  $attrid = $action->getArgument("attrid");
32  $index = $action->getArgument("index", -1);
33  $tid = $action->getArgument("tid");
34  $dbaccess = $action->dbaccess;
35  if (!$tid) $err = _("no task identifier found");
36  else {
37  $ot = new \Dcp\TransformationEngine\Client($action->getParam("TE_HOST") , $action->getParam("TE_PORT"));
38 
39  $err = $ot->getInfo($tid, $info);
40  if ($err == "") {
41  $tr = new TaskRequest($dbaccess, $tid);
42  if ($tr->isAffected()) {
43  $tr->delete(); // no need now
44  $outfile = $info["outfile"];
45  $status = $info["status"];
46  $sem = fopen(sprintf("%s/fdl%s.lck", getTmpDir() , strtr($docid, './', '__')) , "a+");
47 
48  if (flock($sem, LOCK_EX)) {
49  //fwrite($sem,'fdl'.posix_getpid().":lock\n");
51  if (!$doc->isAffected()) $err = sprintf(_("cannot see unknow reference %s") , $docid);
52  if ($err == "") {
53 
54  if (($status == 'D') && ($outfile != '')) {
55  $filename = tempnam(getTmpDir() , 'txt-');
56  if ($filename === false) {
57  $err = sprintf(_("Error creating temporary file in '%s'.") , getTmpDir());
58  } else {
59  $err = $ot->getTransformation($tid, $filename);
60  //$err=$ot->getAndLeaveTransformation($tid,$filename);
61  if ($err == "") {
62  $at = $attrid . '_txt';
63  if (file_exists($filename) && $info['status'] == 'D') {
64  if ($index == - 1) {
65  $doc->$at = file_get_contents($filename);
66  } else {
67  if ($doc->AffectColumn(array(
68  $at
69  ) , false)) {
70  $doc->$at = sep_replace($doc->$at, $index, str_replace("\n", " ", file_get_contents($filename)));
71  }
72  }
73  $av = $attrid . '_vec';
74  $doc->fields[$av] = $av;
75  $doc->$av = '';
76 
77  $doc->fulltext = '';
78  $doc->fields[$at] = $at;
79  $doc->fields['fulltext'] = 'fulltext';
80  $err = $doc->modify(true, array(
81  'fulltext',
82  $at,
83  $av
84  ) , true);
85  $doc->addHistoryEntry(sprintf(_("text conversion done for file %s") , $doc->vault_filename($attrid, false, $index)) , HISTO_NOTICE);
86  if (($err == "") && ($doc->locked == - 1)) {
87  // propagation in case of auto revision
88  $idl = $doc->getLatestId();
89  $ldoc = new_Doc($dbaccess, $idl);
90  if ($doc->getRawValue($attrid) == $ldoc->getRawValue($attrid)) {
91  $ldoc->$at = $doc->$at;
92  $ldoc->$av = '';
93  $ldoc->fulltext = '';
94  $ldoc->fields[$at] = $at;
95  $ldoc->fields[$av] = $av;
96  $ldoc->fields['fulltext'] = 'fulltext';
97  $err = $ldoc->modify(true, array(
98  'fulltext',
99  $at,
100  $av
101  ) , true);
102  }
103  }
104  } else {
105  $err = sprintf(_("output file [%s] not found") , $filename);
106  }
107  }
108  }
109  unlink($filename);
110  } else {
111  $err = sprintf(_("task %s is not done correctly") , $tid);
112  }
113  if ($err != "") $doc->addHistoryEntry(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  flock($sem, LOCK_UN);
119  } else {
120  $err = sprintf(_("semaphore block") , $docid);
121  }
122  fclose($sem);
123  } else {
124  $err = sprintf(_("task %s is not recorded") , $tid);
125  }
126  }
127  }
128  if ($err != '') $action->lay->template = htmlspecialchars($err, ENT_QUOTES);
129  else $action->lay->template = htmlspecialchars("OK : " . sprintf(_("doc %d indexed") , $docid) , ENT_QUOTES);
130  $action->lay->noparse = true;
131 }
$status
Definition: index.php:30
sep_replace($ak, $idx, $by="-", $sep="\n")
Definition: Lib.Util.php:576
global $action
$filename
const HISTO_NOTICE
$docid
Definition: cleanFamily.php:13
$outfile
settxtfile(Action &$action)
Definition: settxtfile.php:28
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
new_Doc($dbaccess, $id= '', $latest=false)
getParam($name, $def="")
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
$info
Definition: geticon.php:30
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen