function fn_delete_news($news_id) { // Log news deletion fn_log_event('news', 'delete', array('news_id' => $news_id)); fn_clean_block_items('news', $news_id); fn_clean_block_links('news', $news_id); db_query("DELETE FROM ?:news WHERE news_id = ?i", $news_id); db_query("DELETE FROM ?:news_descriptions WHERE news_id = ?i", $news_id); fn_set_hook('delete_news', $news_id); }
function fn_delete_product($product_id) { $auth =& $_SESSION['auth']; if (!empty($product_id)) { if (defined('COMPANY_ID')) { $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $product_id); if (COMPANY_ID != $company_id) { fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('access_denied')); return false; } } fn_clean_block_items('products', $product_id); fn_clean_block_links('products', $product_id); // Log product deletion fn_log_event('products', 'delete', array('product_id' => $product_id)); $category_ids = db_get_fields("SELECT category_id FROM ?:products_categories WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:products_categories WHERE product_id = ?i", $product_id); fn_update_product_count($category_ids); db_query("DELETE FROM ?:products WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_descriptions WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_prices WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_features_values WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_options_exceptions WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_popularity WHERE product_id = ?i", $product_id); fn_delete_image_pairs($product_id, 'product'); // Delete product options and inventory records for this product fn_poptions_delete_product($product_id); // Delete product files fn_rm(DIR_DOWNLOADS . $product_id); fn_build_products_cache(array($product_id)); // Executing delete_product functions from active addons fn_set_hook('delete_product', $product_id); $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_id = ?i", $product_id); return empty($pid) ? true : false; } else { return false; } }
/** * Delete page and its subpages * * @param int $page_id Page ID * @param boolean $recurse Delete page recursively or not * @return array Returns ids of deleted pages or false if function can't delete page */ function fn_delete_page($page_id, $recurse = true) { if (!empty($page_id) && fn_check_company_id('pages', 'page_id', $page_id)) { // Delete all subpages if ($recurse == true) { $id_path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $page_id); $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE page_id = ?i OR id_path LIKE ?l", $page_id, "{$id_path}/%"); } else { $page_ids = array($page_id); } foreach ($page_ids as $v) { // Deleting page db_query("DELETE FROM ?:pages WHERE page_id = ?i", $v); db_query("DELETE FROM ?:page_descriptions WHERE page_id = ?i", $v); fn_set_hook('delete_page', $v); fn_clean_block_items('pages', $v); fn_clean_block_links('pages', $v); } return $page_ids; // Returns ids of deleted pages } else { return false; } }
function fn_delete_category($category_id, $recurse = true) { // Log category deletion fn_log_event('categories', 'delete', array('category_id' => $category_id)); fn_clean_block_items('categories', $category_id); fn_clean_block_links('categories', $category_id); $category_ids = array(); $category_ids[] = $category_id; if (!empty($category_ids[0])) { // Delete all subcategories if ($recurse == true) { $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id); $category_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE category_id = ?i OR id_path LIKE ?l", $category_id, "{$id_path}/%"); } foreach ($category_ids as $k => $v) { $category_id = $v; fn_clean_block_items('categories', $category_id); // Deleting category db_query("DELETE FROM ?:categories WHERE category_id = ?i", $category_id); db_query("DELETE FROM ?:category_descriptions WHERE category_id = ?i", $category_id); // Deleting additional product associations without deleting products itself db_query("DELETE FROM ?:products_categories WHERE category_id = ?i AND link_type = 'A'", $category_id); // Remove this category from features assignments db_query("UPDATE ?:product_features SET categories_path = ?p", fn_remove_from_set('categories_path', $v)); // Deleting main products association with deleting products $products_to_delete = db_get_fields("SELECT product_id FROM ?:products_categories WHERE category_id = ?i AND link_type = 'M'", $category_id); if (!empty($products_to_delete)) { foreach ($products_to_delete as $key => $value) { fn_delete_product($value); } } // Deleting category images fn_delete_image_pairs($category_id, 'category'); // Executing delete_category functions from active addons fn_set_hook('delete_category', $category_id); } return $category_ids; // Returns ids of deleted categories } else { return false; } }