Revision 1895
Added by Dietmar over 11 years ago
upgrade.php | ||
---|---|---|
37 | 37 |
|
38 | 38 |
/* -------------------------------------------------------- */ |
39 | 39 |
// Must include code to stop this file being accessed directly |
40 |
require_once( dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php'); |
|
41 |
if(!defined('WB_PATH')) { throw new IllegalFileException(); } |
|
40 |
if(!defined('WB_URL')) { |
|
41 |
require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php'); |
|
42 |
throw new IllegalFileException(); |
|
43 |
} |
|
44 |
|
|
45 |
|
|
42 | 46 |
/* -------------------------------------------------------- */ |
43 | 47 |
/* **** START UPGRADE ******************************************************* */ |
44 |
if(!function_exists('mod_news_Upgrade')) |
|
45 |
{ |
|
46 |
function mod_news_Upgrade() |
|
48 |
//if(!function_exists('mod_news_Upgrade'))
|
|
49 |
//{
|
|
50 |
function mod_news_Upgrade($bDebug=false)
|
|
47 | 51 |
{ |
48 |
global $database, $admin, $MESSAGE,$bDebugModus; |
|
49 |
$msg = array(); |
|
52 |
global $OK ,$FAIL; |
|
53 |
$database=WbDatabase::getInstance(); |
|
54 |
$mLang = Translate::getinstance(); |
|
55 |
$sModName = basename(dirname(__FILE__)); |
|
56 |
$mLang->enableAddon('modules\\'.$sModName); |
|
57 |
$msg = array(); |
|
50 | 58 |
$callingScript = $_SERVER["SCRIPT_NAME"]; |
51 | 59 |
// check if upgrade startet by upgrade-script to echo a message |
52 | 60 |
$tmp = 'upgrade-script.php'; |
53 | 61 |
$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0; |
54 |
/** |
|
55 |
* check database engine |
|
56 |
*/ |
|
62 |
// check for missing tables, if true stop the upgrade |
|
57 | 63 |
$aTable = array('mod_news_posts','mod_news_groups','mod_news_comments','mod_news_settings'); |
58 |
for($x=0; $x<sizeof($aTable);$x++) { |
|
59 |
if(($sOldType = $database->getTableEngine(TABLE_PREFIX.$aTable[$x]))) { |
|
60 |
if(('myisam' != strtolower($sOldType))) { |
|
61 |
if(!$database->query('ALTER TABLE `'.TABLE_PREFIX.$aTable[$x].'` Engine = \'MyISAM\' ')) { |
|
62 |
$msg[] = $database->get_error(); |
|
63 |
} else{ |
|
64 |
$msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` changed to Engine = \'MyISAM\''; |
|
64 |
$aPackage = UpgradeHelper::existsAllTables($aTable); |
|
65 |
if( sizeof($aPackage) > 0){ |
|
66 |
$msg[] = 'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL; |
|
67 |
$msg[] = "WYSIWYG upgrade failed $FAIL"; |
|
68 |
if($globalStarted) { |
|
69 |
echo '<strong>'.implode('<br />',$msg).'</strong><br />'; |
|
70 |
} |
|
71 |
$mLang->disableAddon(); |
|
72 |
return ( ($globalStarted==true ) ? $globalStarted : $msg); |
|
73 |
} else { |
|
74 |
/** |
|
75 |
* check database engine |
|
76 |
*/ |
|
77 |
for($x=0; $x<sizeof($aTable);$x++) { |
|
78 |
if(($sOldType = $database->getTableEngine($database->TablePrefix.$aTable[$x]))) { |
|
79 |
if(('myisam' != strtolower($sOldType))) { |
|
80 |
if(!$database->query('ALTER TABLE `'.$database->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) { |
|
81 |
$msg[] = $database->get_error()." $FAIL"; |
|
82 |
} else{ |
|
83 |
$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK"; |
|
84 |
} |
|
85 |
} else { |
|
86 |
$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK"; |
|
65 | 87 |
} |
66 | 88 |
} else { |
67 |
$msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` has Engine = \'MyISAM\'';
|
|
89 |
$msg[] = $database->get_error()." $FAIL";
|
|
68 | 90 |
} |
69 |
} else { |
|
70 |
$msg[] = $database->get_error(); |
|
71 | 91 |
} |
72 |
} |
|
73 | 92 |
|
74 |
$sPagesPath = WB_PATH.PAGES_DIRECTORY; |
|
75 |
$sPostsPath = $sPagesPath.'/posts'; |
|
93 |
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
|
94 |
$sPostsPath = $sPagesPath.'/posts';
|
|
76 | 95 |
// create /posts/ - directory if not exists |
77 |
if(is_writable($sPagesPath)) { |
|
78 |
if(!($bRetval = is_dir($sPostsPath))) { |
|
79 |
$iOldUmask = umask(0) ; |
|
80 |
// sanitize directory mode to 'o+rwx/g+x/u+x' and create path |
|
81 |
$bRetval = mkdir($sPostsPath, (OCTAL_DIR_MODE |0711), true); |
|
82 |
umask($iOldUmask); |
|
83 |
} |
|
84 |
if($bRetval) { |
|
85 |
$msg[] = 'Directory "'.PAGES_DIRECTORY.'/posts/" already exists or created.'; |
|
96 |
if(is_writable($sPagesPath)) { |
|
97 |
if(!($bRetval = is_dir($sPostsPath))) { |
|
98 |
$iOldUmask = umask(0) ; |
|
99 |
// sanitize directory mode to 'o+rwx/g+x/u+x' and create path |
|
100 |
$bRetval = mkdir($sPostsPath, (OCTAL_DIR_MODE |0711), true); |
|
101 |
umask($iOldUmask); |
|
102 |
} |
|
103 |
if($bRetval) { |
|
104 |
$msg[] = 'Directory "'.PAGES_DIRECTORY.'/posts/" already exists or created.'." $OK"; |
|
105 |
}else { |
|
106 |
$msg[] = ($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE)." $FAIL"; |
|
107 |
} |
|
86 | 108 |
}else { |
87 |
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
|
109 |
$msg[] = ($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE)." $FAIL";
|
|
88 | 110 |
} |
89 |
}else { |
|
90 |
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']); |
|
91 |
} |
|
92 | 111 |
// check if new fields must be added |
93 |
$doImportDate = true; |
|
94 |
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_when')) { |
|
95 |
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_when', |
|
96 |
'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) { |
|
97 |
$msg[] = $MESSAGE['RECORD_MODIFIED_FAILED']; |
|
98 |
} else { |
|
99 |
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_when` added.'; |
|
112 |
$doImportDate = true; |
|
113 |
if(!$database->field_exists($database->TablePrefix.'mod_news_posts', 'created_when')) { |
|
114 |
if(!$database->field_add($database->TablePrefix.'mod_news_posts', 'created_when', |
|
115 |
'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) { |
|
116 |
$msg[] = $mLang->MESSAGE_RECORD_MODIFIED_FAILED." $FAIL"; |
|
117 |
} else { |
|
118 |
$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_when` added.'." $OK"; |
|
119 |
} |
|
120 |
} else { |
|
121 |
$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_when` already exists.'." $OK"; |
|
122 |
$doImportDate = false; |
|
100 | 123 |
} |
101 |
} else { |
|
102 |
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_when` already exists.'; |
|
103 |
$doImportDate = false; |
|
104 |
} |
|
105 | 124 |
|
106 |
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_by')) { |
|
107 |
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_by', |
|
108 |
'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) { |
|
109 |
$msg[] = $MESSAGE['RECORD_MODIFIED_FAILED']; |
|
125 |
if(!$database->field_exists($database->TablePrefix.'mod_news_posts', 'created_by')) { |
|
126 |
if(!$database->field_add($database->TablePrefix.'mod_news_posts', 'created_by', |
|
127 |
'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) { |
|
128 |
$msg[] = $mLang->MESSAGE_RECORD_MODIFIED_FAILED." $FAIL"; |
|
129 |
} else { |
|
130 |
$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_by` added.'." $OK"; |
|
131 |
} |
|
132 |
} else { |
|
133 |
$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_by` already exists.'." $OK"; |
|
134 |
$doImportDate = false; |
|
110 | 135 |
} |
111 |
} else { |
|
112 |
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_by` already exists.'; |
|
113 |
$doImportDate = false; |
|
114 |
} |
|
115 | 136 |
// preset new fields `created_by` and `created_by` from existing values |
116 |
if($doImportDate) { |
|
117 |
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
|
118 |
$sql .= 'SET `created_by`=`posted_by`, `created_when`=`posted_when`'; |
|
119 |
$database->query($sql); |
|
120 |
} |
|
137 |
if($doImportDate) {
|
|
138 |
$sql = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` ';
|
|
139 |
$sql .= 'SET `created_by`=`posted_by`, `created_when`=`posted_when`';
|
|
140 |
$database->query($sql);
|
|
141 |
}
|
|
121 | 142 |
|
122 | 143 |
/** |
123 | 144 |
* rebuild news post folder |
124 | 145 |
*/ |
125 | 146 |
// $array = rebuildFolderProtectFile($sPostsPath); |
126 |
// now iterate through all existing accessfiles, |
|
127 |
// write its creation date into database |
|
128 |
$oDir = new DirectoryIterator($sPostsPath); |
|
129 |
$count = 0; |
|
130 |
foreach ($oDir as $fileinfo) |
|
131 |
{ |
|
132 |
$fileName = $fileinfo->getFilename(); |
|
133 |
if((!$fileinfo->isDot()) && |
|
134 |
($fileName != 'index.php') && |
|
135 |
(substr_compare($fileName,PAGE_EXTENSION,(0-strlen(PAGE_EXTENSION)),strlen(PAGE_EXTENSION)) === 0) |
|
136 |
) |
|
137 |
{ |
|
138 |
// save creation date from old accessfile |
|
139 |
if($doImportDate) { |
|
140 |
$link = '/posts/'.preg_replace('/'.preg_quote(PAGE_EXTENSION).'$/i', '', $fileinfo->getFilename()); |
|
141 |
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` '; |
|
142 |
$sql .= 'SET `created_when`='.$fileinfo->getMTime().' '; |
|
143 |
$sql .= 'WHERE `link`=\''.$link.'\''; |
|
144 |
if($database->query($sql)) { |
|
145 |
// delete old access file |
|
146 |
unlink($fileinfo->getPathname()); |
|
147 |
$count++; |
|
147 |
// now iterate through all existing accessfiles, |
|
148 |
// write its creation date into database |
|
149 |
if(is_writable($sPostsPath)) { |
|
150 |
$oDir = new DirectoryIterator($sPostsPath); |
|
151 |
$count = 0; |
|
152 |
foreach ($oDir as $fileinfo) |
|
153 |
{ |
|
154 |
$fileName = $fileinfo->getFilename(); |
|
155 |
if((!$fileinfo->isDot()) && |
|
156 |
($fileName != 'index.php') && |
|
157 |
(substr_compare($fileName,PAGE_EXTENSION,(0-strlen(PAGE_EXTENSION)),strlen(PAGE_EXTENSION)) === 0) |
|
158 |
) |
|
159 |
{ |
|
160 |
// save creation date from old accessfile |
|
161 |
if($doImportDate) { |
|
162 |
$link = '/posts/'.preg_replace('/'.preg_quote(PAGE_EXTENSION).'$/i', '', $fileinfo->getFilename()); |
|
163 |
$sql = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` '; |
|
164 |
$sql .= 'SET `created_when`='.$fileinfo->getMTime().' '; |
|
165 |
$sql .= 'WHERE `link`=\''.$link.'\''; |
|
166 |
if($database->query($sql)) { |
|
167 |
// delete old access file |
|
168 |
unlink($fileinfo->getPathname()); |
|
169 |
$count++; |
|
170 |
} |
|
171 |
} |
|
148 | 172 |
} |
149 | 173 |
} |
174 |
unset($oDir); |
|
150 | 175 |
} |
151 |
} |
|
152 |
unset($oDir); |
|
153 |
|
|
154 |
if($count > 0) { |
|
155 |
$msg[] = 'Save date of creation from '.$count.' old accessfiles and delete these files.'; |
|
156 |
} |
|
176 |
if($count > 0) { |
|
177 |
$msg[] = 'Save date of creation from '.$count.' old accessfiles and delete these files.'." $OK"; |
|
178 |
} |
|
157 | 179 |
// ************************************************ |
158 |
// Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp' |
|
159 |
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
|
160 |
$sql .= 'SET `created_when`=`published_when` '; |
|
161 |
$sql .= 'WHERE `published_when`<`created_when`'; |
|
162 |
$database->query($sql); |
|
163 |
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
|
164 |
$sql .= 'SET `created_when`=`posted_when` '; |
|
165 |
$sql .= 'WHERE `published_when`=0 OR `published_when`>`posted_when`'; |
|
166 |
$database->query($sql); |
|
180 |
// Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp'
|
|
181 |
$sql = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` ';
|
|
182 |
$sql .= 'SET `created_when`=`published_when` ';
|
|
183 |
$sql .= 'WHERE `published_when`<`created_when`';
|
|
184 |
$database->query($sql);
|
|
185 |
$sql = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` ';
|
|
186 |
$sql .= 'SET `created_when`=`posted_when` ';
|
|
187 |
$sql .= 'WHERE `published_when`=0 OR `published_when`>`posted_when`';
|
|
188 |
$database->query($sql);
|
|
167 | 189 |
// ************************************************ |
168 | 190 |
|
169 |
// only for upgrade-script |
|
170 |
if($globalStarted) { |
|
171 |
if($bDebugModus) { |
|
172 |
foreach($msg as $title) { |
|
173 |
echo '<strong>'.$title.'</strong><br />'; |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
return ( ($globalStarted==true ) ? $globalStarted : $msg); |
|
191 |
// only for upgrade-script |
|
192 |
if($globalStarted) { |
|
193 |
if($bDebug) { |
|
194 |
echo '<strong>'.implode('<br />',$msg).'</strong><br />'; |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
$msg[] = "News upgrade successfull finished $OK"; |
|
199 |
if($globalStarted) { |
|
200 |
echo "<strong>News upgrade successfull finished $OK</strong><br />"; |
|
201 |
} |
|
202 |
$mLang->disableAddon(); |
|
203 |
return ( ($globalStarted==true ) ? $globalStarted : $msg); |
|
178 | 204 |
} |
179 |
} |
|
205 |
//}
|
|
180 | 206 |
// end mod_news_Upgrade |
181 | 207 |
|
182 | 208 |
// ------------------------------------ |
183 | 209 |
// only show if manuell upgrade |
184 |
if( is_array($msg = mod_news_Upgrade()) ) { |
|
210 |
$bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false); |
|
211 |
// Don't show the messages twice |
|
212 |
if( is_array($msg = mod_news_Upgrade($bDebugModus)) ) { |
|
185 | 213 |
$sModulReorg = 'm_news_Reorg'; |
186 | 214 |
if(class_exists($sModulReorg)) { |
187 | 215 |
$oReorg = new $sModulReorg(); |
188 | 216 |
$msg = array_merge($msg, $oReorg->execute() ); // show details |
189 |
// $msg = array_merge($msg,(new $sModulReorg())->execute()); // show details |
|
190 | 217 |
} |
191 |
foreach($msg as $title) { |
|
192 |
echo '<strong>'.$title.'</strong><br />'; |
|
193 |
} |
|
194 |
echo '<strong>News upgrade finished </strong><br /><br>'; |
|
218 |
echo '<strong>'.implode('<br />',$msg).'</strong><br />'; |
|
195 | 219 |
} |
196 | 220 |
/* **** END UPGRADE ********************************************************* */ |
197 | 221 |
Also available in: Unified diff
! update jsadmin module and set Version to 1.4.1
! update news module and set Version to 3.8.7