/** * Expunge currently loaded pigeonhole * @return bool TRUE on success, FALSE if store could not occur. * @access public **/ function expunge($pStructureId = NULL) { $ret = FALSE; // if we have a custom structure id we want to remove, load it if (@BitBase::verifyId($pStructureId)) { $this->mStructureId = $pStructureId; $this->load(); } if ($this->isValid()) { $this->mDb->StartTrans(); // get all items that are part of the sub tree require_once LIBERTY_PKG_PATH . 'LibertyStructure.php'; $struct = new LibertyStructure(); // include the current structure id as well $structureIds[] = $this->mStructureId; $tree = $struct->getSubTree($this->mStructureId); foreach ($tree as $node) { $structureIds[] = $node['structure_id']; } $structureIds = array_unique($structureIds); $where = ''; foreach ($structureIds as $structureId) { $where .= (empty($where) ? " WHERE " : " OR ") . "`structure_id`=?"; } $result = $this->mDb->query("SELECT `content_id` FROM `" . BIT_DB_PREFIX . "liberty_structures` {$where}", $structureIds); $contentIds = $result->getRows(); foreach ($contentIds as $id) { // now we have the content ids - let the nuking begin $query = "DELETE FROM `" . BIT_DB_PREFIX . "pigeonholes` WHERE `content_id` = ?"; $result = $this->mDb->query($query, array($id['content_id'])); $query = "DELETE FROM `" . BIT_DB_PREFIX . "pigeonhole_members` WHERE `parent_id` = ?"; $result = $this->mDb->query($query, array($id['content_id'])); // remove all entries from content tables $this->mContentId = $id['content_id']; if (LibertyMime::expunge()) { $ret = TRUE; $this->mDb->CompleteTrans(); } else { $this->mDb->RollbackTrans(); } } // finally nuke the structure in liberty_structures $struct->removeStructureNode($this->mStructureId, FALSE); } return $ret; }
/** * expunge a gallery * * @param array $pParamHash * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function expunge($pForceDeleteItems = FALSE) { $ret = FALSE; if ($this->isValid()) { $this->mDb->StartTrans(); // get all items that are part of the sub tree require_once LIBERTY_PKG_PATH . 'LibertyStructure.php'; $struct = new LibertyStructure(); $tree = $struct->getSubTree($this->mStructureId); // include the current id as well - needed when there are no sub-galleries $galleryContentIds[] = $this->mContentId; foreach ($tree as $node) { $galleryContentIds[] = $node['content_id']; } $galleryContentIds = array_unique($galleryContentIds); // Create Item Object require_once TREASURY_PKG_PATH . 'TreasuryItem.php'; $itemObject = new TreasuryItem(); // Go through all galleries we want to remove foreach ($galleryContentIds as $gid) { // make sure the gallery is fully loaded $this->mContentId = $gid; $this->load(); $itemContentIds = $this->mDb->getCol("SELECT `item_content_id` FROM `" . BIT_DB_PREFIX . "treasury_map` WHERE `gallery_content_id`=?", array($gid)); $itemContentIds = array_unique($itemContentIds); // Delete items in galleries foreach ($itemContentIds as $iid) { if ($pForceDeleteItems) { // Remove item even if it exists in other galleries $count = 1; } else { // Only delete item if it doesn't exist in other galleries $count = $this->mDb->getOne("SELECT COUNT( `item_content_id` ) FROM `" . BIT_DB_PREFIX . "treasury_map` WHERE `item_content_id`=?", array($iid)); } // Only delete item if it doesn't exist in other galleries if ($count == 1) { $itemObject->mContentId = $iid; $itemObject->load(); if (!$itemObject->expunge()) { $this->mErrors['expunge'][] = $itemObject->mErrors; } } } // Next, we remove any icons if they exist if ($thumbdir = $this->getGalleryThumbBaseUrl()) { @unlink_r(BIT_ROOT_PATH . $thumbdir); } // Now that all the items are gone, we can start nuking gallery entries // remove gallery preferences $query = "DELETE FROM `" . BIT_DB_PREFIX . "liberty_content_prefs` WHERE `content_id`=?"; $result = $this->mDb->query($query, array($this->mContentId)); // Remove map entries $sql = "DELETE FROM `" . BIT_DB_PREFIX . "treasury_map` WHERE `gallery_content_id`=?"; $rs = $this->mDb->query($sql, array($gid)); // Remove gallery entry $sql = "DELETE FROM `" . BIT_DB_PREFIX . "treasury_gallery` WHERE `content_id`=?"; $rs = $this->mDb->query($sql, array($gid)); // Let liberty remove all the content entries for this gallery if (!LibertyContent::expunge()) { $errors = TRUE; } // Finally nuke the structure in liberty_structures $struct->removeStructureNode($this->mStructureId, FALSE); } if (empty($errors)) { $this->mDb->CompleteTrans(); $ret = TRUE; } else { $this->mDb->RollbackTrans(); $ret = FALSE; } } return $ret; }