7 require_once
"Class.DbObj.php";
143 create table docwait ( refererid int not null,
144 refererinitid int not null,
151 date timestamp default now(),
157 create index i_docwait on docwait(transaction);
158 create unique index iu_docwait on docwait(refererinitid, uid);
159 create sequence seq_waittransaction start 1;
176 private $refererDoc = null;
182 private $refererDocId = null;
188 private $waitingDoc = null;
203 $wdoc->doctype = $wdoc->defDoctype;
204 if ($this->localid) {
208 if ($this->localid) {
209 $this->refererid = $wdoc->id;
210 $this->refererinitid = $wdoc->initid;
213 $this->
exec_query(sprintf(
"update docwait set refererid=%d, refererinitid=%d, localid='' where localid='%s'", $this->refererid, $this->refererinitid, pg_escape_string($this->localid)));
221 $this->refererDoc=$wdoc;
224 $this->status = self::constraint;
225 $this->statusmessage = (!empty(
$info->error)) ?
$info->label .
' : ' .
$info->error :
$err;
246 $this->refererinitid =
$doc->initid;
247 $this->refererid =
$doc->id;
248 $this->orivalues = serialize(
$doc->getValues());
249 $this->status = self::upToDate;
250 $this->statusmessage =
'';
251 $this->transaction = 0;
252 $this->date = date(
'Y-m-d H:i:s.u');
264 private function getWriteAttribute(
Doc &
$doc)
268 foreach ($attrs as $aid => $oa) {
269 if (($oa->mvisibility ==
'W') || ($oa->mvisibility ==
'O') || $oa->getOption(
"writted") ==
"yes") {
282 $this->refererDoc = null;
283 $this->waitingDoc = null;
294 if (
$reset) $this->refererDoc = null;
295 if ($this->refererid <= 0)
return null;
296 if (!$this->refererDoc) {
297 $this->refererDoc = new_doc($this->dbaccess, $this->refererid,
true);
298 $this->refererDocId = $this->refererDoc->id;
299 if ($this->waitingDoc) {
300 $this->values = serialize($this->waitingDoc->getValues());
301 $this->waitingDoc = null;
304 if (($this->refererDoc->id != $this->refererDocId) || ($fix = $this->refererDoc->isFixed()) || ($fix === null)) {
305 $this->refererDoc = new_doc($this->dbaccess, $this->refererid,
true);
306 $this->refererDocId = $this->refererDoc->id;
307 if ($this->waitingDoc) {
308 $this->values = serialize($this->waitingDoc->getValues());
309 $this->waitingDoc = null;
313 return $this->refererDoc;
323 if (!$this->waitingDoc) {
325 $cdoc =
createDoc($this->dbaccess, $this->fromid,
false,
false);
327 $this->waitingDoc = clone $cdoc;
328 $waitValues = unserialize($this->values);
329 foreach ($waitValues as $aid => $v) {
330 if ($v ==
'') $v =
' ';
331 $this->waitingDoc->setValue($aid, $v);
333 $this->waitingDoc->doctype =
'I';
335 return $this->waitingDoc;
344 return ($this->status == self::newDocument || $this->status == self::modified || $this->status == self::upToDate);
356 if ($this->status != self::invalid) {
357 if ($this->refererid) {
358 $originValues = unserialize($this->orivalues);
360 if ($currentDoc->isAlive()) {
361 $err = $currentDoc->canEdit(
false);
363 $this->statusmessage =
$err;
364 $this->status = self::conflict;
366 if ($currentDoc->locked != $currentDoc->getSystemUserId()) {
367 $this->statusmessage = sprintf(
"document %s [%d] not locked", $currentDoc->getTitle() , $currentDoc->id);
368 $this->status = self::conflict;
370 if ($mask) $currentDoc->ApplyMask($mask);
371 $attrs = $this->getWriteAttribute($currentDoc);
372 $this->status = self::upToDate;
373 $this->statusmessage =
'';
384 foreach ($attrs as $aid => $oa) {
385 $ovalue = $originValues[$oa->id];
386 $cvalue = $currentDoc->getRawValue($oa->id);
387 if ($ovalue != $cvalue) {
388 $this->status = self::conflict;
389 $this->statusmessage.= sprintf(_(
"conflict %s [%s]: referer=%s, modified=%s") , $oa->getLabel() , $oa->id, $cvalue, $ovalue) .
"\n";
392 $this->statusmessage = substr($this->statusmessage, 0, -1);
396 $this->statusmessage = sprintf(
"document with id %d does not exists", $this->refererid);
397 $this->status = self::conflict;
400 $this->status = self::newDocument;
413 return ($this->extradata) ? json_decode($this->extradata) : null;
getNormalAttributes($onlyopt=false)
computeStatus($mask=0)
restrict to W/O visibilities values
exec_query($sql, $lvl=0, $prepare=false)
modify($nopost=false, $sfields="", $nopre=false)
getRefererDocument($reset=false)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
if($file) if($subject==""&&$file) if($subject=="") $err