Function Reference: geodir_diagnose_multisite_table

Summary

Diagnose multisite related tables.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None

Package

GeoDirectory

Parameters

$filter_arr
(array) (required) The diagnose messages array.

Default: None
$table
(string) (required) The table name. Ex: geodir_countries.

Default: None
$tabel_name
(string) (required) Human readable table name. Ex: Geodir Countries.

Default: None
$fix
(bool) (required) If error during diagnose do you want to fix it? Default: false.

Default: None

Return Values

(array)
  • The diagnose messages array.

Change Log

Since: 1.0.0

Source File

geodir_diagnose_multisite_table() is located in geodirectory-admin/admin_hooks_actions.php [Line: 1023]

Source Code

function geodir_diagnose_multisite_table($filter_arr, $table, $tabel_name, $fix)
{
    global $wpdb;
    //$filter_arr['output_str'] .='###'.$table.'###';
    if ($wpdb->query("SHOW TABLES LIKE '" . $table . "_ms_bak2'") > 0 && $wpdb->query("SHOW TABLES LIKE '" . $table . "_ms_bak'") > 0) {
        $filter_arr['output_str'] .= "
  • " . __('ERROR: You did not follow instructions! Now you will need to contact support to manually fix things.', 'geodirectory') . "
  • "; $filter_arr['is_error_during_diagnose'] = true; } elseif ($wpdb->query("SHOW TABLES LIKE '" . $table . "_ms_bak'") > 0 && $wpdb->query("SHOW TABLES LIKE '" . $wpdb->prefix . "$table'") > 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('ERROR: %s_ms_bak table found', 'geodirectory'), $tabel_name) . "
  • "; $filter_arr['is_error_during_diagnose'] = true; $filter_arr['output_str'] .= "
  • " . __('IMPORTANT: This can be caused by out of date core or addons, please update core + addons before trying the fix OR YOU WILL HAVE A BAD TIME!', 'geodirectory') . "
  • "; $filter_arr['is_error_during_diagnose'] = true; if ($fix) { $ms_bak_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $table . "_ms_bak");// get backup table count $new_table_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "$table");// get new table count if ($ms_bak_count == $new_table_count) {// if they are the same count rename to bak2 //$filter_arr['output_str'] .= "
  • ".sprintf( __('-->PROBLEM: %s table count is the same as new table, contact support' , 'geodirectory'), $table )."
  • " ; $wpdb->query("RENAME TABLE " . $table . "_ms_bak TO " . $table . "_ms_bak2");// rename bak table to new table if ($wpdb->query("SHOW TABLES LIKE '" . $table . "_ms_bak2'") && $wpdb->query("SHOW TABLES LIKE '" . $table . "_ms_bak'") == 0) { $filter_arr['output_str'] .= "
  • " . __('-->FIXED: Renamed and backed up the tables', 'geodirectory') . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . __('-->PROBLEM: Failed to rename tables, please contact support.', 'geodirectory') . "
  • "; } } elseif ($ms_bak_count > $new_table_count) {//if backup is greater then restore it $wpdb->query("RENAME TABLE " . $wpdb->prefix . "$table TO " . $table . "_ms_bak2");// rename new table to bak2 $wpdb->query("RENAME TABLE " . $table . "_ms_bak TO " . $wpdb->prefix . "$table");// rename bak table to new table if ($wpdb->query("SHOW TABLES LIKE '" . $table . "_ms_bak2'") && $wpdb->query("SHOW TABLES LIKE '" . $wpdb->prefix . "$table'") && $wpdb->query("SHOW TABLES LIKE '$table'") == 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->FIXED: restored largest table %s', 'geodirectory'), $table) . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . __('-->PROBLEM: Failed to rename tables, please contact support.', 'geodirectory') . "
  • "; } } elseif ($new_table_count > $ms_bak_count) {// we cant do much so rename the table to stop errors $wpdb->query("RENAME TABLE " . $table . "_ms_bak TO " . $table . "_ms_bak2");// rename ms_bak table to ms_bak2 if ($wpdb->query("SHOW TABLES LIKE '" . $table . "_ms_bak'") == 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->FIXED: table %s_ms_bak renamed and backed up', 'geodirectory'), $table) . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . __('-->PROBLEM: Failed to rename tables, please contact support.', 'geodirectory') . "
  • "; } } } } elseif ($wpdb->query("SHOW TABLES LIKE '$table'") > 0 && $wpdb->query("SHOW TABLES LIKE '" . $wpdb->prefix . "$table'") > 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('ERROR: Two %s tables found', 'geodirectory'), $tabel_name) . "
  • "; $filter_arr['is_error_during_diagnose'] = true; if ($fix) { if ($wpdb->get_var("SELECT COUNT(*) FROM $table") == 0) {// if first table is empty just delete it if ($wpdb->query("DROP TABLE IF EXISTS $table")) { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->FIXED: Deleted table %s', 'geodirectory'), $table) . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->PROBLEM: Delete table %s failed, please try manual delete from DB', 'geodirectory'), $table) . "
  • "; } } elseif ($wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "$table") == 0) {// if main table is empty but original is not, delete main and rename original if ($wpdb->query("DROP TABLE IF EXISTS " . $wpdb->prefix . "$table")) { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->FIXED: Deleted table %s', 'geodirectory'), $wpdb->prefix . $table) . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->PROBLEM: Delete table %s failed, please try manual delete from DB', 'geodirectory'), $wpdb->prefix . $table) . "
  • "; } if ($wpdb->query("RENAME TABLE $table TO " . $wpdb->prefix . "$table") || $wpdb->query("SHOW TABLES LIKE '$table'") == 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->FIXED: Table %s renamed to %s', 'geodirectory'), $table, $wpdb->prefix . $table) . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->PROBLEM: Failed to rename table %s to %s, please try manually from DB', 'geodirectory'), $table, $wpdb->prefix . $table) . "
  • "; } } else {// else rename the original table to _ms_bak if ($wpdb->query("RENAME TABLE $table TO " . $table . "_ms_bak") || $wpdb->query("SHOW TABLES LIKE '$table'") == 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->FIXED: Table contained info so we renamed %s to %s incase it is needed in future', 'geodirectory'), $table, $table . "_ms_bak") . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->PROBLEM: Table %s could not be renamed to %s, this table has info so may need to be reviewed manually in the DB', 'geodirectory'), $table, $table . "_ms_bak") . "
  • "; } } } } elseif ($wpdb->query("SHOW TABLES LIKE '$table'") > 0 && $wpdb->query("SHOW TABLES LIKE '" . $wpdb->prefix . "$table'") == 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('ERROR: %s table not converted', 'geodirectory'), $tabel_name) . "
  • "; $filter_arr['is_error_during_diagnose'] = true; if ($fix) { // if original table exists but new does not, rename if ($wpdb->query("RENAME TABLE $table TO " . $wpdb->prefix . "$table") || $wpdb->query("SHOW TABLES LIKE '$table'") == 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->FIXED: Table %s renamed to %s', 'geodirectory'), $table, $wpdb->prefix . $table) . "
  • "; } else { $filter_arr['output_str'] .= "
  • " . sprintf(__('-->PROBLEM: Failed to rename table %s to %s, please try manually from DB', 'geodirectory'), $table, $wpdb->prefix . $table) . "
  • "; } } } elseif ($wpdb->query("SHOW TABLES LIKE '$table'") == 0 && $wpdb->query("SHOW TABLES LIKE '" . $wpdb->prefix . "$table'") == 0) { $filter_arr['output_str'] .= "
  • " . sprintf(__('ERROR: %s table does not exist', 'geodirectory'), $tabel_name) . "
  • "; $filter_arr['is_error_during_diagnose'] = true; if ($fix) { // if original table does not exist try deleting db_vers of all addons so the initial db_install scripts run; delete_option('geodirlocation_db_version'); delete_option('geodirevents_db_version'); delete_option('geodir_reviewrating_db_version'); delete_option('gdevents_db_version'); delete_option('geodirectory_db_version'); delete_option('geodirclaim_db_version'); delete_option('geodir_custom_posts_db_version'); delete_option('geodir_reviewratings_db_version'); delete_option('geodiradvancesearch_db_version'); $filter_arr['output_str'] .= "
  • " . __('-->TRY: Please refresh page to run table install functions', 'geodirectory') . "
  • "; } } else { $filter_arr['output_str'] .= "
  • " . sprintf(__('%s table converted correctly', 'geodirectory'), $tabel_name) . "
  • "; } return $filter_arr; }