function drop_goods($goods_ids) { //$goods_ids = base64_decode($goods_ids); $goods_id_arr = explode(',', $goods_ids); //check table exist $tableExist = array(); $tableExist['collect_goods'] = checkTableExist('collect_goods'); $tableExist['goods_article'] = checkTableExist('goods_article'); $tableExist['goods_activity'] = checkTableExist('goods_activity'); $tableExist['goods_attr'] = checkTableExist('goods_attr'); $tableExist['goods_cat'] = checkTableExist('goods_cat'); $tableExist['member_price'] = checkTableExist('member_price'); $tableExist['group_goods'] = checkTableExist('group_goods'); $tableExist['link_goods'] = checkTableExist('link_goods'); $tableExist['tag'] = checkTableExist('tag'); $tableExist['comment'] = checkTableExist('comment'); $tableExist['booking_goods'] = checkTableExist('booking_goods'); $tableExist['volume_price'] = checkTableExist('volume_price'); $tableExist['virtual_card'] = checkTableExist('virtual_card'); $tableExist['products'] = checkTableExist('products'); foreach ($goods_id_arr as $goods_id) { $sql = "SELECT goods_id, goods_name, is_delete, is_real, goods_thumb, " . "goods_img, original_img " . "FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_id = '{$goods_id}'"; $goods = $GLOBALS['db']->getRow($sql); if (!empty($goods['goods_id'])) { if (!empty($goods['goods_thumb'])) { @unlink('../' . $goods['goods_thumb']); } if (!empty($goods['goods_img'])) { @unlink('../' . $goods['goods_img']); } if (!empty($goods['original_img'])) { @unlink('../' . $goods['original_img']); } $sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); $sql = "SELECT img_url, thumb_url, img_original " . "FROM " . $GLOBALS['ecs']->table('goods_gallery') . " WHERE goods_id = '{$goods_id}' order by img_id"; $res = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchRow($res)) { if (!empty($row['img_url'])) { @unlink('../' . $row['img_url']); } if (!empty($row['thumb_url'])) { @unlink('../' . $row['thumb_url']); } if (!empty($row['img_original'])) { @unlink('../' . $row['img_original']); } } $sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_gallery') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); if ($tableExist['collect_goods']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('collect_goods') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['goods_article']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_article') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['goods_activity']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_activity') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['goods_attr']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['goods_cat']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_cat') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['member_price']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('member_price') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['group_goods']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('group_goods') . " WHERE parent_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); $sql = "DELETE FROM " . $GLOBALS['ecs']->table('group_goods') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['link_goods']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('link_goods') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); $sql = "DELETE FROM " . $GLOBALS['ecs']->table('link_goods') . " WHERE link_goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['tag']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('tag') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['comment']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('comment') . " WHERE comment_type = 0 AND id_value = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['booking_goods']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('booking_goods') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['volume_price']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('volume_price') . " WHERE price_type = '1' AND goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($goods['is_real'] != 1 && $tableExist['virtual_card']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('virtual_card') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } if ($tableExist['products']) { $sql = "DELETE FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}'"; $GLOBALS['db']->query($sql); } } $sync_item = array(); $sync_item['table'] = "ecs_goods"; $sync_item['guid'] = $goods_id; $sync_item['succ'] = true; //$sync_item['errmsg'] = base64_encode($tmp); $syncitems[] = $sync_item; } //clear_cache_files(); $pack = array("succ" => true, "items" => $syncitems); return $pack; }
$db->query("DELETE FROM instances"); // Populate table. $passboltInstances = Config::read('passbolt.instances'); $seleniumInstances = Config::read('testserver.selenium.instances'); foreach ($passboltInstances as $instance) { $instancesToSave[] = ['type' => 'passbolt', 'address' => $instance, 'locked' => 0]; } foreach ($seleniumInstances as $instance) { $instancesToSave[] = ['type' => 'selenium', 'address' => $instance, 'locked' => 0]; } foreach ($instancesToSave as $instance) { $db->query("INSERT INTO instances (type, address, locked) VALUES('{$instance['type']}', '{$instance['address']}', {$instance['locked']});"); } } // Open or create DB. $db = new mysqli(Config::read('database.host'), Config::read('database.username'), Config::read('database.password'), Config::read('database.name')); // Check for errors if (mysqli_connect_errno()) { echo mysqli_connect_error(); } // Check if table exists. $tableExists = checkTableExist($db); // If table doesn't exist, create it and populate it with instances. if (!$tableExists) { createTable($db); } populateTable($db); $nbEntries = $db->query('SELECT COUNT(*) AS nbdata FROM instances'); $nbEntries = $nbEntries->fetch_array()['nbdata']; echo "Database and table instances have been created, and populated with {$nbEntries} entries\n"; $db->close();