Kronolith_Driver::deleteEvent PHP Method

deleteEvent() public method

Deletes an event.
public deleteEvent ( mixed $eventId, boolean $silent = false )
$eventId mixed Either the event id to delete, or the event object.
$silent boolean Don't send notifications, used when deleting events in bulk from maintenance tasks.
    public function deleteEvent($eventId, $silent = false)
    {
        $event = $this->_deleteEvent($eventId, $silent);
        if (!$event) {
            return;
        }
        /* Log the deletion of this item in the history log. */
        if ($event->uid) {
            try {
                $GLOBALS['injector']->getInstance('Horde_History')->log('kronolith:' . $this->calendar . ':' . $event->uid, array('action' => 'delete'), true);
            } catch (Exception $e) {
                Horde::log($e, 'ERR');
            }
        }
        /* Remove the event from any resources that are attached to it. */
        $resources = $event->getResources();
        if (count($resources)) {
            $rd = Kronolith::getDriver('Resource');
            foreach ($resources as $uid => $resource) {
                if ($resource['response'] !== Kronolith::RESPONSE_DECLINED && $resource['response'] !== Kronolith::RESPONSE_NONE) {
                    try {
                        $r = $rd->getResource($uid);
                        $r->removeEvent($event);
                    } catch (Kronolith_Exception $e) {
                    }
                }
            }
        }
        /* Remove any pending alarms. */
        $GLOBALS['injector']->getInstance('Horde_Alarm')->delete($event->uid);
        /* Remove any tags */
        $tagger = Kronolith::getTagger();
        $tagger->replaceTags($event->uid, array(), $event->creator, Kronolith_Tagger::TYPE_EVENT);
        /* Tell content we removed the object */
        $GLOBALS['injector']->getInstance('Content_Objects_Manager')->delete(array($event->uid), Kronolith_Tagger::TYPE_EVENT);
        /* Remove any geolocation data. */
        try {
            $GLOBALS['injector']->getInstance('Kronolith_Geo')->deleteLocation($event->id);
        } catch (Kronolith_Exception $e) {
        }
        /* Remove any CalDAV mappings. */
        try {
            $davStorage = $GLOBALS['injector']->getInstance('Horde_Dav_Storage');
            try {
                $davStorage->deleteInternalObjectId($event->id, $event->calendar);
            } catch (Horde_Exception $e) {
                Horde::log($e);
            }
        } catch (Horde_Exception $e) {
        }
        /* See if this event represents an exception - if so, touch the base
         * event's history. The $isRecurring check is to prevent an infinite
         * loop in the off chance that an exception is entered as a recurring
         * event.
         */
        if ($event->baseid && !$event->recurs()) {
            try {
                $GLOBALS['injector']->getInstance('Horde_History')->log('kronolith:' . $this->calendar . ':' . $event->baseid, array('action' => 'modify'), true);
            } catch (Exception $e) {
                Horde::log($e, 'ERR');
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
Archivo: Base.php Proyecto: horde/horde
 /**
  * Process the iCalendar data.
  *
  * @return array A hash of UID => id.
  * @throws Kronolith_Exception
  */
 protected function _process()
 {
     $ids = array();
     $components = $this->_iCal->getComponents();
     if (count($components) == 0) {
         throw new Kronolith_Exception(_("No iCalendar data was found."));
     }
     foreach ($components as $component) {
         if (!$this->_preSave($component)) {
             continue;
         }
         try {
             // RECURRENCE-ID - must import after base event is
             // imported/saved so defer these until all other data is
             // processed.
             $component->getAttribute('RECURRENCE-ID');
             $this->_exceptions[] = $component;
         } catch (Horde_Icalendar_Exception $e) {
             $event = $this->_driver->getEvent();
             $event->fromiCalendar($component, true);
             // Delete existing exception events. There is no efficient way
             // to determine if any existing events have been changed/deleted
             // so we just remove them all since they will be re-added during
             // the import process.
             foreach ($event->boundExceptions() as $exception) {
                 $this->_driver->deleteEvent($exception->id);
             }
             // Save and post-process.
             $event->save();
             $this->_postSave($event);
             $ids[$event->uid] = $event->id;
         }
     }
     // Save exception events.
     foreach ($this->_exceptions as $exception) {
         $event = $this->_driver->getEvent();
         $event->fromiCalendar($exception);
         $event->save();
     }
     return $ids;
 }
All Usage Examples Of Kronolith_Driver::deleteEvent