1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Xmf\Database\Tables; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Upgrade from 2.5.10 to 2.5.11 |
7
|
|
|
* |
8
|
|
|
* @copyright (c) 2000-2023 XOOPS Project (https://xoops.org) |
9
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
10
|
|
|
* @package Upgrade |
11
|
|
|
* @since 2.5.11 |
12
|
|
|
* @author XOOPS Team |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
class Upgrade_2511 extends XoopsUpgrade |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* __construct |
19
|
|
|
*/ |
20
|
|
|
public function __construct() |
21
|
|
|
{ |
22
|
|
|
parent::__construct(basename(__DIR__)); |
23
|
|
|
$this->tasks = array( |
24
|
|
|
'cleancache', |
25
|
|
|
'bannerintsize', |
26
|
|
|
'captchadata', |
27
|
|
|
'configkey', |
28
|
|
|
'modulesvarchar', |
29
|
|
|
'qmail', |
30
|
|
|
'rmindexhtml', |
31
|
|
|
'textsanitizer', |
32
|
|
|
'xoopsconfig', |
33
|
|
|
'templates', |
34
|
|
|
'templatesadmin', |
35
|
|
|
'zapsmarty', |
36
|
|
|
'notificationmethod', |
37
|
|
|
); |
38
|
|
|
$this->usedFiles = array(); |
39
|
|
|
$this->pathsToCheck = array( |
40
|
|
|
XOOPS_ROOT_PATH . '/cache', |
41
|
|
|
XOOPS_ROOT_PATH . '/class', |
42
|
|
|
XOOPS_ROOT_PATH . '/Frameworks', |
43
|
|
|
XOOPS_ROOT_PATH . '/images', |
44
|
|
|
XOOPS_ROOT_PATH . '/include', |
45
|
|
|
XOOPS_ROOT_PATH . '/kernel', |
46
|
|
|
XOOPS_ROOT_PATH . '/language', |
47
|
|
|
XOOPS_ROOT_PATH . '/media', |
48
|
|
|
XOOPS_ROOT_PATH . '/modules/pm', |
49
|
|
|
XOOPS_ROOT_PATH . '/modules/profile', |
50
|
|
|
XOOPS_ROOT_PATH . '/modules/protector', |
51
|
|
|
XOOPS_ROOT_PATH . '/modules/system', |
52
|
|
|
XOOPS_ROOT_PATH . '/templates_c', |
53
|
|
|
XOOPS_ROOT_PATH . '/themes/default', |
54
|
|
|
XOOPS_ROOT_PATH . '/themes/xbootstrap', |
55
|
|
|
XOOPS_ROOT_PATH . '/themes/xswatch', |
56
|
|
|
XOOPS_ROOT_PATH . '/themes/xswatch4', |
57
|
|
|
XOOPS_ROOT_PATH . '/uploads', |
58
|
|
|
XOOPS_VAR_PATH, |
59
|
|
|
XOOPS_PATH, |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected $cleanCacheKey = 'cache-cleaned'; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* We must remove stale template caches and compiles |
67
|
|
|
* |
68
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
69
|
|
|
*/ |
70
|
|
|
public function check_cleancache() |
71
|
|
|
{ |
72
|
|
|
if (!array_key_exists($this->cleanCacheKey, $_SESSION) |
73
|
|
|
|| $_SESSION[$this->cleanCacheKey]===false) { |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
return true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Remove all caches and compiles |
81
|
|
|
* |
82
|
|
|
* @return bool true if applied, false if failed |
83
|
|
|
*/ |
84
|
|
|
public function apply_cleancache() |
85
|
|
|
{ |
86
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php'; |
87
|
|
|
$maintenance = new SystemMaintenance(); |
88
|
|
|
$result = $maintenance->CleanCache(array(1,2,3)); |
89
|
|
|
if ($result===true) { |
90
|
|
|
$_SESSION[$this->cleanCacheKey] = true; |
91
|
|
|
} |
92
|
|
|
return $result; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Determine if columns are declared mediumint, and if |
97
|
|
|
* so, queue ddl to alter to int. |
98
|
|
|
* |
99
|
|
|
* @param Tables $migrate |
100
|
|
|
* @param string $bannerTableName |
101
|
|
|
* @param string[] $bannerColumnNames array of columns to check |
102
|
|
|
* |
103
|
|
|
* @return integer count of queue items added |
104
|
|
|
*/ |
105
|
|
|
protected function fromMediumToInt(Tables $migrate, $bannerTableName, $bannerColumnNames) |
106
|
|
|
{ |
107
|
|
|
$migrate->useTable($bannerTableName); |
108
|
|
|
$count = 0; |
109
|
|
|
foreach ($bannerColumnNames as $column) { |
110
|
|
|
$attributes = $migrate->getColumnAttributes($bannerTableName, $column); |
111
|
|
|
if (0 === strpos(trim($attributes), 'mediumint')) { |
|
|
|
|
112
|
|
|
$count++; |
113
|
|
|
$migrate->alterColumn($bannerTableName, $column, 'int(10) UNSIGNED NOT NULL DEFAULT \'0\''); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
return $count; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
private $bannerTableName = 'banner'; |
120
|
|
|
private $bannerColumnNames = array('impmade', 'clicks'); |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Increase count columns from mediumint to int |
124
|
|
|
* |
125
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
126
|
|
|
*/ |
127
|
|
|
public function check_bannerintsize() |
128
|
|
|
{ |
129
|
|
|
$migrate = new Tables(); |
130
|
|
|
$count = $this->fromMediumToInt($migrate, $this->bannerTableName, $this->bannerColumnNames); |
131
|
|
|
|
132
|
|
|
return $count==0; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Increase count columns from mediumint to int (Think BIG!) |
137
|
|
|
* |
138
|
|
|
* @return bool true if applied, false if failed |
139
|
|
|
*/ |
140
|
|
|
public function apply_bannerintsize() |
141
|
|
|
{ |
142
|
|
|
$migrate = new Tables(); |
143
|
|
|
|
144
|
|
|
$count = $this->fromMediumToInt($migrate, $this->bannerTableName, $this->bannerColumnNames); |
145
|
|
|
|
146
|
|
|
$result = $migrate->executeQueue(true); |
147
|
|
|
if (false === $result) { |
148
|
|
|
$this->logs[] = sprintf( |
149
|
|
|
'Migration of %s table failed. Error: %s - %s' . |
150
|
|
|
$this->bannerTableName, |
151
|
|
|
$migrate->getLastErrNo(), |
152
|
|
|
$migrate->getLastError() |
153
|
|
|
); |
154
|
|
|
return false; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
return $count!==0; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Add qmail as valid mailmethod |
162
|
|
|
* |
163
|
|
|
* @return bool |
164
|
|
|
*/ |
165
|
|
|
public function check_qmail() |
166
|
|
|
{ |
167
|
|
|
/** @var XoopsMySQLDatabase $db */ |
168
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
169
|
|
|
|
170
|
|
|
$table = $db->prefix('configoption'); |
171
|
|
|
|
172
|
|
|
$sql = sprintf( |
173
|
|
|
'SELECT count(*) FROM `%s` ' |
174
|
|
|
. "WHERE `conf_id` = 64 AND `confop_name` = 'qmail'", |
175
|
|
|
$db->escape($table) |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
/** @var mysqli_result $result */ |
179
|
|
|
$result = $db->query($sql); |
180
|
|
|
if ($db->isResultSet($result)) { |
181
|
|
|
$row = $db->fetchRow($result); |
182
|
|
|
if ($row) { |
183
|
|
|
$count = $row[0]; |
184
|
|
|
return (0 === (int) $count) ? false : true; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
return false; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Add qmail as valid mailmethod |
192
|
|
|
* |
193
|
|
|
* phpMailer has qmail support, similar to but slightly different than sendmail |
194
|
|
|
* This will allow webmasters to utilize qmail if it is provisioned on server. |
195
|
|
|
* |
196
|
|
|
* @return bool |
197
|
|
|
*/ |
198
|
|
|
public function apply_qmail() |
199
|
|
|
{ |
200
|
|
|
$migrate = new Tables(); |
201
|
|
|
$migrate->useTable('configoption'); |
202
|
|
|
$migrate->insert( |
203
|
|
|
'configoption', |
204
|
|
|
array('confop_name' => 'qmail', 'confop_value' => 'qmail', 'conf_id' => 64) |
205
|
|
|
); |
206
|
|
|
return $migrate->executeQueue(true); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Do we need to move captcha writable data? |
211
|
|
|
* |
212
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
213
|
|
|
*/ |
214
|
|
|
public function check_captchadata() |
215
|
|
|
{ |
216
|
|
|
$captchaConfigFile = XOOPS_VAR_PATH . '/configs/captcha/config.php'; |
217
|
|
|
$oldCaptchaConfigFile = XOOPS_ROOT_PATH . '/class/captcha/config.php'; |
218
|
|
|
if (!file_exists($oldCaptchaConfigFile)) { // nothing to copy |
219
|
|
|
return true; |
220
|
|
|
} |
221
|
|
|
return file_exists($captchaConfigFile); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Attempt to make the supplied path |
226
|
|
|
* |
227
|
|
|
* @param string $newPath |
228
|
|
|
* |
229
|
|
|
* @return bool |
230
|
|
|
*/ |
231
|
|
|
private function makeDirectory($newPath) |
232
|
|
|
{ |
233
|
|
|
if (!mkdir($newPath) && !is_dir($newPath)) { |
234
|
|
|
$this->logs[] = sprintf('Captcha config directory %s was not created', $newPath); |
235
|
|
|
return false; |
236
|
|
|
} |
237
|
|
|
return true; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Copy file $source to $destination |
242
|
|
|
* |
243
|
|
|
* @param string $source |
244
|
|
|
* @param string $destination |
245
|
|
|
* |
246
|
|
|
* @return bool true if successful, false on error |
247
|
|
|
*/ |
248
|
|
|
private function copyFile($source, $destination) |
249
|
|
|
{ |
250
|
|
|
if (!file_exists($destination)) { // don't overwrite anything |
251
|
|
|
$result = copy($source, $destination); |
252
|
|
|
if (false === $result) { |
253
|
|
|
$this->logs[] = sprintf('Captcha config file copy %s failed', basename($source)); |
254
|
|
|
return false; |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
return true; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Move captcha configs to xoops_data to segregate writable data |
262
|
|
|
* |
263
|
|
|
* @return bool |
264
|
|
|
*/ |
265
|
|
|
public function apply_captchadata() |
266
|
|
|
{ |
267
|
|
|
$returnResult = false; |
268
|
|
|
$sourcePath = XOOPS_ROOT_PATH . '/class/captcha/'; |
269
|
|
|
$destinationPath = XOOPS_VAR_PATH . '/configs/captcha/'; |
270
|
|
|
|
271
|
|
|
if (!file_exists($destinationPath)) { |
272
|
|
|
$this->makeDirectory($destinationPath); |
273
|
|
|
} |
274
|
|
|
$directory = dir($sourcePath); |
275
|
|
|
if (false === $directory) { |
276
|
|
|
$this->logs[] = sprintf('Failed to read source %s', $sourcePath); |
277
|
|
|
return false; |
278
|
|
|
} |
279
|
|
|
while (false !== ($entry = $directory->read())) { |
280
|
|
|
if (false === strpos($entry, '.dist.') |
281
|
|
|
&& strpos($entry, 'config.') === 0 && '.php' === substr($entry, -4)) { |
282
|
|
|
$src = $sourcePath . $entry; |
283
|
|
|
$dest = $destinationPath . $entry; |
284
|
|
|
$status = $this->copyFile($src, $dest); |
285
|
|
|
if (false === $status) { |
286
|
|
|
$returnResult = false; |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
$directory->close(); |
291
|
|
|
|
292
|
|
|
return $returnResult; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
//config |
296
|
|
|
/** |
297
|
|
|
* Increase primary key columns from smallint to int |
298
|
|
|
* |
299
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
300
|
|
|
*/ |
301
|
|
|
public function check_configkey() |
302
|
|
|
{ |
303
|
|
|
$tableName = 'config'; |
304
|
|
|
$columnName = 'conf_id'; |
305
|
|
|
|
306
|
|
|
$migrate = new Tables(); |
307
|
|
|
$migrate->useTable($tableName); |
308
|
|
|
$count = 0; |
309
|
|
|
$attributes = $migrate->getColumnAttributes($tableName, $columnName); |
310
|
|
|
if (0 === strpos(trim($attributes), 'smallint')) { |
|
|
|
|
311
|
|
|
$count++; |
312
|
|
|
$migrate->alterColumn($tableName, $columnName, 'int(10) UNSIGNED NOT NULL'); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
return $count==0; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Increase primary key columns from smallint to int |
320
|
|
|
* |
321
|
|
|
* @return bool true if applied, false if failed |
322
|
|
|
*/ |
323
|
|
|
public function apply_configkey() |
324
|
|
|
{ |
325
|
|
|
$tableName = 'config'; |
326
|
|
|
$columnName = 'conf_id'; |
327
|
|
|
|
328
|
|
|
$migrate = new Tables(); |
329
|
|
|
$migrate->useTable($tableName); |
330
|
|
|
$count = 0; |
331
|
|
|
$attributes = $migrate->getColumnAttributes($tableName, $columnName); |
332
|
|
|
if (0 === strpos(trim($attributes), 'smallint')) { |
|
|
|
|
333
|
|
|
$count++; |
334
|
|
|
$migrate->alterColumn($tableName, $columnName, 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT'); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
$result = $migrate->executeQueue(true); |
338
|
|
|
if (false === $result) { |
339
|
|
|
$this->logs[] = sprintf( |
340
|
|
|
'Migration of %s table failed. Error: %s - %s' . |
341
|
|
|
$tableName, |
342
|
|
|
$migrate->getLastErrNo(), |
343
|
|
|
$migrate->getLastError() |
344
|
|
|
); |
345
|
|
|
return false; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
return $count!==0; |
349
|
|
|
} |
350
|
|
|
//configend |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Do we need to create a xoops_data/configs/xoopsconfig.php? |
354
|
|
|
* |
355
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
356
|
|
|
*/ |
357
|
|
|
public function check_xoopsconfig() |
358
|
|
|
{ |
359
|
|
|
$xoopsConfigFile = XOOPS_VAR_PATH . '/configs/xoopsconfig.php'; |
360
|
|
|
return file_exists($xoopsConfigFile); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Create xoops_data/configs/xoopsconfig.php from xoopsconfig.dist.php |
365
|
|
|
* |
366
|
|
|
* @return bool true if applied, false if failed |
367
|
|
|
*/ |
368
|
|
|
public function apply_xoopsconfig() |
369
|
|
|
{ |
370
|
|
|
$source = XOOPS_VAR_PATH . '/configs/xoopsconfig.dist.php'; |
371
|
|
|
$destination = XOOPS_VAR_PATH . '/configs/xoopsconfig.php'; |
372
|
|
|
if (!file_exists($destination)) { // don't overwrite anything |
373
|
|
|
$result = copy($source, $destination); |
374
|
|
|
if (false === $result) { |
375
|
|
|
$this->logs[] = 'xoopsconfig.php file copy failed'; |
376
|
|
|
return false; |
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
return true; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* This is a default list based on extensions as supplied by XOOPS. |
384
|
|
|
* If possible, we will build a list based on contents of class/textsanitizer/ |
385
|
|
|
* key is file path relative to XOOPS_ROOT_PATH . '/class/textsanitizer/ |
386
|
|
|
* value is file path relative to XOOPS_VAR_PATH . '/configs/textsanitizer/' |
387
|
|
|
* |
388
|
|
|
* @var string[] |
389
|
|
|
*/ |
390
|
|
|
protected $textsanitizerConfigFiles = array( |
391
|
|
|
'config.php' => 'config.php', |
392
|
|
|
'censor/config.php' => 'config.censor.php', |
393
|
|
|
'flash/config.php' => 'config.flash.php', |
394
|
|
|
'image/config.php' => 'config.image.php', |
395
|
|
|
'mms/config.php' => 'config.mms.php', |
396
|
|
|
'rtsp/config.php' => 'config.rtsp.php', |
397
|
|
|
'syntaxhighlight/config.php' => 'config.syntaxhighlight.php', |
398
|
|
|
'textfilter/config.php' => 'config.textfilter.php', |
399
|
|
|
'wiki/config.php' => 'config.wiki.php', |
400
|
|
|
'wmp/config.php' => 'config.wmp.php', |
401
|
|
|
); |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Build a list of config files using the existing textsanitizer/config.php |
405
|
|
|
* each as source name => destination name in $this->textsanitizerConfigFiles |
406
|
|
|
* |
407
|
|
|
* This should prevent some issues with customized systems. |
408
|
|
|
* |
409
|
|
|
* @return void |
410
|
|
|
*/ |
411
|
|
|
protected function buildListTSConfigs() |
412
|
|
|
{ |
413
|
|
|
if (file_exists(XOOPS_ROOT_PATH . '/class/textsanitizer/config.php')) { |
414
|
|
|
$config = include XOOPS_ROOT_PATH . '/class/textsanitizer/config.php'; |
415
|
|
|
if (is_array($config) && array_key_exists('extentions', $config)) { |
416
|
|
|
$this->textsanitizerConfigFiles = array( |
417
|
|
|
'config.php' => 'config.php', |
418
|
|
|
); |
419
|
|
|
foreach ($config['extentions'] as $module => $enabled) { |
420
|
|
|
$source = "{$module}/config.php"; |
421
|
|
|
if (file_exists(XOOPS_ROOT_PATH . '/class/textsanitizer/' . $source)) { |
422
|
|
|
$destination = "{$module}/config.{$module}.php"; |
423
|
|
|
$this->textsanitizerConfigFiles[$source] = $destination; |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
return; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Do we need to move any existing files to xoops_data/configs/textsanitizer/ ? |
433
|
|
|
* |
434
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
435
|
|
|
*/ |
436
|
|
|
public function check_textsanitizer() |
437
|
|
|
{ |
438
|
|
|
$this->buildListTSConfigs(); |
439
|
|
|
foreach ($this->textsanitizerConfigFiles as $source => $destination) { |
440
|
|
|
$src = XOOPS_ROOT_PATH . '/class/textsanitizer/' . $source; |
441
|
|
|
$dest = XOOPS_VAR_PATH . '/configs/textsanitizer/' . $destination; |
442
|
|
|
if (!file_exists($dest) && file_exists($src)) { |
443
|
|
|
return false; |
444
|
|
|
} |
445
|
|
|
} |
446
|
|
|
return true; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Copy and rename any existing class/textsanitizer/ config files to xoops_data/configs/textsanitizer/ |
451
|
|
|
* |
452
|
|
|
* @return bool true if applied, false if failed |
453
|
|
|
*/ |
454
|
|
|
public function apply_textsanitizer() |
455
|
|
|
{ |
456
|
|
|
$this->buildListTSConfigs(); |
457
|
|
|
$return = true; |
458
|
|
|
foreach ($this->textsanitizerConfigFiles as $source => $destination) { |
459
|
|
|
$src = XOOPS_ROOT_PATH . '/class/textsanitizer/' . $source; |
460
|
|
|
$dest = XOOPS_VAR_PATH . '/configs/textsanitizer/' . $destination; |
461
|
|
|
if (!file_exists($dest) && file_exists($src)) { |
462
|
|
|
$result = copy($src, $dest); |
463
|
|
|
if (false === $result) { |
464
|
|
|
$this->logs[] = sprintf('textsanitizer file copy to %s failed', $destination); |
465
|
|
|
$return = false; |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
} |
469
|
|
|
return $return; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Attempt to remove index.html files replaced by index.php |
474
|
|
|
*/ |
475
|
|
|
/** |
476
|
|
|
* List of directories supplied by XOOPS. This is used to try and keep us out |
477
|
|
|
* of things added to the system locally. (Set in __construct() for php BC.) |
478
|
|
|
* |
479
|
|
|
* @var string[] |
480
|
|
|
*/ |
481
|
|
|
private $pathsToCheck; |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* Do we need to remove any index.html files that were replaced by index.php files? |
485
|
|
|
* |
486
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
487
|
|
|
*/ |
488
|
|
|
public function check_rmindexhtml() |
489
|
|
|
{ |
490
|
|
|
/** |
491
|
|
|
* If we find an index.html that is writable, we know there is work to do |
492
|
|
|
* |
493
|
|
|
* @param string $name file name to check |
494
|
|
|
* |
495
|
|
|
* @return bool true to continue, false to stop scan |
496
|
|
|
*/ |
497
|
|
|
$stopIfFound = function ($name) { |
498
|
|
|
$ok = is_writable($name); |
499
|
|
|
return !($ok); |
500
|
|
|
}; |
501
|
|
|
|
502
|
|
|
clearstatcache(); |
503
|
|
|
|
504
|
|
|
return $this->dirWalker($stopIfFound); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* Unlink any index.html files that have been replaced by index.php files |
509
|
|
|
* |
510
|
|
|
* @return bool true if patch applied, false if failed |
511
|
|
|
*/ |
512
|
|
|
public function apply_rmindexhtml() |
513
|
|
|
{ |
514
|
|
|
/** |
515
|
|
|
* Do unlink() on file |
516
|
|
|
* Always return true so we process each writable index.html |
517
|
|
|
* |
518
|
|
|
* @param string $name file name to unlink |
519
|
|
|
* |
520
|
|
|
* @return true always report true, even if we can't delete -- best effort only |
521
|
|
|
*/ |
522
|
|
|
$unlinkByName = function ($name) { |
523
|
|
|
if (is_writable($name)) { |
524
|
|
|
$result = unlink($name); |
|
|
|
|
525
|
|
|
} |
526
|
|
|
return true; |
527
|
|
|
}; |
528
|
|
|
|
529
|
|
|
|
530
|
|
|
return $this->dirWalker($unlinkByName); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Walk list of directories in $pathsToCheck |
535
|
|
|
* |
536
|
|
|
* @param \Closure $onFound |
537
|
|
|
* |
538
|
|
|
* @return bool |
539
|
|
|
*/ |
540
|
|
|
private function dirWalker(\Closure $onFound) |
541
|
|
|
{ |
542
|
|
|
$check = true; |
543
|
|
|
foreach ($this->pathsToCheck as $path) { |
544
|
|
|
$check = $this->checkDirForIndexHtml($path, $onFound); |
545
|
|
|
if (false === $check) { |
546
|
|
|
break; |
547
|
|
|
} |
548
|
|
|
} |
549
|
|
|
if (false !== $check) { |
550
|
|
|
$check = true; |
551
|
|
|
} |
552
|
|
|
return $check; |
|
|
|
|
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* Recursively check for index.html files that have a corresponding index.php file |
557
|
|
|
* in the supplied path. |
558
|
|
|
* |
559
|
|
|
* @param string $startingPath |
560
|
|
|
* @param \Closure $onFound |
561
|
|
|
* |
562
|
|
|
* @return false|int false if onFound returned false (don't continue) else count of matches |
563
|
|
|
*/ |
564
|
|
|
private function checkDirForIndexHtml($startingPath, \Closure $onFound) |
565
|
|
|
{ |
566
|
|
|
if (!is_dir($startingPath)) { |
567
|
|
|
return 0; |
568
|
|
|
} |
569
|
|
|
$i = 0; |
570
|
|
|
$rdi = new \RecursiveDirectoryIterator($startingPath); |
571
|
|
|
$rii = new \RecursiveIteratorIterator($rdi); |
572
|
|
|
/** @var \SplFileInfo $fileinfo */ |
573
|
|
|
foreach ($rii as $fileinfo) { |
574
|
|
|
if ($fileinfo->isFile() && 'index.html' === $fileinfo->getFilename() && 60 > $fileinfo->getSize()) { |
575
|
|
|
$path = $fileinfo->getPath(); |
576
|
|
|
$testFilename = $path . '/index.php'; |
577
|
|
|
if (file_exists($testFilename)) { |
578
|
|
|
$unlinkName = $path . '/' . $fileinfo->getFilename(); |
579
|
|
|
++$i; |
580
|
|
|
$continue = $onFound($unlinkName); |
581
|
|
|
if (false === $continue) { |
582
|
|
|
return $continue; |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
} |
587
|
|
|
return $i; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* Determine if columns are declared smallint, and if |
592
|
|
|
* so, queue ddl to alter to varchar. |
593
|
|
|
* |
594
|
|
|
* @param Tables $migrate |
595
|
|
|
* @param string $modulesTableName |
596
|
|
|
* @param string[] $modulesColumnNames array of columns to check |
597
|
|
|
* |
598
|
|
|
* @return integer count of queue items added |
599
|
|
|
*/ |
600
|
|
|
protected function fromSmallintToVarchar(Tables $migrate, $modulesTableName, $modulesColumnNames) |
601
|
|
|
{ |
602
|
|
|
$migrate->useTable($modulesTableName); |
603
|
|
|
$count = 0; |
604
|
|
|
foreach ($modulesColumnNames as $column) { |
605
|
|
|
$attributes = $migrate->getColumnAttributes($modulesTableName, $column); |
606
|
|
|
if (is_string($attributes) && 0 === strpos(trim($attributes), 'smallint')) { |
607
|
|
|
$count++; |
608
|
|
|
$migrate->alterColumn($modulesTableName, $column, 'varchar(32) NOT NULL DEFAULT \'\''); |
609
|
|
|
} |
610
|
|
|
} |
611
|
|
|
return $count; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
private $modulesTableName = 'modules'; |
615
|
|
|
private $modulesColumnNames = array('version'); |
616
|
|
|
|
617
|
|
|
/** |
618
|
|
|
* Increase version columns from smallint to varchar |
619
|
|
|
* |
620
|
|
|
* @return bool true if patch IS applied, false if NOT applied |
621
|
|
|
*/ |
622
|
|
|
public function check_modulesvarchar() |
623
|
|
|
{ |
624
|
|
|
$migrate = new Tables(); |
625
|
|
|
$count = $this->fromSmallintToVarchar($migrate, $this->modulesTableName, $this->modulesColumnNames); |
626
|
|
|
return $count==0; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
/** |
630
|
|
|
* Increase version columns from smallint to varchar |
631
|
|
|
* |
632
|
|
|
* @return bool true if applied, false if failed |
633
|
|
|
*/ |
634
|
|
|
public function apply_modulesvarchar() |
635
|
|
|
{ |
636
|
|
|
$migrate = new Tables(); |
637
|
|
|
|
638
|
|
|
$count = $this->fromSmallintToVarchar($migrate, $this->modulesTableName, $this->modulesColumnNames); |
|
|
|
|
639
|
|
|
|
640
|
|
|
$result = $migrate->executeQueue(true); |
641
|
|
|
if (false === $result) { |
642
|
|
|
$this->logs[] = sprintf( |
643
|
|
|
'Migration of %s table failed. Error: %s - %s' . |
644
|
|
|
$this->modulesTableName, |
645
|
|
|
$migrate->getLastErrNo(), |
646
|
|
|
$migrate->getLastError() |
647
|
|
|
); |
648
|
|
|
return false; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
return true; |
652
|
|
|
} |
653
|
|
|
|
654
|
|
|
/** |
655
|
|
|
* @return bool |
656
|
|
|
*/ |
657
|
|
|
public function check_templates() |
658
|
|
|
{ |
659
|
|
|
$sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('tplfile') . "` WHERE `tpl_file` IN ('system_confirm.tpl') AND `tpl_type` = 'module'"; |
660
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
661
|
|
|
if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
662
|
|
|
return false; |
663
|
|
|
} |
664
|
|
|
list($count) = $GLOBALS['xoopsDB']->fetchRow($result); |
665
|
|
|
|
666
|
|
|
return ($count != 0); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* @return bool |
672
|
|
|
*/ |
673
|
|
|
public function apply_templates() |
674
|
|
|
{ |
675
|
|
|
$modversion = array(); |
676
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/system/xoops_version.php'; |
677
|
|
|
|
678
|
|
|
$dbm = new Db_manager(); |
679
|
|
|
$time = time(); |
680
|
|
|
foreach ($modversion['templates'] as $tplfile) { |
681
|
|
|
if ((isset($tplfile['type']) && $tplfile['type'] === 'module') || !isset($tplfile['type'])) { |
682
|
|
|
|
683
|
|
|
$filePath = XOOPS_ROOT_PATH . '/modules/system/templates/' . $tplfile['file']; |
684
|
|
|
if ($fp = fopen($filePath, 'r')) { |
685
|
|
|
$newtplid = $dbm->insert('tplfile', " VALUES (0, 1, 'system', 'default', '" . addslashes($tplfile['file']) . "', '" . addslashes($tplfile['description']) . "', " . $time . ', ' . $time . ", 'module')"); |
686
|
|
|
$tplsource = fread($fp, filesize($filePath)); |
687
|
|
|
fclose($fp); |
688
|
|
|
$dbm->insert('tplsource', ' (tpl_id, tpl_source) VALUES (' . $newtplid . ", '" . addslashes($tplsource) . "')"); |
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
return true; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
/** |
697
|
|
|
* @return bool |
698
|
|
|
*/ |
699
|
|
|
public function check_templatesadmin() |
700
|
|
|
{ |
701
|
|
|
$sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('tplfile') . "` WHERE `tpl_file` IN ('system_modules.tpl') AND `tpl_type` = 'admin'"; |
702
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
703
|
|
|
if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
704
|
|
|
return false; |
705
|
|
|
} |
706
|
|
|
list($count) = $GLOBALS['xoopsDB']->fetchRow($result); |
707
|
|
|
|
708
|
|
|
return ($count != 0); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* @return bool |
713
|
|
|
*/ |
714
|
|
|
public function apply_templatesadmin() |
715
|
|
|
{ |
716
|
|
|
include XOOPS_ROOT_PATH . '/modules/system/xoops_version.php'; |
717
|
|
|
$dbm = new Db_manager(); |
718
|
|
|
$time = time(); |
719
|
|
|
foreach ($modversion['templates'] as $tplfile) { |
|
|
|
|
720
|
|
|
// Admin templates |
721
|
|
|
if (isset($tplfile['type']) && $tplfile['type'] === 'admin' && $fp = fopen('../modules/system/templates/admin/' . $tplfile['file'], 'r')) { |
722
|
|
|
$newtplid = $dbm->insert('tplfile', " VALUES (0, 1, 'system', 'default', '" . addslashes($tplfile['file']) . "', '" . addslashes($tplfile['description']) . "', " . $time . ', ' . $time . ", 'admin')"); |
723
|
|
|
$tplsource = fread($fp, filesize('../modules/system/templates/admin/' . $tplfile['file'])); |
724
|
|
|
fclose($fp); |
725
|
|
|
$dbm->insert('tplsource', ' (tpl_id, tpl_source) VALUES (' . $newtplid . ", '" . addslashes($tplsource) . "')"); |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
return true; |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
//modules/system/themes/legacy/legacy.php |
733
|
|
|
/** |
734
|
|
|
* Do we need to delete obsolete Smarty files? |
735
|
|
|
* |
736
|
|
|
* @return bool |
737
|
|
|
*/ |
738
|
|
|
public function check_zapsmarty() |
739
|
|
|
{ |
740
|
|
|
return !file_exists('../class/smarty/smarty.class.php'); |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Delete obsolete Smarty files |
745
|
|
|
* |
746
|
|
|
* @return bool |
747
|
|
|
*/ |
748
|
|
|
public function apply_zapsmarty() |
749
|
|
|
{ |
750
|
|
|
// Define the base directory |
751
|
|
|
$baseDir = '../class/smarty/'; |
752
|
|
|
|
753
|
|
|
// List of sub-folders and files to delete |
754
|
|
|
$itemsToDelete = array( |
755
|
|
|
'configs', |
756
|
|
|
'internals', |
757
|
|
|
'xoops_plugins', |
758
|
|
|
'Config_File.class.php', |
759
|
|
|
'debug.tpl', |
760
|
|
|
'Smarty.class.php', |
761
|
|
|
'Smarty_Compiler.class.php' |
762
|
|
|
); |
763
|
|
|
|
764
|
|
|
// Loop through each item and delete it |
765
|
|
|
foreach ($itemsToDelete as $item) { |
766
|
|
|
$path = $baseDir . $item; |
767
|
|
|
|
768
|
|
|
// Check if it's a directory or a file |
769
|
|
|
if (is_dir($path)) { |
770
|
|
|
// Delete directory and its contents |
771
|
|
|
array_map('unlink', glob("$path/*.*")); |
772
|
|
|
rmdir($path); |
773
|
|
|
} elseif (is_file($path)) { |
774
|
|
|
// Delete file |
775
|
|
|
if (is_writable($path)) { |
776
|
|
|
unlink($path); |
777
|
|
|
} |
778
|
|
|
} |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
return true; |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
/** |
785
|
|
|
* Check if default notification method already exists |
786
|
|
|
* |
787
|
|
|
*/ |
788
|
|
|
public function check_notificationmethod() |
789
|
|
|
{ |
790
|
|
|
$sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('config') . "` WHERE `conf_name` IN ('default_notification')"; |
791
|
|
|
if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
|
|
|
|
792
|
|
|
return false; |
793
|
|
|
} |
794
|
|
|
return true; |
795
|
|
|
} |
796
|
|
|
|
797
|
|
|
/** |
798
|
|
|
* @return bool |
799
|
|
|
*/ |
800
|
|
|
public function apply_notificationmethod() |
801
|
|
|
{ |
802
|
|
|
$returnResult = true; |
803
|
|
|
$notification_method = false; |
804
|
|
|
$sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('config') . "` WHERE `conf_name` = 'default_notification'"; |
805
|
|
|
if ($result = $GLOBALS['xoopsDB']->queryF($sql)) { |
806
|
|
|
list($count) = $GLOBALS['xoopsDB']->fetchRow($result); |
807
|
|
|
if ($count == 1) { |
808
|
|
|
$notification_method = true; |
809
|
|
|
} |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
if (!$notification_method) { |
813
|
|
|
$sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('config') . ' (conf_id, conf_modid, conf_catid, conf_name, conf_title, conf_value, conf_desc, conf_formtype, conf_valuetype, conf_order) ' . ' VALUES ' . " (NULL, 0, 2, 'default_notification', '_MD_AM_DEFAULT_NOTIFICATION_METHOD', '1', '_MD_AM_DEFAULT_NOTIFICATION_METHOD_DESC', 'select', 'int', 3)"; |
814
|
|
|
|
815
|
|
|
if (!$GLOBALS['xoopsDB']->queryF($sql)) { |
816
|
|
|
return false; |
817
|
|
|
} |
818
|
|
|
$config_id = $GLOBALS['xoopsDB']->getInsertId(); |
819
|
|
|
|
820
|
|
|
$sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('configoption') . ' (confop_id, confop_name, confop_value, conf_id)'. ' VALUES' |
821
|
|
|
. " (NULL, '_MI_DEFAULT_NOTIFICATION_METHOD_DISABLE', '0', {$config_id})," |
822
|
|
|
. " (NULL, '_MI_DEFAULT_NOTIFICATION_METHOD_PM', '1', {$config_id})," |
823
|
|
|
. " (NULL, '_MI_DEFAULT_NOTIFICATION_METHOD_EMAIL', '2', {$config_id})"; |
824
|
|
|
if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
|
|
|
|
825
|
|
|
return false; |
826
|
|
|
} |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
return $returnResult; |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
|
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
return new Upgrade_2511(); |
836
|
|
|
|