Passed
Push — master ( 3f3727...30b7f7 )
by Goffy
03:19
created

wggithub_check_db()   F

Complexity

Conditions 21
Paths > 20000

Size

Total Lines 153
Code Lines 101

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 21
eloc 101
c 1
b 0
f 1
nc 59049
nop 1
dl 0
loc 153
rs 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
 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
 * Wggithub module for xoops
14
 *
15
 * @param mixed      $module
16
 * @param null|mixed $prev_version
17
 * @package        Wggithub
18
 * @since          1.0
19
 * @min_xoops      2.5.9
20
 * @author         Wedega - Email:<[email protected]> - Website:<https://wedega.com>
21
 * @version        $Id: 1.0 update.php 1 Mon 2018-03-19 10:04:53Z XOOPS Project (www.xoops.org) $
22
 * @copyright      module for xoops
23
 * @license        GPL 2.0 or later
24
 */
25
26
/**
27
 * @param      $module
28
 * @param null $prev_version
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $prev_version is correct as it would always require null to be passed?
Loading history...
29
 *
30
 * @return bool|null
31
 */
32
function xoops_module_update_wggithub($module, $prev_version = null)
0 ignored issues
show
Unused Code introduced by
The parameter $prev_version is not used and could be removed. ( Ignorable by Annotation )

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

32
function xoops_module_update_wggithub($module, /** @scrutinizer ignore-unused */ $prev_version = null)

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

Loading history...
33
{
34
    //wggithub_check_db($module);
35
36
    //check upload directory
37
    include_once __DIR__ . '/install.php';
38
    xoops_module_install_wggithub($module);
39
40
    $errors = $module->getErrors();
41
    if (!empty($errors)) {
42
        print_r($errors);
43
    }
44
45
    return true;
46
47
}
48
49
/**
50
 * @param $module
51
 *
52
 * @return bool
53
 */
54
function wggithub_check_db($module)
55
{
56
    $ret = true;
57
    //insert here code for database check
58
59
    // update table (add new field)
60
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_repositories');
61
    $field   = 'repo_release';
62
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
63
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
64
    if (!$numRows) {
65
        $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`;";
66
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
67
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
0 ignored issues
show
Bug introduced by
The function xoops_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

67
            /** @scrutinizer ignore-call */ xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
Loading history...
68
            $module->setErrors("Error when adding '$field' to table '$table'.");
69
            $ret = false;
70
        }
71
    }
72
73
    // update table (add new field)
74
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_repositories');
75
    $field   = 'repo_prerelease';
76
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
77
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
78
    if (!$numRows) {
79
        $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`;";
80
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
81
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
82
            $module->setErrors("Error when adding '$field' to table '$table'.");
83
            $ret = false;
84
        }
85
    }
86
    // update table (add new field)
87
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_repositories');
88
    $field   = 'repo_readme';
89
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
90
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
91
    if (!$numRows) {
92
        $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`;";
93
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
94
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
95
            $module->setErrors("Error when adding '$field' to table '$table'.");
96
            $ret = false;
97
        }
98
    }
99
100
    // update table (add new field)
101
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_directories');
102
    $field   = 'dir_filterrelease';
103
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
104
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
105
    if (!$numRows) {
106
        $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `dir_online`;";
107
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
108
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
109
            $module->setErrors("Error when adding '$field' to table '$table'.");
110
            $ret = false;
111
        }
112
    }
113
114
    // create new table
115
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_logs');
116
    $check   = $GLOBALS['xoopsDB']->queryF("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='$table'");
117
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
118
    if (!$numRows) {
119
        // create new table
120
        $sql = "CREATE TABLE `$table` (
121
              `log_id` INT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
122
              `log_type` INT(1) NOT NULL DEFAULT '0',
123
              `log_details` VARCHAR(255) NOT NULL DEFAULT '',
124
              `log_result` TEXT NOT NULL ,
125
              `log_datecreated` INT(11) NOT NULL DEFAULT '0',
126
              `log_submitter` INT(10) NOT NULL DEFAULT '0',
127
              PRIMARY KEY (`log_id`)
128
                ) ENGINE=InnoDB;";
129
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
130
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
131
            $module->setErrors("Error when creating table '$table'.");
132
            $ret = false;
133
        }
134
    }
135
136
    // update table (add new field)
137
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_directories');
138
    $field   = 'dir_content';
139
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
140
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
141
    if (!$numRows) {
142
        $sql = "ALTER TABLE `$table` ADD `$field` INT(10) NOT NULL DEFAULT '0' AFTER `dir_type`;";
143
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
144
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
145
            $module->setErrors("Error when adding '$field' to table '$table'.");
146
            $ret = false;
147
        }
148
    }
149
150
    // update table (add new field)
151
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_directories');
152
    $field   = 'dir_descr';
153
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
154
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
155
    if (!$numRows) {
156
        $sql = "ALTER TABLE `$table` ADD `$field` TEXT NOT NULL AFTER `dir_type`;";
157
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
158
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
159
            $module->setErrors("Error when adding '$field' to table '$table'.");
160
            $ret = false;
161
        }
162
    }
163
164
    // update table (add new field)
165
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_readmes');
166
    $field   = 'rm_baseurl';
167
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
168
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
169
    if (!$numRows) {
170
        $sql = "ALTER TABLE `$table` ADD `$field` VARCHAR(255) NOT NULL DEFAULT '' AFTER `rm_downloadurl`;";
171
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
172
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
173
            $module->setErrors("Error when adding '$field' to table '$table'.");
174
            $ret = false;
175
        }
176
    }
177
178
    // update table (add new field)
179
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_directories');
180
    $field   = 'dir_weight';
181
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
182
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
183
    if (!$numRows) {
184
        $sql = "ALTER TABLE `$table` ADD `$field` INT(10) NOT NULL DEFAULT '0' AFTER `dir_filterrelease`;";
185
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
186
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
187
            $module->setErrors("Error when adding '$field' to table '$table'.");
188
            $ret = false;
189
        }
190
    }
191
192
    // update table (add new field)
193
    $table   = $GLOBALS['xoopsDB']->prefix('wggithub_repositories');
194
    $field   = 'repo_approved';
195
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
196
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
197
    if (!$numRows) {
198
        $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_release`;";
199
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
200
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
201
            $module->setErrors("Error when adding '$field' to table '$table'.");
202
            $ret = false;
203
        }
204
    }
205
206
    return $ret;
207
}
208