/** * Overwrite save function. Writes the data in this object into the * database. * * @return int The id of the saved object */ public function save() { if (!$this->recordValidate()) { $errors = $this->getError(); $error = array_pop($errors); throw new Zend_Controller_Action_Exception($error['label'] . ': ' . $error['message'], 400); } if ($this->_isFirst) { $endOfLast = $this->getRruleHelper()->getUpperTimeBoundary(); if ($endOfLast) { $this->lastEnd = $endOfLast->format('Y-m-d H:i:s'); } else { // I hate to do this, but item casts null to '1970-01-01 00;00:00'. $this->_data['lastEnd'] = null; } if (!self::isValidVisibility($this->visibility)) { throw new Zend_Controller_Action_Exception("Invalid visibility {$this->visibility}", 400); } $this->_fetchParticipantData(); // We need to check this before we call parent::save() as it will be // set after. $isNew = empty($this->_storedId); $now = new Datetime('now', new DateTimeZone('UTC')); $this->lastModified = $now->format('Y-m-d H:i:s'); if (!$this->uri) { $this->uri = $this->uid; } $start = new Datetime('@' . Phprojekt_Converter_Time::userToUtc($this->start)); // This is here to fix a special case where P6 interprets things different from iCalendar. Assume a event // starts on tuesdays, has bi-weekly recurrence and BYDAY monday and wednesday. P6 will have the tuesday, // the wednesday after that and monday on the next week, wednesday the week after that, etc. Caldav will // have one week pause and then monday and wednesday in the same week. // TODO: Remove this after we changed to a predicate-based generation of events. if (strpos($this->rrule, ';BYDAY=') && !strpos($this->rrule, ';WKST=')) { $this->rrule = $this->rrule . ';WKST=' . strtoupper(substr($start->format('D'), 0, 2)); } parent::save(); $this->_saveParticipantData(); $this->_updateRights(); // If the start time has changed, we have to adjust all the excluded // dates. if (!$isNew && $start != $this->_originalStart) { $delta = $this->_originalStart->diff($start); $db = $this->getAdapter(); foreach ($this->getExcludedDates() as $date) { $where = $db->quoteInto('calendar2_id = ?', $this->id); $where .= $db->quoteInto('AND date = ?', $date->format('Y-m-d H:i:s')); $date->add($delta); $db->update('calendar2_excluded_dates', array('date' => $date->format('Y-m-d H:i:s')), $where); } } } else { // Split the series into two parts. $this will be the second part. $new = $this; $old = $this->create(); $old->find($this->id); $splitDate = new Datetime('@' . Phprojekt_Converter_Time::userToUtc($new->start)); $helper = $old->getRruleHelper(); $rrules = $helper->splitRrule($splitDate); $old->rrule = $rrules['old']; // Only overwrite the new rrule if the user didn't change it if ($new->rrule == $old->rrule) { $new->rrule = $rrules['new']; } // Regenerate the uid if the new event has multiple occurrences, see // http://jira.opensource.mayflower.de/jira/browse/PHPROJEKT-298 // As they don't belong together anymore, we also need to set a new uri. if ($new->rrule) { $this->uid = Phprojekt::generateUniqueIdentifier(); $new->uri = $new->uid; } $old->save(); $new->_saveToNewRow(); // Update the excluded occurences $where = "id = {$old->id} "; $where .= "AND date >= '{$splitDate->format('Y-m-d H:i:s')}'"; $this->getAdapter()->update('calendar2_excluded_dates', array('id' => $new->id), $where); } $this->_originalStart = new Datetime('@' . Phprojekt_Converter_Time::userToUtc($this->start)); return $this->id; }
/** * Delete the tree cache after save. * * @return boolean True for a sucessful save. */ public function save() { $result = parent::save(); Phprojekt_Tree_Node_Database::deleteCache(); return $result; }
/** * Delete the tree cache after save. * * @return boolean True for a sucessful save. */ public function save() { $result = parent::save(); return $result; }