Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         wysiwyg
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, Website Baker Org. e.V.
8
 * @link            http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.3
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: upgrade.php 1890 2013-03-19 10:45:14Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/wysiwyg/upgrade.php $
14
 * @lastmodified    $Date: 2013-03-19 11:45:14 +0100 (Tue, 19 Mar 2013) $
15
 *
16
 */
17
/* -------------------------------------------------------- */
18
// Must include code to stop this file being accessed directly
19
if(!defined('WB_PATH')) {
20
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
21
	throw new IllegalFileException();
22
}
23
/* -------------------------------------------------------- */
24

    
25
	function mod_wysiwyg_upgrade ($bDebug=false) {
26
		global $OK ,$FAIL;
27
		$database=WbDatabase::getInstance();
28
		$msg = array();
29
		$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
// check for missing tables, if true stop the upgrade
34
		$aTable = array('mod_wysiwyg');
35
		$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
					}
55
				} else {
56
					$msg[] = $database->get_error();
57
				}
58
			}
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
			} else {
70
				$msg[] = 'Create PRIMARY KEY ( `section_id` )'." $OK";
71
			}
72
// 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
			}
81
			$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
				}
101
			}
102
		}
103
		$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
	}
109
// ------------------------------------
110
$bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
111
if( is_array($msg = mod_wysiwyg_upgrade($bDebugModus)) ) {
112
	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
113
}
(9-9/10)