} print_stop_message('product_x_uninstalled', $vbulletin->GPC['productid']); } // ############################################################################# if ($_REQUEST['do'] == 'productdelete') { $vbulletin->input->clean_array_gpc('r', array('productid' => TYPE_STR)); if (strtolower($vbulletin->GPC['productid']) == 'vbulletin') { print_cp_redirect('plugin.php?do=product'); } $dependency_result = $db->query_read("\r\n\t\tSELECT productid, parentproductid\r\n\t\tFROM " . TABLE_PREFIX . "productdependency\r\n\t\tWHERE dependencytype = 'product' AND parentproductid <> ''\r\n\t"); // find child products -- these may break if we uninstall this $dependency_list = array(); while ($dependency = $db->fetch_array($dependency_result)) { $dependency_list["{$dependency['parentproductid']}"][] = $dependency['productid']; } $children = fetch_product_dependencies($vbulletin->GPC['productid'], $dependency_list); $product_list = fetch_product_list(true); $children_text = array(); foreach ($children as $childproductid) { $childproduct = $product_list["{$childproductid}"]; if ($childproduct) { $children_text[] = $childproduct['title']; } } if ($children_text) { $affected_children = construct_phrase($vbphrase['uninstall_product_break_products_x'], '<li>' . implode('</li><li>', $children_text) . '</li>'); } else { $affected_children = ''; } print_delete_confirmation('product', $vbulletin->GPC['productid'], 'plugin', 'productkill', '', 0, $affected_children); }
/** * Fetches an array of products dependent on a specific product, though whether * this is a parent-child or child-parent relationship is determined based on * the construction of the dependency list. * If the parent is the key, this function will recursively find a list of children. * If the child is the key, the function will recursively find a list of parents. * * @param string Product to find parents/children for * @param array An array of dependencies to pull from in form [pid][] => pid * * @return array Array of children/parents */ function fetch_product_dependencies($productid, &$dependency_list) { if (!is_array($dependency_list["{$productid}"])) { return array(); } $list = array(); foreach ($dependency_list["{$productid}"] as $subproductid) { // only traverse this branch if we haven't done it before -- prevent infinte recursion if (!isset($list["{$subproductid}"])) { $list["{$subproductid}"] = $subproductid; $list = array_merge($list, fetch_product_dependencies($subproductid, $dependency_list)); } } return $list; }