Completed
Branch master (95d503)
by Michael
03:25
created

update_function.php ➔ xoops_module_update_extgallery()   D

Complexity

Conditions 11
Paths 240

Size

Total Lines 78
Code Lines 46

Duplication

Lines 20
Ratio 25.64 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 11
eloc 46
c 4
b 0
f 1
nc 240
nop 2
dl 20
loc 78
rs 4.074

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 http://xoops.org/ XOOPS Project}
13
 * @license     GNU GPL 2 (http://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
function xoops_module_update_extgallery(XoopsModule $xoopsModule, $oldVersion = null)
24
{
25
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
26
    $catHandler->rebuild();
27
28 View Code Duplication
    if ($oldVersion < 101) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
        $db = XoopsDatabaseFactory::getDatabaseConnection();
30
        // Remove the UNIQUE key on the rating table. This constraint is software cheked now
31
        $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicrating') . '` DROP INDEX `photo_rate` ;';
32
        $db->query($sql);
33
    }
34
35
    if ($oldVersion < 102) {
36
        $db = XoopsDatabaseFactory::getDatabaseConnection();
37
38
        $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publiccat') . '` ADD `cat_imgurl` VARCHAR(150) NOT NULL AFTER `cat_nb_photo` ;';
39
        $db->query($sql);
40
41
        $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . '` ADD `photo_title` VARCHAR(150) NOT NULL AFTER `photo_id` ;';
42
        $db->query($sql);
43
44
        $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . '` ADD `photo_weight` int(11) NOT NULL AFTER `photo_extra` ;';
45
        $db->query($sql);
46
    }
47
48
    if ($oldVersion < 104) {
49
        $db = XoopsDatabaseFactory::getDatabaseConnection();
50
51
        $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . "` ADD `dohtml` BOOL NOT NULL DEFAULT '0';";
52
        $db->query($sql);
53
54
        $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publicphoto') . '` CHANGE `photo_desc` `photo_desc` TEXT;';
55
        $db->query($sql);
56
57
        // Set display parmission for all XOOPS base Groups
58
        $sql          = 'SELECT cat_id FROM `' . $db->prefix('extgallery_publiccat') . '`;';
59
        $result       = $db->query($sql);
60
        $module_id    = $xoopsModule->getVar('mid');
61
        /** @var XoopsGroupPermHandler $gpermHandler*/
62
        $gpermHandler = xoops_getHandler('groupperm');
63
        while ($cat = $db->fetchArray($result)) {
64
            $gpermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ADMIN, $module_id);
65
            $gpermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_USERS, $module_id);
66
            $gpermHandler->addRight('public_displayed', $cat['cat_id'], XOOPS_GROUP_ANONYMOUS, $module_id);
67
        }
68
    }
69
70
    if ($oldVersion < 106) {
71 View Code Duplication
        if (!file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/index.html')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
            $indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html';
73
            copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/index.html');
74
        }
75
76 View Code Duplication
        if (!file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
            $indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html';
78
            copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html');
79
        }
80
    }
81
82
    if ($oldVersion < 107) {
83
84
        // Fix extension Bug if it's installed
85
        if (file_exists(XOOPS_ROOT_PATH . '/class/textsanitizer/gallery/gallery.php')) {
86
            $conf                          = include XOOPS_ROOT_PATH . '/class/textsanitizer/config.php';
87
            $conf['extensions']['gallery'] = 1;
88
            file_put_contents(XOOPS_ROOT_PATH . '/class/textsanitizer/config.custom.php', "<?php\rreturn \$config = " . var_export($conf, true) . "\r?>");
89
        }
90
    }
91
92 View Code Duplication
    if ($oldVersion < 109) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
        $db = XoopsDatabaseFactory::getDatabaseConnection();
94
95
        $sql = 'ALTER TABLE `' . $db->prefix('extgallery_publiccat') . "` CHANGE `cat_weight` `cat_weight` INT( 11 ) NOT NULL DEFAULT '0' ;";
96
        $db->query($sql);
97
    }
98
99
    return true;
100
}
101