Total Complexity | 108 |
Total Lines | 816 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 1 | Features | 1 |
Complex classes like Upgrade_2511 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Upgrade_2511, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Upgrade_2511 extends XoopsUpgrade |
||
16 | { |
||
17 | /** |
||
18 | * __construct |
||
19 | */ |
||
20 | public function __construct() |
||
21 | { |
||
22 | parent::__construct(basename(__DIR__)); |
||
23 | $this->tasks = [ |
||
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 = []; |
||
39 | $this->pathsToCheck = [ |
||
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 | || false === $_SESSION[$this->cleanCacheKey]) { |
||
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([1, 2, 3]); |
||
89 | if (true === $result) { |
||
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 = ['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 0 == $count; |
||
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 0 !== $count; |
||
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() |
||
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) |
||
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 | && 0 === strpos($entry, 'config.') |
||
282 | && '.php' === substr($entry, -4)) { |
||
283 | $src = $sourcePath . $entry; |
||
284 | $dest = $destinationPath . $entry; |
||
285 | $status = $this->copyFile($src, $dest); |
||
286 | if (false === $status) { |
||
287 | $returnResult = false; |
||
288 | } |
||
289 | } |
||
290 | } |
||
291 | $directory->close(); |
||
292 | |||
293 | return $returnResult; |
||
294 | } |
||
295 | |||
296 | //config |
||
297 | /** |
||
298 | * Increase primary key columns from smallint to int |
||
299 | * |
||
300 | * @return bool true if patch IS applied, false if NOT applied |
||
301 | */ |
||
302 | public function check_configkey() |
||
303 | { |
||
304 | $tableName = 'config'; |
||
305 | $columnName = 'conf_id'; |
||
306 | |||
307 | $migrate = new Tables(); |
||
308 | $migrate->useTable($tableName); |
||
309 | $count = 0; |
||
310 | $attributes = $migrate->getColumnAttributes($tableName, $columnName); |
||
311 | if (0 === strpos(trim($attributes), 'smallint')) { |
||
312 | $count++; |
||
313 | $migrate->alterColumn($tableName, $columnName, 'int(10) UNSIGNED NOT NULL'); |
||
314 | } |
||
315 | |||
316 | return 0 == $count; |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * Increase primary key columns from smallint to int |
||
321 | * |
||
322 | * @return bool true if applied, false if failed |
||
323 | */ |
||
324 | public function apply_configkey() |
||
325 | { |
||
326 | $tableName = 'config'; |
||
327 | $columnName = 'conf_id'; |
||
328 | |||
329 | $migrate = new Tables(); |
||
330 | $migrate->useTable($tableName); |
||
331 | $count = 0; |
||
332 | $attributes = $migrate->getColumnAttributes($tableName, $columnName); |
||
333 | if (0 === strpos(trim($attributes), 'smallint')) { |
||
334 | $count++; |
||
335 | $migrate->alterColumn($tableName, $columnName, 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT'); |
||
336 | } |
||
337 | |||
338 | $result = $migrate->executeQueue(true); |
||
339 | if (false === $result) { |
||
340 | $this->logs[] = sprintf( |
||
341 | 'Migration of %s table failed. Error: %s - %s' . |
||
342 | $tableName, |
||
343 | $migrate->getLastErrNo(), |
||
344 | $migrate->getLastError(), |
||
345 | ); |
||
346 | return false; |
||
347 | } |
||
348 | |||
349 | return 0 !== $count; |
||
350 | } |
||
351 | //configend |
||
352 | |||
353 | /** |
||
354 | * Do we need to create a xoops_data/configs/xoopsconfig.php? |
||
355 | * |
||
356 | * @return bool true if patch IS applied, false if NOT applied |
||
357 | */ |
||
358 | public function check_xoopsconfig() |
||
359 | { |
||
360 | $xoopsConfigFile = XOOPS_VAR_PATH . '/configs/xoopsconfig.php'; |
||
361 | return file_exists($xoopsConfigFile); |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * Create xoops_data/configs/xoopsconfig.php from xoopsconfig.dist.php |
||
366 | * |
||
367 | * @return bool true if applied, false if failed |
||
368 | */ |
||
369 | public function apply_xoopsconfig() |
||
370 | { |
||
371 | $source = XOOPS_VAR_PATH . '/configs/xoopsconfig.dist.php'; |
||
372 | $destination = XOOPS_VAR_PATH . '/configs/xoopsconfig.php'; |
||
373 | if (!file_exists($destination)) { // don't overwrite anything |
||
374 | $result = copy($source, $destination); |
||
375 | if (false === $result) { |
||
376 | $this->logs[] = 'xoopsconfig.php file copy failed'; |
||
377 | return false; |
||
378 | } |
||
379 | } |
||
380 | return true; |
||
381 | } |
||
382 | |||
383 | /** |
||
384 | * This is a default list based on extensions as supplied by XOOPS. |
||
385 | * If possible, we will build a list based on contents of class/textsanitizer/ |
||
386 | * key is file path relative to XOOPS_ROOT_PATH . '/class/textsanitizer/ |
||
387 | * value is file path relative to XOOPS_VAR_PATH . '/configs/textsanitizer/' |
||
388 | * |
||
389 | * @var string[] |
||
390 | */ |
||
391 | protected $textsanitizerConfigFiles = [ |
||
392 | 'config.php' => 'config.php', |
||
393 | 'censor/config.php' => 'config.censor.php', |
||
394 | 'flash/config.php' => 'config.flash.php', |
||
395 | 'image/config.php' => 'config.image.php', |
||
396 | 'mms/config.php' => 'config.mms.php', |
||
397 | 'rtsp/config.php' => 'config.rtsp.php', |
||
398 | 'syntaxhighlight/config.php' => 'config.syntaxhighlight.php', |
||
399 | 'textfilter/config.php' => 'config.textfilter.php', |
||
400 | 'wiki/config.php' => 'config.wiki.php', |
||
401 | 'wmp/config.php' => 'config.wmp.php', |
||
402 | ]; |
||
403 | |||
404 | /** |
||
405 | * Build a list of config files using the existing textsanitizer/config.php |
||
406 | * each as source name => destination name in $this->textsanitizerConfigFiles |
||
407 | * |
||
408 | * This should prevent some issues with customized systems. |
||
409 | * |
||
410 | * @return void |
||
411 | */ |
||
412 | protected function buildListTSConfigs() |
||
430 | } |
||
431 | |||
432 | /** |
||
433 | * Do we need to move any existing files to xoops_data/configs/textsanitizer/ ? |
||
434 | * |
||
435 | * @return bool true if patch IS applied, false if NOT applied |
||
436 | */ |
||
437 | public function check_textsanitizer() |
||
438 | { |
||
439 | $this->buildListTSConfigs(); |
||
440 | foreach ($this->textsanitizerConfigFiles as $source => $destination) { |
||
441 | $src = XOOPS_ROOT_PATH . '/class/textsanitizer/' . $source; |
||
442 | $dest = XOOPS_VAR_PATH . '/configs/textsanitizer/' . $destination; |
||
443 | if (!file_exists($dest) && file_exists($src)) { |
||
444 | return false; |
||
445 | } |
||
446 | } |
||
447 | return true; |
||
448 | } |
||
449 | |||
450 | /** |
||
451 | * Copy and rename any existing class/textsanitizer/ config files to xoops_data/configs/textsanitizer/ |
||
452 | * |
||
453 | * @return bool true if applied, false if failed |
||
454 | */ |
||
455 | public function apply_textsanitizer() |
||
456 | { |
||
457 | $this->buildListTSConfigs(); |
||
458 | $return = true; |
||
459 | foreach ($this->textsanitizerConfigFiles as $source => $destination) { |
||
460 | $src = XOOPS_ROOT_PATH . '/class/textsanitizer/' . $source; |
||
461 | $dest = XOOPS_VAR_PATH . '/configs/textsanitizer/' . $destination; |
||
462 | if (!file_exists($dest) && file_exists($src)) { |
||
463 | $result = copy($src, $dest); |
||
464 | if (false === $result) { |
||
465 | $this->logs[] = sprintf('textsanitizer file copy to %s failed', $destination); |
||
466 | $return = false; |
||
467 | } |
||
468 | } |
||
469 | } |
||
470 | return $return; |
||
471 | } |
||
472 | |||
473 | /** |
||
474 | * Attempt to remove index.html files replaced by index.php |
||
475 | */ |
||
476 | /** |
||
477 | * List of directories supplied by XOOPS. This is used to try and keep us out |
||
478 | * of things added to the system locally. (Set in __construct() for php BC.) |
||
479 | * |
||
480 | * @var string[] |
||
481 | */ |
||
482 | private $pathsToCheck; |
||
483 | |||
484 | /** |
||
485 | * Do we need to remove any index.html files that were replaced by index.php files? |
||
486 | * |
||
487 | * @return bool true if patch IS applied, false if NOT applied |
||
488 | */ |
||
489 | public function check_rmindexhtml() |
||
490 | { |
||
491 | /** |
||
492 | * If we find an index.html that is writable, we know there is work to do |
||
493 | * |
||
494 | * @param string $name file name to check |
||
495 | * |
||
496 | * @return bool true to continue, false to stop scan |
||
497 | */ |
||
498 | $stopIfFound = function ($name) { |
||
499 | $ok = is_writable($name); |
||
500 | return !($ok); |
||
501 | }; |
||
502 | |||
503 | clearstatcache(); |
||
504 | |||
505 | return $this->dirWalker($stopIfFound); |
||
506 | } |
||
507 | |||
508 | /** |
||
509 | * Unlink any index.html files that have been replaced by index.php files |
||
510 | * |
||
511 | * @return bool true if patch applied, false if failed |
||
512 | */ |
||
513 | public function apply_rmindexhtml() |
||
514 | { |
||
515 | /** |
||
516 | * Do unlink() on file |
||
517 | * Always return true so we process each writable index.html |
||
518 | * |
||
519 | * @param string $name file name to unlink |
||
520 | * |
||
521 | * @return true always report true, even if we can't delete -- best effort only |
||
522 | */ |
||
523 | $unlinkByName = function ($name) { |
||
524 | if (is_writable($name)) { |
||
525 | $result = unlink($name); |
||
526 | } |
||
527 | return true; |
||
528 | }; |
||
529 | |||
530 | |||
531 | return $this->dirWalker($unlinkByName); |
||
532 | } |
||
533 | |||
534 | /** |
||
535 | * Walk list of directories in $pathsToCheck |
||
536 | * |
||
537 | * @param \Closure $onFound |
||
538 | * |
||
539 | * @return bool |
||
540 | */ |
||
541 | private function dirWalker(\Closure $onFound) |
||
542 | { |
||
543 | $check = true; |
||
544 | foreach ($this->pathsToCheck as $path) { |
||
545 | $check = $this->checkDirForIndexHtml($path, $onFound); |
||
546 | if (false === $check) { |
||
547 | break; |
||
548 | } |
||
549 | } |
||
550 | if (false !== $check) { |
||
551 | $check = true; |
||
552 | } |
||
553 | return $check; |
||
554 | } |
||
555 | |||
556 | /** |
||
557 | * Recursively check for index.html files that have a corresponding index.php file |
||
558 | * in the supplied path. |
||
559 | * |
||
560 | * @param string $startingPath |
||
561 | * @param \Closure $onFound |
||
562 | * |
||
563 | * @return false|int false if onFound returned false (don't continue) else count of matches |
||
564 | */ |
||
565 | private function checkDirForIndexHtml($startingPath, \Closure $onFound) |
||
566 | { |
||
567 | if (!is_dir($startingPath)) { |
||
568 | return 0; |
||
569 | } |
||
570 | $i = 0; |
||
571 | $rdi = new \RecursiveDirectoryIterator($startingPath); |
||
572 | $rii = new \RecursiveIteratorIterator($rdi); |
||
573 | /** @var \SplFileInfo $fileinfo */ |
||
574 | foreach ($rii as $fileinfo) { |
||
575 | if ($fileinfo->isFile() && 'index.html' === $fileinfo->getFilename() && 60 > $fileinfo->getSize()) { |
||
576 | $path = $fileinfo->getPath(); |
||
577 | $testFilename = $path . '/index.php'; |
||
578 | if (file_exists($testFilename)) { |
||
579 | $unlinkName = $path . '/' . $fileinfo->getFilename(); |
||
580 | ++$i; |
||
581 | $continue = $onFound($unlinkName); |
||
582 | if (false === $continue) { |
||
583 | return $continue; |
||
584 | } |
||
585 | } |
||
586 | } |
||
587 | } |
||
588 | return $i; |
||
589 | } |
||
590 | |||
591 | /** |
||
592 | * Determine if columns are declared smallint, and if |
||
593 | * so, queue ddl to alter to varchar. |
||
594 | * |
||
595 | * @param Tables $migrate |
||
596 | * @param string $modulesTableName |
||
597 | * @param string[] $modulesColumnNames array of columns to check |
||
598 | * |
||
599 | * @return integer count of queue items added |
||
600 | */ |
||
601 | protected function fromSmallintToVarchar(Tables $migrate, $modulesTableName, $modulesColumnNames) |
||
602 | { |
||
603 | $migrate->useTable($modulesTableName); |
||
604 | $count = 0; |
||
605 | foreach ($modulesColumnNames as $column) { |
||
606 | $attributes = $migrate->getColumnAttributes($modulesTableName, $column); |
||
607 | if (is_string($attributes) && 0 === strpos(trim($attributes), 'smallint')) { |
||
608 | $count++; |
||
609 | $migrate->alterColumn($modulesTableName, $column, 'varchar(32) NOT NULL DEFAULT \'\''); |
||
610 | } |
||
611 | } |
||
612 | return $count; |
||
613 | } |
||
614 | |||
615 | private $modulesTableName = 'modules'; |
||
616 | private $modulesColumnNames = ['version']; |
||
617 | |||
618 | /** |
||
619 | * Increase version columns from smallint to varchar |
||
620 | * |
||
621 | * @return bool true if patch IS applied, false if NOT applied |
||
622 | */ |
||
623 | public function check_modulesvarchar() |
||
624 | { |
||
625 | $migrate = new Tables(); |
||
626 | $count = $this->fromSmallintToVarchar($migrate, $this->modulesTableName, $this->modulesColumnNames); |
||
627 | return 0 == $count; |
||
628 | } |
||
629 | |||
630 | /** |
||
631 | * Increase version columns from smallint to varchar |
||
632 | * |
||
633 | * @return bool true if applied, false if failed |
||
634 | */ |
||
635 | public function apply_modulesvarchar() |
||
636 | { |
||
637 | $migrate = new Tables(); |
||
638 | |||
639 | $count = $this->fromSmallintToVarchar($migrate, $this->modulesTableName, $this->modulesColumnNames); |
||
640 | |||
641 | $result = $migrate->executeQueue(true); |
||
642 | if (false === $result) { |
||
643 | $this->logs[] = sprintf( |
||
644 | 'Migration of %s table failed. Error: %s - %s' . |
||
645 | $this->modulesTableName, |
||
646 | $migrate->getLastErrNo(), |
||
647 | $migrate->getLastError(), |
||
648 | ); |
||
649 | return false; |
||
650 | } |
||
651 | |||
652 | return true; |
||
653 | } |
||
654 | |||
655 | /** |
||
656 | * @return bool |
||
657 | */ |
||
658 | public function check_templates() |
||
659 | { |
||
660 | $sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('tplfile') . "` WHERE `tpl_file` IN ('system_confirm.tpl') AND `tpl_type` = 'module'"; |
||
661 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
662 | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { |
||
663 | return false; |
||
664 | } |
||
665 | [$count] = $GLOBALS['xoopsDB']->fetchRow($result); |
||
666 | |||
667 | return (0 != $count); |
||
668 | } |
||
669 | |||
670 | |||
671 | /** |
||
672 | * @return bool |
||
673 | */ |
||
674 | public function apply_templates() |
||
695 | } |
||
696 | |||
697 | /** |
||
698 | * @return bool |
||
699 | */ |
||
700 | public function check_templatesadmin() |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * @return bool |
||
714 | */ |
||
715 | public function apply_templatesadmin() |
||
716 | { |
||
717 | include XOOPS_ROOT_PATH . '/modules/system/xoops_version.php'; |
||
718 | $dbm = new Db_manager(); |
||
719 | $time = time(); |
||
720 | foreach ($modversion['templates'] as $tplfile) { |
||
721 | // Admin templates |
||
722 | if (isset($tplfile['type']) && 'admin' === $tplfile['type'] && $fp = fopen('../modules/system/templates/admin/' . $tplfile['file'], 'r')) { |
||
723 | $newtplid = $dbm->insert('tplfile', " VALUES (0, 1, 'system', 'default', '" . addslashes($tplfile['file']) . "', '" . addslashes($tplfile['description']) . "', " . $time . ', ' . $time . ", 'admin')"); |
||
724 | $tplsource = fread($fp, filesize('../modules/system/templates/admin/' . $tplfile['file'])); |
||
725 | fclose($fp); |
||
726 | $dbm->insert('tplsource', ' (tpl_id, tpl_source) VALUES (' . $newtplid . ", '" . addslashes($tplsource) . "')"); |
||
727 | } |
||
728 | } |
||
729 | |||
730 | return true; |
||
731 | } |
||
732 | |||
733 | //modules/system/themes/legacy/legacy.php |
||
734 | /** |
||
735 | * Do we need to delete obsolete Smarty files? |
||
736 | * |
||
737 | * @return bool |
||
738 | */ |
||
739 | public function check_zapsmarty() |
||
740 | { |
||
741 | return !file_exists('../class/smarty/smarty.class.php'); |
||
742 | } |
||
743 | |||
744 | /** |
||
745 | * Delete obsolete Smarty files |
||
746 | * |
||
747 | * @return bool |
||
748 | */ |
||
749 | public function apply_zapsmarty() |
||
750 | { |
||
751 | // Define the base directory |
||
752 | $baseDir = '../class/smarty/'; |
||
753 | |||
754 | // List of sub-folders and files to delete |
||
755 | $itemsToDelete = [ |
||
756 | 'configs', |
||
757 | 'internals', |
||
758 | 'xoops_plugins', |
||
759 | 'Config_File.class.php', |
||
760 | 'debug.tpl', |
||
761 | 'Smarty.class.php', |
||
762 | 'Smarty_Compiler.class.php', |
||
763 | ]; |
||
764 | |||
765 | // Loop through each item and delete it |
||
766 | foreach ($itemsToDelete as $item) { |
||
767 | $path = $baseDir . $item; |
||
768 | |||
769 | // Check if it's a directory or a file |
||
770 | if (is_dir($path)) { |
||
771 | // Delete directory and its contents |
||
772 | array_map('unlink', glob("$path/*.*")); |
||
773 | rmdir($path); |
||
774 | } elseif (is_file($path)) { |
||
775 | // Delete file |
||
776 | if (is_writable($path)) { |
||
777 | unlink($path); |
||
778 | } |
||
779 | } |
||
780 | } |
||
781 | |||
782 | return true; |
||
783 | } |
||
784 | |||
785 | /** |
||
786 | * Check if default notification method already exists |
||
787 | * |
||
788 | */ |
||
789 | public function check_notificationmethod() |
||
790 | { |
||
791 | $sql = 'SELECT COUNT(*) FROM `' . $GLOBALS['xoopsDB']->prefix('config') . "` WHERE `conf_name` IN ('default_notification')"; |
||
792 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
793 | return false; |
||
794 | } |
||
795 | return true; |
||
796 | } |
||
797 | |||
798 | /** |
||
799 | * @return bool |
||
800 | */ |
||
801 | public function apply_notificationmethod() |
||
831 | } |
||
832 | |||
833 | |||
834 | } |
||
835 | |||
836 | return new Upgrade_2511(); |
||
837 |