module.php ➔ xoops_module_uninstall_userlog()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 21.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 *  userlog module
13
 *
14
 * @copyright       XOOPS Project (https://xoops.org)
15
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
16
 * @package         userlog include
17
 * @since           1
18
 * @author          irmtfan ([email protected])
19
 * @author          XOOPS Project <www.xoops.org> <www.xoops.ir>
20
 */
21
defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
22
require_once __DIR__ . '/common.php';
23
/**
24
 * @param XoopsModule $module
25
 *
26
 * @return int
27
 */
28
function xoops_module_uninstall_userlog(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
{
30
    $logsetObj = UserlogSetting::getInstance();
31
32
    return $logsetObj->cleanCache(); // delete all settings caches
33
}
34
35
/**
36
 * @param XoopsModule $module
37
 * @param null        $prev_version
38
 *
39
 * @return bool|mixed
40
 */
41
42
function xoops_module_update_userlog(XoopsModule $module, $prev_version = null)
43
{
44
    if ($prev_version == round($module->getInfo('version') * 100, 2)) {
45
        $module->setErrors('You have the latest ' . $module->getInfo('name') . ' module (' . $module->getInfo('dirname') . ' version ' . $module->getInfo('version') . ') and update is not necessary');
46
//        print_r($module->getErrors());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
47
48
        return true;
49
    }
50
    $ret = true;
51
    // first db update
52
    if (100 == $prev_version) {
53
        $ret = update_userlog_v100($module);
54
    }
55
    if ($prev_version < 114) {
56
        $ret = update_userlog_v114($module);
57
    }
58
    if ($prev_version < 115) {
59
        $ret = update_userlog_v115($module);
60
    }
61
    if ($prev_version < 116) {
62
        $ret = update_userlog_v116($module);
63
    }
64
    $errors = $module->getErrors();
65
    if (!empty($errors)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
66
//        print_r($errors);
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...
67
    }
68
69
    return $ret;
70
}
71
72
// update database from v1 to 1.01 (Beta1 to RC1)
73
// module_name VARCHAR(25) change to VARCHAR(50)
74
/**
75
 * @param XoopsModule $module
76
 *
77
 * @return bool
78
 */
79 View Code Duplication
function update_userlog_v100(XoopsModule $module)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
80
{
81
    $field   = 'module_name';
82
    $userlog  = Userlog::getInstance();
83
    $ret     = $userlog->getHandler('log')->showFields($field);
84
    preg_match_all('!\d+!', $ret[$field]['Type'], $nums);
85
    // only change if module_name Type was VARCHAR(25)
86
    if (25 == $nums[0][0]) {
87
        $ret2 = $userlog->getHandler('log')->changeField($field, "VARCHAR(50) NOT NULL default ''");
88
    } else {
89
        $ret2 = true;
90
        $module->setErrors("Your table field ({$field}) with size {$ret[$field]['Type']} don't need change.");
91
    }
92
93
    return $ret2;
94
}
95
96
// add ",active,inside,outside,unset_pass" to all settings
97
/**
98
 * @param XoopsModule $module
99
 *
100
 * @return bool
101
 */
102 View Code Duplication
function update_userlog_v114(XoopsModule $module)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
103
{
104
    $userlog    = Userlog::getInstance();
105
    $logsetsObj = $userlog->getHandler('setting')->getAll();
106
    $ret        = true;
107
    foreach ($logsetsObj as $setObj) {
108
        if (strpos($setObj->getVar('options'), 'active')) {
109
            continue;
110
        }
111
        $setObj->setVar('options', $setObj->getVar('options') . ',active,inside,outside,unset_pass');
112
        if (!$setObj->storeSet(true)) {
113
            $ret = false;
114
            $module->setErrors(_AM_USERLOG_SET_ERROR . ' id=' . $setObj->set_id() . ' options=' . $setObj->options());
115
        }
116
    }
117
118
    return $ret;
119
}
120
121
/**
122
 * @param XoopsModule $module
123
 *
124
 * @return mixed
125
 */
126 View Code Duplication
function update_userlog_v115(XoopsModule $module)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
127
{
128
    $userlog  = Userlog::getInstance();
129
    // Only change the field from INDEX to UNIQUE if it is not unique
130
    // if (isset($indexArr[0]["Non_unique"]) || $indexArr[0]["Non_unique"] == 1) { }
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
131
    // change the index in _stats table
132
    if (!$ret = $userlog->getHandler('stats')->changeIndex('stats_type_link_period', ['stats_type', 'stats_link', 'stats_period'], 'UNIQUE')) {
133
        $module->setErrors("'stats_type_link_period' index is not changed to unique. Warning: do not use module until you change this index to unique.");
134
    }
135
    // drop the index in _log table
136
    if (!$ret = $userlog->getHandler('log')->dropIndex('log_id_uid')) {
137
        $module->setErrors("'log_id_uid' index is not dropped.");
138
    }
139
    // add the index in _log table
140
    if (!$ret = $userlog->getHandler('log')->addIndex('log_time', ['log_time'])) {
141
        $module->setErrors("'log_time' index is not added.");
142
    }
143
144
    return $ret;
145
}
146
147
/**
148
 * @param XoopsModule $module
149
 *
150
 * @return bool
151
 */
152 View Code Duplication
function update_userlog_v116(XoopsModule $module)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
153
{
154
    // remove old html template files
155
    $template_directory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/';
156
    $template_list      = array_diff(scandir($template_directory, SCANDIR_SORT_NONE), ['..', '.']);
157
    foreach ($template_list as $k => $v) {
158
        $fileinfo = new SplFileInfo($template_directory . $v);
159
        if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) {
160
            @unlink($template_directory . $v);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
161
        }
162
    }
163
164
    return true;
165
}
166