Tinebase_Model_Tree_Node validation for revision and notifiction props
authorPaul Mehrer <p.mehrer@metaways.de>
Fri, 2 Jun 2017 10:48:05 +0000 (12:48 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Fri, 2 Jun 2017 12:48:03 +0000 (14:48 +0200)
Change-Id: I5ac6ca54c1f482c46b9a35cec50b14c088938d09
Reviewed-on: http://gerrit.tine20.com/customers/4812
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Filemanager/Frontend/JsonTests.php
tine20/Tinebase/Model/Tree/Node.php

index cfb87e7..3021bd6 100644 (file)
@@ -747,6 +747,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
 
         $personalContainerNode = $this->_getUit()->getNode($personalContainerNode['id']);
         $personalContainerNode['customfields'][$cf->name] = 'cf value';
+        $personalContainerNode['revisionProps']['nodeId'] = $personalContainerNode['id'];
         $personalContainerNode['revisionProps']['keep'] = true;
         $personalContainerNode['revisionProps']['keepNum'] = 3;
         $personalContainerNode['revisionProps']['keepMonth'] = 4;
@@ -760,6 +761,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         static::assertTrue(isset($updatedNode['revisionProps']) && isset($updatedNode['revisionProps']['keep']) &&
             isset($updatedNode['revisionProps']['keepNum']) && isset($updatedNode['revisionProps']['keepMonth']),
             'revisionProps not saved: ' . print_r($updatedNode, true));
+        static::assertEquals($personalContainerNode['revisionProps']['nodeId'], $personalContainerNode['id']);
         static::assertEquals($personalContainerNode['revisionProps']['keep'], true);
         static::assertEquals($personalContainerNode['revisionProps']['keepNum'], 3);
         static::assertEquals($personalContainerNode['revisionProps']['keepMonth'], 4);
index e79d629..670abf2 100644 (file)
@@ -29,7 +29,8 @@
  * @property    string             available_revisions
  * @property    string             description
  * @property    string             acl_node
- * @property    string             revisionProps
+ * @property    array              revisionProps
+ * @property    array              notificationProps
  * @property    string             preview_count
  * @property    Tinebase_Record_RecordSet grants
  */
@@ -228,4 +229,51 @@ class Tinebase_Model_Tree_Node extends Tinebase_Record_Abstract
         return $baseDir . DIRECTORY_SEPARATOR . substr($this->hash, 0, 3) . DIRECTORY_SEPARATOR .
             substr($this->hash, 3);
     }
+
+    public function isValid($_throwExceptionOnInvalidData = false)
+    {
+        if ($this->_isValidated === true) {
+            return true;
+        }
+
+        $invalid = array();
+        if (!empty($this->revisionProps)) {
+            if (count($this->revisionProps) > 4 || !isset($this->revisionProps[static::XPROPS_REVISION_NODE_ID])
+                    || !isset($this->revisionProps[static::XPROPS_REVISION_MONTH]) ||
+                    !isset($this->revisionProps[static::XPROPS_REVISION_ON]) ||
+                    !isset($this->revisionProps[static::XPROPS_REVISION_NUM])) {
+                $invalid[] = 'revisionProps';
+            }
+        }
+        if (!empty($this->notificationProps)) {
+            foreach ($this->notificationProps as $val) {
+                foreach ($val as $key => $val1) {
+                    if (!in_array($key, array(
+                            static::XPROPS_NOTIFICATION_ACCOUNT_ID,
+                            static::XPROPS_NOTIFICATION_ACCOUNT_TYPE,
+                            static::XPROPS_NOTIFICATION_ACTIVE,
+                            static::XPROPS_NOTIFICATION_SUMMARY))) {
+                        $invalid[] = 'notificationProps';
+                        break 2;
+                    }
+                }
+            }
+        }
+
+        if (!empty($invalid) && $_throwExceptionOnInvalidData) {
+            $e = new Tinebase_Exception_Record_Validation('Some fields ' . implode(',', $invalid)
+                . ' have invalid content');
+
+            if (Tinebase_Core::isLogLevel(Zend_Log::ERR)) Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " "
+                . $e->getMessage()
+                . print_r($this->_validationErrors, true));
+            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                . ' Record: ' . print_r($this->toArray(), true));
+
+            throw $e;
+        }
+
+        return parent::isValid($_throwExceptionOnInvalidData);
+    }
+
 }