Example #1
0
File: Api.php Project: Gomez/horde
 /**
  * Deletes a file from the Nag tree.
  *
  * @param string $path  The path to the file.
  *
  * @return string  The event's UID
  * @throws Nag_Exception
  */
 public function path_delete($path)
 {
     global $injector, $nag_shares;
     if (substr($path, 0, 3) == 'nag') {
         $path = substr($path, 3);
     }
     $path = trim($path, '/');
     $parts = explode('/', $path);
     if (count($parts) == 2) {
         // @TODO Deny deleting of the entire tasklist for now.
         // Allow users to delete tasklists but not create them via WebDAV
         // will be more confusing than helpful.  They are, however, still
         // able to delete individual task items within the tasklist folder.
         throw Nag_Exception(_("Deleting entire task lists is not supported."), 403);
         // To re-enable the functionality just remove this if {} block.
     }
     if (substr($parts[1], -4) == '.ics') {
         $tasklistID = substr($parts[1], 0, -4);
     } else {
         $tasklistID = $parts[1];
     }
     if (!(count($parts) == 2 || count($parts) == 3) || !Nag::hasPermission($tasklistID, Horde_Perms::DELETE)) {
         throw new Nag_Exception(_("Task list does not exist or no permission to delete"), 403);
     }
     /* Create a Nag storage instance. */
     try {
         $storage = $injector->getInstance('Nag_Factory_Driver')->create($tasklistID);
         $storage->retrieve();
     } catch (Nag_Exception $e) {
         throw new Nag_Exception(sprintf(_("Connection failed: %s"), $e->getMessage()), 500);
     }
     if (count($parts) == 3) {
         // Delete just a single entry
         $dav = $injector->getInstance('Horde_Dav_Storage');
         $id = $parts[2];
         try {
             $id = $dav->getInternalObjectId($id, $tasklistID) ?: $id;
         } catch (Horde_Dav_Exception $e) {
         }
         return $storage->delete($id);
     } else {
         // Delete the entire task list
         try {
             $storage->deleteAll();
         } catch (Nag_Exception $e) {
             throw new Nag_Exception(sprintf(_("Unable to delete task list \"%s\": %s"), $tasklistID, $e->getMessage()), 500);
         }
         // Remove share and all groups/permissions.
         $share = $nag_shares->getShare($tasklistID);
         try {
             $nag_shares->removeShare($share);
         } catch (Horde_Share_Exception $e) {
             throw new Nag_Exception($e->getMessage());
         }
     }
 }
Example #2
0
 /**
  * Deletes a task from the backend.
  *
  * @param string $taskId  The task to delete.
  *
  * @throws Nag_Exception
  */
 protected function _delete($taskId)
 {
     /* Get the task's details for use later. */
     $task = $this->get($taskId);
     $query = sprintf('DELETE FROM %s WHERE task_owner = ? AND task_id = ?', $this->_params['table']);
     $values = array($this->_tasklist, $taskId);
     try {
         $this->_db->delete($query, $values);
     } catch (Horde_Db_Exception $e) {
         throw Nag_Exception($e->getMessage());
     }
 }