xoops_module_update_extgallery()   C
last analyzed

Complexity

Conditions 11
Paths 240

Size

Total Lines 76
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 11
eloc 45
nc 240
nop 2
dl 0
loc 76
rs 5.9833
c 2
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 * ExtGallery functions
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   {@link https://xoops.org/ XOOPS Project}
13
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Zoullou (http://www.zoullou.net)
15
 * @package     ExtGallery
16
 */
17
18
/**
19
 * @param XoopsModule $xoopsModule
20
 * @param null        $oldVersion
21
 * @return bool
22
 */
23
24
use XoopsModules\Extgallery;
25
26
/**
27
 * @param \XoopsModule $xoopsModule
28
 * @param null         $oldVersion
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $oldVersion is correct as it would always require null to be passed?
Loading history...
29
 * @return bool
30
 */
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);
0 ignored issues
show
Bug introduced by
XOOPS_GROUP_ADMIN of type string is incompatible with the type integer expected by parameter $gperm_groupid of XoopsGroupPermHandler::addRight(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
            $grouppermHandler->addRight('public_displayed', $cat['cat_id'], /** @scrutinizer ignore-type */ XOOPS_GROUP_ADMIN, $module_id);
Loading history...
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