1
|
<?php
|
2
|
/**
|
3
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
4
|
*
|
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.
|
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/>.
|
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: 1866 $
|
31
|
* @link $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/upgrade.php $
|
32
|
* @lastmodified $Date: 2013-02-19 21:47:39 +0100 (Tue, 19 Feb 2013) $
|
33
|
* @since File available since 17.01.2013
|
34
|
* @description xyz
|
35
|
*
|
36
|
*/
|
37
|
|
38
|
/* -------------------------------------------------------- */
|
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(); }
|
42
|
/* -------------------------------------------------------- */
|
43
|
/* **** START UPGRADE ******************************************************* */
|
44
|
if(!function_exists('mod_news_Upgrade'))
|
45
|
{
|
46
|
function mod_news_Upgrade()
|
47
|
{
|
48
|
global $database, $admin, $MESSAGE,$bDebugModus;
|
49
|
$msg = array();
|
50
|
$callingScript = $_SERVER["SCRIPT_NAME"];
|
51
|
// check if upgrade startet by upgrade-script to echo a message
|
52
|
$tmp = 'upgrade-script.php';
|
53
|
$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
|
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
|
}
|
73
|
|
74
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
75
|
$sPostsPath = $sPagesPath.'/posts';
|
76
|
// 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.';
|
86
|
}else {
|
87
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
88
|
}
|
89
|
}else {
|
90
|
$msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
91
|
}
|
92
|
// 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.';
|
100
|
}
|
101
|
} else {
|
102
|
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_when` already exists.';
|
103
|
$doImportDate = false;
|
104
|
}
|
105
|
|
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'];
|
110
|
}
|
111
|
} else {
|
112
|
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_by` already exists.';
|
113
|
$doImportDate = false;
|
114
|
}
|
115
|
// 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
|
}
|
121
|
|
122
|
/**
|
123
|
* rebuild news post folder
|
124
|
*/
|
125
|
// $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++;
|
148
|
}
|
149
|
}
|
150
|
}
|
151
|
}
|
152
|
unset($oDir);
|
153
|
|
154
|
if($count > 0) {
|
155
|
$msg[] = 'Save date of creation from '.$count.' old accessfiles and delete these files.';
|
156
|
}
|
157
|
// ************************************************
|
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);
|
167
|
// ************************************************
|
168
|
|
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);
|
178
|
}
|
179
|
}
|
180
|
// end mod_news_Upgrade
|
181
|
|
182
|
// ------------------------------------
|
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 ********************************************************* */
|