| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
     | 
  
  
    | 
      4
     | 
    
       *
 
     | 
  
  
    | 
      5
     | 
    
       * This program is free software: you can redistribute it and/or modify
 
     | 
  
  
    | 
      6
     | 
    
       * it under the terms of the GNU General Public License as published by
 
     | 
  
  
    | 
      7
     | 
    
       * the Free Software Foundation, either version 3 of the License, or
 
     | 
  
  
    | 
      8
     | 
    
       * (at your option) any later version.
 
     | 
  
  
    | 
      9
     | 
    
       *
 
     | 
  
  
    | 
      10
     | 
    
       * This program is distributed in the hope that it will be useful,
 
     | 
  
  
    | 
      11
     | 
    
       * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
     | 
  
  
    | 
      12
     | 
    
       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
     | 
  
  
    | 
      13
     | 
    
       * GNU General Public License for more details.
 
     | 
  
  
    | 
      14
     | 
    
       *
 
     | 
  
  
    | 
      15
     | 
    
       * You should have received a copy of the GNU General Public License
 
     | 
  
  
    | 
      16
     | 
    
       * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
     | 
  
  
    | 
      17
     | 
    
       */
 
     | 
  
  
    | 
      18
     | 
    
      
 
     | 
  
  
    | 
      19
     | 
    
      /**
 
     | 
  
  
    | 
      20
     | 
    
       * uprade.php
 
     | 
  
  
    | 
      21
     | 
    
       *
 
     | 
  
  
    | 
      22
     | 
    
       * @category     Modules
 
     | 
  
  
    | 
      23
     | 
    
       * @package      Modules_MultiLingual
 
     | 
  
  
    | 
      24
     | 
    
       * @author       Werner v.d.Decken <wkl@isteam.de>
 
     | 
  
  
    | 
      25
     | 
    
       * @author       Dietmar Wöllbrink <dietmar.woellbrink@websiteBaker.org>
 
     | 
  
  
    | 
      26
     | 
    
       * @copyright    Werner v.d.Decken <wkl@isteam.de>
 
     | 
  
  
    | 
      27
     | 
    
       * @license      http://www.gnu.org/licenses/gpl.html   GPL License
 
     | 
  
  
    | 
      28
     | 
    
       * @version      1.6.9
 
     | 
  
  
    | 
      29
     | 
    
       * @revision     $Revision: 2070 $
 
     | 
  
  
    | 
      30
     | 
    
       * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/MultiLingual/upgrade.php $
 
     | 
  
  
    | 
      31
     | 
    
       * @lastmodified $Date: 2014-01-03 02:21:42 +0100 (Fri, 03 Jan 2014) $
 
     | 
  
  
    | 
      32
     | 
    
       * @since        File available since 09.01.2013
 
     | 
  
  
    | 
      33
     | 
    
       * @description  provides a flexible posibility for changeing to a translated page
 
     | 
  
  
    | 
      34
     | 
    
       */
 
     | 
  
  
    | 
      35
     | 
    
      
 
     | 
  
  
    | 
      36
     | 
    
      /* ------------------------------------------------------------------------------------ */
 
     | 
  
  
    | 
      37
     | 
    
      // Must include code to stop this file being accessed directly
 
     | 
  
  
    | 
      38
     | 
    
      if(!defined('WB_URL')) {
     | 
  
  
    | 
      39
     | 
    
      	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
 
     | 
  
  
    | 
      40
     | 
    
      	throw new IllegalFileException();
 
     | 
  
  
    | 
      41
     | 
    
      }
 
     | 
  
  
    | 
      42
     | 
    
      /* ------------------------------------------------------------------------------------ */
 
     | 
  
  
    | 
      43
     | 
    
      
 
     | 
  
  
    | 
      44
     | 
    
      	function mod_MultiLingual_upgrade($bDebug=false) {
     | 
  
  
    | 
      45
     | 
    
      		global $OK ,$FAIL;
 
     | 
  
  
    | 
      46
     | 
    
      		$database=WbDatabase::getInstance();
 
     | 
  
  
    | 
      47
     | 
    
      		$msg = array();
 
     | 
  
  
    | 
      48
     | 
    
      		$callingScript = $_SERVER["SCRIPT_NAME"];
 
     | 
  
  
    | 
      49
     | 
    
      		// check if upgrade startet by upgrade-script to echo a message
 
     | 
  
  
    | 
      50
     | 
    
      		$tmp = 'upgrade-script.php';
 
     | 
  
  
    | 
      51
     | 
    
      		$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
 
     | 
  
  
    | 
      52
     | 
    
      // change table structure
 
     | 
  
  
    | 
      53
     | 
    
      		$sTable = $database->TablePrefix.'pages';
 
     | 
  
  
    | 
      54
     | 
    
          	$sFieldName = 'page_code';
 
     | 
  
  
    | 
      55
     | 
    
          	$sDescription = "INT NOT NULL DEFAULT '0' AFTER `language`";
 
     | 
  
  
    | 
      56
     | 
    
      		if(!$database->field_add($sTable,$sFieldName,$sDescription)) {
     | 
  
  
    | 
      57
     | 
    
      			$msg[] = ''.$database->get_error();
 
     | 
  
  
    | 
      58
     | 
    
      		} else {
     | 
  
  
    | 
      59
     | 
    
      			$msg[] = 'Field ( `page_code` ) description has been add successfully'." $OK";
 
     | 
  
  
    | 
      60
     | 
    
      		}
 
     | 
  
  
    | 
      61
     | 
    
      // Work-out if we should check old format for existing page_code
 
     | 
  
  
    | 
      62
     | 
    
              $sql = 'DESCRIBE `'.$database->TablePrefix.'pages` `page_code`';
 
     | 
  
  
    | 
      63
     | 
    
              $field_sql = $database->query($sql);
 
     | 
  
  
    | 
      64
     | 
    
      //        $field_set = $field_sql->numRows();
 
     | 
  
  
    | 
      65
     | 
    
              $format = $field_sql->fetchRow(MYSQL_ASSOC) ;
 
     | 
  
  
    | 
      66
     | 
    
              // upgrade only if old format
 
     | 
  
  
    | 
      67
     | 
    
              if($format['Type'] == 'varchar(255)' )
 
     | 
  
  
    | 
      68
     | 
    
              {
     | 
  
  
    | 
      69
     | 
    
                  $sql = 'SELECT `page_code`,`page_id` FROM `'.$database->TablePrefix.'pages` ORDER BY `page_id`';
 
     | 
  
  
    | 
      70
     | 
    
                  if($query_code = $database->query($sql))
 
     | 
  
  
    | 
      71
     | 
    
                  {
     | 
  
  
    | 
      72
     | 
    
                      // extract page_id from old format
 
     | 
  
  
    | 
      73
     | 
    
                      $pattern = '/(?<=_)([0-9]{1,11})/s';
     | 
  
  
    | 
      74
     | 
    
                      while( $page  = $query_code->fetchRow(MYSQL_ASSOC))
 
     | 
  
  
    | 
      75
     | 
    
                      {
     | 
  
  
    | 
      76
     | 
    
                          preg_match($pattern, $page['page_code'], $array);
 
     | 
  
  
    | 
      77
     | 
    
                          $page_code = $array[0];
 
     | 
  
  
    | 
      78
     | 
    
                          $page_id =  $page['page_id'];
 
     | 
  
  
    | 
      79
     | 
    
                          $sql  = 'UPDATE `'.$database->TablePrefix.'pages` SET ';
 
     | 
  
  
    | 
      80
     | 
    
                          $sql .= ((empty($array[0])) ? '`page_code` = 0 ' : '`page_code` = '.$page_code.' ');
 
     | 
  
  
    | 
      81
     | 
    
                          $sql .= 'WHERE `page_id` = '.$page_id;
 
     | 
  
  
    | 
      82
     | 
    
                          $database->query($sql);
 
     | 
  
  
    | 
      83
     | 
    
                      }
 
     | 
  
  
    | 
      84
     | 
    
                      $field_set = $database->field_modify($sTable,$sFieldName,$sDescription);
 
     | 
  
  
    | 
      85
     | 
    
                      $msg[] = 'Field ( `page_code` ) description has been changed successfully'." $OK";
 
     | 
  
  
    | 
      86
     | 
    
      // only for upgrade-script
 
     | 
  
  
    | 
      87
     | 
    
          			if($globalStarted) {
     | 
  
  
    | 
      88
     | 
    
          				if($bDebug) {
     | 
  
  
    | 
      89
     | 
    
          					echo '<strong>'.implode('<br />',$msg).'</strong><br />';
     | 
  
  
    | 
      90
     | 
    
          				}
 
     | 
  
  
    | 
      91
     | 
    
          			}
 
     | 
  
  
    | 
      92
     | 
    
                  }  else {
     | 
  
  
    | 
      93
     | 
    
                      $msg[] = ''.$database->get_error();
 
     | 
  
  
    | 
      94
     | 
    
                  }  
 
     | 
  
  
    | 
      95
     | 
    
              }
 
     | 
  
  
    | 
      96
     | 
    
              //
 
     | 
  
  
    | 
      97
     | 
    
      		$msg[] = 'MultiLingual upgrade successfull finished ';
 
     | 
  
  
    | 
      98
     | 
    
      		if($globalStarted) {
     | 
  
  
    | 
      99
     | 
    
      			echo "<strong>MultiLingual upgrade successfull finished $OK</strong><br />";
 
     | 
  
  
    | 
      100
     | 
    
      		}
 
     | 
  
  
    | 
      101
     | 
    
      		return ( ($globalStarted==true ) ? $globalStarted : $msg);
 
     | 
  
  
    | 
      102
     | 
    
      
 
     | 
  
  
    | 
      103
     | 
    
      	}
 
     | 
  
  
    | 
      104
     | 
    
      // ------------------------------------
 
     | 
  
  
    | 
      105
     | 
    
      //$directory = dirname(__FILE__).'/'.'info.php';
 
     | 
  
  
    | 
      106
     | 
    
      //// update entry in table addons to new version
 
     | 
  
  
    | 
      107
     | 
    
      //load_module($directory, $install = false);
 
     | 
  
  
    | 
      108
     | 
    
      
 
     | 
  
  
    | 
      109
     | 
    
      $bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
 
     | 
  
  
    | 
      110
     | 
    
      // Don't show the messages twice
 
     | 
  
  
    | 
      111
     | 
    
      if( is_array($msg = mod_MultiLingual_upgrade($bDebugModus))) {
     | 
  
  
    | 
      112
     | 
    
      	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
     | 
  
  
    | 
      113
     | 
    
      }
 
     | 
  
  
    | 
      114
     | 
    
      
 
     | 
  
  
    | 
      115
     | 
    
      // ------------------------------------
 
     |