refactor saveEvent
authorMichael Spahn <m.spahn@metaways.de>
Wed, 26 Jul 2017 14:37:40 +0000 (16:37 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Wed, 26 Jul 2017 16:05:50 +0000 (18:05 +0200)
Change-Id: I17f44097f2433abf052e7971b7a297ca1abad179
Reviewed-on: http://gerrit.tine20.com/customers/5331
Tested-by: sstamer <s.stamer@metaways.de>
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Tested-by: Michael Spahn <m.spahn@metaways.de>
tine20/Calendar/Frontend/Json.php

index f5352cd..f68fcb6 100644 (file)
@@ -420,6 +420,9 @@ class Calendar_Frontend_Json extends Tinebase_Frontend_Json_Abstract
     /**
      * creates/updates an event / recur
      *
+     * WARNING: the Calendar_Controller_Event::create method is not conform to the regular interface!
+     *          The parent's _save method doesn't work here!
+     *
      * @param   array   $recordData
      * @param   bool    $checkBusyConflicts
      * @param   string  $range
@@ -427,9 +430,21 @@ class Calendar_Frontend_Json extends Tinebase_Frontend_Json_Abstract
      */
     public function saveEvent($recordData, $checkBusyConflicts = FALSE, $range = Calendar_Model_Event::RANGE_THIS)
     {
-        return $this->_save($recordData, Calendar_Controller_Event::getInstance(), 'Event', 'id', array($checkBusyConflicts, $range));
+        $record = new Calendar_Model_Event([], true);
+        $record->setFromJsonInUsersTimezone($recordData);
+
+        // if there are dependent records, set the timezone of them and add them to a recordSet
+        $this->_dependentRecordsFromJson($record);
+
+        if ((empty($record->id))) {
+            $savedRecord = Calendar_Controller_Event::getInstance()->create($record, $checkBusyConflicts, false);
+        } else {
+            $savedRecord = Calendar_Controller_Event::getInstance()->update($record, $checkBusyConflicts, $range, false);
+        }
+
+        return $this->_recordToJson($savedRecord);
     }
-    
+
     /**
      * creates/updates a Resource
      *