1 |
1457
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category WebsiteBaker
|
5 |
|
|
* @package modules
|
6 |
|
|
* @subpackage news
|
7 |
|
|
* @copyright 2009-2011, 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.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 |
1538
|
Luisehahne
|
global $database, $msg, $admin, $MESSAGE;
|
29 |
1457
|
Luisehahne
|
$callingScript = $_SERVER["SCRIPT_NAME"];
|
30 |
|
|
$tmp = 'upgrade-script.php';
|
31 |
|
|
$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
|
32 |
|
|
|
33 |
|
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
34 |
|
|
$sPostsPath = $sPagesPath.'/posts';
|
35 |
|
|
// create /posts/ - directory if not exists
|
36 |
|
|
if(!file_exists($sPostsPath)) {
|
37 |
|
|
if(is_writable($sPagesPath)) {
|
38 |
|
|
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
|
39 |
|
|
}else {
|
40 |
|
|
if(!$globalStarted){
|
41 |
1538
|
Luisehahne
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
42 |
1457
|
Luisehahne
|
}else {
|
43 |
1538
|
Luisehahne
|
$msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'<br />';
|
44 |
1457
|
Luisehahne
|
return;
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
if($globalStarted) {echo 'directory "'.PAGES_DIRECTORY.'/posts/" created.<br />'; }
|
48 |
|
|
}
|
49 |
|
|
// check if new fields must be added
|
50 |
|
|
$doImportDate = true;
|
51 |
|
|
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_when')) {
|
52 |
|
|
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_when',
|
53 |
|
|
'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) {
|
54 |
|
|
if($globalStarted){
|
55 |
|
|
echo $MESSAGE['RECORD_MODIFIED_FAILED'].'<br />';
|
56 |
|
|
return;
|
57 |
|
|
}else {
|
58 |
|
|
$admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
if($globalStarted) { echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_when` added.<br />'; }
|
62 |
|
|
}else { $doImportDate = false; }
|
63 |
|
|
if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_by')) {
|
64 |
|
|
if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_by',
|
65 |
|
|
'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) {
|
66 |
|
|
if($globalStarted){
|
67 |
|
|
echo $MESSAGE['RECORD_MODIFIED_FAILED'].'<br />';
|
68 |
|
|
return;
|
69 |
|
|
}else {
|
70 |
|
|
$admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
if($globalStarted) {echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_by` added.<br />'; }
|
74 |
|
|
}
|
75 |
|
|
// preset new fields `created_by` and `created_when` from existing values
|
76 |
|
|
if($doImportDate) {
|
77 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
78 |
|
|
$sql .= 'SET `created_by`=`posted_by`, `created_when`=`posted_when`';
|
79 |
|
|
$database->query($sql);
|
80 |
|
|
}
|
81 |
|
|
// now iterate through all existing accessfiles,
|
82 |
|
|
// write its creation date into database
|
83 |
|
|
$oDir = new DirectoryIterator($sPostsPath);
|
84 |
|
|
$count = 0;
|
85 |
|
|
foreach ($oDir as $fileinfo)
|
86 |
|
|
{
|
87 |
|
|
$fileName = $fileinfo->getFilename();
|
88 |
|
|
if((!$fileinfo->isDot()) &&
|
89 |
|
|
($fileName != 'index.php') &&
|
90 |
|
|
(substr_compare($fileName,PAGE_EXTENSION,(0-strlen(PAGE_EXTENSION)),strlen(PAGE_EXTENSION)) === 0)
|
91 |
|
|
)
|
92 |
|
|
{
|
93 |
|
|
// save creation date from old accessfile
|
94 |
|
|
if($doImportDate) {
|
95 |
|
|
$link = '/posts/'.preg_replace('/'.preg_quote(PAGE_EXTENSION).'$/i', '', $fileinfo->getFilename());
|
96 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
97 |
|
|
$sql .= 'SET `created_when`='.$fileinfo->getMTime().' ';
|
98 |
|
|
$sql .= 'WHERE `link`=\''.$link.'\'';
|
99 |
|
|
$database->query($sql);
|
100 |
|
|
}
|
101 |
|
|
// delete old access file
|
102 |
|
|
unlink($fileinfo->getPathname());
|
103 |
|
|
$count++;
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
unset($oDir);
|
107 |
|
|
if($globalStarted && $count > 0) {
|
108 |
1538
|
Luisehahne
|
$msg[] = 'save date of creation from '.$count.' old accessfiles and delete these files.<br />';
|
109 |
1457
|
Luisehahne
|
}
|
110 |
|
|
// ************************************************
|
111 |
|
|
// Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp'
|
112 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
113 |
|
|
$sql .= 'SET `created_when`=`published_when` ';
|
114 |
|
|
$sql .= 'WHERE `published_when`<`created_when`';
|
115 |
|
|
$database->query($sql);
|
116 |
|
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
117 |
|
|
$sql .= 'SET `created_when`=`posted_when` ';
|
118 |
|
|
$sql .= 'WHERE `published_when`=0 OR `published_when`>`posted_when`';
|
119 |
|
|
$database->query($sql);
|
120 |
|
|
// ************************************************
|
121 |
|
|
|
122 |
|
|
// rebuild all access-files
|
123 |
|
|
$count = 0;
|
124 |
|
|
$backSteps = preg_replace('@^'.preg_quote(WB_PATH).'@', '', $sPostsPath);
|
125 |
|
|
$backSteps = str_repeat( '../', substr_count($backSteps, '/'));
|
126 |
|
|
$sql = 'SELECT `page_id`,`post_id`,`section_id`,`link` ';
|
127 |
|
|
$sql .= 'FROM `'.TABLE_PREFIX.'mod_news_posts`';
|
128 |
|
|
$sql .= 'WHERE `link` != \'\'';
|
129 |
|
|
if( ($resPosts = $database->query($sql)) )
|
130 |
|
|
{
|
131 |
|
|
while( $recPost = $resPosts->fetchRow() )
|
132 |
|
|
{
|
133 |
|
|
$file = $sPagesPath.$recPost['link'].PAGE_EXTENSION;
|
134 |
|
|
$content =
|
135 |
|
|
'<?php'."\n".
|
136 |
|
|
'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n".
|
137 |
|
|
'// *** Creation date: '.date('c')."\n".
|
138 |
|
|
'// *** Do not modify this file manually'."\n".
|
139 |
|
|
'// *** WB will rebuild this file from time to time!!'."\n".
|
140 |
|
|
'// *************************************************'."\n".
|
141 |
|
|
"\t".'$page_id = '.$recPost['page_id'].';'."\n".
|
142 |
|
|
"\t".'$section_id = '.$recPost['section_id'].';'."\n".
|
143 |
|
|
"\t".'$post_id = '.$recPost['post_id'].';'."\n".
|
144 |
|
|
"\t".'$post_section = '.$recPost['section_id'].';'."\n".
|
145 |
|
|
"\t".'require(\''.$backSteps.'index.php\');'."\n".
|
146 |
|
|
'// *************************************************'."\n";
|
147 |
|
|
if( file_put_contents($file, $content) !== false ) {
|
148 |
|
|
// Chmod the file
|
149 |
|
|
change_mode($file);
|
150 |
|
|
}else {
|
151 |
|
|
if($globalStarted){
|
152 |
1538
|
Luisehahne
|
$msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'<br />';
|
153 |
1457
|
Luisehahne
|
return;
|
154 |
|
|
}else {
|
155 |
1538
|
Luisehahne
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
156 |
1457
|
Luisehahne
|
}
|
157 |
|
|
}
|
158 |
|
|
$count++;
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
1538
|
Luisehahne
|
if($globalStarted) { $msg[] = 'created '.$count.' new accessfiles.'; }
|
162 |
1457
|
Luisehahne
|
}
|
163 |
1477
|
Luisehahne
|
}
|
164 |
|
|
|
165 |
1587
|
darkviper
|
$msg = array();
|
166 |
|
|
$aTable = array('mod_news_posts','mod_news_groups','mod_news_comments','mod_news_settings');
|
167 |
|
|
for($x=0; $x<sizeof($aTable);$x++) {
|
168 |
|
|
if(($sOldType = $database->getTableEngine(TABLE_PREFIX.$aTable[$x]))) {
|
169 |
|
|
if(('myisam' != strtolower($sOldType))) {
|
170 |
|
|
if(!$database->query('ALTER TABLE `'.TABLE_PREFIX.$aTable[$x].'` Engine = \'MyISAM\' ')) {
|
171 |
|
|
$msg[] = $database->get_error();
|
172 |
|
|
}
|
173 |
1538
|
Luisehahne
|
}
|
174 |
1587
|
darkviper
|
} else {
|
175 |
|
|
$msg[] = $database->get_error();
|
176 |
1538
|
Luisehahne
|
}
|
177 |
|
|
}
|
178 |
|
|
// ------------------------------------
|
179 |
1457
|
Luisehahne
|
mod_news_Upgrade();
|
180 |
1587
|
darkviper
|
/* **** END UPGRADE ********************************************************* */
|