Project

General

Profile

« Previous | Next » 

Revision 2058

Added by darkviper over 10 years ago

! change wysiwyg module from filterMediaRel to filterReplaceSysvar
! change wb::ReplaceAbsoluteMediaUrl from filterMediaRel to filterReplaceSysvar

View differences:

upgrade.php
24 24

  
25 25
	function mod_wysiwyg_upgrade ($bDebug=false) {
26 26
		global $OK ,$FAIL;
27
		$database=WbDatabase::getInstance();
27
		$oDb = WbDatabase::getInstance();
28
        $oReg = WbAdaptor::getInstance();
28 29
		$msg = array();
29 30
		$callingScript = $_SERVER["SCRIPT_NAME"];
30 31
		// check if upgrade startet by upgrade-script to echo a message
......
42 43
			return ( ($globalStarted==true ) ? $globalStarted : $msg);
43 44
		} else {
44 45
			for($x=0; $x<sizeof($aTable);$x++) {
45
				if(($sOldType = $database->getTableEngine($database->TablePrefix.$aTable[$x]))) {
46
				if(($sOldType = $oDb->getTableEngine($oDb->TablePrefix.$aTable[$x]))) {
46 47
					if(('myisam' != strtolower($sOldType))) {
47
						if(!$database->query('ALTER TABLE `'.$database->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
48
							$msg[] = $database->get_error();
48
						if(!$oDb->query('ALTER TABLE `'.$oDb->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
49
							$msg[] = $oDb->get_error();
49 50
						} else{
50
							$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
51
							$msg[] = 'TABLE `'.$oDb->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
51 52
						}
52 53
					} else {
53
						 $msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
54
						 $msg[] = 'TABLE `'.$oDb->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
54 55
					}
55 56
				} else {
56
					$msg[] = $database->get_error();
57
					$msg[] = $oDb->get_error();
57 58
				}
58 59
			}
59 60
// 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();
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();
65 66
				}
66 67
			}
67
			if(!$database->index_add($sTable, '', 'section_id', 'PRIMARY')) {
68
				$msg[] = ''.$database->get_error();
68
			if(!$oDb->index_add($sTable, '', 'section_id', 'PRIMARY')) {
69
				$msg[] = ''.$oDb->get_error();
69 70
			} else {
70 71
				$msg[] = 'Create PRIMARY KEY ( `section_id` )'." $OK";
71 72
			}
72 73
// change table structure
73
			$sTable = $database->TablePrefix.'mod_wysiwyg';
74
			$sTable = $oDb->TablePrefix.'mod_wysiwyg';
74 75
			$sDescription = 'LONGTEXT NOT NULL';
75 76
			$sFieldName = 'text';
76
			if(!$database->field_modify($sTable,$sFieldName,$sDescription)) {
77
				$msg[] = ''.$database->get_error();
77
			if(!$oDb->field_modify($sTable,$sFieldName,$sDescription)) {
78
				$msg[] = ''.$oDb->get_error();
78 79
			} else {
79 80
				$msg[] = 'Field ( `text` ) description has been changed successfully'." $OK";
80 81
			}
81 82
			$sFieldName = 'content';
82
			if(!$database->field_modify($sTable,$sFieldName,$sDescription)) {
83
				$msg[] = ''.$database->get_error();
83
			if(!$oDb->field_modify($sTable,$sFieldName,$sDescription)) {
84
				$msg[] = ''.$oDb->get_error();
84 85
			} else {
85 86
				$msg[] = 'Field ( `content` ) description has been changed successfully'." $OK";
86 87
			}
87
// change internal absolute Media 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 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
				$msg[] = 'Change internal absolute links into relative links'." $OK";
104
			}
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\}[\/\\\\]?/sU',
95
                                  '/\{SYSVAR\:WB_URL\}[\/\\\\]?/sU',
96
                                  '/(\{SYSVAR\:AppUrl\.MediaDir\})[\/\\\\]?/sU',
97
                                  '/(\{SYSVAR\:AppUrl\})[\/\\\\]?/sU'
98
                                );
99
                $aReplace = array( '{SYSVAR:AppUrl.MediaDir}', '{SYSVAR:AppUrl}', '\1', '\1' );
100
                while (($aEntry = $oEntrySet->fetchRow(MYSQL_ASSOC))) {
101
                    $iCount = 0;
102
                    $aEntry['content'] = preg_replace($aSearch, $aReplace, $aEntry['content'], -1, $iCount);
103
                    if ($iCount > 0) {
104
                        $iReplaced += $iCount;
105
                        $sql = 'UPDATE `'.$oDb->TablePrefix.'mod_wysiwyg` '
106
                             . 'SET `content`=\''.$oDb->escapeString($aEntry['content']).'\' '
107
                             . 'WHERE `section_id`='.$aEntry['section_id'];
108
                        $oDb->doQuery($sql);
109
                        $iRecords++;
110
                    }
111
                }
112
                $msg[] = '['.$iRecords.'] records with ['.$iReplaced.'] SYSVAR placeholder(s) repaired'." $OK";
113
            }
114
            try {
115
                $sql  = 'UPDATE `'.$sTable.'` ';
116
                $sql .= 'SET `content` = REPLACE(`content`, \'"'.$oReg->AppPath.$oReg->MediaDir.'\', \'"{SYSVAR:AppPath.MediaDir}\')';
117
                $oDb->doQuery($sql);
118
				$msg[] = 'Change internal absolute Media links into SYSVAR placeholders'." $OK";
119
            } catch(WbDatabaseException $e) {
120
				$msg[] = ''.$oDb->get_error();
121
            }
122
            try {
123
                $sql  = 'UPDATE `'.$sTable.'` ';
124
                $sql .= 'SET `content` = REPLACE(`content`, \'"'.$oReg->AppPath.'\', \'"{SYSVAR:AppPath}\')';
125
                $oDb->doQuery($sql);
126
				$msg[] = 'Change internal absolute links into SYSVAR placeholders'." $OK";
127
            } catch(WbDatabaseException $e) {
128
				$msg[] = ''.$oDb->get_error();
129
            }
105 130
// only for $callingScript upgrade-script.php
106 131
			if($globalStarted) {
107 132
				if($bDebug) {

Also available in: Unified diff