Better process of writing Kolab objects: don't use isValid() but check kolabformat::error() after writing. Fixes #769
This commit is contained in:
parent
c3cfc084a7
commit
5cc7fc616f
4 changed files with 46 additions and 9 deletions
|
@ -158,6 +158,40 @@ abstract class kolab_format
|
||||||
return $vec;
|
return $vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for format errors after calling kolabformat::write*()
|
||||||
|
*
|
||||||
|
* @return boolean True if there were errors, False if OK
|
||||||
|
*/
|
||||||
|
protected function format_errors()
|
||||||
|
{
|
||||||
|
$ret = $log = false;
|
||||||
|
switch (kolabformat::error()) {
|
||||||
|
case kolabformat.NoError:
|
||||||
|
$ret = false;
|
||||||
|
break;
|
||||||
|
case kolabformat.Warning:
|
||||||
|
$ret = false;
|
||||||
|
$log = "Warning";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$ret = true;
|
||||||
|
$log = "Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($log) {
|
||||||
|
raise_error(array(
|
||||||
|
'code' => 660,
|
||||||
|
'type' => 'php',
|
||||||
|
'file' => __FILE__,
|
||||||
|
'line' => __LINE__,
|
||||||
|
'message' => "kolabformat write $log: " . kolabformat::errorMessage(),
|
||||||
|
), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the last generated UID to the object properties.
|
* Save the last generated UID to the object properties.
|
||||||
* Should be called after kolabformat::writeXXXX();
|
* Should be called after kolabformat::writeXXXX();
|
||||||
|
|
|
@ -132,11 +132,12 @@ class kolab_format_contact extends kolab_format
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
if ($this->obj->isValid()) {
|
|
||||||
$this->xmldata = kolabformat::writeContact($this->obj);
|
$this->xmldata = kolabformat::writeContact($this->obj);
|
||||||
|
|
||||||
|
if (!parent::format_errors())
|
||||||
parent::update_uid();
|
parent::update_uid();
|
||||||
}
|
else
|
||||||
|
$this->xmldata = null;
|
||||||
|
|
||||||
return $this->xmldata;
|
return $this->xmldata;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,12 @@ class kolab_format_distributionlist extends kolab_format
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
if ($this->obj->isValid()) {
|
|
||||||
$this->xmldata = kolabformat::writeDistlist($this->obj);
|
$this->xmldata = kolabformat::writeDistlist($this->obj);
|
||||||
|
|
||||||
|
if (!parent::format_errors())
|
||||||
parent::update_uid();
|
parent::update_uid();
|
||||||
}
|
else
|
||||||
|
$this->xmldata = null;
|
||||||
|
|
||||||
return $this->xmldata;
|
return $this->xmldata;
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,11 +116,12 @@ class kolab_format_event extends kolab_format
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
if ($this->obj->isValid()) {
|
|
||||||
$this->xmldata = kolabformat::writeEvent($this->obj);
|
$this->xmldata = kolabformat::writeEvent($this->obj);
|
||||||
|
|
||||||
|
if (!parent::format_errors())
|
||||||
parent::update_uid();
|
parent::update_uid();
|
||||||
}
|
else
|
||||||
|
$this->xmldata = null;
|
||||||
|
|
||||||
return $this->xmldata;
|
return $this->xmldata;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue