Changeset 880 for trunk/Modules/Import/Import.php
- Timestamp:
- Apr 7, 2020, 10:15:48 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Import/Import.php
r859 r880 49 49 $Columns = ''; 50 50 //$Values = ''; 51 foreach ($this->Group['Items'] as $GroupItem)51 foreach ($this->Group['Items'] as $GroupItem) 52 52 { 53 53 $Columns .= ', `'.$GroupItem['Column'].'` '; … … 61 61 $DbResultAfter = $this->System->Database->query('SELECT `VersionEnd`,`VersionStart`, `ID`, `Entry`, '.$Columns.' FROM `'.$this->Group['TablePrefix'].'` WHERE '.$Where.' AND `VersionStart` >= '.$this->Version['BuildNumber'].' ORDER BY `VersionStart` LIMIT 1'); 62 62 63 if (($DbResultMiddle->num_rows > 0) or ($DbResultBefore->num_rows > 0) or ($DbResultAfter->num_rows > 0))63 if (($DbResultMiddle->num_rows > 0) or ($DbResultBefore->num_rows > 0) or ($DbResultAfter->num_rows > 0)) 64 64 { 65 65 // Update existed text … … 68 68 $DbRowBefore = $DbResultBefore->fetch_assoc(); 69 69 70 if ($this->HaveSameText($this->Group, $DbRowBefore, $Value) and ($DbResultBefore->num_rows > 0) )70 if ($this->HaveSameText($this->Group, $DbRowBefore, $Value) and ($DbResultBefore->num_rows > 0) ) 71 71 { 72 72 $insert = false; … … 78 78 79 79 } else 80 if ($this->HaveSameText($this->Group, $DbRowAfter, $Value) and ($DbResultAfter->num_rows > 0))80 if ($this->HaveSameText($this->Group, $DbRowAfter, $Value) and ($DbResultAfter->num_rows > 0)) 81 81 { 82 82 $insert = false; … … 104 104 105 105 //if [DEPRECATED] do not import 106 foreach ($this->Group['Items'] as $GroupItem) {106 foreach ($this->Group['Items'] as $GroupItem) { 107 107 if (false !== strpos($Value[$GroupItem['Column']],'[DEPRECATED')) { 108 108 echo('d '.$DbRowBefore['Entry'].' '); … … 113 113 if ($insert) { 114 114 $insert = false; 115 foreach ($this->Group['Items'] as $GroupItem)115 foreach ($this->Group['Items'] as $GroupItem) 116 116 { 117 117 if ($Value[$GroupItem['Column']] <> '') $insert = true; … … 128 128 $Columns = '`Entry`, `Language`, `VersionStart`, `VersionEnd`'; 129 129 $Values = $Value['Entry'].', 0, '.$this->Version['BuildNumber'].', '.$this->Version['BuildNumber']; 130 foreach ($this->Group['Items'] as $GroupItem)130 foreach ($this->Group['Items'] as $GroupItem) 131 131 { 132 132 $Columns .= ', `'.$GroupItem['Column'].'`'; … … 150 150 { 151 151 // Insert new text 152 if (is_numeric($Value[$this->Group['PrimaryKeyItem']])) $Value['Entry'] = $Value[$this->Group['PrimaryKeyItem']];152 if (is_numeric($Value[$this->Group['PrimaryKeyItem']])) $Value['Entry'] = $Value[$this->Group['PrimaryKeyItem']]; 153 153 else 154 154 { … … 156 156 $Value['Entry'] = 1; 157 157 $DbResult = $this->System->Database->query('SELECT MAX(`Entry`) FROM `'.$this->Group['TablePrefix'].'`'); 158 if ($DbResult->num_rows > 0)158 if ($DbResult->num_rows > 0) 159 159 { 160 160 $DbRow = $DbResult->fetch_row(); … … 165 165 $Values = $Value['Entry'].', 0, '.$this->Version['BuildNumber'].', '.$this->Version['BuildNumber']; 166 166 $insert = false; 167 foreach ($this->Group['Items'] as $GroupItem)167 foreach ($this->Group['Items'] as $GroupItem) 168 168 { 169 169 $Columns .= ', `'.$GroupItem['Column'].'`'; … … 188 188 $Output = 'Načítání textů z LUA souboru...'; 189 189 190 if (($this->Group['LuaFileName'] != '') and ($this->Group['TablePrefix'] != ''))190 if (($this->Group['LuaFileName'] != '') and ($this->Group['TablePrefix'] != '')) 191 191 { 192 192 193 193 $Output .= '<br />'.$this->Group['Name'].'<br />'; 194 // if ($this->Group['LastVersion'] < $this->Version['BuildNumber'] + 1)194 // if ($this->Group['LastVersion'] < $this->Version['BuildNumber'] + 1) 195 195 { 196 196 $File = new FileStream(); … … 199 199 $this->NewItemCount = 0; 200 200 $Count = 0; 201 while (!$File->EOF())201 while (!$File->EOF()) 202 202 { 203 203 $Line = $File->ReadLine(); 204 if (strpos($Line, '=') !== false)204 if (strpos($Line, '=') !== false) 205 205 { 206 206 $LineParts = explode('=', $Line, 2); 207 207 $Value['ShortCut'] = trim($LineParts[0]); 208 208 $Line = trim($LineParts[1]); 209 if ($Line[0] == '"')209 if ($Line[0] == '"') 210 210 { 211 211 // Quoted string value … … 234 234 } else $Output .= ShowMessage('Není definováno jméno zdrojového souboru', MESSAGE_CRITICAL); 235 235 $Output .= ShowMessage('Dokončeno.'); 236 return ($Output);236 return $Output; 237 237 } 238 238 … … 243 243 $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree(); 244 244 $Output = '<br /><br />Začínám se synchronizací VersionEnd u přeložených textů<br />'; 245 foreach ($TranslationTree as $Group)245 foreach ($TranslationTree as $Group) 246 246 { 247 247 $Output .= '<br />'.$Group['Name'].' '; 248 248 $do = true; 249 while ($do)249 while ($do) 250 250 { 251 251 $DbResult = $this->System->Database->query('SELECT `gs_tran`.`ID`, '. … … 258 258 '`gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd` OR `gs_tran`.`VersionStart` <> `gs_orig`.`VersionStart`'); 259 259 $do = ($DbResult->num_rows > 0); 260 while ($DbRow = $DbResult->fetch_assoc())260 while ($DbRow = $DbResult->fetch_assoc()) 261 261 { 262 262 echo('`'); … … 267 267 $Output .= '<strong>Dokončeno.</strong>'; 268 268 } 269 return ($Output);269 return $Output; 270 270 } 271 271 … … 273 273 { 274 274 $result = true; 275 foreach ($Group['Items'] as $GroupItem)275 foreach ($Group['Items'] as $GroupItem) 276 276 { 277 277 $old = $DbRow2[$GroupItem['Column']]; … … 324 324 } 325 325 326 if (($old == 'null') or ($old == 'NULL')) $old = '';327 if (($new == 'null') or ($new == 'NULL')) $new = '';328 329 if (($new <> '') and ($old <> $new) and ($GroupItem['Column'] <> 'Comment'))326 if (($old == 'null') or ($old == 'NULL')) $old = ''; 327 if (($new == 'null') or ($new == 'NULL')) $new = ''; 328 329 if (($new <> '') and ($old <> $new) and ($GroupItem['Column'] <> 'Comment')) 330 330 { 331 331 // echo $old.'X'.$new; … … 339 339 } 340 340 341 return ($result);341 return $result; 342 342 } 343 343 … … 348 348 $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree(); 349 349 $Output = 'Načítání textů z DBC souboru...'; 350 if (($this->Group['DBCFileName'] != '') and ($this->Group['TablePrefix'] != ''))350 if (($this->Group['DBCFileName'] != '') and ($this->Group['TablePrefix'] != '')) 351 351 { 352 352 $Output .= '<br />'.$this->Group['Name'].'<br />'; … … 357 357 $ColumnIndexes = array(); 358 358 $ColumnFormat = array(); 359 while ($DbRow = $DbResult->fetch_assoc())359 while ($DbRow = $DbResult->fetch_assoc()) 360 360 { 361 361 $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING; … … 369 369 $Count = 0; 370 370 371 for ($I = 0; $I < $ItemCount; $I++)372 { 373 foreach ($this->Group['Items'] as $GroupItem)374 if (array_key_exists($GroupItem['Id'], $ColumnIndexes))371 for ($I = 0; $I < $ItemCount; $I++) 372 { 373 foreach ($this->Group['Items'] as $GroupItem) 374 if (array_key_exists($GroupItem['Id'], $ColumnIndexes)) 375 375 { 376 376 $Value[$GroupItem['Column']] = addslashes($DBCFile->GetString($I, $ColumnIndexes[$GroupItem['Id']])); … … 380 380 $Columns = explode(',', $this->Group['DBCIndex']); 381 381 $ColumnValue = ''; 382 foreach ($Columns as $Column)382 foreach ($Columns as $Column) 383 383 $ColumnValue .= '_'.$DBCFile->GetUint($I, $Column); 384 384 $ColumnValue = substr($ColumnValue, 1); … … 391 391 } 392 392 $Output .= '<strong>Dokončeno.</strong>'; 393 return ($Output);393 return $Output; 394 394 } 395 395 … … 400 400 $this->Group = $TranslationTree[$GroupId]; 401 401 402 if ($this->Group['SourceType'] == 'dbc') $Output = $this->ImportDBC();403 else if ($this->Group['SourceType'] == 'sql') $Output = $this->ImportSQL();404 else if ($this->Group['SourceType'] == 'lua') $Output = $this->ImportLUA();402 if ($this->Group['SourceType'] == 'dbc') $Output = $this->ImportDBC(); 403 else if ($this->Group['SourceType'] == 'sql') $Output = $this->ImportSQL(); 404 else if ($this->Group['SourceType'] == 'lua') $Output = $this->ImportLUA(); 405 405 else $Output = ShowMessage('Neznámý typ zdroje pro import', MESSAGE_CRITICAL); 406 406 $Output .= $this->UpdateTranslated(); 407 return ($Output);407 return $Output; 408 408 } 409 409 … … 420 420 $folow_structure = false; 421 421 $i = 0; 422 while ((!$File->EOF()))422 while ((!$File->EOF())) 423 423 { 424 424 $Line = $File->ReadLine(); 425 425 // Struktura 426 if (strpos($Line, 'CREATE TABLE `'.$this->Group['MangosTable'].'`') !== false)426 if (strpos($Line, 'CREATE TABLE `'.$this->Group['MangosTable'].'`') !== false) 427 427 { 428 428 $Line = ''; … … 430 430 $i = 0; 431 431 } 432 if ((strpos($Line, ';') !== false) and ($folow_structure == true))432 if ((strpos($Line, ';') !== false) and ($folow_structure == true)) 433 433 { 434 434 $folow_structure = false; … … 437 437 // echo ('<br /><br />'); 438 438 } 439 if (($folow_structure == true) and ($Line != ''))439 if (($folow_structure == true) and ($Line != '')) 440 440 { 441 441 $str = substr($Line, 0, strpos($Line, '`')); 442 442 $Line = substr($Line, strpos($Line, '`') + 1); 443 443 $Line = substr($Line, 0, strpos($Line, '`')); 444 if (strlen($str) < 3) $structure[$i] = $Line;444 if (strlen($str) < 3) $structure[$i] = $Line; 445 445 $i++; 446 446 } 447 447 448 448 //data 449 if ((strpos($Line, 'INSERT INTO `'.$this->Group['MangosTable'].'`') !== false) and (isset($structure)))449 if ((strpos($Line, 'INSERT INTO `'.$this->Group['MangosTable'].'`') !== false) and (isset($structure))) 450 450 { 451 451 while ((strpos($Line, ');') === false) or ($File->EOF())) … … 461 461 $value_buff = ''; 462 462 $Value = ''; 463 foreach ($LineParts as $LinePart)463 foreach ($LineParts as $LinePart) 464 464 { 465 465 466 466 unset($Value, $value_buff); 467 foreach ($structure as $i => $column)467 foreach ($structure as $i => $column) 468 468 { 469 469 if (substr($LinePart, 0, 1) != "'") … … 475 475 $LinePart = substr($LinePart, 1); 476 476 $value_buff = substr($LinePart, 0, strpos($LinePart, "'")); 477 while (substr($value_buff, strlen($value_buff) - 1, 1) == "\\")477 while (substr($value_buff, strlen($value_buff) - 1, 1) == "\\") 478 478 { 479 479 $str = substr($LinePart, strlen($value_buff)); … … 484 484 $LinePart = substr($LinePart, strlen($value_buff) + 2); 485 485 } 486 if (($value_buff != 'null') and ($value_buff != 'NULL'))486 if (($value_buff != 'null') and ($value_buff != 'NULL')) 487 487 { 488 488 $str = ''; 489 while (substr($value_buff, strlen($value_buff) - 1,1) == " ")489 while (substr($value_buff, strlen($value_buff) - 1,1) == " ") 490 490 { 491 491 $value_buff = substr($value_buff, 0, strlen($value_buff) - 1); … … 493 493 } 494 494 $str2 = ''; 495 while (substr($value_buff, 0, 1) == ' ')495 while (substr($value_buff, 0, 1) == ' ') 496 496 { 497 497 $value_buff = substr($value_buff, 1, strlen($value_buff) - 1); … … 505 505 // echo ($column.'-"'.$Value[$column].'"<br>'); 506 506 } 507 foreach ($this->Group['Items'] as $GroupItem)507 foreach ($this->Group['Items'] as $GroupItem) 508 508 { 509 if ($GroupItem['MangosColumn'] != '')509 if ($GroupItem['MangosColumn'] != '') 510 510 if (isset($Value[$GroupItem['MangosColumn']])) 511 511 $Value[$GroupItem['Column']] = $Value[$GroupItem['MangosColumn']]; … … 519 519 $Columns = explode(',', $this->Group['MangosTableIndex']); 520 520 $ColumnValue = ''; 521 foreach ($Columns as $Column)521 foreach ($Columns as $Column) 522 522 $ColumnValue .= '_'.$Value[$Column]; 523 523 $ColumnValue = substr($ColumnValue, 1); … … 530 530 $Output = '<br />Celkem: '.$Count.' Nových: '.$this->NewItemCount.'<br />'; 531 531 $this->UpdateLastVersion(); 532 return ($Output);532 return $Output; 533 533 } 534 534
Note:
See TracChangeset
for help on using the changeset viewer.