Passed
Push — master ( 81a617...f7060c )
by Goffy
02:56 queued 52s
created

update_tdmdownloads_v200()   C

Complexity

Conditions 12
Paths 12

Size

Total Lines 43
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 34
nc 12
nop 1
dl 0
loc 43
rs 6.9666
c 1
b 0
f 0

How to fix   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
 * TDMDownload
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   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 * @param      $module
16
 * @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...
17
 * @return bool|null
18
 */
19
function xoops_module_update_tdmdownloads(&$module, $prev_version = null)
20
{
21
    $ret = null;
22
    if ($prev_version < 163) {
23
        $ret = update_tdmdownloads_v163($module);
0 ignored issues
show
Unused Code introduced by
The call to update_tdmdownloads_v163() has too many arguments starting with $module. ( Ignorable by Annotation )

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

23
        $ret = /** @scrutinizer ignore-call */ update_tdmdownloads_v163($module);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
24
    }
25
    if ($prev_version < 167) {
26
        $ret = update_tdmdownloads_v167($module);
27
    }
28
	if ($prev_version < 200) {
29
        $ret = update_tdmdownloads_v200($module);
30
    }
31
    $errors = $module->getErrors();
32
    if (!empty($errors)) {
33
        //        print_r($errors);
34
    }
35
36
    return $ret;
37
}
38
39
/**
40
 * @param $module
41
 *
42
 * @return bool
43
 */
44
function update_tdmdownloads_v200(&$module)
0 ignored issues
show
Unused Code introduced by
The parameter $module 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

44
function update_tdmdownloads_v200(/** @scrutinizer ignore-unused */ &$module)

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...
45
{
46
	$db  = \XoopsDatabaseFactory::getDatabaseConnection();
47
	$sql = 'SELECT lid, size FROM ' . $db->prefix('tdmdownloads_downloads');
48
	$result = $db->query($sql);
49
	$helper = \XoopsModules\Tdmdownloads\Helper::getInstance();
50
	$helper->loadLanguage('admin');
51
	//print_r($result);
52
	while (false !== ($myrow = $db->fetchArray($result))) {
53
		$size_value_arr = explode(' ', $myrow['size']);
54
		switch ($size_value_arr[1]) {
55
			case _AM_TDMDOWNLOADS_BYTES:
56
			case 'Bytes':
57
				$sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' B\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';';
58
				$db->query($sql);
59
				break;
60
				
61
			case _AM_TDMDOWNLOADS_KBYTES:
62
			case 'kB':
63
				$sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' K\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';';
64
				$db->query($sql);
65
				break;
66
				
67
			case _AM_TDMDOWNLOADS_MBYTES:
68
			case 'MB':
69
				$sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' M\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';';
70
				$db->query($sql);
71
				break;
72
				
73
			case _AM_TDMDOWNLOADS_GBYTES:
74
			case 'GB':
75
				$sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' G\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';';
76
				$db->query($sql);
77
				break;
78
				
79
			case _AM_TDMDOWNLOADS_TBYTES:
80
			case 'TB':
81
				$sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `size` = \'' . $size_value_arr[0] . ' T\'' . ' WHERE `lid` = ' . $myrow['lid'] . ';';
82
				$db->query($sql);
83
				break;
84
		}
85
	}
86
	return true;	
87
}
88
89
/**
90
 * @param $module
91
 *
92
 * @return bool
93
 */
94
function update_tdmdownloads_v167(&$module)
0 ignored issues
show
Unused Code introduced by
The parameter $module 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

94
function update_tdmdownloads_v167(/** @scrutinizer ignore-unused */ &$module)

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...
95
{
96
    // rename module dir from upper case to lower case
97
    rename(XOOPS_ROOT_PATH . '/modules/TDMDownloads', XOOPS_ROOT_PATH . '/modules/tdmdownloads');
98
    // rename upload dir from upper case to lower case
99
    rename(XOOPS_ROOT_PATH . '/uploads/TDMDownloads', XOOPS_ROOT_PATH . '/uploads/tdmdownloads');
100
101
    // files have been moved to assets-folder
102
    $src = XOOPS_ROOT_PATH . '/modules/tdmdownloads/css/';
103
104
    rrmdir($src);
105
    $src = XOOPS_ROOT_PATH . '/modules/tdmdownloads/images/';
106
107
    rrmdir($src);
108
109
    // delete unneeded/replacfiles
110
    // unlink( XOOPS_ROOT_PATH.'/modules/tdmdownloads/admin/admin_header.php' );
111
112
    // clean template directory
113
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_brokenfile.html');
114
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_download.html');
115
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_index.html');
116
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_modfile.html');
117
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_ratefile.html');
118
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_singlefile.html');
119
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_submit.html');
120
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_viewcat.html');
121
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_liste.html');
122
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_rss.html');
123
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_new.html');
124
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_random.html');
125
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_rating.html');
126
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_search.html');
127
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_top.html');
128
129
    return true;
130
}
131
132
/**
133
 * @param $src
134
 */
135
function rrmdir($src)
136
{
137
    if (is_dir($src)) {
138
        $dir = opendir($src);
139
        while (false !== ($file = readdir($dir))) {
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type false; however, parameter $dir_handle of readdir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

139
        while (false !== ($file = readdir(/** @scrutinizer ignore-type */ $dir))) {
Loading history...
140
            if (('.' !== $file) && ('..' !== $file)) {
141
                $full = $src . '/' . $file;
142
                if (is_dir($full)) {
143
                    rrmdir($full);
144
                } else {
145
                    unlink($full);
146
                }
147
            }
148
        }
149
        closedir($dir);
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type false; however, parameter $dir_handle of closedir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

149
        closedir(/** @scrutinizer ignore-type */ $dir);
Loading history...
150
        rmdir($src);
151
    }
152
}
153
154
/**
155
 * @return bool
156
 */
157
function update_tdmdownloads_v163()
158
{
159
    /** @var \XoopsMySQLDatabase $db */
160
    $db  = \XoopsDatabaseFactory::getDatabaseConnection();
161
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `cid` `cat_cid` INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ;';
162
    $db->query($sql);
163
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . "` CHANGE `pid` `cat_pid` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' ;";
164
    $db->query($sql);
165
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `title` `cat_title` VARCHAR( 255 ) NOT NULL ;';
166
    $db->query($sql);
167
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `imgurl` `cat_imgurl` VARCHAR( 255 ) NOT NULL ;';
168
    $db->query($sql);
169
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `description_main` `cat_description_main` TEXT NOT NULL ;';
170
    $db->query($sql);
171
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . "` CHANGE `weight` `cat_weight` INT( 11 ) NOT NULL DEFAULT '0' ;";
172
    $db->query($sql);
173
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_downloads') . '` ADD `paypal` VARCHAR( 255 ) NOT NULL;';
174
    $db->query($sql);
175
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_downloads') . "` CHANGE `size` `size` VARCHAR( 15 ) NOT NULL DEFAULT '';";
176
    $db->query($sql);
177
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_mod') . "` CHANGE `size` `size` VARCHAR( 15 ) NOT NULL DEFAULT '';";
178
    $db->query($sql);
179
    $sql = 'CREATE TABLE `' . $db->prefix('tdmdownloads_downlimit') . "` (downlimit_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, downlimit_lid INT(11) UNSIGNED NOT NULL DEFAULT '0',
180
           downlimit_uid INT(11) NOT NULL DEFAULT '0', downlimit_hostname VARCHAR(60) NOT NULL DEFAULT '', downlimit_date INT(10) NOT NULL DEFAULT '0', PRIMARY KEY  (downlimit_id)
181
           ) ENGINE=MyISAM";
182
    $db->query($sql);
183
184
    return true;
185
}
186