Changeset 118 for trunk/import
- Timestamp:
- Feb 21, 2009, 4:06:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/import/index.php
r117 r118 4 4 include('../includes/dbc.php'); 5 5 6 $PatchVersion = '3.0.3'; 7 8 function ImportSQLMangos() 9 { 10 global $Database, $TranslationTree; 11 12 echo('Načítání textů z databáze MaNGOSu...'); 13 foreach($TranslationTree as $Group) 14 { 15 if(($Group['MangosTable'] != '') and ($Group['TablePrefix'] != '')) 16 { 17 echo('<br />'.$Group['Name'].'<br />'); 18 $Columns = '`'.$Group['MangosDatabase'].'`.`'.$Group['MangosTable'].'`.`'.$Group['MangosTableIndex'].'`'; 19 foreach($Group['Items'] as $GroupItem) 20 $Columns .= ', `'.$Group['MangosDatabase'].'`.`'.$Group['MangosTable'].'`.`'.$GroupItem['MangosColumn'].'` AS `'.$GroupItem['Column'].'`'; 21 $Query = 'SELECT '.$Columns.' FROM `'.$Group['MangosDatabase'].'`.`'.$Group['MangosTable'].'`'; 22 //echo($Query.'<br />'); 23 $Count = 0; 24 $NewCount = 0; 25 $DbResult = $Database->SQLCommand($Query); 26 while($DbRow = mysql_fetch_assoc($DbResult)) 27 { 28 //echo('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$DbRow[$Group['MangosTableIndex']].' AND Language=0'."<br>"); 29 $DbResult2 = $Database->SQLCommand('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$DbRow[$Group['MangosTableIndex']].' AND Language=0'); 30 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 31 { 32 $DbRow2 = mysql_fetch_assoc($DbResult2); 33 //echo($DbRow2['ID']); 34 $ColumnsValues = ''; 35 foreach($Group['Items'] as $GroupItem) 36 { 37 $ColumnsValues .= ', `'.$GroupItem['Column'].'`="'.addslashes($DbRow[$GroupItem['MangosColumn']]).'"'; 38 } 39 $ColumnsValues = substr($ColumnsValues, 2); 40 echo('. '); //'UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']."<br>"); 41 //print_r($DbRow2); 42 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']); 43 } else 44 { 45 $Columns = 'entry, language'; 46 $Values = $DbRow[$Group['MangosTableIndex']].', 0'; 47 foreach($Group['Items'] as $GroupItem) 48 { 49 $Columns .= ', `'.$GroupItem['Column'].'`'; 50 $Values .= ', "'.addslashes($DbRow[$GroupItem['MangosColumn']]).'"'; 51 } 52 //$Columns = substr($Columns, 2); 53 //$Values = substr($Values, 2); 54 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 55 echo('# '); 56 //echo('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'."<br>"); 57 $NewCount++; 58 } 59 $Count++; 60 } 61 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 62 } 63 } 64 echo('Dokončeno.</div>'); 65 } 66 67 function ImportDBC() 68 { 69 global $Database, $TranslationTree, $PatchVersion; 70 71 echo('Načítání textů z DBC souborů...'); 72 foreach($TranslationTree as $Group) 73 { 74 if(($Group['DBCFileName'] != '') and ($Group['TablePrefix'] != '')) 75 { 76 echo('<br />'.$Group['Name'].'<br />'); 77 $DBCFile = new DBCFile(); 78 $DBCFile->OpenFile('../source/'.$PatchVersion.'/dbc/'.$Group['DBCFileName'].'.dbc', $Group['DBCColumns']); 79 $ItemCount = $DBCFile->GetRecordCount(); 80 $NewCount = 0; 81 $Count = 0; 82 for($i = 0; $i < $ItemCount; $i++) 83 { 84 $ItemId = $DBCFile->GetUint($i, 0); 85 $DbResult2 = $Database->SQLCommand('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$ItemId.' AND Language=0'); 86 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 87 { 88 $DbRow2 = mysql_fetch_assoc($DbResult2); 89 //echo($DbRow2['ID']); 90 $ColumnsValues = ''; 91 foreach($Group['Items'] as $GroupItem) 92 { 93 $ColumnsValues .= ', `'.$GroupItem['Column'].'`="'.addslashes($DBCFile->GetString($i, $GroupItem['DBCColumnIndex'])).'"'; 94 } 95 $ColumnsValues = substr($ColumnsValues, 2); 96 echo('. '); //'UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']."<br>"); 97 //print_r($DbRow2); 98 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']); 99 } else 100 { 101 $Columns = 'entry, language'; 102 $Values = $ItemId.', 0'; 103 foreach($Group['Items'] as $GroupItem) 104 { 105 $Columns .= ', `'.$GroupItem['Column'].'`'; 106 $Values .= ', "'.addslashes($DBCFile->GetString($i, $GroupItem['DBCColumnIndex'])).'"'; 107 } 108 //$Columns = substr($Columns, 2); 109 //$Values = substr($Values, 2); 110 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 111 echo('# '); 112 //echo('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'."<br>"); 113 $NewCount++; 114 } 115 $Count++; 116 } 117 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 118 } 119 } 120 echo('Dokončeno.</div>'); 121 } 122 123 function ImportLUA() 124 { 125 global $Database, $TranslationTree, $PatchVersion; 126 127 echo('Načítání textů z LUA souborů...'); 128 foreach($TranslationTree as $Group) 129 { 130 if(($Group['LuaFileName'] != '') and ($Group['TablePrefix'] != '')) 131 { 132 echo('<br />'.$Group['Name'].'<br />'); 133 $File = new FileStream(); 134 $File->OpenFile('../source/'.$PatchVersion.'/lua/'.$Group['LuaFileName'].'.lua'); 135 $NewCount = 0; 136 $Count = 0; 137 while(!$File->EOF()) 138 { 139 $Line = $File->ReadLine(); 140 if(strpos($Line, '=') !== false) 141 { 142 $LineParts = explode(';', $Line); 143 $LineParts2 = explode('=', $LineParts[0]); 144 $Value['ShortCut'] = addslashes(trim($LineParts2[0])); 145 $Value['Text'] = addslashes(substr(trim($LineParts2[1]), 1, -1)); 146 $Value['Comment'] = addslashes(trim($LineParts[1])); 147 148 $DbResult2 = $Database->SQLCommand('SELECT ID FROM '.$Group['TablePrefix'].' WHERE ShortCut="'.$Value['ShortCut'].'" AND (Language=0)'); 149 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 150 { 151 $ColumnsValues = ''; 152 foreach($Group['Items'] as $GroupItem) 153 { 154 $ColumnsValues .= ', `'.$GroupItem['Column'].'`="'.$Value[$GroupItem['Column']].'"'; 155 } 156 $ColumnsValues = substr($ColumnsValues, 2); 157 158 $DbRow2 = mysql_fetch_assoc($DbResult2); 159 echo('. '); //'UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']."<br>"); 160 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']); 161 } else 162 { 163 $Entry = 1; 164 $DbResult = $Database->SQLCommand('SELECT MAX(`entry`) FROM `'.$Group['TablePrefix'].'`'); 165 if(mysql_num_rows($DbResult) > 0) 166 { 167 $DbRow = mysql_fetch_row($DbResult); 168 $Entry += $DbRow[0]; 169 } 170 171 $Columns = 'entry, language, ShortCut'; 172 $Values = $Entry.', 0, "'.$Value['ShortCut'].'"'; 173 foreach($Group['Items'] as $GroupItem) 174 { 175 $Columns .= ', `'.$GroupItem['Column'].'`'; 176 $Values .= ', "'.$Value[$GroupItem['Column']].'"'; 177 } 178 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 179 echo('# '); 180 $NewCount++; 181 } 182 }; 183 $Count++; 184 } 185 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 186 } 187 } 188 echo('Dokončeno.</div>'); 189 } 190 6 191 ShowPage(); 7 192 … … 12 197 } 13 198 14 echo('Načítání textů z databáze MaNGOSu: '); 15 echo('<div style="font-size: xx-small;">'); 16 17 foreach($TranslationTree as $Group) 18 { 19 if(($Group['MangosTable'] != '') and ($Group['TablePrefix'] != '')) 20 { 21 echo('<br />'.$Group['Name'].'<br />'); 22 $Columns = '`'.$Group['MangosDatabase'].'`.`'.$Group['MangosTable'].'`.`'.$Group['MangosTableIndex'].'`'; 23 foreach($Group['Items'] as $GroupItem) 24 $Columns .= ', `'.$Group['MangosDatabase'].'`.`'.$Group['MangosTable'].'`.`'.$GroupItem['MangosColumn'].'` AS `'.$GroupItem['Column'].'`'; 25 $Query = 'SELECT '.$Columns.' FROM `'.$Group['MangosDatabase'].'`.`'.$Group['MangosTable'].'`'; 26 //echo($Query.'<br />'); 27 $Count = 0; 28 $NewCount = 0; 29 $DbResult = $Database->SQLCommand($Query); 30 while($DbRow = mysql_fetch_assoc($DbResult)) 31 { 32 //echo('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$DbRow[$Group['MangosTableIndex']].' AND Language=0'."<br>"); 33 $DbResult2 = $Database->SQLCommand('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$DbRow[$Group['MangosTableIndex']].' AND Language=0'); 34 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 35 { 36 $DbRow2 = mysql_fetch_assoc($DbResult2); 37 //echo($DbRow2['ID']); 38 $ColumnsValues = ''; 39 foreach($Group['Items'] as $GroupItem) 40 { 41 $ColumnsValues .= ', `'.$GroupItem['Column'].'`="'.addslashes($DbRow[$GroupItem['MangosColumn']]).'"'; 42 } 43 $ColumnsValues = substr($ColumnsValues, 2); 44 echo('. '); //'UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']."<br>"); 45 //print_r($DbRow2); 46 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']); 47 } else 48 { 49 $Columns = 'entry, language'; 50 $Values = $DbRow[$Group['MangosTableIndex']].', 0'; 51 foreach($Group['Items'] as $GroupItem) 52 { 53 $Columns .= ', `'.$GroupItem['Column'].'`'; 54 $Values .= ', "'.addslashes($DbRow[$GroupItem['MangosColumn']]).'"'; 55 } 56 //$Columns = substr($Columns, 2); 57 //$Values = substr($Values, 2); 58 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 59 echo('# '); 60 //echo('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'."<br>"); 61 $NewCount++; 62 } 63 $Count++; 64 } 65 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 66 } else 67 if(($Group['DBCFileName'] != '') and ($Group['TablePrefix'] != '')) 68 { 69 echo('<br />'.$Group['Name'].'<br />'); 70 $DBCFile = new DBCFile(); 71 $DBCFile->OpenFile('dbc/'.$Group['DBCFileName'].'.dbc', $Group['DBCColumns']); 72 $ItemCount = $DBCFile->RecordCount(); 73 $NewCount = 0; 74 $Count = 0; 75 for($i = 0; $i < $ItemCount; $i++) 76 { 77 $ItemId = $DBCFile->GetUint($i, 0); 78 $DbResult2 = $Database->SQLCommand('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$ItemId.' AND Language=0'); 79 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 80 { 81 $DbRow2 = mysql_fetch_assoc($DbResult2); 82 //echo($DbRow2['ID']); 83 $ColumnsValues = ''; 84 foreach($Group['Items'] as $GroupItem) 85 { 86 $ColumnsValues .= ', `'.$GroupItem['Column'].'`="'.addslashes($DBCFile->GetString($i, $GroupItem['DBCColumnIndex'])).'"'; 87 } 88 $ColumnsValues = substr($ColumnsValues, 2); 89 echo('. '); //'UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']."<br>"); 90 //print_r($DbRow2); 91 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']); 92 } else 93 { 94 $Columns = 'entry, language'; 95 $Values = $ItemId.', 0'; 96 foreach($Group['Items'] as $GroupItem) 97 { 98 $Columns .= ', `'.$GroupItem['Column'].'`'; 99 $Values .= ', "'.addslashes($DBCFile->GetString($i, $GroupItem['DBCColumnIndex'])).'"'; 100 } 101 //$Columns = substr($Columns, 2); 102 //$Values = substr($Values, 2); 103 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 104 echo('# '); 105 //echo('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'."<br>"); 106 $NewCount++; 107 } 108 $Count++; 109 } 110 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 111 } 112 } 113 echo('Dokončeno.</div>'); 114 115 WriteLog('Plnění databáze', 4); 199 if(!array_key_exists('source', $_GET)) 200 { 201 echo('<div>Načíst zdroj:</strong></div>'); 202 echo('<div><a href="?source=dbc">DBC soubory</a></div>'); 203 echo('<div><a href="?source=sql_mangos">SQL MaNGOS</a></div>'); 204 echo('<div><a href="?source=lua">LUA soubory</a></div>'); 205 } else 206 { 207 echo('<div style="font-size: xx-small;">'); 208 switch($_GET['source']) 209 { 210 case 'sql_mangos': 211 ImportSQLMangos(); 212 break; 213 case 'dbc': 214 ImportDBC(); 215 break; 216 case 'lua': 217 ImportLUA(); 218 break; 219 } 220 WriteLog('Plnění databáze', 4); 221 } 116 222 117 223 ShowFooter();
Note:
See TracChangeset
for help on using the changeset viewer.