/** * Executes alert index scripts from idx.txt file. * * @global object $wpdb Wordpress DB class * @global string $table_prefix Wordpress table prefix * @param string $path base path to folder where the install folder is located with trailing slash * @param string $fname file name to use */ function alter_index($path, $fname = 'idx.txt') { global $wpdb, $table_prefix; $path .= "install/mod/" . $fname; if (file_exists($path)) { $alters = file($path); $table_cache = $matches = array(); if (is_array($alters) && count($alters) > 0) { foreach ($alters as $a) { if (trim($a) != '') { $a = sprintf($a, $table_prefix); $tbl = trim(substr($a, 12, strpos($a, " ADD") - 12)); if (!in_array($tbl, array_keys($table_cache))) { $table_cache[$tbl] = $wpdb->get_results("SHOW INDEX FROM " . $tbl); } $found = preg_match("/ADD\\sINDEX\\s`(.+?)`\\s\\(`(.+?)`\\)/i", $a, $matches); if ($found == 1) { if (gdDBInstallGDPT::check_for_index($table_cache[$tbl], $matches[2])) { $wpdb->query($a); } } else { $found = preg_match("/ADD\\sPRIMARY\\sKEY\\s\\(`(.+?)`\\)/i", $a, $matches); if ($found == 1) { if (gdDBInstallGDPT::check_for_index($table_cache[$tbl], $matches[2])) { $wpdb->query($a); } } } } } } } }