Esempio n. 1
0
 /**
  * Deletes the parent and associated child events in a series.
  * @param $api
  * @param $args
  * @return array
  */
 public function deleteRecordAndRecurrences($api, $args)
 {
     $bean = $this->loadBean($api, $args, 'delete');
     if (!empty($bean->repeat_parent_id)) {
         $parentArgs = array_merge($args, array('record' => $bean->repeat_parent_id));
         $bean = $this->loadBean($api, $parentArgs, 'delete');
     }
     // Turn off The Cache Updates while deleting the multiple recurrences.
     // The current Cache Enabled status is returned so it can be appropriately
     // restored when all the recurrences have been deleted.
     $cacheEnabled = vCal::setCacheUpdateEnabled(false);
     $this->deleteRecurrences($bean);
     $bean->mark_deleted($bean->id);
     // Restore the Cache Enabled status to its previous state
     vCal::setCacheUpdateEnabled($cacheEnabled);
     $this->getCalendarEvents()->rebuildFreeBusyCache($GLOBALS['current_user']);
     return array('id' => $bean->id);
 }
Esempio n. 2
0
 /**
  * @param SugarBean $parentBean
  * @return array events saved
  * @throws SugarException
  */
 public function saveRecurringEvents(SugarBean $parentBean)
 {
     global $timedate;
     if (!$this->isEventRecurring($parentBean)) {
         $logmsg = 'SaveRecurringEvents() : Event is not a Recurring Event';
         $GLOBALS['log']->error($logmsg);
         throw new SugarException('LBL_CALENDAR_EVENT_NOT_A_RECURRING_EVENT', array($parentBean->object_name));
     }
     if (!empty($parentBean->repeat_parent_id)) {
         $logmsg = 'SaveRecurringEvents() : Event received is not the Parent Occcurrence';
         $GLOBALS['log']->error($logmsg);
         throw new SugarException('LBL_CALENDAR_EVENT_IS_NOT_A_PARENT_OCCURRENCE', array($parentBean->object_name));
     }
     $dateStart = $this->formatDateTime('datetime', $parentBean->date_start, 'user');
     $params = array();
     $params['type'] = $parentBean->repeat_type;
     $params['interval'] = $parentBean->repeat_interval;
     $params['count'] = $parentBean->repeat_count;
     $params['until'] = $this->formatDateTime('date', $parentBean->repeat_until, 'user');
     $params['dow'] = $parentBean->repeat_dow;
     $repeatDateTimeArray = $this->buildRecurringSequence($dateStart, $params);
     $limit = $this->getRecurringLimit();
     if (count($repeatDateTimeArray) > $limit - 1) {
         $logMessage = sprintf('Calendar Events (%d) exceed Event Limit: (%d)', count($repeatDateTimeArray), $limit);
         $GLOBALS['log']->warning($logMessage);
     }
     // Turn off The Cache Updates while deleting the multiple recurrences.
     // The current Cache Enabled status is returned so it can be appropriately
     // restored when all the recurrences have been deleted.
     $cacheEnabled = vCal::setCacheUpdateEnabled(false);
     $this->markRepeatDeleted($parentBean);
     // Restore the Cache Enabled status to its previous state
     vCal::setCacheUpdateEnabled($cacheEnabled);
     return $this->saveRecurring($parentBean, $repeatDateTimeArray);
 }