♥bruyndoncx 260 Posted November 9, 2006 My easypopulate code contains this sceleton code, I'm a bit lazy today and am wondering if anyone has already made this effort and figured out the different tables needing cleanup. It doesn't look difficult to me, but maybe I missed something. my list of tables to clean: products, products_description, products_to_categories, products_attributes /* if ( $items['v_status'] == $deleteit ){ // they want to delete this product. echo "Deleting product " . $items['v_products_model'] . " from the database<br>"; // Get the ID // kill in the products_to_categories // Kill in the products table return; // we're done deleteing! } */ Looking at my categories.php file, I find this piece of code case 'delete_product_confirm': if (isset($HTTP_POST_VARS['products_id']) && isset($HTTP_POST_VARS['product_categories']) && is_array($HTTP_POST_VARS['product_categories'])) { $product_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']); $product_categories = $HTTP_POST_VARS['product_categories']; for ($i=0, $n=sizeof($product_categories); $i<$n; $i++) { tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "' and categories_id = '" . (int)$product_categories[$i] . "'"); } $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'"); $product_categories = tep_db_fetch_array($product_categories_query); if ($product_categories['total'] == '0') { tep_remove_product($product_id); } } if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); } tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath)); break; So combining this logic, I think all that is needed in EasyPopulate is: if ( $items['v_status'] == $deleteit ){ // they want to delete this product. echo "Deleting product " . $items['v_products_model'] . " from the database<br>"; // Get the ID $sql = "SELECT p.products_id as v_products_id FROM ".TABLE_PRODUCTS." as p WHERE p.products_model = '" . $items[$filelayout['v_products_model']] . "'"; $result = tep_db_query($sql); $row = tep_db_fetch_array($result); if (tep_db_num_rows($result) == 1 ) { tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'"); $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'"); $product_categories = tep_db_fetch_array($product_categories_query); if ($product_categories['total'] == '0') { tep_remove_product($product_id); } if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); } } else { echo "Did not delete " . $items['v_products_model'] . " since it is not unique "; } return; // we're done deleteing! } KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Share this post Link to post Share on other sites
♥bruyndoncx 260 Posted November 9, 2006 OK, logic seemed to be ok, but some syntactic errors and array references where made. Thhs is the piece of code I have now, plus I also uncommented the $deleteit constant and set it to something appropriate like 'Delete'. if ( $items[$filelayout['v_status']] == $deleteit ){ // they want to delete this product. echo "Deleting product " . $items[$filelayout['v_products_model']] . " from the database<br>"; // Get the ID $sql = "SELECT p.products_id as v_products_id FROM ".TABLE_PRODUCTS." as p WHERE p.products_model = '" . $items[$filelayout['v_products_model']] . "'"; $result = tep_db_query($sql); $row = tep_db_fetch_array($result); if (tep_db_num_rows($result) == 1 ) { tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'"); $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $row['v_products_id'] . "'"); $product_categories = tep_db_fetch_array($product_categories_query); if ($product_categories['total'] == '0') { tep_remove_product($row['v_products_id']); } if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); } } else { echo "Did not delete " . $items['v_products_model'] . " since it is not unique "; } return; // we're done deleteing! } I almost can't believe it is this simple and no-one has attempted this yet ? If you read through the code, you'll see that it will only attempt to delete a product if the products model uniquely identifies a single product, this to avoid data issues and accidentally deleting a whole bunch of products. I believe this is consistent with the design of EP and it's requirement for a unique products_model field. Enjoy your cleanup ! KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Share this post Link to post Share on other sites
beller 0 Posted November 9, 2006 Forgive me if I missed this somewhere, but this is quite a large post. I have downloaded enable, but when I pull down my EP text file to edit, I don't see the filename(of the file to be downloaded) variable listed. I guess it's on option variable not included in the program, but how can I edit the filename attribute? Thanks all Share this post Link to post Share on other sites
♥bruyndoncx 260 Posted November 9, 2006 Forgive me if I missed this somewhere, but this is quite a large post. I have downloaded enable, but when I pull down my EP text file to edit, I don't see the filename(of the file to be downloaded) variable listed. I guess it's on option variable not included in the program, but how can I edit the filename attribute? Thanks all Sorry, posted in the wrong thread, and I personally don't know the answer on your question (otherwise I would have answered :) ) KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Share this post Link to post Share on other sites