Completed
Push — master ( 2a7c05...7c1d68 )
by Michael
02:50
created

oninstall.php ➔ xoops_module_install_adslight()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 79
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 32
nc 16
nop 1
dl 0
loc 79
rs 6.5649
c 0
b 0
f 0

How to fix   Long Method   

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    XOOPS Project http://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author       XOOPS Development Team
16
 */
17
18
/**
19
 * Prepares system prior to attempting to install module
20
 * @param XoopsModule $xoopsModule {@link XoopsModule}
21
 *
22
 * @return bool true if ready to install, false if not
23
 */
24
function xoops_module_pre_install_adslight(XoopsModule $xoopsModule)
25
{
26
    $moduleDirName = basename(dirname(__DIR__));
27
    $className     = ucfirst($moduleDirName) . 'Utility';
28
    if (!class_exists($className)) {
29
        xoops_load('utility', $moduleDirName);
30
    }
31
    //check for minimum XOOPS version
32
    if (!$className::checkXoopsVer($xoopsModule)) {
33
        return false;
34
    }
35
36
    // check for minimum PHP version
37
    if (!$className::checkPhpVer($xoopsModule)) {
38
        return false;
39
    }
40
41
    $mod_tables = $xoopsModule->getInfo('tables');
42
    foreach ($mod_tables as $table) {
43
        $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
44
    }
45
46
    return true;
47
}
48
49
/**
50
 *
51
 * Performs tasks required during installation of the module
52
 * @param XoopsModule $xoopsModule {@link XoopsModule}
53
 *
54
 * @return bool true if installation successful, false if not
55
 */
56
function xoops_module_install_adslight(XoopsModule $xoopsModule)
57
{
58
    require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
59
60
    global $xoopsDB;
61
    //    $moduleDirName = $xoopsModule->getVar('dirname');
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
    $moduleDirName = basename(dirname(__DIR__));
63
    xoops_loadLanguage('admin', $moduleDirName);
64
    xoops_loadLanguage('modinfo', $moduleDirName);
65
66
    $configurator = include __DIR__ . '/config.php';
67
    $classUtility     = ucfirst($moduleDirName) . 'Utility';
68
    ;
69
    if (!class_exists($classUtility)) {
70
        xoops_load('utility', $moduleDirName);
71
    }
72
73
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
74
75
    // default Permission Settings ----------------------
76
    $moduleId = $xoopsModule->getVar('mid');
77
    //    $module_name = $xoopsModule->getVar('name');
78
    //    $module_dirname = $xoopsModule->getVar('dirname');
79
    //    $module_version = $xoopsModule->getVar('version');
80
    $gpermHandler = xoops_getHandler('groupperm');
81
    // access rights ------------------------------------------
82
    $gpermHandler->addRight($moduleDirName . '_premium', 1, XOOPS_GROUP_ADMIN, $moduleId);
83
    $gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
84
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
85
    $gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_USERS, $moduleId);
86
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
87
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
88
89
    $result8 = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_categories'));
90
    $rowsCount = $xoopsDB->getRowsNum($xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('adslight_categories') . ''));
91
92
93
94
    $classUtility::saveCategoryPermissions($groups, $categoryId, $permName);
95
*/
96
97
    $groups1 = [XOOPS_GROUP_ADMIN];
98
    $groups2 = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS];
99
    $groups3 = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS];
100
101
    $permName1 = $moduleDirName . '_premium';
102
    $permName2 = $moduleDirName . '_submit';
103
    $permName3 = $moduleDirName . '_view';
104
105
    $rowsCount = $xoopsDB->getRowsNum($xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('adslight_categories') . ''));
0 ignored issues
show
Unused Code introduced by
$rowsCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
106
107
    $result = $xoopsDB->query('SELECT cid FROM ' . $xoopsDB->prefix('adslight_categories'));
108
109
    while ($myrow = $xoopsDB->fetchArray($result)) {
110
        $categoryId = (int)($myrow['cid']);
111
        $classUtility::saveCategoryPermissions($groups1, $categoryId, $permName1);
112
        $classUtility::saveCategoryPermissions($groups2, $categoryId, $permName2);
113
        $classUtility::saveCategoryPermissions($groups3, $categoryId, $permName3);
114
    }
115
116
    //  ---  CREATE FOLDERS ---------------
117
    if (count($configurator['uploadFolders']) > 0) {
118
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
119
        foreach (array_keys($configurator['uploadFolders']) as $i) {
120
            $classUtility::createFolder($configurator['uploadFolders'][$i]);
121
        }
122
    }
123
124
    //  ---  COPY blank.png FILES ---------------
125
    if (count($configurator['copyFiles']) > 0) {
126
        $file = __DIR__ . '/../assets/images/blank.png';
127
        foreach (array_keys($configurator['copyFiles']) as $i) {
128
            $dest = $configurator['copyFiles'][$i] . '/blank.png';
129
            $classUtility::copyFile($file, $dest);
130
        }
131
    }
132
133
    return true;
134
}
135