| 1 | 
        
            1538
         | 
        
            Luisehahne
         | 
        <?php
  | 
      
      
        | 2 | 
        
         | 
        
         | 
        /**
  | 
      
      
        | 3 | 
        
         | 
        
         | 
         *
  | 
      
      
        | 4 | 
        
         | 
        
         | 
         * @category        modules
  | 
      
      
        | 5 | 
        
         | 
        
         | 
         * @package         wysiwyg
  | 
      
      
        | 6 | 
        
         | 
        
         | 
         * @author          WebsiteBaker Project
  | 
      
      
        | 7 | 
        
            1576
         | 
        
            darkviper
         | 
         * @copyright       2009-2012, Website Baker Org. e.V.
  | 
      
      
        | 8 | 
        
            1890
         | 
        
            Luisehahne
         | 
         * @link            http://www.websitebaker2.org/
  | 
      
      
        | 9 | 
        
            1538
         | 
        
            Luisehahne
         | 
         * @license         http://www.gnu.org/licenses/gpl.html
  | 
      
      
        | 10 | 
        
            1652
         | 
        
            Luisehahne
         | 
         * @platform        WebsiteBaker 2.8.3
  | 
      
      
        | 11 | 
        
            1538
         | 
        
            Luisehahne
         | 
         * @requirements    PHP 5.2.2 and higher
  | 
      
      
        | 12 | 
        
            1890
         | 
        
            Luisehahne
         | 
         * @version         $Id$
  | 
      
      
        | 13 | 
        
         | 
        
         | 
         * @filesource      $HeadURL$
  | 
      
      
        | 14 | 
        
            1538
         | 
        
            Luisehahne
         | 
         * @lastmodified    $Date$
  | 
      
      
        | 15 | 
        
         | 
        
         | 
         *
  | 
      
      
        | 16 | 
        
         | 
        
         | 
         */
  | 
      
      
        | 17 | 
        
         | 
        
         | 
        /* -------------------------------------------------------- */
  | 
      
      
        | 18 | 
        
            1576
         | 
        
            darkviper
         | 
        // Must include code to stop this file being accessed directly
  | 
      
      
        | 19 | 
        
         | 
        
         | 
        if(!defined('WB_PATH')) {
 | 
      
      
        | 20 | 
        
            1652
         | 
        
            Luisehahne
         | 
        	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
  | 
      
      
        | 21 | 
        
            1576
         | 
        
            darkviper
         | 
        	throw new IllegalFileException();
  | 
      
      
        | 22 | 
        
            1538
         | 
        
            Luisehahne
         | 
        }
  | 
      
      
        | 23 | 
        
         | 
        
         | 
        /* -------------------------------------------------------- */
  | 
      
      
        | 24 | 
        
            1754
         | 
        
            Luisehahne
         | 
        
  | 
      
      
        | 25 | 
        
            1890
         | 
        
            Luisehahne
         | 
        	function mod_wysiwyg_upgrade ($bDebug=false) {
 | 
      
      
        | 26 | 
        
         | 
        
         | 
        		global $OK ,$FAIL;
  | 
      
      
        | 27 | 
        
         | 
        
         | 
        		$database=WbDatabase::getInstance();
  | 
      
      
        | 28 | 
        
         | 
        
         | 
        		$msg = array();
  | 
      
      
        | 29 | 
        
            1875
         | 
        
            Luisehahne
         | 
        		$callingScript = $_SERVER["SCRIPT_NAME"];
  | 
      
      
        | 30 | 
        
         | 
        
         | 
        		// check if upgrade startet by upgrade-script to echo a message
  | 
      
      
        | 31 | 
        
         | 
        
         | 
        		$tmp = 'upgrade-script.php';
  | 
      
      
        | 32 | 
        
         | 
        
         | 
        		$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
  | 
      
      
        | 33 | 
        
            1890
         | 
        
            Luisehahne
         | 
        // check for missing tables, if true stop the upgrade
  | 
      
      
        | 34 | 
        
            1875
         | 
        
            Luisehahne
         | 
        		$aTable = array('mod_wysiwyg');
 | 
      
      
        | 35 | 
        
            1890
         | 
        
            Luisehahne
         | 
        		$aPackage = UpgradeHelper::existsAllTables($aTable);
  | 
      
      
        | 36 | 
        
         | 
        
         | 
        		if( sizeof($aPackage) > 0){
 | 
      
      
        | 37 | 
        
         | 
        
         | 
        			$msg[] =  'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL;
 | 
      
      
        | 38 | 
        
         | 
        
         | 
        			$msg[] = 'WYSIWYG upgrade failed '." $FAIL";
  | 
      
      
        | 39 | 
        
         | 
        
         | 
        			if($globalStarted) {
 | 
      
      
        | 40 | 
        
         | 
        
         | 
        				echo '<strong>'.implode('<br />',$msg).'</strong><br />';
 | 
      
      
        | 41 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 42 | 
        
         | 
        
         | 
        			return ( ($globalStarted==true ) ? $globalStarted : $msg);
  | 
      
      
        | 43 | 
        
         | 
        
         | 
        		} else {
 | 
      
      
        | 44 | 
        
         | 
        
         | 
        			for($x=0; $x<sizeof($aTable);$x++) {
 | 
      
      
        | 45 | 
        
         | 
        
         | 
        				if(($sOldType = $database->getTableEngine($database->TablePrefix.$aTable[$x]))) {
 | 
      
      
        | 46 | 
        
         | 
        
         | 
        					if(('myisam' != strtolower($sOldType))) {
 | 
      
      
        | 47 | 
        
         | 
        
         | 
        						if(!$database->query('ALTER TABLE `'.$database->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
 | 
      
      
        | 48 | 
        
         | 
        
         | 
        							$msg[] = $database->get_error();
  | 
      
      
        | 49 | 
        
         | 
        
         | 
        						} else{
 | 
      
      
        | 50 | 
        
         | 
        
         | 
        							$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
  | 
      
      
        | 51 | 
        
         | 
        
         | 
        						}
  | 
      
      
        | 52 | 
        
         | 
        
         | 
        					} else {
 | 
      
      
        | 53 | 
        
         | 
        
         | 
        						 $msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
  | 
      
      
        | 54 | 
        
            1875
         | 
        
            Luisehahne
         | 
        					}
  | 
      
      
        | 55 | 
        
         | 
        
         | 
        				} else {
 | 
      
      
        | 56 | 
        
            1890
         | 
        
            Luisehahne
         | 
        					$msg[] = $database->get_error();
  | 
      
      
        | 57 | 
        
            1875
         | 
        
            Luisehahne
         | 
        				}
  | 
      
      
        | 58 | 
        
            1890
         | 
        
            Luisehahne
         | 
        			}
  | 
      
      
        | 59 | 
        
         | 
        
         | 
        // add change or missing index
  | 
      
      
        | 60 | 
        
         | 
        
         | 
        			$sTable = $database->TablePrefix.'mod_wysiwyg';
  | 
      
      
        | 61 | 
        
         | 
        
         | 
        			if($database->index_exists($sTable, 'PRIMARY')) {
 | 
      
      
        | 62 | 
        
         | 
        
         | 
        				$sql = 'ALTER TABLE `'.$database->DbName.'`.`'.$sTable.'` DROP PRIMARY KEY';
  | 
      
      
        | 63 | 
        
         | 
        
         | 
        				if(!$database->query($sql)) {
 | 
      
      
        | 64 | 
        
         | 
        
         | 
        					$msg[] = ''.$database->get_error();
  | 
      
      
        | 65 | 
        
         | 
        
         | 
        				}
  | 
      
      
        | 66 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 67 | 
        
         | 
        
         | 
        			if(!$database->index_add($sTable, '', 'section_id', 'PRIMARY')) {
 | 
      
      
        | 68 | 
        
         | 
        
         | 
        				$msg[] = ''.$database->get_error();
  | 
      
      
        | 69 | 
        
            1875
         | 
        
            Luisehahne
         | 
        			} else {
 | 
      
      
        | 70 | 
        
            1890
         | 
        
            Luisehahne
         | 
        				$msg[] = 'Create PRIMARY KEY ( `section_id` )'." $OK";
  | 
      
      
        | 71 | 
        
            1875
         | 
        
            Luisehahne
         | 
        			}
  | 
      
      
        | 72 | 
        
            1890
         | 
        
            Luisehahne
         | 
        // change table structure
  | 
      
      
        | 73 | 
        
         | 
        
         | 
        			$sTable = $database->TablePrefix.'mod_wysiwyg';
  | 
      
      
        | 74 | 
        
         | 
        
         | 
        			$sDescription = 'LONGTEXT NOT NULL';
  | 
      
      
        | 75 | 
        
         | 
        
         | 
        			$sFieldName = 'text';
  | 
      
      
        | 76 | 
        
         | 
        
         | 
        			if(!$database->field_modify($sTable,$sFieldName,$sDescription)) {
 | 
      
      
        | 77 | 
        
         | 
        
         | 
        				$msg[] = ''.$database->get_error();
  | 
      
      
        | 78 | 
        
         | 
        
         | 
        			} else {
 | 
      
      
        | 79 | 
        
         | 
        
         | 
        				$msg[] = 'Field ( `text` ) description has been changed successfully'." $OK";
  | 
      
      
        | 80 | 
        
            1875
         | 
        
            Luisehahne
         | 
        			}
  | 
      
      
        | 81 | 
        
            1890
         | 
        
            Luisehahne
         | 
        			$sFieldName = 'content';
  | 
      
      
        | 82 | 
        
         | 
        
         | 
        			if(!$database->field_modify($sTable,$sFieldName,$sDescription)) {
 | 
      
      
        | 83 | 
        
         | 
        
         | 
        				$msg[] = ''.$database->get_error();
  | 
      
      
        | 84 | 
        
         | 
        
         | 
        			} else {
 | 
      
      
        | 85 | 
        
         | 
        
         | 
        				$msg[] = 'Field ( `content` ) description has been changed successfully'." $OK";
  | 
      
      
        | 86 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 87 | 
        
         | 
        
         | 
        // change internal absolute links into relative links
  | 
      
      
        | 88 | 
        
         | 
        
         | 
        			$sTable = $database->TablePrefix.'mod_wysiwyg';
  | 
      
      
        | 89 | 
        
         | 
        
         | 
        			$sql  = 'UPDATE `'.$sTable.'` ';
  | 
      
      
        | 90 | 
        
         | 
        
         | 
        			$sql .= 'SET `content` = REPLACE(`content`, \'"'.WB_URL.MEDIA_DIRECTORY.'\', \'"{SYSVAR:MEDIA_REL}\')';
 | 
      
      
        | 91 | 
        
         | 
        
         | 
        			if (!$database->query($sql)) {
 | 
      
      
        | 92 | 
        
         | 
        
         | 
        				$msg[] = ''.$database->get_error();
  | 
      
      
        | 93 | 
        
         | 
        
         | 
        			} else {
 | 
      
      
        | 94 | 
        
         | 
        
         | 
        				$msg[] = 'Change internal absolute links into relative links'." $OK";
  | 
      
      
        | 95 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 96 | 
        
         | 
        
         | 
        // only for $callingScript upgrade-script.php
  | 
      
      
        | 97 | 
        
         | 
        
         | 
        			if($globalStarted) {
 | 
      
      
        | 98 | 
        
         | 
        
         | 
        				if($bDebug) {
 | 
      
      
        | 99 | 
        
         | 
        
         | 
        					echo '<strong>'.implode('<br />',$msg).'</strong><br />';
 | 
      
      
        | 100 | 
        
            1875
         | 
        
            Luisehahne
         | 
        				}
  | 
      
      
        | 101 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 102 | 
        
         | 
        
         | 
        		}
  | 
      
      
        | 103 | 
        
            1890
         | 
        
            Luisehahne
         | 
        		$msg[] = 'WYSIWYG upgrade successfull finished'." $OK";
  | 
      
      
        | 104 | 
        
         | 
        
         | 
        		if($globalStarted) {
 | 
      
      
        | 105 | 
        
         | 
        
         | 
        			echo "<strong>WYSIWYG upgrade successfull finished $OK</strong><br />";
  | 
      
      
        | 106 | 
        
         | 
        
         | 
        		}
  | 
      
      
        | 107 | 
        
         | 
        
         | 
        		return ( ($globalStarted==true ) ? $globalStarted : $msg);
  | 
      
      
        | 108 | 
        
            1875
         | 
        
            Luisehahne
         | 
        	}
  | 
      
      
        | 109 | 
        
            1890
         | 
        
            Luisehahne
         | 
        // ------------------------------------
  | 
      
      
        | 110 | 
        
         | 
        
         | 
        $bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
  | 
      
      
        | 111 | 
        
         | 
        
         | 
        if( is_array($msg = mod_wysiwyg_upgrade($bDebugModus)) ) {
 | 
      
      
        | 112 | 
        
         | 
        
         | 
        	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
 | 
      
      
        | 113 | 
        
            1576
         | 
        
            darkviper
         | 
        }
  |