Example #1
0
 /**
  * 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;
 }