Changeset 880 for trunk/Modules/Import


Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
Location:
trunk/Modules/Import
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Import/Import.php

    r859 r880  
    4949    $Columns = '';
    5050    //$Values = '';
    51     foreach($this->Group['Items'] as $GroupItem)
     51    foreach ($this->Group['Items'] as $GroupItem)
    5252    {
    5353      $Columns .= ', `'.$GroupItem['Column'].'` ';
     
    6161    $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');
    6262
    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))
    6464    {
    6565      // Update existed text
     
    6868      $DbRowBefore = $DbResultBefore->fetch_assoc();
    6969
    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) )
    7171      {
    7272          $insert = false;
     
    7878
    7979      } 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))
    8181      {
    8282          $insert = false;
     
    104104
    105105            //if [DEPRECATED] do not import
    106         foreach($this->Group['Items'] as $GroupItem) {
     106        foreach ($this->Group['Items'] as $GroupItem) {
    107107          if (false !== strpos($Value[$GroupItem['Column']],'[DEPRECATED')) {
    108108            echo('d '.$DbRowBefore['Entry'].' ');
     
    113113        if ($insert) {
    114114          $insert = false;
    115           foreach($this->Group['Items'] as $GroupItem)
     115          foreach ($this->Group['Items'] as $GroupItem)
    116116          {
    117117            if ($Value[$GroupItem['Column']] <> '') $insert = true;
     
    128128          $Columns = '`Entry`, `Language`, `VersionStart`, `VersionEnd`';
    129129          $Values = $Value['Entry'].', 0, '.$this->Version['BuildNumber'].', '.$this->Version['BuildNumber'];
    130           foreach($this->Group['Items'] as $GroupItem)
     130          foreach ($this->Group['Items'] as $GroupItem)
    131131          {
    132132            $Columns .= ', `'.$GroupItem['Column'].'`';
     
    150150    {
    151151      // 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']];
    153153      else
    154154      {
     
    156156        $Value['Entry'] = 1;
    157157        $DbResult = $this->System->Database->query('SELECT MAX(`Entry`) FROM `'.$this->Group['TablePrefix'].'`');
    158         if($DbResult->num_rows > 0)
     158        if ($DbResult->num_rows > 0)
    159159        {
    160160          $DbRow = $DbResult->fetch_row();
     
    165165      $Values = $Value['Entry'].', 0, '.$this->Version['BuildNumber'].', '.$this->Version['BuildNumber'];
    166166      $insert = false;
    167       foreach($this->Group['Items'] as $GroupItem)
     167      foreach ($this->Group['Items'] as $GroupItem)
    168168      {
    169169        $Columns .= ', `'.$GroupItem['Column'].'`';
     
    188188    $Output = 'Načítání textů z LUA souboru...';
    189189
    190     if(($this->Group['LuaFileName'] != '') and ($this->Group['TablePrefix'] != ''))
     190    if (($this->Group['LuaFileName'] != '') and ($this->Group['TablePrefix'] != ''))
    191191    {
    192192
    193193        $Output .= '<br />'.$this->Group['Name'].'<br />';
    194       //  if($this->Group['LastVersion'] < $this->Version['BuildNumber'] + 1)
     194      //  if ($this->Group['LastVersion'] < $this->Version['BuildNumber'] + 1)
    195195        {
    196196          $File = new FileStream();
     
    199199          $this->NewItemCount = 0;
    200200          $Count = 0;
    201           while(!$File->EOF())
     201          while (!$File->EOF())
    202202          {
    203203            $Line = $File->ReadLine();
    204             if(strpos($Line, '=') !== false)
     204            if (strpos($Line, '=') !== false)
    205205            {
    206206              $LineParts = explode('=', $Line, 2);
    207207              $Value['ShortCut'] = trim($LineParts[0]);
    208208              $Line = trim($LineParts[1]);
    209               if($Line[0] == '"')
     209              if ($Line[0] == '"')
    210210              {
    211211                // Quoted string value
     
    234234      } else $Output .= ShowMessage('Není definováno jméno zdrojového souboru', MESSAGE_CRITICAL);
    235235    $Output .= ShowMessage('Dokončeno.');
    236     return ($Output);
     236    return $Output;
    237237  }
    238238
     
    243243    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    244244    $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)
    246246    {
    247247      $Output .= '<br />'.$Group['Name'].' ';
    248248      $do = true;
    249       while($do)
     249      while ($do)
    250250      {
    251251      $DbResult = $this->System->Database->query('SELECT `gs_tran`.`ID`, '.
     
    258258        '`gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd` OR `gs_tran`.`VersionStart` <> `gs_orig`.`VersionStart`');
    259259        $do = ($DbResult->num_rows > 0);
    260         while($DbRow = $DbResult->fetch_assoc())
     260        while ($DbRow = $DbResult->fetch_assoc())
    261261        {
    262262          echo('`');
     
    267267      $Output .= '<strong>Dokončeno.</strong>';
    268268    }
    269     return($Output);
     269    return $Output;
    270270  }
    271271
     
    273273  {
    274274    $result = true;
    275     foreach($Group['Items'] as $GroupItem)
     275    foreach ($Group['Items'] as $GroupItem)
    276276    {
    277277      $old = $DbRow2[$GroupItem['Column']];
     
    324324        }
    325325
    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'))
    330330      {
    331331        //  echo $old.'X'.$new;
     
    339339    }
    340340
    341     return($result);
     341    return $result;
    342342  }
    343343
     
    348348    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    349349    $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'] != ''))
    351351    {
    352352      $Output .= '<br />'.$this->Group['Name'].'<br />';
     
    357357      $ColumnIndexes = array();
    358358      $ColumnFormat = array();
    359       while($DbRow = $DbResult->fetch_assoc())
     359      while ($DbRow = $DbResult->fetch_assoc())
    360360      {
    361361        $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING;
     
    369369      $Count = 0;
    370370
    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))
    375375        {
    376376          $Value[$GroupItem['Column']] = addslashes($DBCFile->GetString($I, $ColumnIndexes[$GroupItem['Id']]));
     
    380380        $Columns = explode(',', $this->Group['DBCIndex']);
    381381        $ColumnValue = '';
    382         foreach($Columns as $Column)
     382        foreach ($Columns as $Column)
    383383          $ColumnValue .= '_'.$DBCFile->GetUint($I, $Column);
    384384        $ColumnValue = substr($ColumnValue, 1);
     
    391391    }
    392392    $Output .= '<strong>Dokončeno.</strong>';
    393     return($Output);
     393    return $Output;
    394394  }
    395395
     
    400400    $this->Group = $TranslationTree[$GroupId];
    401401
    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();
    405405    else $Output = ShowMessage('Neznámý typ zdroje pro import', MESSAGE_CRITICAL);
    406406    $Output .= $this->UpdateTranslated();
    407     return($Output);
     407    return $Output;
    408408  }
    409409
     
    420420    $folow_structure = false;
    421421    $i = 0;
    422     while((!$File->EOF()))
     422    while ((!$File->EOF()))
    423423    {
    424424      $Line = $File->ReadLine();
    425425      // Struktura
    426       if(strpos($Line, 'CREATE TABLE `'.$this->Group['MangosTable'].'`') !== false)
     426      if (strpos($Line, 'CREATE TABLE `'.$this->Group['MangosTable'].'`') !== false)
    427427      {
    428428        $Line = '';
     
    430430        $i = 0;
    431431      }
    432       if((strpos($Line, ';') !== false) and ($folow_structure == true))
     432      if ((strpos($Line, ';') !== false) and ($folow_structure == true))
    433433      {
    434434        $folow_structure = false;
     
    437437        //  echo ('<br /><br />');
    438438      }
    439       if(($folow_structure == true) and ($Line != ''))
     439      if (($folow_structure == true) and ($Line != ''))
    440440      {
    441441        $str = substr($Line, 0, strpos($Line, '`'));
    442442        $Line = substr($Line, strpos($Line, '`') + 1);
    443443        $Line = substr($Line, 0, strpos($Line, '`'));
    444         if(strlen($str) < 3) $structure[$i] = $Line;
     444        if (strlen($str) < 3) $structure[$i] = $Line;
    445445        $i++;
    446446      }
    447447
    448448      //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)))
    450450      {
    451451        while ((strpos($Line, ');') === false) or ($File->EOF()))
     
    461461        $value_buff = '';
    462462        $Value = '';
    463         foreach($LineParts as $LinePart)
     463        foreach ($LineParts as $LinePart)
    464464        {
    465465
    466466          unset($Value, $value_buff);
    467           foreach($structure as $i => $column)
     467          foreach ($structure as $i => $column)
    468468          {
    469469            if (substr($LinePart, 0, 1) != "'")
     
    475475              $LinePart = substr($LinePart, 1);
    476476              $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) == "\\")
    478478              {
    479479                $str = substr($LinePart, strlen($value_buff));
     
    484484              $LinePart = substr($LinePart, strlen($value_buff) + 2);
    485485            }
    486             if(($value_buff != 'null') and ($value_buff != 'NULL'))
     486            if (($value_buff != 'null') and ($value_buff != 'NULL'))
    487487            {
    488488              $str = '';
    489               while(substr($value_buff, strlen($value_buff) - 1,1) == " ")
     489              while (substr($value_buff, strlen($value_buff) - 1,1) == " ")
    490490              {
    491491                $value_buff = substr($value_buff, 0, strlen($value_buff) - 1);
     
    493493              }
    494494              $str2 = '';
    495               while(substr($value_buff, 0, 1) == ' ')
     495              while (substr($value_buff, 0, 1) == ' ')
    496496              {
    497497                $value_buff = substr($value_buff, 1, strlen($value_buff) - 1);
     
    505505            //  echo ($column.'-"'.$Value[$column].'"<br>');
    506506          }
    507           foreach($this->Group['Items'] as $GroupItem)
     507          foreach ($this->Group['Items'] as $GroupItem)
    508508          {
    509             if($GroupItem['MangosColumn'] != '')
     509            if ($GroupItem['MangosColumn'] != '')
    510510              if (isset($Value[$GroupItem['MangosColumn']]))
    511511                $Value[$GroupItem['Column']] = $Value[$GroupItem['MangosColumn']];
     
    519519          $Columns = explode(',', $this->Group['MangosTableIndex']);
    520520          $ColumnValue = '';
    521           foreach($Columns as $Column)
     521          foreach ($Columns as $Column)
    522522            $ColumnValue .= '_'.$Value[$Column];
    523523          $ColumnValue = substr($ColumnValue, 1);
     
    530530    $Output = '<br />Celkem: '.$Count.'  Nových: '.$this->NewItemCount.'<br />';
    531531    $this->UpdateLastVersion();
    532     return($Output);
     532    return $Output;
    533533  }
    534534
  • trunk/Modules/Import/Manage.php

    r859 r880  
    1919    '<li>Po provedení importu je potřeba několikrát spustit skript na aktualizaci verze u překladu. Je potřeba ho provádět opakovaně dokud nezmizí tečky označující, že byly provedeny změny.</li>'.
    2020    '</ol>';
    21     return($Output);
     21    return $Output;
    2222  }
    2323
     
    2626    global $System;
    2727
    28     if(array_key_exists('id', $_GET))
     28    if (array_key_exists('id', $_GET))
    2929    {
    3030      $Output = '<div style="font-size: xx-small;">';
     
    3838      $Output .= '</div>';
    3939    } else $Output = ShowMessage('Nebylo zadáno id skupiny.', MESSAGE_CRITICAL);
    40     return($Output);
     40    return $Output;
    4141  }
    4242
     
    6868
    6969    $DbResult = $this->System->Database->query('SELECT * FROM `Group`'.$Order['SQL'].$PageList['SQLLimit']);
    70     while($Group = $DbResult->fetch_assoc())
     70    while ($Group = $DbResult->fetch_assoc())
    7171    {
    7272      $Output .= '<tr><td>'.T($Group['Name']).'</td>'.
    7373        '<td>'.$Group['SourceType'].'</td><td>';
    74       if($Group['MangosTable'] != '') $Output .= $Group['MangosTable'].'.sql ';
    75       if($Group['DBCFileName'] != '') $Output .= $Group['DBCFileName'].'.dbc ';
    76       if($Group['LuaFileName'] != '') $Output .= $Group['LuaFileName'].'.lua ';
     74      if ($Group['MangosTable'] != '') $Output .= $Group['MangosTable'].'.sql ';
     75      if ($Group['DBCFileName'] != '') $Output .= $Group['DBCFileName'].'.dbc ';
     76      if ($Group['LuaFileName'] != '') $Output .= $Group['LuaFileName'].'.lua ';
    7777      $Output .= '</td>'.
    7878        '<td><a title="Změny po posledním importu u vybrané překladové skupiny" href="../log/?group='.$Group['Id'].'&amp;type=11">'.HumanDate($Group['LastImport']).'</a></td>'.
     
    8282    }
    8383    $Output .= '</table>';
    84     return($Output);
     84    return $Output;
    8585  }
    8686
     
    9393    $Output .= $Import->UpdateTranslated();
    9494    $Output .= '</div>';
    95     return($Output);
     95    return $Output;
    9696  }
    9797
     
    100100    $this->Title = T('Import');
    101101    $Output = '';
    102     if($this->System->User->Licence(LICENCE_ADMIN))
     102    if ($this->System->User->Licence(LICENCE_ADMIN))
    103103    {
    104     if(array_key_exists('action', $_GET))
     104    if (array_key_exists('action', $_GET))
    105105    {
    106       if($_GET['action'] == 'instructions') $Output .= $this->ShowInstructions();
    107       else if($_GET['action'] == 'importgroup') $Output .= $this->ShowImportGroup();
    108       else if($_GET['action'] == 'update_translated') $Output .= $this->UpdateTranslated();
     106      if ($_GET['action'] == 'instructions') $Output .= $this->ShowInstructions();
     107      else if ($_GET['action'] == 'importgroup') $Output .= $this->ShowImportGroup();
     108      else if ($_GET['action'] == 'update_translated') $Output .= $this->UpdateTranslated();
    109109      else $Output .= $this->ShowMenu();
    110110    } else $Output .= $this->ShowMenu();
    111111    } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
    112     return($Output);
     112    return $Output;
    113113  }
    114114}
  • trunk/Modules/Import/cmd.php

    r859 r880  
    1313$Output = '';
    1414
    15 if(defined('STDIN') == false)
     15if (defined('STDIN') == false)
    1616{
    1717  $Output = T('Access denied');
     
    1919}
    2020
    21 foreach($_SERVER['argv'] as $parameter)
     21foreach ($_SERVER['argv'] as $parameter)
    2222{
    23   if(strpos($parameter, '=') !== false)
     23  if (strpos($parameter, '=') !== false)
    2424  {
    2525    $index = substr($parameter, 0, strpos($parameter, '='));
     
    3030}
    3131
    32 if(!array_key_exists('id', $_GET))
     32if (!array_key_exists('id', $_GET))
    3333{
    3434  $Output .= '
     
    4949  $Output .= '   version=<version> - nastaví verzi importu default: '.$System->Config['Web']['GameVersion'].'<br /><br />';
    5050      $Output .= '    <id_import_group>:';
    51     foreach($TranslationTree as $Group)
     51    foreach ($TranslationTree as $Group)
    5252    {
    5353      $Output .= '<br />    '.$Group['Id'].' ';
  • trunk/Modules/Import/generatecodeXML.php

    r815 r880  
    3030
    3131$files = scandir($verze);
    32 foreach($files as $file)
     32foreach ($files as $file)
    3333{
    3434  $end = substr($file, strlen($file) - 3);
    35   if($end == 'xml')
     35  if ($end == 'xml')
    3636  {
    3737    echo('<br />--'.$file.'<br /><br />');
Note: See TracChangeset for help on using the changeset viewer.