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