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