Turba_Driver::delete PHP Method

delete() public method

Deletes the specified entry from the contact source.
public delete ( string $object_id, boolean $remove_tags = true )
$object_id string The ID of the object to delete.
$remove_tags boolean Remove tags if true.
    public function delete($object_id, $remove_tags = true)
    {
        $object = $this->getObject($object_id);
        if (!$object->hasPermission(Horde_Perms::DELETE)) {
            throw new Turba_Exception(_("Permission denied"));
        }
        $this->_delete($this->toDriver('__key'), $object_id);
        $own_contact = $GLOBALS['prefs']->getValue('own_contact');
        if (!empty($own_contact)) {
            @(list(, $id) = explode(';', $own_contact));
            if ($id == $object_id) {
                $GLOBALS['prefs']->setValue('own_contact', '');
            }
        }
        /* Log the deletion of this item in the history log. */
        if ($object->getValue('__uid')) {
            try {
                $GLOBALS['injector']->getInstance('Horde_History')->log($object->getGuid(), array('action' => 'delete'), true);
            } catch (Exception $e) {
                Horde::log($e, 'ERR');
            }
        }
        /* Remove any CalDAV mappings. */
        try {
            $davStorage = $GLOBALS['injector']->getInstance('Horde_Dav_Storage');
            try {
                $davStorage->deleteInternalObjectId($object_id, $this->_name);
            } catch (Horde_Exception $e) {
                Horde::log($e);
            }
        } catch (Horde_Exception $e) {
        }
        /* Remove tags */
        if ($remove_tags) {
            $GLOBALS['injector']->getInstance('Turba_Tagger')->replaceTags($object->getValue('__uid'), array(), $this->getContactOwner(), 'contact');
            /* Tell content we removed the object
               /* (Might have tags disabled, hence no Content_* objects autoloadable).
                */
            try {
                $GLOBALS['injector']->getInstance('Content_Objects_Manager')->delete(array($object->getValue('__uid')), 'contact');
            } catch (Horde_Exception $e) {
            }
        }
    }