Revision 1866
Added by Dietmar over 11 years ago
upgrade.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
/** |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 | 4 |
* |
4 |
* @category modules |
|
5 |
* @package news |
|
6 |
* @subpackage upgrade |
|
7 |
* @copyright 2009-2012, WebsiteBaker Org. e.V. |
|
8 |
* @link http://www.websitebaker2.org/ |
|
9 |
* @license http://www.gnu.org/licenses/gpl.html |
|
10 |
* @platform WebsiteBaker 2.8.x |
|
11 |
* @requirements PHP 5.2.2 and higher |
|
12 |
* @version $Id$ |
|
13 |
* @filesource $HeadURL$ |
|
14 |
* @lastmodified $Date$ |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (at your option) any later version. |
|
15 | 9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 17 |
*/ |
17 | 18 |
|
19 |
/** |
|
20 |
* upgrade.php |
|
21 |
* |
|
22 |
* @category Module |
|
23 |
* @package Module_news |
|
24 |
* @subpackage upgrade |
|
25 |
* @author Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org> |
|
26 |
* @author Werner v.d.Decken <wkl@isteam.de> |
|
27 |
* @copyright Werner v.d.Decken <wkl@isteam.de> |
|
28 |
* @license http://www.gnu.org/licenses/gpl.html GPL License |
|
29 |
* @version 0.0.1 |
|
30 |
* @revision $Revision$ |
|
31 |
* @link $HeadURL$ |
|
32 |
* @lastmodified $Date$ |
|
33 |
* @since File available since 17.01.2013 |
|
34 |
* @description xyz |
|
35 |
* |
|
36 |
*/ |
|
37 |
|
|
18 | 38 |
/* -------------------------------------------------------- */ |
19 | 39 |
// Must include code to stop this file being accessed directly |
20 | 40 |
require_once( dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php'); |
... | ... | |
26 | 46 |
function mod_news_Upgrade() |
27 | 47 |
{ |
28 | 48 |
global $database, $admin, $MESSAGE,$bDebugModus; |
29 |
$msg = array();
|
|
49 |
$msg = array();
|
|
30 | 50 |
$callingScript = $_SERVER["SCRIPT_NAME"]; |
31 | 51 |
// check if upgrade startet by upgrade-script to echo a message |
32 | 52 |
$tmp = 'upgrade-script.php'; |
33 | 53 |
$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0; |
34 |
/**
|
|
35 |
* check database engine
|
|
36 |
*/
|
|
37 |
$aTable = array('mod_news_posts','mod_news_groups','mod_news_comments','mod_news_settings');
|
|
38 |
for($x=0; $x<sizeof($aTable);$x++) {
|
|
39 |
if(($sOldType = $database->getTableEngine(TABLE_PREFIX.$aTable[$x]))) {
|
|
40 |
if(('myisam' != strtolower($sOldType))) {
|
|
41 |
if(!$database->query('ALTER TABLE `'.TABLE_PREFIX.$aTable[$x].'` Engine = \'MyISAM\' ')) {
|
|
42 |
$msg[] = $database->get_error();
|
|
43 |
} else{
|
|
44 |
$msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` changed to Engine = \'MyISAM\'';
|
|
45 |
}
|
|
46 |
} else {
|
|
47 |
$msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` has Engine = \'MyISAM\'';
|
|
48 |
}
|
|
49 |
} else {
|
|
50 |
$msg[] = $database->get_error();
|
|
51 |
}
|
|
52 |
}
|
|
54 |
/**
|
|
55 |
* check database engine
|
|
56 |
*/
|
|
57 |
$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\'';
|
|
65 |
}
|
|
66 |
} else {
|
|
67 |
$msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` has Engine = \'MyISAM\'';
|
|
68 |
}
|
|
69 |
} else {
|
|
70 |
$msg[] = $database->get_error();
|
|
71 |
}
|
|
72 |
}
|
|
53 | 73 |
|
54 |
|
|
55 | 74 |
$sPagesPath = WB_PATH.PAGES_DIRECTORY; |
56 | 75 |
$sPostsPath = $sPagesPath.'/posts'; |
57 | 76 |
// create /posts/ - directory if not exists |
58 |
if(!file_exists($sPostsPath)) { |
|
59 |
if(is_writable($sPagesPath)) { |
|
60 |
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/'); |
|
61 |
} else { |
|
62 |
if(!$globalStarted){ |
|
63 |
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']); |
|
64 |
// $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']); |
|
65 |
return $msg; |
|
66 |
} else { |
|
67 |
echo ''.$MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].''; |
|
68 |
return $msg; |
|
69 |
} |
|
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); |
|
70 | 83 |
} |
71 |
$msg[] = '<strong>Directory "'.PAGES_DIRECTORY.'/posts/" created</strong>'; |
|
72 |
} else { |
|
73 |
$msg[] = '<strong>Directory "'.PAGES_DIRECTORY.'/posts/" already exists.</strong>'; |
|
84 |
if($bRetval) { |
|
85 |
$msg[] = 'Directory "'.PAGES_DIRECTORY.'/posts/" already exists or created.'; |
|
86 |
}else { |
|
87 |
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']); |
|
88 |
} |
|
89 |
}else { |
|
90 |
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']); |
|
74 | 91 |
} |
75 | 92 |
// check if new fields must be added |
76 | 93 |
$doImportDate = true; |
77 | 94 |
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_when')) { |
78 | 95 |
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_when', |
79 | 96 |
'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) { |
80 |
if($globalStarted){ |
|
81 |
echo ''.$MESSAGE['RECORD_MODIFIED_FAILED'].''; |
|
82 |
return $msg; |
|
83 |
} else { |
|
84 |
// $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']); |
|
85 | 97 |
$msg[] = $MESSAGE['RECORD_MODIFIED_FAILED']; |
86 |
return $msg;
|
|
87 |
}
|
|
98 |
} else {
|
|
99 |
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_when` added.';
|
|
88 | 100 |
} |
101 |
} else { |
|
102 |
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_when` already exists.'; |
|
103 |
$doImportDate = false; |
|
104 |
} |
|
89 | 105 |
|
90 |
if($globalStarted) { |
|
91 |
echo 'Datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_when` added.<br />'; |
|
92 |
} |
|
93 |
} else { $doImportDate = false; } |
|
94 |
|
|
95 | 106 |
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_by')) { |
96 | 107 |
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_by', |
97 | 108 |
'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) { |
98 |
if($globalStarted){ |
|
99 |
echo ''.$MESSAGE['RECORD_MODIFIED_FAILED'].''; |
|
100 |
return $msg; |
|
101 |
}else { |
|
102 |
// $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']); |
|
103 |
$msg[] = $MESSAGE['RECORD_MODIFIED_FAILED']; |
|
104 |
return $msg; |
|
105 |
} |
|
109 |
$msg[] = $MESSAGE['RECORD_MODIFIED_FAILED']; |
|
106 | 110 |
} |
107 |
if($globalStarted) {
|
|
108 |
echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_by` added.<br />';
|
|
109 |
}
|
|
111 |
} else {
|
|
112 |
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_by` already exists.';
|
|
113 |
$doImportDate = false;
|
|
110 | 114 |
} |
111 |
// preset new fields `created_by` and `created_when` from existing values
|
|
115 |
// preset new fields `created_by` and `created_by` from existing values
|
|
112 | 116 |
if($doImportDate) { |
113 | 117 |
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` '; |
114 | 118 |
$sql .= 'SET `created_by`=`posted_by`, `created_when`=`posted_when`'; |
115 | 119 |
$database->query($sql); |
116 | 120 |
} |
117 | 121 |
|
118 |
/**
|
|
119 |
* rebuild news post folder
|
|
120 |
*/
|
|
121 |
$array = rebuildFolderProtectFile($sPostsPath); |
|
122 |
/**
|
|
123 |
* rebuild news post folder
|
|
124 |
*/
|
|
125 |
// $array = rebuildFolderProtectFile($sPostsPath);
|
|
122 | 126 |
// now iterate through all existing accessfiles, |
123 | 127 |
// write its creation date into database |
124 | 128 |
$oDir = new DirectoryIterator($sPostsPath); |
... | ... | |
137 | 141 |
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` '; |
138 | 142 |
$sql .= 'SET `created_when`='.$fileinfo->getMTime().' '; |
139 | 143 |
$sql .= 'WHERE `link`=\''.$link.'\''; |
140 |
$database->query($sql); |
|
144 |
if($database->query($sql)) { |
|
145 |
// delete old access file |
|
146 |
unlink($fileinfo->getPathname()); |
|
147 |
$count++; |
|
148 |
} |
|
141 | 149 |
} |
142 |
// delete old access file |
|
143 |
unlink($fileinfo->getPathname()); |
|
144 |
$count++; |
|
145 | 150 |
} |
146 | 151 |
} |
147 | 152 |
unset($oDir); |
148 | 153 |
|
149 | 154 |
if($count > 0) { |
150 |
$msg[] = 'save date of creation from '.$count.' old accessfiles and delete these files.';
|
|
155 |
$msg[] = 'Save date of creation from '.$count.' old accessfiles and delete these files.';
|
|
151 | 156 |
} |
152 | 157 |
// ************************************************ |
153 | 158 |
// Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp' |
... | ... | |
161 | 166 |
$database->query($sql); |
162 | 167 |
// ************************************************ |
163 | 168 |
|
164 |
// rebuild all access-files |
|
165 |
$count = 0; |
|
166 |
$backSteps = preg_replace('@^'.preg_quote(WB_PATH).'@', '', $sPostsPath); |
|
167 |
$backSteps = str_repeat( '../', substr_count($backSteps, '/')); |
|
168 |
$sql = 'SELECT `page_id`,`post_id`,`section_id`,`link` '; |
|
169 |
$sql .= 'FROM `'.TABLE_PREFIX.'mod_news_posts`'; |
|
170 |
$sql .= 'WHERE `link` != \'\''; |
|
171 |
if( ($resPosts = $database->query($sql)) ) |
|
172 |
{ |
|
173 |
while( $recPost = $resPosts->fetchRow() ) |
|
174 |
{ |
|
175 |
$file = $sPagesPath.$recPost['link'].PAGE_EXTENSION; |
|
176 |
$content = |
|
177 |
'<?php'."\n". |
|
178 |
'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n". |
|
179 |
'// *** Creation date: '.date('c')."\n". |
|
180 |
'// *** Do not modify this file manually'."\n". |
|
181 |
'// *** WB will rebuild this file from time to time!!'."\n". |
|
182 |
'// *************************************************'."\n". |
|
183 |
"\t".'$page_id = '.$recPost['page_id'].';'."\n". |
|
184 |
"\t".'$section_id = '.$recPost['section_id'].';'."\n". |
|
185 |
"\t".'$post_id = '.$recPost['post_id'].';'."\n". |
|
186 |
"\t".'$post_section = '.$recPost['section_id'].';'."\n". |
|
187 |
"\t".'require(\''.$backSteps.'index.php\');'."\n". |
|
188 |
'// *************************************************'."\n"; |
|
189 |
if( file_put_contents($file, $content) !== false ) { |
|
190 |
// Chmod the file |
|
191 |
change_mode($file); |
|
192 |
}else { |
|
193 |
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']); |
|
194 |
} |
|
195 |
$count++; |
|
196 |
} |
|
197 |
$msg[] = '<strong>Number of new created access files: '.$count.'</strong>'; |
|
198 |
} |
|
199 | 169 |
// only for upgrade-script |
200 | 170 |
if($globalStarted) { |
201 | 171 |
if($bDebugModus) { |
... | ... | |
203 | 173 |
echo '<strong>'.$title.'</strong><br />'; |
204 | 174 |
} |
205 | 175 |
} |
206 |
} |
|
207 |
return $msg;
|
|
176 |
}
|
|
177 |
return ( ($globalStarted==true ) ? $globalStarted : $msg);
|
|
208 | 178 |
} |
209 | 179 |
} |
210 | 180 |
// end mod_news_Upgrade |
211 | 181 |
|
212 | 182 |
// ------------------------------------ |
213 |
|
|
214 |
$msg = mod_news_Upgrade(); |
|
215 |
|
|
216 |
|
|
217 |
/* **** END UPGRADE ********************************************************* */ |
|
183 |
// only show if manuell upgrade |
|
184 |
if( is_array($msg = mod_news_Upgrade()) ) { |
|
185 |
$sModulReorg = 'm_news_Reorg'; |
|
186 |
if(class_exists($sModulReorg)) { |
|
187 |
$oReorg = new $sModulReorg(); |
|
188 |
$msg = array_merge($msg, $oReorg->execute() ); // show details |
|
189 |
// $msg = array_merge($msg,(new $sModulReorg())->execute()); // show details |
|
190 |
} |
|
191 |
foreach($msg as $title) { |
|
192 |
echo '<strong>'.$title.'</strong><br />'; |
|
193 |
} |
|
194 |
echo '<strong>News upgrade finished </strong><br /><br>'; |
|
195 |
} |
|
196 |
/* **** END UPGRADE ********************************************************* */ |
Also available in: Unified diff
! framework/functions.php set function create_access_file to deprecated
! set ModLanguage.php to deprecated
! add methode escapeString to class WbDatabase
! update upgrade-script.php
! add getter property LastInsertId to class WbDatabase