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 2084 2014-01-16 03:10:01Z darkviper $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/wysiwyg/upgrade.php $
|
14
|
* @lastmodified $Date: 2014-01-16 04:10:01 +0100 (Thu, 16 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
|
$aEntry['content'] = preg_replace($aSearch, $aReplace, $aEntry['content'], -1, $iCount);
|
105
|
if ($iCount > 0) {
|
106
|
$iReplaced += $iCount;
|
107
|
$sql = 'UPDATE `'.$oDb->TablePrefix.'mod_wysiwyg` '
|
108
|
. 'SET `content`=\''.$oDb->escapeString($aEntry['content']).'\' '
|
109
|
. 'WHERE `section_id`='.$aEntry['section_id'];
|
110
|
$oDb->doQuery($sql);
|
111
|
$iRecords++;
|
112
|
}
|
113
|
}
|
114
|
$msg[] = '['.$iRecords.'] records with ['.$iReplaced.'] SYSVAR placeholder(s) repaired/inserted'." $OK";
|
115
|
// only for $callingScript upgrade-script.php
|
116
|
if($globalStarted && $bDebug) {
|
117
|
echo '<strong>'.implode('<br />',$msg).'</strong><br />';
|
118
|
}
|
119
|
}
|
120
|
}
|
121
|
$msg[] = 'WYSIWYG upgrade successfull finished'." $OK";
|
122
|
if($globalStarted) {
|
123
|
echo "<strong>WYSIWYG upgrade successfull finished $OK</strong><br />";
|
124
|
}
|
125
|
return ( ($globalStarted==true ) ? $globalStarted : $msg);
|
126
|
}
|
127
|
// ------------------------------------
|
128
|
$bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
|
129
|
if( is_array($msg = mod_wysiwyg_upgrade($bDebugModus)) ) {
|
130
|
echo '<strong>'.implode('<br />',$msg).'</strong><br />';
|
131
|
}
|