Example #1
0
 /**
  * Any code to run before deleting.
  *
  * @param	string	What are we deleteing?
  */
 function pre_delete($type = 'attachment', $doquery = true, $checkperms = true)
 {
     $this->lists['content'] = array();
     $this->lists['filedataids'] = array();
     $this->lists['attachmentids'] = array();
     $this->lists['picturecomments'] = array();
     $this->lists['userids'] = array();
     $this->set_info('type', $type);
     if ($type == 'filedata') {
         $ids = $this->registry->db->query_read("\n\t\t\t\tSELECT a.attachmentid, fd.userid, fd.filedataid, a.userid AS auserid, a.contenttypeid\n\t\t\t\tFROM " . TABLE_PREFIX . "filedata AS fd\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "attachment AS a ON (a.filedataid = fd.filedataid)\n\t\t\t\tWHERE " . $this->condition);
     } else {
         $ids = $this->registry->db->query_read("\n\t\t\t\tSELECT a.attachmentid, fd.userid, fd.filedataid, a.userid AS auserid, a.contenttypeid\n\t\t\t\tFROM " . TABLE_PREFIX . "attachment AS a\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "filedata AS fd ON (a.filedataid = fd.filedataid)\n\t\t\t\tWHERE " . $this->condition);
     }
     while ($id = $this->registry->db->fetch_array($ids)) {
         if ($id['attachmentid']) {
             $this->lists['content']["{$id['contenttypeid']}"][] = $id['attachmentid'];
             $this->lists['attachmentids'][] = $id['attachmentid'];
             $this->lists['userids']["{$id['auserid']}"] = 1;
             if ($id['filedataid'] and $id['auserid']) {
                 $this->lists['picturecomments'][] = "(filedataid = {$id['filedataid']} AND userid = {$id['auserid']})";
             }
         }
         if ($id['filedataid']) {
             $this->lists['filedataids']["{$id['filedataid']}"] = $id['userid'];
         }
     }
     require_once DIR . '/packages/vbattach/attach.php';
     if ($this->registry->db->num_rows($ids) == 0) {
         // nothing to delete
         return false;
     } else {
         foreach ($this->lists['content'] as $contenttypeid => $list) {
             if ($attach =& vB_Attachment_Dm_Library::fetch_library($this->registry, $contenttypeid)) {
                 if (!$attach->pre_delete($list, $checkperms, $this)) {
                     return false;
                 }
             } else {
                 // This means we have an unrecognized contenttypeid, just delete the attachments..
             }
             unset($attach);
         }
     }
     return parent::pre_delete($doquery);
 }
Example #2
0
	/**
	* Any code to run before deleting.
	*
	* @param	string	What are we deleteing?
	*/
	function pre_delete($type = 'attachment', $doquery = true, $checkperms = true)
	{
		$this->lists['content'] = array();
		$this->lists['filedataids'] = array();
		$this->lists['attachmentids'] = array();
		$this->lists['picturecomments'] = array();
		$this->lists['userids'] = array();
		$this->set_info('type', $type);

		if ($type == 'filedata')
		{
			$ids = $this->registry->db->query_read("
				SELECT a.attachmentid, fd.userid, fd.filedataid, a.userid AS auserid, a.contenttypeid
				FROM " . TABLE_PREFIX . "filedata AS fd
				LEFT JOIN " . TABLE_PREFIX . "attachment AS a ON (a.filedataid = fd.filedataid)
				WHERE " . $this->condition
			);
		}
		else
		{
			$ids = $this->registry->db->query_read("
				SELECT a.attachmentid, fd.userid, fd.filedataid, a.userid AS auserid, a.contenttypeid
				FROM " . TABLE_PREFIX . "attachment AS a
				LEFT JOIN " . TABLE_PREFIX . "filedata AS fd ON (a.filedataid = fd.filedataid)
				WHERE " . $this->condition
			);
		}
		while ($id = $this->registry->db->fetch_array($ids))
		{
			if ($id['attachmentid'])
			{
				$this->lists['content']["$id[contenttypeid]"][] = $id['attachmentid'];
				$this->lists['attachmentids'][] = $id['attachmentid'];
				$this->lists['picturecomments'][] = "(filedataid = $id[filedataid] AND userid = $id[auserid])";
				$this->lists['userids']["$id[auserid]"] = 1;
			}
			if ($id['filedataid'])
			{
				$this->lists['filedataids']["$id[filedataid]"] = $id['userid'];
			}
		}

		require_once(DIR . '/packages/vbattach/attach.php');
		if ($this->registry->db->num_rows($ids) == 0)
		{	// nothing to delete
			return false;
		}
		else
		{
			foreach ($this->lists['content'] AS $contenttypeid => $list)
			{
				if (!($attach =& vB_Attachment_Dm_Library::fetch_library($this->registry, $contenttypeid)))
				{
					return false;
				}
				if (!$attach->pre_delete($list, $checkperms, $this))
				{
					return false;
				}
				unset($attach);
			}
		}

		return parent::pre_delete($doquery);
	}