Changeset 224 for trunk/import
- Timestamp:
- Jul 1, 2009, 10:28:11 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/import/import_sql_mangos.php
r214 r224 1 1 <?php 2 2 3 function ImportSQLMangos( )3 function ImportSQLMangos($import_version,$GroupId) 4 4 { 5 global $Database, $TranslationTree, $Config; 5 global $Database, $TranslationTree, $PatchVersion, $Config; 6 $BuildNumber = GetBuildNumber($import_version); 7 8 $Group = $TranslationTree[$GroupId]; 6 9 7 echo('Načítání textů z databáze MaNGOSu...'); 8 foreach($TranslationTree as $Group) 9 { 10 if(($Group['MangosTable'] != '') and ($Group['TablePrefix'] != '')) 11 { 12 echo('<br />'.$Group['Name'].'<br />'); 13 $DbName = $Config['Database']['MangosPrefix'].$Group['MangosDatabase']; 14 $Columns = '`'.$DbName.'`.`'.$Group['MangosTable'].'`.`'.$Group['MangosTableIndex'].'`'; 15 $Where = ''; 16 foreach($Group['Items'] as $GroupItem) 17 { 18 $Columns .= ', `'.$DbName.'`.`'.$Group['MangosTable'].'`.`'.$GroupItem['MangosColumn'].'` AS `'.$GroupItem['Column'].'`'; 19 $Where .= ' OR `'.$DbName.'`.`'.$Group['MangosTable'].'`.`'.$GroupItem['MangosColumn'].'` != "" '; 20 } 21 $Where = substr($Where, 4); 22 $Query = 'SELECT '.$Columns.' FROM `'.$DbName.'`.`'.$Group['MangosTable'].'` WHERE '.$Where; 23 //echo($Query.'<br />'); 24 $Count = 0; 25 $NewCount = 0; 26 $DbResult = $Database->SQLCommand($Query); 27 while($DbRow = mysql_fetch_assoc($DbResult)) 28 { 29 //echo('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$DbRow[$Group['MangosTableIndex']].' AND Language=0'."<br>"); 30 $DbResult2 = $Database->SQLCommand('SELECT ID FROM '.$Group['TablePrefix'].' WHERE entry='.$DbRow[$Group['MangosTableIndex']].' AND Language=0'); 31 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 32 { 33 $DbRow2 = mysql_fetch_assoc($DbResult2); 34 //echo($DbRow2['ID']); 35 $ColumnsValues = ''; 36 foreach($Group['Items'] as $GroupItem) 10 $files = scandir('../source/'.$import_version.'/sql/', 1); 11 unset($files[count($files) - 1]); 12 unset($files[count($files) - 1]); 13 14 $File = new FileStream(); 15 $File->OpenFile('../source/'.$import_version.'/sql/'.$files[0]); 16 $NewCount = 0; 17 $Count = 0; 18 $folow_structure = False; 19 $i = 0; 20 while((!$File->EOF())) 21 { 22 $Line = $File->ReadLine(); 23 //Struktura 24 if(strpos($Line, 'CREATE TABLE `'.$Group['MangosTable'].'`') !== false) 25 { 26 $Line = ''; 27 $folow_structure = True; 28 $i = 0; 29 } 30 if((strpos($Line, ';') !== false) and ($folow_structure == true)) 31 { 32 $folow_structure = False; 33 echo ('Struktura: <br />'); 34 print_r($structure); 35 echo ('<br /><br />'); 36 } 37 if (($folow_structure == True) and ($Line != '')) 38 { 39 $str = substr($Line,0, strpos($Line,'`')); 40 $Line = substr($Line, strpos($Line,'`')+1); 41 $Line = substr($Line,0, strpos($Line,'`')); 42 if (strlen($str) < 3) 43 $structure[$i] = $Line; 44 $i++; 45 } 46 47 //data 48 if ((strpos($Line, 'INSERT INTO `'.$Group['MangosTable'].'`') !== false) and (isset($structure))) 49 { 50 $Line = substr($Line, strpos($Line,'(')+1); 51 $Line = substr($Line,0, strpos($Line,');')); 52 $LineParts = explode('),(', $Line); 53 unset($Line); 54 55 foreach($LineParts as $LinePart) 37 56 { 38 $ColumnsValues .= ', `'.$GroupItem['Column'].'`="'.addslashes($DbRow[$GroupItem['Column']]).'"'; 57 unset($Value,$value_buff); 58 foreach($structure as $i => $column) 59 { 60 if (substr($LinePart,0, 1) != "'") 61 { 62 $value_buff = substr($LinePart,0, strpos($LinePart,',')); 63 $LinePart = substr($LinePart,strlen($value_buff)+1); 64 } else { 65 $LinePart = substr($LinePart,1); 66 $value_buff = substr($LinePart,0, strpos($LinePart,"',")); 67 if ((strpos($LinePart,"',") !== true) and (strpos($LinePart,"'") !== false) and ($value_buff == '')) 68 $value_buff = substr($LinePart,0, strlen($LinePart)-1); 69 while(substr($value_buff,strlen($value_buff)-1,1) == "\\") 70 { 71 $str = substr($LinePart,strlen($value_buff)); 72 $str2 = substr($str,0, strpos($str,"',",2)); 73 $value_buff = $value_buff.$str2; 74 $str = substr($str,strlen($str2)); 75 76 } 77 $LinePart = substr($LinePart,strlen($value_buff)+2); 78 } 79 $Value[$column] = trim($value_buff); 80 //echo ($column.'-'.$Value[$column].'<br>'); 81 } 82 83 //************************************************ 84 85 $Columns = ''; 86 foreach($Group['Items'] as $GroupItem) 87 { 88 $Columns .= ', '.$GroupItem['Column'].' '; 89 } 90 $Columns = substr($Columns, 1); 91 92 if ($Group['Id'] == 8) 93 $DbResult2 = $Database->SQLCommand('SELECT VersionEnd, ID, entry, '.$Columns.' FROM '.$Group['TablePrefix'].' WHERE Name="'.$Value['name'].'" AND (Language=0) ORDER BY VersionStart DESC LIMIT 1'); 94 else 95 $DbResult2 = $Database->SQLCommand('SELECT VersionEnd, ID, entry, '.$Columns.' FROM '.$Group['TablePrefix'].' WHERE entry='.$Value[$Group['MangosTableIndex']].' AND (Language=0) ORDER BY VersionStart DESC LIMIT 1'); 96 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 97 { 98 // Update existed text 99 $DbRow2 = mysql_fetch_assoc($DbResult2); 100 if(HaveSameText($Group, $DbRow2, $Value)) 101 { 102 if ($DbRow2['VersionEnd'] <> $BuildNumber) { 103 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET VersionEnd = "'.$BuildNumber.'" WHERE ID='.$DbRow2['ID']); 104 echo(', '); 105 } else 106 echo('. '); 107 } else 108 { 109 $Columns = 'entry, language, VersionStart, VersionEnd'; 110 $Values = $DbRow2['entry'].', 0, '.$BuildNumber.', '.$BuildNumber; 111 foreach($Group['Items'] as $GroupItem) 112 { 113 $Columns .= ', `'.$GroupItem['Column'].'`'; 114 $Values .= ', "'.$Value[$GroupItem['MangosColumn']].'"'; 115 } 116 117 if ($DbRow2['VersionEnd'] <> $BuildNumber) { 118 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 119 echo('# '); 120 } else 121 echo('. '); 122 123 WriteLog('Text <a href="form.php?group='.$Group['Id'].'&ID='.$DbRow2['ID'].'">'.$DbRow2['ID'].'</a> ('.$DbRow2['entry'].') ze skupiny '.$Group['Name'].' byl v nové verzi '.$import_version.' změněn.', 11); 124 } 125 } else 126 { 127 // Insert new text 128 129 if ($Group['Id'] == 8) 130 { 131 $Entry = 1; 132 $DbResult = $Database->SQLCommand('SELECT MAX(`entry`) FROM `'.$Group['TablePrefix'].'`'); 133 if(mysql_num_rows($DbResult) > 0) 134 { 135 $DbRow = mysql_fetch_row($DbResult); 136 $Entry += $DbRow[0]; 137 } 138 } else { 139 $Entry = $Value[$Group['MangosTableIndex']]; 140 } 141 142 $Columns = 'entry, language, VersionStart, VersionEnd'; 143 $Values = $Entry.', 0, '.$BuildNumber.', '.$BuildNumber; 144 foreach($Group['Items'] as $GroupItem) 145 { 146 $Columns .= ', `'.$GroupItem['Column'].'`'; 147 $Values .= ', "'.$Value[$GroupItem['MangosColumn']].'"'; 148 } 149 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 150 echo('+ '); 151 $NewCount++; 152 WriteLog('Text <a href="form.php?group='.$Group['Id'].'&ID='.mysql_insert_id().'">'.mysql_insert_id().'</a> ('.$Entry.') ze skupiny '.$Group['Name'].' byl v nové verzi '.$import_version.' přidán.', 11); 153 } 154 155 //******************************************** 156 $Count++; 39 157 } 40 $ColumnsValues = substr($ColumnsValues, 2); 41 echo('. '); //'UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']."<br>"); 42 //print_r($DbRow2); 43 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET '.$ColumnsValues.' WHERE ID='.$DbRow2['ID']); 44 } else 45 { 46 $Columns = 'entry, language'; 47 $Values = $DbRow[$Group['MangosTableIndex']].', 0'; 48 foreach($Group['Items'] as $GroupItem) 49 { 50 $Columns .= ', `'.$GroupItem['Column'].'`'; 51 $Values .= ', "'.addslashes($DbRow[$GroupItem['Column']]).'"'; 52 } 53 //$Columns = substr($Columns, 2); 54 //$Values = substr($Values, 2); 55 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 56 echo('# '); 57 //echo('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'."<br>"); 58 $NewCount++; 59 } 60 $Count++; 61 } 62 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 63 } 64 } 65 echo('<strong>Dokončeno.</strong>'); 158 } 159 } 160 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 66 161 } 67 68 162 ?>
Note:
See TracChangeset
for help on using the changeset viewer.