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