Passed
Push — master ( c8b59f...a7d1b0 )
by
unknown
29s
created

update_tdmdownloads_v163()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 0
dl 0
loc 28
rs 9.568
c 0
b 0
f 0
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
20
function xoops_module_update_tdmdownloads(&$module, $prev_version = null)
21
{
22
    $ret = null;
23
    if ($prev_version < 163) {
24
        $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

24
        $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...
25
    }
26
    if ($prev_version < 167) {
27
        $ret = update_tdmdownloads_v167($module);
28
    }
29
    $errors = $module->getErrors();
30
    if (!empty($errors)) {
31
        //        print_r($errors);
32
    }
33
    return $ret;
34
}
35
36
/**
37
 * @param $module
38
 *
39
 * @return bool
40
 */
41
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

41
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...
42
{
43
    // rename module dir from upper case to lower case
44
    rename(XOOPS_ROOT_PATH . '/modules/TDMDownloads', XOOPS_ROOT_PATH . '/modules/tdmdownloads');
45
    // rename upload dir from upper case to lower case
46
    rename(XOOPS_ROOT_PATH . '/uploads/TDMDownloads', XOOPS_ROOT_PATH . '/uploads/tdmdownloads');
47
48
    // files have been moved to assets-folder
49
    $src = XOOPS_ROOT_PATH . '/modules/tdmdownloads/css/';;
50
    rrmdir($src);
51
    $src = XOOPS_ROOT_PATH . '/modules/tdmdownloads/images/';;
52
    rrmdir($src);
53
54
    // delete unneeded/replacfiles
55
    // unlink( XOOPS_ROOT_PATH.'/modules/tdmdownloads/admin/admin_header.php' );
56
57
    // clean template directory
58
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_brokenfile.html');
59
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_download.html');
60
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_index.html');
61
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_modfile.html');
62
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_ratefile.html');
63
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_singlefile.html');
64
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_submit.html');
65
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_viewcat.html');
66
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_liste.html');
67
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_rss.html');
68
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_new.html');
69
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_random.html');
70
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_rating.html');
71
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_search.html');
72
    unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_top.html');
73
74
    return true;
75
}
76
77
/**
78
 * @param $src
79
 */
80
function rrmdir($src)
81
{
82
83
    if (is_dir($src)) {
84
        $dir = opendir($src);
85
        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

85
        while (false !== ($file = readdir(/** @scrutinizer ignore-type */ $dir))) {
Loading history...
86
            if (('.' !== $file) && ('..' !== $file)) {
87
                $full = $src . '/' . $file;
88
                if (is_dir($full)) {
89
                    rrmdir($full);
90
                } else {
91
                    unlink($full);
92
                }
93
            }
94
        }
95
        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

95
        closedir(/** @scrutinizer ignore-type */ $dir);
Loading history...
96
        rmdir($src);
97
    }
98
}
99
100
/**
101
 * @return bool
102
 */
103
function update_tdmdownloads_v163()
104
{
105
    /** @var \XoopsMySQLDatabase $db */
106
    $db  = \XoopsDatabaseFactory::getDatabaseConnection();
107
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `cid` `cat_cid` INT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ;';
108
    $db->query($sql);
109
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . "` CHANGE `pid` `cat_pid` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' ;";
110
    $db->query($sql);
111
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `title` `cat_title` VARCHAR( 255 ) NOT NULL ;';
112
    $db->query($sql);
113
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `imgurl` `cat_imgurl` VARCHAR( 255 ) NOT NULL ;';
114
    $db->query($sql);
115
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . '` CHANGE `description_main` `cat_description_main` TEXT NOT NULL ;';
116
    $db->query($sql);
117
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_cat') . "` CHANGE `weight` `cat_weight` INT( 11 ) NOT NULL DEFAULT '0' ;";
118
    $db->query($sql);
119
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_downloads') . '` ADD `paypal` VARCHAR( 255 ) NOT NULL;';
120
    $db->query($sql);
121
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_downloads') . "` CHANGE `size` `size` VARCHAR( 15 ) NOT NULL DEFAULT '';";
122
    $db->query($sql);
123
    $sql = 'ALTER TABLE `' . $db->prefix('tdmdownloads_mod') . "` CHANGE `size` `size` VARCHAR( 15 ) NOT NULL DEFAULT '';";
124
    $db->query($sql);
125
    $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',
126
           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)
127
           ) ENGINE=MyISAM";
128
    $db->query($sql);
129
130
    return true;
131
}
132