| Conditions | 11 |
| Paths | 240 |
| Total Lines | 76 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 31 | function xoops_module_update_extgallery(\XoopsModule $xoopsModule, $oldVersion = null) |
||
| 32 | { |
||
| 33 | $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
||
| 34 | $catHandler->rebuild(); |
||
| 35 | |||
| 36 | if ($oldVersion < 101) { |
||
| 37 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 38 | // Remove the UNIQUE key on the rating table. This constraint is software cheked now |
||
| 39 | $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicrating') . '` DROP INDEX `photo_rate` ;'; |
||
| 40 | $db->query($sql); |
||
| 41 | } |
||
| 42 | |||
| 43 | if ($oldVersion < 102) { |
||
| 44 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 45 | |||
| 46 | $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publiccat') . '` ADD `cat_imgurl` VARCHAR(150) NOT NULL AFTER `cat_nb_photo` ;'; |
||
| 47 | $db->query($sql); |
||
| 48 | |||
| 49 | $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . '` ADD `photo_title` VARCHAR(150) NOT NULL AFTER `photo_id` ;'; |
||
| 50 | $db->query($sql); |
||
| 51 | |||
| 52 | $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . '` ADD `photo_weight` INT(11) NOT NULL AFTER `photo_extra` ;'; |
||
| 53 | $db->query($sql); |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($oldVersion < 104) { |
||
| 57 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 58 | |||
| 59 | $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . "` ADD `dohtml` BOOL NOT NULL DEFAULT '0';"; |
||
| 60 | $db->query($sql); |
||
| 61 | |||
| 62 | $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . '` CHANGE `photo_desc` `photo_desc` TEXT;'; |
||
| 63 | $db->query($sql); |
||
| 64 | |||
| 65 | // Set display parmission for all XOOPS base Groups |
||
| 66 | $sql = 'SELECT cat_id FROM `' . $db->prefix('extgallery_publiccat') . '`;'; |
||
| 67 | $result = $db->query($sql); |
||
| 68 | $module_id = $xoopsModule->getVar('mid'); |
||
| 69 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 70 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 71 | while (false !== ($cat = $db->fetchArray($result))) { |
||
| 72 | $grouppermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ADMIN, $module_id); |
||
| 73 | $grouppermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_USERS, $module_id); |
||
| 74 | $grouppermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ANONYMOUS, $module_id); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($oldVersion < 106) { |
||
| 79 | if (!is_file(XOOPS_ROOT_PATH . '/uploads/extgallery/index.html')) { |
||
| 80 | $indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html'; |
||
| 81 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/index.html'); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!is_file(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html')) { |
||
| 85 | $indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html'; |
||
| 86 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html'); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($oldVersion < 107) { |
||
| 91 | // Fix extension Bug if it's installed |
||
| 92 | if (file_exists(XOOPS_ROOT_PATH . '/class/textsanitizer/gallery/gallery.php')) { |
||
| 93 | $conf = require XOOPS_ROOT_PATH . '/class/textsanitizer/config.php'; |
||
| 94 | $conf['extensions']['gallery'] = 1; |
||
| 95 | file_put_contents(XOOPS_ROOT_PATH . '/class/textsanitizer/config.custom.php', "<?php\rreturn \$config = " . var_export($conf, true) . "\r?>", LOCK_EX); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($oldVersion < 109) { |
||
| 100 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 101 | |||
| 102 | $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publiccat') . "` CHANGE `cat_weight` `cat_weight` INT( 11 ) NOT NULL DEFAULT '0' ;"; |
||
| 103 | $db->query($sql); |
||
| 104 | } |
||
| 105 | |||
| 106 | return true; |
||
| 107 | } |
||
| 108 |