Reflect format errors in is_valid() method to avoid invalid data being loadd and written to cache (#2360)

This commit is contained in:
Thomas Bruederli 2013-10-16 15:30:51 +02:00
parent fbf3207dfb
commit 29ab9b594e
8 changed files with 15 additions and 8 deletions

View file

@ -40,6 +40,7 @@ abstract class kolab_format
protected $data; protected $data;
protected $xmldata; protected $xmldata;
protected $xmlobject; protected $xmlobject;
protected $formaterror;
protected $loaded = false; protected $loaded = false;
protected $version = '3.0'; protected $version = '3.0';
@ -248,7 +249,7 @@ abstract class kolab_format
$log = "Error"; $log = "Error";
} }
if ($log) { if ($log && !isset($this->formaterror)) {
rcube::raise_error(array( rcube::raise_error(array(
'code' => 660, 'code' => 660,
'type' => 'php', 'type' => 'php',
@ -256,6 +257,8 @@ abstract class kolab_format
'line' => __LINE__, 'line' => __LINE__,
'message' => "kolabformat $log: " . kolabformat::errorMessage(), 'message' => "kolabformat $log: " . kolabformat::errorMessage(),
), true); ), true);
$this->formaterror = $ret;
} }
return $ret; return $ret;
@ -342,6 +345,7 @@ abstract class kolab_format
*/ */
public function load($xml) public function load($xml)
{ {
$this->formaterror = null;
$read_func = $this->libfunc($this->read_func); $read_func = $this->libfunc($this->read_func);
if (is_array($read_func)) if (is_array($read_func))
@ -365,6 +369,8 @@ abstract class kolab_format
*/ */
public function write($version = null) public function write($version = null)
{ {
$this->formaterror = null;
$this->init(); $this->init();
$write_func = $this->libfunc($this->write_func); $write_func = $this->libfunc($this->write_func);
if (is_array($write_func)) if (is_array($write_func))

View file

@ -268,7 +268,7 @@ class kolab_format_contact extends kolab_format
*/ */
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && $this->obj->uid() /*$this->obj->isValid()*/); return !$this->formaterror && ($this->data || (is_object($this->obj) && $this->obj->uid() /*$this->obj->isValid()*/));
} }
/** /**

View file

@ -69,7 +69,7 @@ class kolab_format_distributionlist extends kolab_format
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && $this->obj->isValid()); return !$this->formaterror && ($this->data || (is_object($this->obj) && $this->obj->isValid()));
} }
/** /**

View file

@ -111,7 +111,8 @@ class kolab_format_event extends kolab_format_xcal
*/ */
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && $this->obj->isValid() && $this->obj->uid()); return !$this->formaterror && (($this->data && !empty($this->data['start']) && !empty($this->data['end'])) ||
(is_object($this->obj) && $this->obj->isValid() && $this->obj->uid()));
} }
/** /**

View file

@ -95,7 +95,7 @@ class kolab_format_file extends kolab_format
*/ */
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && $this->obj->isValid()); return !$this->formaterror && ($this->data || (is_object($this->obj) && $this->obj->isValid()));
} }
/** /**

View file

@ -54,7 +54,7 @@ class kolab_format_journal extends kolab_format
*/ */
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && $this->obj->isValid()); return !$this->formaterror && ($this->data || (is_object($this->obj) && $this->obj->isValid()));
} }
/** /**

View file

@ -54,7 +54,7 @@ class kolab_format_note extends kolab_format
*/ */
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && $this->obj->isValid()); return !$this->formaterror && ($this->data || (is_object($this->obj) && $this->obj->isValid()));
} }
/** /**

View file

@ -63,7 +63,7 @@ class kolab_format_task extends kolab_format_xcal
*/ */
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && $this->obj->isValid()); return !$this->formaterror && ($this->data || (is_object($this->obj) && $this->obj->isValid()));
} }
/** /**