protected function _importRecord(Tinebase_Record_Abstract $_record) { if ($_record->getId()) { return $this->_controllerToImport->update($_record, false); } else { return $this->_controllerToImport->create($_record, false); } }
/** * update existing entry * * @param unknown_type $_collectionId * @param string $_id * @param SimpleXMLElement $_data * @return Tinebase_Record_Abstract */ public function updateEntry($_folderId, $_serverId, SimpleXMLElement $_entry) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " update CollectionId: {$_folderId} Id: {$_serverId}"); } $oldEntry = $this->_contentController->get($_serverId); $entry = $this->toTineModel($_entry, $oldEntry); $entry->last_modified_time = new Tinebase_DateTime($this->_syncTimeStamp); $entry = $this->_contentController->update($entry); return $entry->getId(); }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::update() */ public function update(Tinebase_Record_Interface $_record) { parent::update($_record); // after update if ($this->mustUpdateReceiptAtOnce()) { try { $receiptPosition = Billing_Controller_ReceiptPosition::getInstance()->getByOrderPositionId($_record->getId()); $receipt = $receiptPosition->getForeignRecordBreakNull('receipt_id', Billing_Controller_Receipt::getInstance()); if ($receipt) { Billing_Controller_ReceiptPosition::getInstance()->updateReceipt($receipt); } } catch (Tinebase_Exception_NotFound $e) { // no receipt to be updated } } return $this->get($_record->getId()); }
/** * (non-PHPdoc) * @see Syncroton_Data_IData::updateEntry() */ public function updateEntry($folderId, $serverId, Syncroton_Model_IEntry $entry) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " update CollectionId: {$folderId} Id: {$serverId}"); } try { $oldEntry = $this->_contentController->get($serverId); } catch (Tinebase_Exception_NotFound $tenf) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $tenf); } throw new Syncroton_Exception_NotFound($tenf->getMessage()); } $updatedEmtry = $this->toTineModel($entry, $oldEntry); // @FIXME: this skips concurrency handling $updatedEmtry->last_modified_time = new Tinebase_DateTime($this->_syncTimeStamp); try { $updatedEmtry = $this->_contentController->update($updatedEmtry); } catch (Tinebase_Exception_AccessDenied $tead) { throw new Syncroton_Exception_AccessDenied(); } return $updatedEmtry->getId(); }
/** * update one record * - save timeaccount grants * * @param Tinebase_Record_Interface $_record * @param boolean $_duplicateCheck * * @return Tinebase_Record_Interface */ public function update(Tinebase_Record_Interface $_record, $_duplicateCheck = TRUE) { $timeaccount = parent::update($_record, $_duplicateCheck); // save grants if (count($_record->grants) > 0) { Timetracker_Model_TimeaccountGrants::setTimeaccountGrants($timeaccount, $_record->grants); } return $timeaccount; }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::update() */ public function update(Tinebase_Record_Interface $_record) { if (!$this->_checkACLContainer($this->_backend->getNodeContainer($_record->getId()), 'update')) { throw new Tinebase_Exception_AccessDenied('No permission to update nodes.'); } return parent::update($_record); }
/** * update one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied */ public function update(Tinebase_Record_Interface $_record) { $container = Tinebase_Container::getInstance()->getContainerById($_record->container_id); $container->name = $_record->name; Tinebase_Container::getInstance()->update($container); return parent::update($_record); }
/** * update one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied * @throws Tinebase_Exception_Record_Validation */ public function update(Tinebase_Record_Interface $_task) { $this->_handleCompleted($_task); return parent::update($_task); }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::update() */ public function update(Tinebase_Record_Interface $_record) { parent::update($_record); // after update if ($this->mustUpdateReceiptAtOnce($receiptPosition->getForeignRecord('receipt_id', Billing_Controller_Receipt::getInstance()))) { $this->updateReceipt($_record); } return $this->get($_record->getId()); }
/** * update one record * * @param Tinebase_Record_Interface $_record * @param boolean $_duplicateCheck * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied * */ public function update(Tinebase_Record_Interface $_record, $_duplicateCheck = TRUE) { $sharedSeenValue = $_record->shared_seen; $updatedRecord = parent::update($_record, $_duplicateCheck); if ($this->_checkSharedSeenSupport($_record)) { $updatedRecord->shared_seen_support = TRUE; if ($this->_setSharedSeenValue($_record, $sharedSeenValue)) { $updatedRecord->shared_seen = $sharedSeenValue; } else { Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' Imap command failed when setting sharedseen value!'); $translate = Tinebase_Translation::getTranslation('Expressomail'); $message = $translate->_('Imap command failed when setting sharedseen value!'); throw new Expressomail_Exception_IMAPCommandFailed($message); } } Tinebase_Core::setupCache(); $cache = Tinebase_Core::getCache(); $cache->save($updatedRecord, $this->_createExpressomailModelAccountCacheId($updatedRecord->id), array('expressomailAccount')); return $updatedRecord; }
/** * update one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied */ public function update(Tinebase_Record_Interface $_record) { $container = Tinebase_Container::getInstance()->getContainerById($_record->container_id); $container->name = $_record->name; Tinebase_Container::getInstance()->update($container); if ($_record->grants instanceof Tinebase_Record_RecordSet) { Tinebase_Container::getInstance()->setGrants($container->getId(), $_record->grants, TRUE, FALSE); } return parent::update($_record); }
/** * creates an exception instance of a recurring event * * NOTE: deleting persistent exceptions is done via a normal delete action * and handled in the deleteInspection * * @param Calendar_Model_Event $_event * @param bool $_deleteInstance * @param bool $_allFollowing * @param bool $_checkBusyConflicts * @return Calendar_Model_Event exception Event | updated baseEvent * * @todo replace $_allFollowing param with $range * @deprecated replace with create/update/delete */ public function createRecurException($_event, $_deleteInstance = FALSE, $_allFollowing = FALSE, $_checkBusyConflicts = FALSE) { $baseEvent = $this->getRecurBaseEvent($_event); if ($baseEvent->last_modified_time != $_event->last_modified_time) { if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " It is not allowed to create recur instance if it is clone of base event"); } throw new Tinebase_Timemachine_Exception_ConcurrencyConflict('concurrency conflict!'); } // // Maybe Later // // exdates needs to stay in baseEvents container // if ($_event->container_id != $baseEvent->container_id) { // throw new Calendar_Exception_ExdateContainer(); // } // check if this is an exception to the first occurence if ($baseEvent->getId() == $_event->getId()) { if ($_allFollowing) { throw new Exception('please edit or delete complete series!'); } // NOTE: if the baseEvent gets a time change, we can't compute the recurdid w.o. knowing the original dtstart $recurid = $baseEvent->setRecurId($baseEvent->getId()); unset($baseEvent->recurid); $_event->recurid = $recurid; } // just do attender status update if user has no edit grant if ($this->_doContainerACLChecks && !$baseEvent->{Tinebase_Model_Grants::GRANT_EDIT}) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " user has no editGrant for event: '{$baseEvent->getId()}'. Only creating exception for attendee status"); } if ($_event->attendee instanceof Tinebase_Record_RecordSet) { foreach ($_event->attendee as $attender) { if ($attender->status_authkey) { $exceptionAttender = $this->attenderStatusCreateRecurException($_event, $attender, $attender->status_authkey, $_allFollowing); } } } if (!isset($exceptionAttender)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG) && $_event->attendee instanceof Tinebase_Record_RecordSet) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Failed to update attendee: " . print_r($_event->attendee->toArray(), true)); } throw new Tinebase_Exception_AccessDenied('Failed to update attendee, status authkey might be missing'); } return $this->get($exceptionAttender->cal_event_id); } // NOTE: recurid is computed by rrule recur computations and therefore is already part of the event. if (empty($_event->recurid)) { throw new Exception('recurid must be present to create exceptions!'); } // we do notifications ourself $sendNotifications = $this->sendNotifications(FALSE); // EDIT for baseEvent is checked above, CREATE, DELETE for recur exceptions is implied with it $doContainerACLChecks = $this->doContainerACLChecks(FALSE); $db = $this->_backend->getAdapter(); $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db); $exdate = new Tinebase_DateTime(substr($_event->recurid, -19)); $exdates = is_array($baseEvent->exdate) ? $baseEvent->exdate : array(); $originalDtstart = $_event->getOriginalDtStart(); $originalEvent = Calendar_Model_Rrule::computeNextOccurrence($baseEvent, new Tinebase_Record_RecordSet('Calendar_Model_Event'), $originalDtstart); if ($_allFollowing != TRUE) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Adding exdate for: '{$_event->recurid}'"); } array_push($exdates, $exdate); $baseEvent->exdate = $exdates; $updatedBaseEvent = $this->update($baseEvent, FALSE); if ($_deleteInstance == FALSE) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Creating persistent exception for: '{$_event->recurid}'"); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " Recur exception: " . print_r($_event->toArray(), TRUE)); } $_event->base_event_id = $baseEvent->getId(); $_event->setId(NULL); unset($_event->rrule); unset($_event->exdate); foreach (array('attendee', 'notes', 'alarms') as $prop) { if ($_event->{$prop} instanceof Tinebase_Record_RecordSet) { $_event->{$prop}->setId(NULL); } } $originalDtstart = $_event->getOriginalDtStart(); $dtStartHasDiff = $originalDtstart->compare($_event->dtstart) != 0; // php52 compat if (!$dtStartHasDiff) { $attendees = $_event->attendee; unset($_event->attendee); } $note = $_event->notes; unset($_event->notes); $persistentExceptionEvent = $this->create($_event, $_checkBusyConflicts); if (!$dtStartHasDiff) { // we save attendee seperatly to preserve their attributes if ($attendees instanceof Tinebase_Record_RecordSet) { $attendees->cal_event_id = $persistentExceptionEvent->getId(); $calendar = Tinebase_Container::getInstance()->getContainerById($_event->container_id); foreach ($attendees as $attendee) { $this->_createAttender($attendee, $_event, TRUE, $calendar); $this->_increaseDisplayContainerContentSequence($attendee, $persistentExceptionEvent, Tinebase_Model_ContainerContent::ACTION_CREATE); } } } // @todo save notes and add a update note -> what was updated? -> modlog is also missing $persistentExceptionEvent = $this->get($persistentExceptionEvent->getId()); } } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " shorten recur series for/to: '{$_event->recurid}'"); } // split past/future exceptions $pastExdates = array(); $futureExdates = array(); foreach ($exdates as $exdate) { $exdate->isLater($_event->dtstart) ? $futureExdates[] = $exdate : ($pastExdates[] = $exdate); } $persistentExceptionEvents = $this->getRecurExceptions($_event); $pastPersistentExceptionEvents = new Tinebase_Record_RecordSet('Calendar_Model_Event'); $futurePersistentExceptionEvents = new Tinebase_Record_RecordSet('Calendar_Model_Event'); foreach ($persistentExceptionEvents as $persistentExceptionEvent) { $persistentExceptionEvent->getOriginalDtStart()->isLater($_event->dtstart) ? $futurePersistentExceptionEvents->addRecord($persistentExceptionEvent) : $pastPersistentExceptionEvents->addRecord($persistentExceptionEvent); } // update baseEvent $rrule = Calendar_Model_Rrule::getRruleFromString($baseEvent->rrule); if (isset($rrule->count)) { // get all occurences and find the split $exdate = $baseEvent->exdate; $baseEvent->exdate = NULL; //$baseCountOccurrence = Calendar_Model_Rrule::computeNextOccurrence($baseEvent, new Tinebase_Record_RecordSet('Calendar_Model_Event'), $baseEvent->rrule_until, $baseCount); $recurSet = Calendar_Model_Rrule::computeRecurrenceSet($baseEvent, new Tinebase_Record_RecordSet('Calendar_Model_Event'), $baseEvent->dtstart, $baseEvent->rrule_until); $baseEvent->exdate = $exdate; $originalDtstart = $_event->getOriginalDtStart(); foreach ($recurSet as $idx => $rInstance) { if ($rInstance->dtstart >= $originalDtstart) { break; } } $rrule->count = $idx + 1; } else { $lastBaseOccurence = Calendar_Model_Rrule::computeNextOccurrence($baseEvent, new Tinebase_Record_RecordSet('Calendar_Model_Event'), $_event->getOriginalDtStart()->subSecond(1), -1); $rrule->until = $lastBaseOccurence ? $lastBaseOccurence->getOriginalDtStart() : $baseEvent->dtstart; } $baseEvent->rrule = (string) $rrule; $baseEvent->exdate = $pastExdates; // NOTE: we don't want implicit attendee updates //$updatedBaseEvent = $this->update($baseEvent, FALSE); $this->_inspectEvent($baseEvent); $updatedBaseEvent = parent::update($baseEvent); if ($_deleteInstance == TRUE) { // delete all future persistent events $this->delete($futurePersistentExceptionEvents->getId()); } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " create new recur series for/at: '{$_event->recurid}'"); } // NOTE: in order to move exceptions correctly in time we need to find out the original dtstart // and create the new baseEvent with this time. A following update also updates its exceptions $originalDtstart = new Tinebase_DateTime(substr($_event->recurid, -19)); $adoptedDtstart = clone $_event->dtstart; $dtStartHasDiff = $adoptedDtstart->compare($originalDtstart) != 0; // php52 compat $eventLength = $_event->dtstart->diff($_event->dtend); $_event->dtstart = clone $originalDtstart; $_event->dtend = clone $originalDtstart; $_event->dtend->add($eventLength); // adopt count if (isset($rrule->count)) { $baseCount = $rrule->count; $rrule = Calendar_Model_Rrule::getRruleFromString($_event->rrule); $rrule->count = $rrule->count - $baseCount; $_event->rrule = (string) $rrule; } $_event->setId(Tinebase_Record_Abstract::generateUID()); $_event->uid = $futurePersistentExceptionEvents->uid = Tinebase_Record_Abstract::generateUID(); $_event->setId(Tinebase_Record_Abstract::generateUID()); $futurePersistentExceptionEvents->setRecurId($_event->getId()); unset($_event->recurid); unset($_event->base_event_id); foreach (array('attendee', 'notes', 'alarms') as $prop) { if ($_event->{$prop} instanceof Tinebase_Record_RecordSet) { $_event->{$prop}->setId(NULL); } } $_event->exdate = $futureExdates; $attendees = $_event->attendee; unset($_event->attendee); $note = $_event->notes; unset($_event->notes); $persistentExceptionEvent = $this->create($_event, $_checkBusyConflicts && $dtStartHasDiff); // we save attendee separately to preserve their attributes if ($attendees instanceof Tinebase_Record_RecordSet) { foreach ($attendees as $attendee) { $this->_createAttender($attendee, $persistentExceptionEvent, true); } } // @todo save notes and add a update note -> what was updated? -> modlog is also missing $persistentExceptionEvent = $this->get($persistentExceptionEvent->getId()); foreach ($futurePersistentExceptionEvents as $futurePersistentExceptionEvent) { $this->update($futurePersistentExceptionEvent, FALSE); } if ($dtStartHasDiff) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " new recur series has adpted dtstart -> update to adopt exceptions'"); } $persistentExceptionEvent->dtstart = clone $adoptedDtstart; $persistentExceptionEvent->dtend = clone $adoptedDtstart; $persistentExceptionEvent->dtend->add($eventLength); $persistentExceptionEvent = $this->update($persistentExceptionEvent, $_checkBusyConflicts); } } } Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); // restore original notification handling $this->sendNotifications($sendNotifications); $notificationAction = $_deleteInstance ? 'deleted' : 'changed'; $notificationEvent = $_deleteInstance ? $_event : $persistentExceptionEvent; // restore acl $this->doContainerACLChecks($doContainerACLChecks); // send notifications if ($this->_sendNotifications && $_event->mute != 1) { // NOTE: recur exception is a fake event from client. // this might lead to problems, so we wrap the calls try { if (count($_event->attendee) > 0) { $_event->attendee->bypassFilters = TRUE; } $_event->created_by = $baseEvent->created_by; $this->doSendNotifications($notificationEvent, Tinebase_Core::getUser(), $notificationAction, $originalEvent); } catch (Exception $e) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " " . $e->getTraceAsString()); } Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " could not send notification {$e->getMessage()}"); } } return $_deleteInstance ? $updatedBaseEvent : $persistentExceptionEvent; }
/** * update one record * * @param Tinebase_Record_Interface $_record * @param array $_additionalArguments * @return Tinebase_Record_Interface */ public function update(Tinebase_Record_Interface $_record, $_additionalArguments = array()) { $container = parent::update($_record); if ($container->type === Tinebase_Model_Container::TYPE_PERSONAL) { $this->_sendNotification($container, isset($_additionalArguments['note']) || array_key_exists('note', $_additionalArguments) ? $_additionalArguments['note'] : ''); } return $container; }
/** * update one record * * @param Tinebase_Record_Interface $_record * @param bool $_checkBusyConflicts * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied * @throws Tinebase_Exception_Record_Validation */ public function update(Tinebase_Record_Interface $_record, $_checkBusyConflicts = FALSE) { try { $db = $this->_backend->getAdapter(); $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db); $sendNotifications = $this->sendNotifications(FALSE); $event = $this->get($_record->getId()); if ($this->_doContainerACLChecks === FALSE || $event->hasGrant(Tinebase_Model_Grants::GRANT_EDIT)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " updating event: {$_record->id} "); // we need to resolve groupmembers before free/busy checking Calendar_Model_Attender::resolveGroupMembers($_record->attendee); if ($_checkBusyConflicts) { // only do free/busy check if start/endtime changed or attendee added or rrule changed if (!$event->dtstart->equals($_record->dtstart) || !$event->dtend->equals($_record->dtend) || count(array_diff($_record->attendee->user_id, $event->attendee->user_id)) > 0 || $event->rrule != $_record->rrule) { // ensure that all attendee are free $this->checkBusyConflicts($_record); } } $this->_inspectEvent($_record); parent::update($_record); $this->_saveAttendee($_record, $_record->isRescheduled($event)); } else { if ($_record->attendee instanceof Tinebase_Record_RecordSet) { //check if user is delegating attendance to another attendee $attendee = $this->__getAttendeeIds($_record->attendee); $previous = $this->__getAttendeeIds($event->__get('attendee')); $new_attender = array_values(array_diff($attendee, $previous)); $old_attender = array_values(array_diff($previous, $attendee)); $userId = $this->_currentAccount->__get('contact_id'); if (count($new_attender) == 1 && count($old_attender) == 1 && $old_attender[0] === $userId) { $delegated = true; $this->_saveAttendee($_record, $_record->isRescheduled($event)); } if (!$delegated) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " user has no editGrant for event: {$_record->id}, updating attendee status with valid authKey only"); } foreach ($_record->attendee as $attender) { if ($attender->status_authkey) { $this->attenderStatusUpdate($event, $attender, $attender->status_authkey); } } } } } Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); $this->sendNotifications($sendNotifications); throw $e; } if (!$delegated) { $updatedEvent = $this->get($event->getId()); } else { $containerACLChecks = $this->_doContainerACLChecks; $this->_doContainerACLChecks = FALSE; $updatedEvent = $this->get($event->getId()); $this->_doContainerACLChecks = $containerACLChecks; } // send notifications $this->sendNotifications($sendNotifications); if ($this->_sendNotifications) { $this->doSendNotifications($updatedEvent, $this->_currentAccount, 'changed', $event); } return $updatedEvent; }