removeAttachment() public method

Remove a single version or all versions of an attachment to $pageId from the VFS backend.
public removeAttachment ( integer $pageId, string $attachment, string $version = null )
$pageId integer The Id of the page the file is attached to.
$attachment string The name of the file.
$version string If specified, the version to delete. If null, then all versions of $attachment will be removed.
Esempio n. 1
0
 /**
  * Removes a single version or all versions of an attachment from
  * $pageId.
  *
  * @param integer $pageId     The Id of the page the file is attached to.
  * @param string $attachment  The name of the file.
  * @param string $version     If specified, the version to delete. If null,
  *                            then all versions of $attachment will be
  *                            removed.
  *
  * @throws Wicked_Exception
  */
 public function removeAttachment($pageId, $attachment, $version = null)
 {
     /* Try to delete from the VFS first. */
     parent::removeAttachment($pageId, $attachment, $version);
     /* First try against the current attachments table. */
     $sql = 'DELETE FROM ' . $this->_params['attachmenttable'] . ' WHERE page_id = ? AND attachment_name = ?';
     $params = array((int) $pageId, $attachment);
     if (!is_null($version)) {
         $sql .= ' AND attachment_version = ?';
         $params[] = (int) $version;
     }
     try {
         $this->_db->beginDbTransaction();
         $result = $this->_db->delete($sql, $params);
         /* Now try against the attachment history table. $params is
          * unchanged. */
         $sql = 'DELETE FROM ' . $this->_params['attachmenthistorytable'] . ' WHERE page_id = ? AND attachment_name = ?';
         if (!is_null($version)) {
             $sql .= ' AND attachment_version = ?';
         }
         $this->_db->delete($sql, $params);
         $this->_db->commitDbTransaction();
     } catch (Horde_Db_Exception $e) {
         $this->_db->rollbackDbTransaction();
         throw new Wicked_Exception($e);
     }
 }