1 |
1457
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
1866
|
Luisehahne
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
4 |
1457
|
Luisehahne
|
*
|
5 |
1866
|
Luisehahne
|
* 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 |
1457
|
Luisehahne
|
*
|
10 |
1866
|
Luisehahne
|
* 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 |
1457
|
Luisehahne
|
*/
|
18 |
|
|
|
19 |
1866
|
Luisehahne
|
/**
|
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 |
|
|
|
38 |
1538
|
Luisehahne
|
/* -------------------------------------------------------- */
|
39 |
1587
|
darkviper
|
// 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 |
1457
|
Luisehahne
|
/* **** START UPGRADE ******************************************************* */
|
44 |
1477
|
Luisehahne
|
if(!function_exists('mod_news_Upgrade'))
|
45 |
|
|
{
|
46 |
1457
|
Luisehahne
|
function mod_news_Upgrade()
|
47 |
|
|
{
|
48 |
1765
|
Luisehahne
|
global $database, $admin, $MESSAGE,$bDebugModus;
|
49 |
1866
|
Luisehahne
|
$msg = array();
|
50 |
1457
|
Luisehahne
|
$callingScript = $_SERVER["SCRIPT_NAME"];
|
51 |
1765
|
Luisehahne
|
// check if upgrade startet by upgrade-script to echo a message
|
52 |
1457
|
Luisehahne
|
$tmp = 'upgrade-script.php';
|
53 |
|
|
$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
|
54 |
1866
|
Luisehahne
|
/**
|
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 |
1457
|
Luisehahne
|
|
74 |
|
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
75 |
|
|
$sPostsPath = $sPagesPath.'/posts';
|
76 |
|
|
// create /posts/ - directory if not exists
|
77 |
1866
|
Luisehahne
|
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 |
1457
|
Luisehahne
|
}
|
84 |
1866
|
Luisehahne
|
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 |
1457
|
Luisehahne
|
}
|
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 |
1770
|
Luisehahne
|
$msg[] = $MESSAGE['RECORD_MODIFIED_FAILED'];
|
98 |
1866
|
Luisehahne
|
} else {
|
99 |
|
|
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_when` added.';
|
100 |
1457
|
Luisehahne
|
}
|
101 |
1866
|
Luisehahne
|
} else {
|
102 |
|
|
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_when` already exists.';
|
103 |
|
|
$doImportDate = false;
|
104 |
|
|
}
|
105 |
1765
|
Luisehahne
|
|
106 |
1457
|
Luisehahne
|
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 |
1866
|
Luisehahne
|
$msg[] = $MESSAGE['RECORD_MODIFIED_FAILED'];
|
110 |
1457
|
Luisehahne
|
}
|
111 |
1866
|
Luisehahne
|
} else {
|
112 |
|
|
$msg[] = 'TABLE `'.TABLE_PREFIX.'mod_news_posts` Datafield `created_by` already exists.';
|
113 |
|
|
$doImportDate = false;
|
114 |
1457
|
Luisehahne
|
}
|
115 |
1866
|
Luisehahne
|
// preset new fields `created_by` and `created_by` from existing values
|
116 |
1457
|
Luisehahne
|
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 |
1593
|
Luisehahne
|
|
122 |
1866
|
Luisehahne
|
/**
|
123 |
|
|
* rebuild news post folder
|
124 |
|
|
*/
|
125 |
|
|
// $array = rebuildFolderProtectFile($sPostsPath);
|
126 |
1457
|
Luisehahne
|
// 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 |
1866
|
Luisehahne
|
if($database->query($sql)) {
|
145 |
|
|
// delete old access file
|
146 |
|
|
unlink($fileinfo->getPathname());
|
147 |
|
|
$count++;
|
148 |
|
|
}
|
149 |
1457
|
Luisehahne
|
}
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
unset($oDir);
|
153 |
1765
|
Luisehahne
|
|
154 |
|
|
if($count > 0) {
|
155 |
1866
|
Luisehahne
|
$msg[] = 'Save date of creation from '.$count.' old accessfiles and delete these files.';
|
156 |
1457
|
Luisehahne
|
}
|
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 |
1765
|
Luisehahne
|
// only for upgrade-script
|
170 |
|
|
if($globalStarted) {
|
171 |
|
|
if($bDebugModus) {
|
172 |
|
|
foreach($msg as $title) {
|
173 |
|
|
echo '<strong>'.$title.'</strong><br />';
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
1866
|
Luisehahne
|
}
|
177 |
|
|
return ( ($globalStarted==true ) ? $globalStarted : $msg);
|
178 |
1457
|
Luisehahne
|
}
|
179 |
1477
|
Luisehahne
|
}
|
180 |
1765
|
Luisehahne
|
// end mod_news_Upgrade
|
181 |
1477
|
Luisehahne
|
|
182 |
1538
|
Luisehahne
|
// ------------------------------------
|
183 |
1866
|
Luisehahne
|
// 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 ********************************************************* */
|