Changeset 215 for trunk/import/import_lua.php
- Timestamp:
- Jun 23, 2009, 10:03:53 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/import/import_lua.php
r214 r215 1 1 <?php 2 function HaveSameText($Group,$DbRow2,$Value) 2 3 function HaveSameText($Group, $DbRow2, $Value) 3 4 { 4 $result = true; 5 foreach($Group['Items'] as $GroupItem) { 6 $old = $DbRow2[$GroupItem['Column']]; 7 $old = str_replace(chr(10),'',$old); 8 $old = str_replace(chr(13),'',$old); 9 $old = str_replace('\n','',$old); 10 $old = str_replace('\r','',$old); 11 $old = str_replace('\"','"',$old); 12 $old = str_replace('\\\\','\\',$old); 13 $old = str_replace('\32','32',$old); 14 $old = str_replace('\124','124',$old); 15 16 $new = $Value[$GroupItem['Column']]; 17 $new = str_replace(chr(10),'',$new); 18 $new = str_replace(chr(13),'',$new); 19 $new = str_replace('\n','',$new); 20 $new = str_replace('\r','',$new); 21 $new = str_replace('\"','"',$new); 22 $new = str_replace('\\\\','\\',$new); 23 $new = str_replace('\32','32',$new); 24 $new = str_replace('\124','124',$new); 5 $result = true; 6 foreach($Group['Items'] as $GroupItem) 7 { 8 $old = $DbRow2[$GroupItem['Column']]; 9 $old = str_replace(chr(10), '', $old); 10 $old = str_replace(chr(13), '', $old); 11 $old = str_replace('\n', '', $old); 12 $old = str_replace('\r', '', $old); 13 $old = str_replace('\"', '"', $old); 14 $old = str_replace('\\\\', '\\', $old); 15 $old = str_replace('\32', '32', $old); 16 $old = str_replace('\124', '124', $old); 17 18 $new = $Value[$GroupItem['Column']]; 19 $new = str_replace(chr(10), '', $new); 20 $new = str_replace(chr(13), '', $new); 21 $new = str_replace('\n', '', $new); 22 $new = str_replace('\r', '', $new); 23 $new = str_replace('\"', '"', $new); 24 $new = str_replace('\\\\', '\\', $new); 25 $new = str_replace('\32', '32', $new); 26 $new = str_replace('\124', '124', $new); 25 27 26 if (($old <> $new) and ($GroupItem['Column'] <> 'Comment')) { 27 // echo $old.'-'.$new; 28 $result = false; 29 } 30 } 31 return($result); 28 if(($old <> $new) and ($GroupItem['Column'] <> 'Comment')) 29 { 30 // echo $old.'-'.$new; 31 $result = false; 32 } 33 } 34 return($result); 32 35 } 33 36 … … 41 44 if(($Group['LuaFileName'] != '') and ($Group['TablePrefix'] != '')) 42 45 { 43 echo('<br />'.$Group['Name'].'<br />'); 44 45 46 47 48 49 50 51 52 53 46 echo('<br />'.$Group['Name'].'<br />'); 47 $File = new FileStream(); 48 $File->OpenFile('../source/'.$import_version.'/lua/'.$Group['LuaFileName'].'.lua'); 49 $NewCount = 0; 50 $Count = 0; 51 while(!$File->EOF()) 52 { 53 $Line = $File->ReadLine(); 54 if(strpos($Line, '=') !== false) 55 { 56 $LineParts = explode(';', $Line); 54 57 $LineParts2 = explode('=', $LineParts[0]); 55 56 57 58 $Value['ShortCut'] = trim($LineParts2[0]); 59 $Value['Text'] = substr(trim($LineParts2[1]), 1, -1); 60 $Value['Comment'] = addslashes(substr(trim($LineParts[1]), 3)); 58 61 59 60 $Columns = ''; 61 foreach($Group['Items'] as $GroupItem) 62 { 63 $Columns .= ', '.$GroupItem['Column'].' '; 64 } 65 $Columns = substr($Columns, 1); 62 $Columns = ''; 63 foreach($Group['Items'] as $GroupItem) 64 { 65 $Columns .= ', '.$GroupItem['Column'].' '; 66 } 67 $Columns = substr($Columns, 1); 66 68 67 69 $DbResult2 = $Database->SQLCommand('SELECT ID, entry, '.$Columns.' FROM '.$Group['TablePrefix'].' WHERE ShortCut="'.$Value['ShortCut'].'" AND (Language=0) ORDER BY VersionStart DESC LIMIT 1'); 68 70 if(isset($DbResult2) and (mysql_num_rows($DbResult2) > 0)) 69 { 70 $DbRow2 = mysql_fetch_assoc($DbResult2); 71 if (HaveSameText($Group,$DbRow2,$Value)) { 71 { 72 // Update existed text 73 $DbRow2 = mysql_fetch_assoc($DbResult2); 74 if(HaveSameText($Group, $DbRow2, $Value)) 75 { 72 76 $Database->SQLCommand('UPDATE `'.$Group['TablePrefix'].'` SET VersionEnd = "'.GetBuildNumber($import_version).'" WHERE ID='.$DbRow2['ID']); 73 } else { 74 75 $Columns = 'entry, language, VersionStart, VersionEnd'; 76 $Values = $DbRow2['entry'].', 0, '.GetBuildNumber($import_version).', '.GetBuildNumber($import_version); 77 foreach($Group['Items'] as $GroupItem) { 78 $Columns .= ', `'.$GroupItem['Column'].'`'; 79 $Values .= ', "'.$Value[$GroupItem['Column']].'"'; 80 } 81 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 82 echo('# '); 83 $NewCount++; 84 85 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); 86 } 87 88 echo('. '); 89 } else 90 { 91 $Entry = 1; 92 $DbResult = $Database->SQLCommand('SELECT MAX(`entry`) FROM `'.$Group['TablePrefix'].'`'); 93 if(mysql_num_rows($DbResult) > 0) 94 { 95 $DbRow = mysql_fetch_row($DbResult); 96 $Entry += $DbRow[0]; 77 } else 78 { 79 $Columns = 'entry, language, VersionStart, VersionEnd'; 80 $Values = $DbRow2['entry'].', 0, '.GetBuildNumber($import_version).', '.GetBuildNumber($import_version); 81 foreach($Group['Items'] as $GroupItem) 82 { 83 $Columns .= ', `'.$GroupItem['Column'].'`'; 84 $Values .= ', "'.$Value[$GroupItem['Column']].'"'; 85 } 86 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 87 echo('# '); 88 $NewCount++; 89 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); 90 } 91 echo('. '); 92 } else 93 { 94 // Insert new text 95 $Entry = 1; 96 $DbResult = $Database->SQLCommand('SELECT MAX(`entry`) FROM `'.$Group['TablePrefix'].'`'); 97 if(mysql_num_rows($DbResult) > 0) 98 { 99 $DbRow = mysql_fetch_row($DbResult); 100 $Entry += $DbRow[0]; 101 } 102 $Columns = 'entry, language, VersionStart, VersionEnd'; 103 $Values = $Entry.', 0, '.GetBuildNumber($import_version).', '.GetBuildNumber($import_version); 104 foreach($Group['Items'] as $GroupItem) 105 { 106 $Columns .= ', `'.$GroupItem['Column'].'`'; 107 $Values .= ', "'.$Value[$GroupItem['Column']].'"'; 97 108 } 98 99 $Columns = 'entry, language, VersionStart, VersionEnd'; 100 $Values = $Entry.', 0, '.GetBuildNumber($import_version).', '.GetBuildNumber($import_version); 101 foreach($Group['Items'] as $GroupItem) 102 { 103 $Columns .= ', `'.$GroupItem['Column'].'`'; 104 $Values .= ', "'.$Value[$GroupItem['Column']].'"'; 105 } 106 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 107 echo('# '); 108 $NewCount++; 109 WriteLog('Text <a href="form.php?group='.$Group['Id'].'&ID='.mysql_insert_id().'">'.$DbRow2['ID'].'</a> ('.$Entry.') ze skupiny '.$Group['Name'].' byl v nové verzi '.$import_version.' přidán.', 11); 110 } 111 }; 109 $Database->SQLCommand('INSERT `'.$Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')'); 110 echo('# '); 111 $NewCount++; 112 WriteLog('Text <a href="form.php?group='.$Group['Id'].'&ID='.mysql_insert_id().'">'.$DbRow2['ID'].'</a> ('.$Entry.') ze skupiny '.$Group['Name'].' byl v nové verzi '.$import_version.' přidán.', 11); 113 } 114 }; 112 115 $Count++; 113 114 115 } 116 } 117 echo('<br />Celkem: '.$Count.' Nových: '.$NewCount.'<br />'); 118 } 116 119 } 117 120 echo('<strong>Dokončeno.</strong>');
Note:
See TracChangeset
for help on using the changeset viewer.