Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 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
Note: See TracChangeset for help on using the changeset viewer.