1 |
1457
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
1765
|
Luisehahne
|
* @category modules
|
5 |
|
|
* @package news
|
6 |
|
|
* @subpackage upgrade
|
7 |
|
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8 |
1457
|
Luisehahne
|
* @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$
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
|
18 |
1538
|
Luisehahne
|
/* -------------------------------------------------------- */
|
19 |
1587
|
darkviper
|
// Must include code to stop this file being accessed directly
|
20 |
|
|
require_once( dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
|
21 |
|
|
if(!defined('WB_PATH')) { throw new IllegalFileException(); }
|
22 |
|
|
/* -------------------------------------------------------- */
|
23 |
1457
|
Luisehahne
|
/* **** START UPGRADE ******************************************************* */
|
24 |
1477
|
Luisehahne
|
if(!function_exists('mod_news_Upgrade'))
|
25 |
|
|
{
|
26 |
1457
|
Luisehahne
|
function mod_news_Upgrade()
|
27 |
|
|
{
|
28 |
1765
|
Luisehahne
|
global $database, $admin, $MESSAGE,$bDebugModus;
|
29 |
|
|
$msg = array();
|
30 |
1457
|
Luisehahne
|
$callingScript = $_SERVER["SCRIPT_NAME"];
|
31 |
1765
|
Luisehahne
|
// check if upgrade startet by upgrade-script to echo a message
|
32 |
1457
|
Luisehahne
|
$tmp = 'upgrade-script.php';
|
33 |
|
|
$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
|
34 |
1765
|
Luisehahne
|
/**
|
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 |
|
|
}
|
53 |
1457
|
Luisehahne
|
|
54 |
1765
|
Luisehahne
|
|
55 |
1457
|
Luisehahne
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
56 |
|
|
$sPostsPath = $sPagesPath.'/posts';
|
57 |
|
|
// 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 |
1765
|
Luisehahne
|
} else {
|
62 |
1457
|
Luisehahne
|
if(!$globalStarted){
|
63 |
1538
|
Luisehahne
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
64 |
1765
|
Luisehahne
|
// $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
65 |
|
|
return $msg;
|
66 |
|
|
} else {
|
67 |
|
|
echo ''.$MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'';
|
68 |
1457
|
Luisehahne
|
return;
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
1765
|
Luisehahne
|
$msg[] = '<strong>Directory "'.PAGES_DIRECTORY.'/posts/" created</strong>';
|
72 |
|
|
} else {
|
73 |
|
|
$msg[] = '<strong>Directory "'.PAGES_DIRECTORY.'/posts/" already exists.</strong>';
|
74 |
1457
|
Luisehahne
|
}
|
75 |
|
|
// check if new fields must be added
|
76 |
|
|
$doImportDate = true;
|
77 |
|
|
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_when')) {
|
78 |
|
|
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_when',
|
79 |
|
|
'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) {
|
80 |
|
|
if($globalStarted){
|
81 |
1765
|
Luisehahne
|
echo ''.$MESSAGE['RECORD_MODIFIED_FAILED'].'';
|
82 |
1457
|
Luisehahne
|
return;
|
83 |
1765
|
Luisehahne
|
} else {
|
84 |
|
|
// $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
|
85 |
|
|
$msg[] = $$MESSAGE['RECORD_MODIFIED_FAILED'];
|
86 |
|
|
return $msg;
|
87 |
1457
|
Luisehahne
|
}
|
88 |
|
|
}
|
89 |
1765
|
Luisehahne
|
|
90 |
|
|
if($globalStarted) {
|
91 |
|
|
echo 'Datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_when` added.<br />';
|
92 |
|
|
}
|
93 |
|
|
} else { $doImportDate = false; }
|
94 |
|
|
|
95 |
1457
|
Luisehahne
|
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_by')) {
|
96 |
|
|
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_by',
|
97 |
|
|
'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) {
|
98 |
|
|
if($globalStarted){
|
99 |
1765
|
Luisehahne
|
echo ''.$MESSAGE['RECORD_MODIFIED_FAILED'].'';
|
100 |
1457
|
Luisehahne
|
return;
|
101 |
|
|
}else {
|
102 |
1765
|
Luisehahne
|
// $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
|
103 |
|
|
$msg[] = $$MESSAGE['RECORD_MODIFIED_FAILED'];
|
104 |
|
|
return $msg;
|
105 |
1457
|
Luisehahne
|
}
|
106 |
|
|
}
|
107 |
1765
|
Luisehahne
|
if($globalStarted) {
|
108 |
|
|
echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_by` added.<br />';
|
109 |
|
|
}
|
110 |
1457
|
Luisehahne
|
}
|
111 |
|
|
// preset new fields `created_by` and `created_when` from existing values
|
112 |
|
|
if($doImportDate) {
|
113 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
114 |
|
|
$sql .= 'SET `created_by`=`posted_by`, `created_when`=`posted_when`';
|
115 |
|
|
$database->query($sql);
|
116 |
|
|
}
|
117 |
1593
|
Luisehahne
|
|
118 |
1765
|
Luisehahne
|
/**
|
119 |
|
|
* rebuild news post folder
|
120 |
|
|
*/
|
121 |
1593
|
Luisehahne
|
$array = rebuildFolderProtectFile($sPostsPath);
|
122 |
1457
|
Luisehahne
|
// now iterate through all existing accessfiles,
|
123 |
|
|
// write its creation date into database
|
124 |
|
|
$oDir = new DirectoryIterator($sPostsPath);
|
125 |
|
|
$count = 0;
|
126 |
|
|
foreach ($oDir as $fileinfo)
|
127 |
|
|
{
|
128 |
|
|
$fileName = $fileinfo->getFilename();
|
129 |
|
|
if((!$fileinfo->isDot()) &&
|
130 |
|
|
($fileName != 'index.php') &&
|
131 |
|
|
(substr_compare($fileName,PAGE_EXTENSION,(0-strlen(PAGE_EXTENSION)),strlen(PAGE_EXTENSION)) === 0)
|
132 |
|
|
)
|
133 |
|
|
{
|
134 |
|
|
// save creation date from old accessfile
|
135 |
|
|
if($doImportDate) {
|
136 |
|
|
$link = '/posts/'.preg_replace('/'.preg_quote(PAGE_EXTENSION).'$/i', '', $fileinfo->getFilename());
|
137 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
138 |
|
|
$sql .= 'SET `created_when`='.$fileinfo->getMTime().' ';
|
139 |
|
|
$sql .= 'WHERE `link`=\''.$link.'\'';
|
140 |
|
|
$database->query($sql);
|
141 |
|
|
}
|
142 |
|
|
// delete old access file
|
143 |
|
|
unlink($fileinfo->getPathname());
|
144 |
|
|
$count++;
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
|
|
unset($oDir);
|
148 |
1765
|
Luisehahne
|
|
149 |
|
|
if($count > 0) {
|
150 |
|
|
$msg[] = 'save date of creation from '.$count.' old accessfiles and delete these files.';
|
151 |
1457
|
Luisehahne
|
}
|
152 |
|
|
// ************************************************
|
153 |
|
|
// Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp'
|
154 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
155 |
|
|
$sql .= 'SET `created_when`=`published_when` ';
|
156 |
|
|
$sql .= 'WHERE `published_when`<`created_when`';
|
157 |
|
|
$database->query($sql);
|
158 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
159 |
|
|
$sql .= 'SET `created_when`=`posted_when` ';
|
160 |
|
|
$sql .= 'WHERE `published_when`=0 OR `published_when`>`posted_when`';
|
161 |
|
|
$database->query($sql);
|
162 |
|
|
// ************************************************
|
163 |
|
|
|
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 |
1765
|
Luisehahne
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
194 |
1457
|
Luisehahne
|
}
|
195 |
|
|
$count++;
|
196 |
|
|
}
|
197 |
1765
|
Luisehahne
|
$msg[] = '<strong>Number of new created access files: '.$count.'</strong>';
|
198 |
1457
|
Luisehahne
|
}
|
199 |
1765
|
Luisehahne
|
// only for upgrade-script
|
200 |
|
|
if($globalStarted) {
|
201 |
|
|
if($bDebugModus) {
|
202 |
|
|
foreach($msg as $title) {
|
203 |
|
|
echo '<strong>'.$title.'</strong><br />';
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
}
|
207 |
|
|
return $msg;
|
208 |
1457
|
Luisehahne
|
}
|
209 |
1477
|
Luisehahne
|
}
|
210 |
1765
|
Luisehahne
|
// end mod_news_Upgrade
|
211 |
1477
|
Luisehahne
|
|
212 |
1538
|
Luisehahne
|
// ------------------------------------
|
213 |
1765
|
Luisehahne
|
|
214 |
|
|
$msg = mod_news_Upgrade();
|
215 |
|
|
|
216 |
|
|
|
217 |
1587
|
darkviper
|
/* **** END UPGRADE ********************************************************* */
|