8 require_once
"Class.DbObj.php";
108 create table docwait ( refererid int not null,
109 refererinitid int not null,
116 date timestamp default now(),
122 create index i_docwait on docwait(transaction);
123 create unique index iu_docwait on docwait(refererinitid, uid);
124 create sequence seq_waittransaction start 1;
141 private $refererDoc = null;
147 private $refererDocId = null;
153 private $waitingDoc = null;
161 public function save(&$info = null)
168 $wdoc->doctype = $wdoc->defDoctype;
169 if ($this->localid) {
173 if ($this->localid) {
174 $this->refererid = $wdoc->id;
175 $this->refererinitid = $wdoc->initid;
178 $this->
exec_query(sprintf(
"update docwait set refererid=%d, refererinitid=%d, localid='' where localid='%s'", $this->refererid, $this->refererinitid, pg_escape_string($this->localid)));
184 $err = $wdoc->save($info);
187 $this->status = self::constraint;
188 $this->statusmessage = ($info->error) ? $info->label .
' : ' . $info->error :
$err;
209 $this->refererinitid =
$doc->initid;
210 $this->refererid =
$doc->id;
211 $this->orivalues = serialize(
$doc->getValues());
212 $this->status = self::upToDate;
213 $this->statusmessage =
'';
214 $this->transaction = 0;
215 $this->date = date(
'Y-m-d H:i:s.u');
227 private function getWriteAttribute(
Doc &
$doc)
229 $attrs = $doc->getNormalAttributes();
231 foreach ($attrs as $aid => $oa) {
232 if (($oa->mvisibility ==
'W') || ($oa->mvisibility ==
'O') || $oa->getOption(
"writted") ==
"yes") {
245 $this->refererDoc = null;
246 $this->waitingDoc = null;
257 if ($reset) $this->refererDoc = null;
258 if ($this->refererid <= 0)
return null;
259 if (!$this->refererDoc) {
260 $this->refererDoc = new_doc($this->dbaccess, $this->refererid,
true);
261 $this->refererDocId = $this->refererDoc->id;
262 if ($this->waitingDoc) {
263 $this->values = serialize($this->waitingDoc->getValues());
264 $this->waitingDoc = null;
267 if (($this->refererDoc->id != $this->refererDocId) || ($fix = $this->refererDoc->isFixed()) || ($fix === null)) {
268 $this->refererDoc = new_doc($this->dbaccess, $this->refererid,
true);
269 $this->refererDocId = $this->refererDoc->id;
270 if ($this->waitingDoc) {
271 $this->values = serialize($this->waitingDoc->getValues());
272 $this->waitingDoc = null;
276 return $this->refererDoc;
286 if (!$this->waitingDoc) {
288 $cdoc =
createDoc($this->dbaccess, $this->fromid,
false,
false);
290 $this->waitingDoc = clone $cdoc;
291 $waitValues = unserialize($this->values);
292 foreach ($waitValues as $aid => $v) {
293 if ($v ==
'') $v =
' ';
294 $this->waitingDoc->setValue($aid, $v);
296 $this->waitingDoc->doctype =
'I';
298 return $this->waitingDoc;
307 return ($this->status == self::newDocument || $this->status == self::modified || $this->status == self::upToDate);
319 if ($this->status != self::invalid) {
320 if ($this->refererid) {
321 $originValues = unserialize($this->orivalues);
323 if ($currentDoc->isAlive()) {
324 $err = $currentDoc->canEdit(
false);
326 $this->statusmessage =
$err;
327 $this->status = self::conflict;
329 if ($currentDoc->locked != $currentDoc->getSystemUserId()) {
330 $this->statusmessage = sprintf(
'document "%s" [%d] not locked', $currentDoc->getTitle() , $currentDoc->id);
331 $this->status = self::conflict;
333 if ($mask) $currentDoc->ApplyMask($mask);
334 $attrs = $this->getWriteAttribute($currentDoc);
335 $this->status = self::upToDate;
336 $this->statusmessage =
'';
344 foreach ($attrs as $aid => $oa) {
345 $ovalue = $originValues[$oa->id];
346 $cvalue = $currentDoc->getValue($oa->id);
347 if ($ovalue != $cvalue) {
348 $this->status = self::conflict;
349 $this->statusmessage.= sprintf(_(
"conflict %s [%s]: referer=%s, modified=%s") , $oa->getLabel() , $oa->id, $cvalue, $ovalue) .
"\n";
352 $this->statusmessage = substr($this->statusmessage, 0, -1);
356 $this->statusmessage = sprintf(
"document with id %d does not exists", $this->refererid);
357 $this->status = self::conflict;
360 $this->status = self::newDocument;
373 return ($this->extradata) ? json_decode($this->extradata) : null;