xoops_module_update_extcal()   B
last analyzed

Complexity

Conditions 11
Paths 20

Size

Total Lines 78
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 36
dl 0
loc 78
rs 7.3166
c 2
b 0
f 0
cc 11
nc 20
nop 2

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
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal\Helper;
21
22
/**
23
 * @param \XoopsModule $xoopsModule
24
 * @param null         $previousVersion
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $previousVersion is correct as it would always require null to be passed?
Loading history...
25
 *
26
 * @return bool
27
 */
28
function xoops_module_update_extcal(\XoopsModule $xoopsModule, $previousVersion = null)
29
{
30
    $helper     = Helper::getInstance();
31
    $newVersion = $helper->getModule()->getVar('version') * 100;
32
    if ($newVersion == $previousVersion) {
33
        return true;
34
    }
35
36
    //----------------------------------------------------------
37
    // Create eXtCal upload directory
38
    $indexFile = __DIR__ . '/index.html';
39
40
    $dir = XOOPS_ROOT_PATH . '/uploads/extcal';
41
    if (!is_dir($dir)) {
42
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
43
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
44
        }
45
        copy($indexFile, $dir . '/index.html');
46
    }
47
48
    $dir = XOOPS_ROOT_PATH . '/uploads/extcal/location';
49
    if (!is_dir($dir)) {
50
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
51
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
52
        }
53
        copy($indexFile, $dir . '/index.html');
54
    }
55
    //------------------------------------------------------------
56
57
    $fld = XOOPS_ROOT_PATH . '/modules/' . $helper->getModule()->getVar('dirname') . '/versions/';
58
    $cls = 'extcal_%1$s';
59
60
    $version = [
61
        '2_04' => 204,
62
        '2_15' => 215,
63
        '2_21' => 221,
64
        '2_28' => 228,
65
        '2_29' => 229,
66
        '2_33' => 233,
67
        '2_34' => 234,
68
        '2_35' => 235,
69
        '2_37' => 237,
70
    ];
71
72
    //    while (list($key, $val) = each($version)) {
73
    foreach ($version as $key => $val) {
74
        if ($previousVersion < $val) {
75
            $name = sprintf($cls, $key);
76
            $f    = $fld . $name . '.php';
77
            //ext_echo ("<hr>{$f}<hr>");
78
            if (is_readable($f)) {
79
                echo "_AM_EXTCAL_UPDATE_VERSION {$key} = {$val}<br>";
80
                require_once $f;
81
                $cl = new $name($xoopsModule, ['previousVersion' => $previousVersion]);
0 ignored issues
show
Unused Code introduced by
The assignment to $cl is dead and can be removed.
Loading history...
82
            }
83
        }
84
    }
85
86
    /*
87
        //$db = \XoopsDatabaseFactory::getDatabaseConnection();
88
        $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
89
90
        $sql = "ALTER TABLE `".$db->prefix('extcal_event')."` ADD `event_organisateur` varchar( 255 ) NOT NULL AFTER `event_desc` ;";
91
        $db->query($sql);
92
        ///////////
93
        // Create eXtcal upload directory
94
        $dir = XOOPS_ROOT_PATH."/uploads/extcal/location";
95
        if(!is_dir($dir))
96
            mkdir($dir, 0777);
97
            chmod($dir, 0777);
98
99
        // Copy index.html files on uploads folders
100
        $indexFile = XOOPS_ROOT_PATH."/modules/extcal/include/index.html";
101
        copy($indexFile, XOOPS_ROOT_PATH."/uploads/extcal/location/index.html");
102
103
        */
104
105
    return true;
106
}
107