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 2083 2014-01-15 17:58:49Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/wysiwyg/upgrade.php $
14
 * @lastmodified    $Date: 2014-01-15 18:58:49 +0100 (Wed, 15 Jan 2014) $
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
		$oDb = WbDatabase::getInstance();
28
        $oReg = WbAdaptor::getInstance();
29
		$msg = array();
30
		$callingScript = $_SERVER["SCRIPT_NAME"];
31
		// check if upgrade startet by upgrade-script to echo a message
32
		$tmp = 'upgrade-script.php';
33
		$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
34
// check for missing tables, if true stop the upgrade
35
		$aTable = array('mod_wysiwyg');
36
		$aPackage = UpgradeHelper::existsAllTables($aTable);
37
		if( sizeof($aPackage) > 0){
38
			$msg[] =  'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL;
39
			$msg[] = 'WYSIWYG upgrade failed '." $FAIL";
40
			if($globalStarted) {
41
				echo '<strong>'.implode('<br />',$msg).'</strong><br />';
42
			}
43
			return ( ($globalStarted==true ) ? $globalStarted : $msg);
44
		} else {
45
			for($x=0; $x<sizeof($aTable);$x++) {
46
				if(($sOldType = $oDb->getTableEngine($oDb->TablePrefix.$aTable[$x]))) {
47
					if(('myisam' != strtolower($sOldType))) {
48
						if(!$oDb->query('ALTER TABLE `'.$oDb->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
49
							$msg[] = $oDb->get_error();
50
						} else{
51
							$msg[] = 'TABLE `'.$oDb->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
52
						}
53
					} else {
54
						 $msg[] = 'TABLE `'.$oDb->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
55
					}
56
				} else {
57
					$msg[] = $oDb->get_error();
58
				}
59
			}
60
// add change or missing index
61
			$sTable = $oDb->TablePrefix.'mod_wysiwyg';
62
			if($oDb->index_exists($sTable, 'PRIMARY')) {
63
				$sql = 'ALTER TABLE `'.$oDb->DbName.'`.`'.$sTable.'` DROP PRIMARY KEY';
64
				if(!$oDb->query($sql)) {
65
					$msg[] = ''.$oDb->get_error();
66
				}
67
			}
68
			if(!$oDb->index_add($sTable, '', 'section_id', 'PRIMARY')) {
69
				$msg[] = ''.$oDb->get_error();
70
			} else {
71
				$msg[] = 'Create PRIMARY KEY ( `section_id` )'." $OK";
72
			}
73
// change table structure
74
			$sTable = $oDb->TablePrefix.'mod_wysiwyg';
75
			$sDescription = 'LONGTEXT NOT NULL';
76
			$sFieldName = 'text';
77
			if(!$oDb->field_modify($sTable,$sFieldName,$sDescription)) {
78
				$msg[] = ''.$oDb->get_error();
79
			} else {
80
				$msg[] = 'Field ( `text` ) description has been changed successfully'." $OK";
81
			}
82
			$sFieldName = 'content';
83
			if(!$oDb->field_modify($sTable,$sFieldName,$sDescription)) {
84
				$msg[] = ''.$oDb->get_error();
85
			} else {
86
				$msg[] = 'Field ( `content` ) description has been changed successfully'." $OK";
87
			}
88
// change internal absolute links into Sysvar placeholders and repair already existing entries
89
			$sTable = $oDb->TablePrefix.'mod_wysiwyg';
90
            $sql = 'SELECT `section_id`, `content` FROM `'.$oDb->TablePrefix.'mod_wysiwyg` ';
91
            if (($oEntrySet = $oDb->doQuery($sql))) {
92
                $iRecords = 0;
93
                $iReplaced = 0;
94
                $aSearch = array( '/\{SYSVAR\:MEDIA_REL\}\/*/s',
95
                                  '/\{SYSVAR\:WB_URL\}\/*/s',
96
                                  '/'.preg_quote('"'.$oReg->AppUrl.$oReg->MediaDir, '/').'*/s',
97
                                  '/'.preg_quote('"'.$oReg->AppUrl, '/').'*/s',
98
                                  '/(\{SYSVAR\:AppUrl\.MediaDir\})\/+/s',
99
                                  '/(\{SYSVAR\:AppUrl\})\/+/s'
100
                                );
101
                $aReplace = array( '{SYSVAR:AppUrl.MediaDir}', '{SYSVAR:AppUrl}', '{SYSVAR:AppUrl.MediaDir}', '{SYSVAR:AppUrl}', '\1', '\1');
102
                while (($aEntry = $oEntrySet->fetchRow(MYSQL_ASSOC))) {
103
                    $iCount = 0;
104
                    $aSubject = array($aEntry['content_long'], $aEntry['content_short']);
105
                    $aNewContents = preg_replace($aSearch, $aReplace, $aSubject, -1, $iCount);
106
                    if ($iCount > 0) {
107
                        $iReplaced += $iCount;
108
                        $sql = 'UPDATE `'.$oDb->TablePrefix.'mod_news_posts` '
109
                             . 'SET `content_long`=\''.$oDb->escapeString($aNewContents[0]).'\', '
110
                             .     '`content_short`=\''.$oDb->escapeString($aNewContents[1]).'\' '
111
                             . 'WHERE `post_id`='.$aEntry['post_id'];
112
                        $oDb->doQuery($sql);
113
                        $iRecords++;
114
                    }
115
                }
116
                $msg[] = '['.$iRecords.'] records with ['.$iReplaced.'] SYSVAR placeholder(s) repaired/inserted'." $OK";
117
// only for $callingScript upgrade-script.php
118
                if($globalStarted && $bDebug) {
119
                    echo '<strong>'.implode('<br />',$msg).'</strong><br />';
120
                }
121
            }
122
        }
123
		$msg[] = 'WYSIWYG upgrade successfull finished'." $OK";
124
		if($globalStarted) {
125
			echo "<strong>WYSIWYG upgrade successfull finished $OK</strong><br />";
126
		}
127
		return ( ($globalStarted==true ) ? $globalStarted : $msg);
128
	}
129
// ------------------------------------
130
$bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
131
if( is_array($msg = mod_wysiwyg_upgrade($bDebugModus)) ) {
132
	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
133
}
(9-9/10)