Created
June 25, 2015 23:39
-
-
Save toddnestor/24fd9bffc6c68e542ee6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function PostInit() | |
{ | |
if( !isset($_GET['dbfix']) ) | |
return; | |
$this->Helper('tools')->remove_server_limits(); | |
global $db; | |
$objects = $this->GetObjects('routes'); | |
foreach( $objects as $key => $value ) | |
{ | |
$value->MakeTableIfItDoesntExist(); | |
} | |
//exit; | |
$data = $this->Helper('db')->Query( "SHOW TABLES"); | |
foreach( $data as $key => $value ) | |
{ | |
$table_name = $value[0]; | |
$bits = $original_bits = explode('_', $table_name ); | |
$is_company_table = strpos( $bits[1], 'c' ) !== false ? true : false; | |
$is_site_table = strpos( $bits[1], 's' ) !== false ? true : false; | |
$the_number = str_replace( 'c', '', $bits[1] ); | |
$the_number = str_replace( 's', '', $the_number ); | |
if( is_numeric($the_number) ) | |
{ | |
unset($original_bits[1]); | |
$clean_table_name = implode( '_', $original_bits ); | |
$real_data = $this->Helper('db')->Query( "SELECT * FROM $table_name" ); | |
if( $real_data ) | |
{ | |
foreach( $real_data as $key2 => $value2 ) | |
{ | |
$value2['old_id'] = $value2['id']; | |
unset($value2['id']); | |
$value2['site_id'] = $is_site_table ? $the_number : ''; | |
$value2['company_id'] = $is_company_table ? $the_number : ''; | |
foreach ($value2 as $key3 => $value3) | |
if (is_numeric($key3)) // only numbers, a point and an `e` like in 1.1e10 | |
unset($value2[$key3]); | |
//$this->ItemDebug( $value2 );exit; | |
$last_id = $db->insert($clean_table_name, $value2); | |
} | |
} | |
//$this->ItemDebug( 'company: '.$is_company_table ); | |
//$this->ItemDebug( 'site: '.$is_site_table ); | |
//$this->ItemDebug( $bits ); | |
//$this->ItemDebug( $clean_table_name ); | |
$this->Helper('db')->Query( "DROP TABLE $table_name" ); | |
echo "Dropped $table_name<br>"; | |
} | |
else | |
{ | |
} | |
} | |
$this->Helper('db')->Query("update `smartm_lessons` l left join `smartm_modules` m on l.site_id = m.site_id and l.module_id = m.old_id set l.module_id = m.id where l.module_id != 0"); | |
$this->Helper('db')->Query("update `smartm_support_article` l left join smartm_support_category m on l.site_id = m.site_id and l.category_id = m.old_id set l.category_id = m.id where l.category_id != 0"); | |
$this->Helper('db')->Query("update `smartm_accessledgers` l left join smartm_accesslevels m on l.site_id = m.site_id and l.access_level_id = m.old_id set l.access_level_id = m.id where l.access_level_id != 0"); | |
echo 'dont forget to add the index back to access ledgers<br>'; | |
$this->Helper('db')->Query("update `smartm_comments` l left join smartm_livecasts m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0"); | |
$this->Helper('db')->Query("update `smartm_downloads` l left join smartm_media_items m on l.site_id = m.site_id and l.media_item_id = m.old_id set l.media_item_id = m.id where l.media_item_id != 0"); | |
$this->Helper('db')->Query("update `smartm_extra_meta` l left join smartm_downloads m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'download'"); | |
$this->Helper('db')->Query("update `smartm_extra_meta` l left join smartm_special_pages m on l.site_id = m.site_id and l.target_id = m.old_id and l.type = m.type set l.target_id = m.id where l.target_id != 0 and ( l.type = 'refund-page' or l.type = 'free-bonus' )"); | |
$this->Helper('db')->Query("update `smartm_extra_meta` l left join smartm_livecasts m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'livecast'"); | |
$this->Helper('db')->Query("update `smartm_extra_meta` l left join smartm_media_items m on l.site_id = m.site_id and l.meta_value = m.old_id set l.meta_value = m.id where l.meta_value != 0 and l.meta_key = 'free_item_id'"); | |
echo 'dont forget to add the index back to extra meta<br>'; | |
$this->Helper('db')->Query("update `smartm_file_download` l left join smartm_media_items m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0"); | |
$this->Helper('db')->Query("update `smartm_lessons` l left join smartm_accesslevels m on l.site_id = m.site_id and l.access_level = m.old_id set l.access_level = m.id where l.access_level != 'public' and l.access_level != 'private' and l.access_level != 'logged_in'"); | |
$this->Helper('db')->Query("update `smartm_livecasts` l left join smartm_accesslevels m on l.site_id = m.site_id and l.access_level = m.old_id set l.access_level = m.id where l.access_level != 'public' and l.access_level != 'private' and l.access_level != 'logged_in'"); | |
$this->Helper('db')->Query("update `smartm_pages` l left join smartm_accesslevels m on l.site_id = m.site_id and l.access_level = m.old_id set l.access_level = m.id where l.access_level != 'public' and l.access_level != 'private' and l.access_level != 'logged_in'"); | |
$this->Helper('db')->Query("update `smartm_downloads` l left join smartm_accesslevels m on l.site_id = m.site_id and l.access_level = m.old_id set l.access_level = m.id where l.access_level != 'public' and l.access_level != 'private' and l.access_level != 'logged_in'"); | |
$this->Helper('db')->Query("update `smartm_permalinks` l left join smartm_lessons m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'lesson'"); | |
$this->Helper('db')->Query("update `smartm_permalinks` l left join smartm_pages m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'page'"); | |
$this->Helper('db')->Query("update `smartm_permalinks` l left join smartm_downloads m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'download'"); | |
$this->Helper('db')->Query("update `smartm_permalinks` l left join smartm_livecasts m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'livecast'"); | |
$this->Helper('db')->Query("update `smartm_permalinks` l left join smartm_support_article m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'support-article'"); | |
echo 'dont forget to add both indexes back to permalinks!<br>'; | |
$this->Helper('db')->Query("update `smartm_seo_settings` l left join smartm_lessons m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'lesson'"); | |
$this->Helper('db')->Query("update `smartm_seo_settings` l left join smartm_pages m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'page'"); | |
$this->Helper('db')->Query("update `smartm_seo_settings` l left join smartm_downloads m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'download'"); | |
$this->Helper('db')->Query("update `smartm_seo_settings` l left join smartm_livecasts m on l.site_id = m.site_id and l.target_id = m.old_id set l.target_id = m.id where l.target_id != 0 and l.type = 'livecast'"); | |
echo 'dont forget to add the index back to seo settings!<br>'; | |
$this->Helper('db')->Query("update `smartm_support_ticket` l left join `smartm_support_ticket` m on l.site_id = m.site_id and l.parent_id = m.old_id set l.parent_id = m.id where l.parent_id != 0"); | |
$this->Helper('db')->Query("update `smartm_user_note` l left join `smartm_lessons` m on l.site_id = m.site_id and l.lesson_id = m.old_id set l.lesson_id = m.id where l.lesson_id != 0"); | |
echo 'dont forget to add the index back to user notes!<br>'; | |
//$this->ItemDebug( $data ); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment