Ignore:
Timestamp:
Mar 6, 2023, 12:16:38 PM (14 months ago)
Author:
chronos
Message:
  • Fixed: Export error due to PHP 8.1 deprecated code.
  • Modified: Code cleanup.
File:
1 edited

Legend:

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

    r888 r894  
    33include_once(dirname(__FILE__).'/../../includes/dbc.php');
    44include_once(dirname(__FILE__).'/Manage.php');
    5 
    65
    76class ModuleImport extends Module
     
    3837  function SetVersion($Version)
    3938  {
    40     global $System;
    41 
    42     $DbResult = $System->Database->query('SELECT * FROM `ClientVersion` WHERE `Version` = "'.$Version.'"');
     39    $DbResult = $this->System->Database->query('SELECT * FROM `ClientVersion` WHERE `Version` = "'.$Version.'"');
    4340    $this->Version = $DbResult->fetch_assoc();
    4441  }
     
    6865      $DbRowBefore = $DbResultBefore->fetch_assoc();
    6966
    70       if ($this->HaveSameText($this->Group, $DbRowBefore, $Value) and ($DbResultBefore->num_rows > 0) )
     67      if ($this->HaveSameText($this->Group, $DbRowBefore, $Value) and ($DbResultBefore->num_rows > 0))
    7168      {
    7269          $insert = false;
    73           if ($this->Group['Id'] == 1) {
     70          if ($this->Group['Id'] == 1)
     71          {
    7472             $set = ' , EndText = "'.$Value['EndText'].'" , ObjectiveText1 = "'.$Value['ObjectiveText1'].'"'.' , ObjectiveText2 = "'.$Value['ObjectiveText2'].'"'.' , ObjectiveText3 = "'.$Value['ObjectiveText3'].'"'.' , ObjectiveText4 = "'.$Value['ObjectiveText4'].'"';
    7573          } else $set = '';
     
    8078      if ($this->HaveSameText($this->Group, $DbRowAfter, $Value) and ($DbResultAfter->num_rows > 0))
    8179      {
    82           $insert = false;
    83           if ($this->Group['Id'] == 1) {
    84              $set = ' , EndText = "'.$Value['EndText'].'" , ObjectiveText1 = "'.$Value['ObjectiveText1'].'"'.' , ObjectiveText2 = "'.$Value['ObjectiveText2'].'"'.' , ObjectiveText3 = "'.$Value['ObjectiveText3'].'"'.' , ObjectiveText4 = "'.$Value['ObjectiveText4'].'"';
    85           } else $set = '';
    86           $this->System->Database->query('UPDATE `'.$this->Group['TablePrefix'].'` SET `VersionStart` = "'.$this->Version['BuildNumber'].'" '.$set.' WHERE `ID`='.$DbRowAfter['ID']);
    87           echo('a ');
    88 
     80        $insert = false;
     81        if ($this->Group['Id'] == 1)
     82        {
     83          $set = ' , EndText = "'.$Value['EndText'].'" , ObjectiveText1 = "'.$Value['ObjectiveText1'].'"'.' , ObjectiveText2 = "'.$Value['ObjectiveText2'].'"'.' , ObjectiveText3 = "'.$Value['ObjectiveText3'].'"'.' , ObjectiveText4 = "'.$Value['ObjectiveText4'].'"';
     84        } else $set = '';
     85        $this->System->Database->query('UPDATE `'.$this->Group['TablePrefix'].'` SET `VersionStart` = "'.$this->Version['BuildNumber'].'" '.$set.' WHERE `ID`='.$DbRowAfter['ID']);
     86        echo('a ');
    8987      } else
    9088      {
    91 
    92         if (isset($DbRowAfter['VersionStart'])) {
    93           if ($DbRowAfter['VersionStart'] <= $this->Version['BuildNumber']) {
     89        if (isset($DbRowAfter['VersionStart']))
     90        {
     91          if ($DbRowAfter['VersionStart'] <= $this->Version['BuildNumber'])
     92          {
    9493            echo('Allready imported '.$DbRowBefore['Entry'].' ');
    9594            $insert = false;
    9695          }
    9796        }
    98         if (isset($DbRowBefore['VersionEnd'])) {
    99           if ($DbRowBefore['VersionEnd'] >= $this->Version['BuildNumber']) {
     97        if (isset($DbRowBefore['VersionEnd']))
     98        {
     99          if ($DbRowBefore['VersionEnd'] >= $this->Version['BuildNumber'])
     100          {
    100101            echo('Allready imported '.$DbRowBefore['Entry'].' ');
    101102            $inserted = false;
     
    103104        }
    104105
    105             //if [DEPRECATED] do not import
    106         foreach ($this->Group['Items'] as $GroupItem) {
    107           if (false !== strpos($Value[$GroupItem['Column']],'[DEPRECATED')) {
     106        // if [DEPRECATED] do not import
     107        foreach ($this->Group['Items'] as $GroupItem)
     108        {
     109          if (false !== strpos($Value[$GroupItem['Column']],'[DEPRECATED'))
     110          {
    108111            echo('d '.$DbRowBefore['Entry'].' ');
    109112            $insert = false;
     
    111114        }
    112115
    113         if ($insert) {
     116        if ($insert)
     117        {
    114118          $insert = false;
    115119          foreach ($this->Group['Items'] as $GroupItem)
     
    125129        if ($insert)
    126130        {
    127 
    128131          $Columns = '`Entry`, `Language`, `VersionStart`, `VersionEnd`';
    129132          $Values = $Value['Entry'].', 0, '.$this->Version['BuildNumber'].', '.$this->Version['BuildNumber'];
     
    135138          $this->System->Database->query('INSERT `'.$this->Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')');
    136139
    137           echo '
     140          echo('
    138141          '.$Value['Entry'].' = '.$DbRowBefore['VersionStart'].'.'.$DbRowBefore['VersionEnd'].'< '.$this->Version['BuildNumber'].' <'.$DbRowAfter['VersionStart'].'.'.$DbRowAfter['VersionEnd'].'... '.$DbRowMiddle['VersionStart'].' '.$DbRowMiddle['VersionEnd'].'
    139           ';
     142          ');
    140143
    141144          if (false !== strpos($Values,'[DEPRECATED'))
    142           echo $Values;
     145          echo($Values);
    143146
    144147          echo('# ');
     
    171174        if ($Value[$GroupItem['Column']] <> '') $insert = true;
    172175      }
    173       if ($insert) {
     176      if ($insert)
     177      {
    174178        $this->System->Database->query('INSERT `'.$this->Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')');
    175179        $InsertId = $this->System->Database->insert_id;
     
    183187  function ImportLUA()
    184188  {
    185     global $PatchVersion;
    186 
    187     $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    188189    $Output = 'Načítání textů z LUA souboru...';
    189190
    190191    if (($this->Group['LuaFileName'] != '') and ($this->Group['TablePrefix'] != ''))
    191192    {
    192 
    193         $Output .= '<br />'.$this->Group['Name'].'<br />';
     193      $Output .= '<br />'.$this->Group['Name'].'<br />';
    194194      //  if ($this->Group['LastVersion'] < $this->Version['BuildNumber'] + 1)
    195         {
    196           $File = new FileStream();
    197 
    198           $File->OpenFile(dirname(__FILE__).'/../../source/'.$this->Version['Version'].'/lua/'.$this->Group['LuaFileName'].'.lua');
    199           $this->NewItemCount = 0;
    200           $Count = 0;
    201           while (!$File->EOF())
    202           {
    203             $Line = $File->ReadLine();
    204             if (strpos($Line, '=') !== false)
    205             {
    206               $LineParts = explode('=', $Line, 2);
    207               $Value['ShortCut'] = trim($LineParts[0]);
    208               $Line = trim($LineParts[1]);
    209               if ($Line[0] == '"')
    210               {
    211                 // Quoted string value
    212                 $Line = substr($Line, 1); // Skip start qoute
    213                 $TempLine = str_replace('\"', '  ', $Line); // Temporary remove slashed quotes
    214                 $Value['Text'] = substr($Line, 0, strpos($TempLine, '"'));
    215                 $Value['Text'] = str_replace('\n', "\n", $Value['Text']);
    216                 $Value['Text'] = addslashes(stripslashes($Value['Text']));
    217                 $Line = trim(substr($Line, strpos($TempLine, '"') + 1)); // Skip closing quote and semicolon
    218               } else
    219               {
    220                 // Nonstring value
    221                 $Value['Text'] = substr($Line, 0, strpos($Line, ';'));
    222               }
    223               $Line = substr($Line, strpos($Line, ';') + 1);
    224               $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --"
    225 
    226               $this->InsertItem($Value);
    227             };
    228             $Count++;
    229           }
    230           $Output .= '<br />Celkem: '.$Count.'  Nových: '.$this->NewItemCount.'<br />';
    231           $this->UpdateLastVersion();
    232         }
    233         // else $Output .= ShowMessage('Již importován pro verzi '.$this->Version['Version'], MESSAGE_CRITICAL);
    234       } else $Output .= ShowMessage('Není definováno jméno zdrojového souboru', MESSAGE_CRITICAL);
     195      {
     196        $File = new FileStream();
     197
     198        $File->OpenFile(dirname(__FILE__).'/../../source/'.$this->Version['Version'].'/lua/'.$this->Group['LuaFileName'].'.lua');
     199        $this->NewItemCount = 0;
     200        $Count = 0;
     201        while (!$File->EOF())
     202        {
     203          $Line = $File->ReadLine();
     204          if (strpos($Line, '=') !== false)
     205          {
     206            $LineParts = explode('=', $Line, 2);
     207            $Value['ShortCut'] = trim($LineParts[0]);
     208            $Line = trim($LineParts[1]);
     209            if ($Line[0] == '"')
     210            {
     211              // Quoted string value
     212              $Line = substr($Line, 1); // Skip start qoute
     213              $TempLine = str_replace('\"', '  ', $Line); // Temporary remove slashed quotes
     214              $Value['Text'] = substr($Line, 0, strpos($TempLine, '"'));
     215              $Value['Text'] = str_replace('\n', "\n", $Value['Text']);
     216              $Value['Text'] = addslashes(stripslashes($Value['Text']));
     217              $Line = trim(substr($Line, strpos($TempLine, '"') + 1)); // Skip closing quote and semicolon
     218            } else
     219            {
     220              // Nonstring value
     221              $Value['Text'] = substr($Line, 0, strpos($Line, ';'));
     222            }
     223            $Line = substr($Line, strpos($Line, ';') + 1);
     224            $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --"
     225
     226            $this->InsertItem($Value);
     227          };
     228          $Count++;
     229        }
     230        $Output .= '<br />Celkem: '.$Count.'  Nových: '.$this->NewItemCount.'<br />';
     231        $this->UpdateLastVersion();
     232      }
     233      // else $Output .= ShowMessage('Již importován pro verzi '.$this->Version['Version'], MESSAGE_CRITICAL);
     234    } else $Output .= ShowMessage('Není definováno jméno zdrojového souboru', MESSAGE_CRITICAL);
    235235    $Output .= ShowMessage('Dokončeno.');
    236236    return $Output;
     
    239239  function UpdateTranslated()
    240240  {
    241     global $PatchVersion, $Config;
    242 
    243241    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    244242    $Output = '<br /><br />Začínám se synchronizací VersionEnd u přeložených textů<br />';
     
    249247      while ($do)
    250248      {
    251       $DbResult = $this->System->Database->query('SELECT `gs_tran`.`ID`, '.
    252         '`gs_tran`.`VersionEnd` AS `VersionEnd_tran`, '.
    253         '`gs_tran`.`VersionStart` AS `VersionStart_tran`, '.
    254         '`gs_orig`.`VersionEnd` AS `VersionEnd_orig`, '.
    255         '`gs_orig`.`VersionStart` AS `VersionStart_orig` FROM `'.
     249        $DbResult = $this->System->Database->query('SELECT `gs_tran`.`ID`, '.
     250          '`gs_tran`.`VersionEnd` AS `VersionEnd_tran`, '.
     251          '`gs_tran`.`VersionStart` AS `VersionStart_tran`, '.
     252          '`gs_orig`.`VersionEnd` AS `VersionEnd_orig`, '.
     253          '`gs_orig`.`VersionStart` AS `VersionStart_orig` FROM `'.
    256254        $Group['TablePrefix'].'` AS `gs_tran` JOIN `'.$Group['TablePrefix'].
    257         '` AS `gs_orig` ON `gs_orig`.`ID` = `gs_tran`.`Take` WHERE '.
    258         '`gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd` OR `gs_tran`.`VersionStart` <> `gs_orig`.`VersionStart`');
     255          '` AS `gs_orig` ON `gs_orig`.`ID` = `gs_tran`.`Take` WHERE '.
     256          '`gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd` OR `gs_tran`.`VersionStart` <> `gs_orig`.`VersionStart`');
    259257        $do = ($DbResult->num_rows > 0);
    260258        while ($DbRow = $DbResult->fetch_assoc())
     
    293291
    294292      if ($this->Group['Id'] == 1)
    295        while ($part = substr($old, strpos($old, '<'), strpos($old, '>')-strpos($old, '<')))
    296         if ($part <> '') {
    297           $old = str_replace($part.'>', '', $old);
    298         }
     293      {
     294        while ($part = substr($old, strpos($old, '<'), strpos($old, '>')-strpos($old, '<')))
     295        {
     296          if ($part <> '')
     297          {
     298            $old = str_replace($part.'>', '', $old);
     299          }
     300        }
     301      }
    299302
    300303      if (($GroupItem['MangosColumn'] <> '') and ($Group['MangosDatabase'] == 'mangos'))
     
    319322
    320323      if ($this->Group['Id'] == 1)
    321        while ($part = substr($new, strpos($new, '<'), strpos($new, '>')-strpos($new, '<')))
    322         if ($part <> '') {
    323           $new = str_replace($part.'>', '', $new);
    324         }
     324      {
     325        while ($part = substr($new, strpos($new, '<'), strpos($new, '>')-strpos($new, '<')))
     326        {
     327          if ($part <> '')
     328          {
     329            $new = str_replace($part.'>', '', $new);
     330          }
     331        }
     332      }
    325333
    326334      if (($old == 'null') or ($old == 'NULL')) $old = '';
     
    344352  function ImportDBC()
    345353  {
    346     global $System, $Config;
    347 
    348     $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
     354    global $System;
     355
    349356    $Output = 'Načítání textů z DBC souboru...';
    350357    if (($this->Group['DBCFileName'] != '') and ($this->Group['TablePrefix'] != ''))
     
    381388        $ColumnValue = '';
    382389        foreach ($Columns as $Column)
     390        {
    383391          $ColumnValue .= '_'.$DBCFile->GetUint($I, $Column);
     392        }
    384393        $ColumnValue = substr($ColumnValue, 1);
    385394        $Value[$this->Group['PrimaryKeyItem']] = $ColumnValue;
     
    410419  function ImportSQL()
    411420  {
    412     global $PatchVersion;
    413 
    414     $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    415421    $Output = '';
    416422    $File = new FileStream();
     
    418424    $this->NewItemCount = 0;
    419425    $Count = 0;
    420     $folow_structure = false;
     426    $FollowStructure = false;
    421427    $i = 0;
    422428    while ((!$File->EOF()))
     
    427433      {
    428434        $Line = '';
    429         $folow_structure = true;
     435        $FollowStructure = true;
    430436        $i = 0;
    431437      }
    432       if ((strpos($Line, ';') !== false) and ($folow_structure == true))
    433       {
    434         $folow_structure = false;
    435         //  echo ('Struktura: <br />');
    436         //  print_r($structure);
    437         //  echo ('<br /><br />');
    438       }
    439       if (($folow_structure == true) and ($Line != ''))
     438      if ((strpos($Line, ';') !== false) and ($FollowStructure == true))
     439      {
     440        $FollowStructure = false;
     441      }
     442      if (($FollowStructure == true) and ($Line != ''))
    440443      {
    441444        $str = substr($Line, 0, strpos($Line, '`'));
     
    446449      }
    447450
    448       //data
     451      // data
    449452      if ((strpos($Line, 'INSERT INTO `'.$this->Group['MangosTable'].'`') !== false) and (isset($structure)))
    450453      {
     
    503506              $Value[$column] = '';
    504507            }
    505             //  echo ($column.'-"'.$Value[$column].'"<br>');
    506508          }
    507509          foreach ($this->Group['Items'] as $GroupItem)
    508510          {
    509511            if ($GroupItem['MangosColumn'] != '')
     512            {
    510513              if (isset($Value[$GroupItem['MangosColumn']]))
     514              {
    511515                $Value[$GroupItem['Column']] = $Value[$GroupItem['MangosColumn']];
    512               else {
     516              }
     517              else
     518              {
    513519                $Value[$GroupItem['Column']] = '';
    514520                $Value[$GroupItem['MangosColumn']] ='';
    515521              }
     522            }
    516523          }
    517524
     
    520527          $ColumnValue = '';
    521528          foreach ($Columns as $Column)
     529          {
    522530            $ColumnValue .= '_'.$Value[$Column];
     531          }
    523532          $ColumnValue = substr($ColumnValue, 1);
    524533          $Value[$this->Group['PrimaryKeyItem']] = $ColumnValue;
     
    533542  }
    534543
    535   function UpdateLastVersion() {
     544  function UpdateLastVersion()
     545  {
    536546    $DbResult = $this->System->Database->query('SELECT * FROM `Group` WHERE `Id`='.$this->Group['Id']);
    537547    $Version = $DbResult->fetch_assoc();
Note: See TracChangeset for help on using the changeset viewer.