| 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 | 2007 | darkviper | // change internal absolute Media links into relative links
 | 
      
        | 88 | 1890 | Luisehahne | 			$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 | 2007 | darkviper | 				$msg[] = 'Change internal absolute Media links into relative links'." $OK";
 | 
      
        | 95 |  |  | 			}
 | 
      
        | 96 |  |  | // change all other internal absolute links into relative links
 | 
      
        | 97 |  |  | 			$sTable = $database->TablePrefix.'mod_wysiwyg';
 | 
      
        | 98 |  |  | 			$sql  = 'UPDATE `'.$sTable.'` ';
 | 
      
        | 99 |  |  | 			$sql .= 'SET `content` = REPLACE(`content`, \'"'.WB_URL.'\', \'"{SYSVAR:WB_REL}\')';
 | 
      
        | 100 |  |  | 			if (!$database->query($sql)) {
 | 
      
        | 101 |  |  | 				$msg[] = ''.$database->get_error();
 | 
      
        | 102 |  |  | 			} else {
 | 
      
        | 103 | 1890 | Luisehahne | 				$msg[] = 'Change internal absolute links into relative links'." $OK";
 | 
      
        | 104 |  |  | 			}
 | 
      
        | 105 |  |  | // only for $callingScript upgrade-script.php
 | 
      
        | 106 |  |  | 			if($globalStarted) {
 | 
      
        | 107 |  |  | 				if($bDebug) {
 | 
      
        | 108 |  |  | 					echo '<strong>'.implode('<br />',$msg).'</strong><br />';
 | 
      
        | 109 | 1875 | Luisehahne | 				}
 | 
      
        | 110 |  |  | 			}
 | 
      
        | 111 |  |  | 		}
 | 
      
        | 112 | 1890 | Luisehahne | 		$msg[] = 'WYSIWYG upgrade successfull finished'." $OK";
 | 
      
        | 113 |  |  | 		if($globalStarted) {
 | 
      
        | 114 |  |  | 			echo "<strong>WYSIWYG upgrade successfull finished $OK</strong><br />";
 | 
      
        | 115 |  |  | 		}
 | 
      
        | 116 |  |  | 		return ( ($globalStarted==true ) ? $globalStarted : $msg);
 | 
      
        | 117 | 1875 | Luisehahne | 	}
 | 
      
        | 118 | 1890 | Luisehahne | // ------------------------------------
 | 
      
        | 119 |  |  | $bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
 | 
      
        | 120 |  |  | if( is_array($msg = mod_wysiwyg_upgrade($bDebugModus)) ) {
 | 
      
        | 121 |  |  | 	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
 | 
      
        | 122 | 1576 | darkviper | }
 |