Passed
Pull Request — master (#5)
by Michael
02:50
created

xoops_module_install_tdmdownloads()   F

Complexity

Conditions 20
Paths 254

Size

Total Lines 121
Code Lines 86

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 86
nc 254
nop 0
dl 0
loc 121
rs 2.6583
c 0
b 0
f 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
use XoopsModules\Tdmdownloads;
4
/**
5
 * TDMDownload
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * @copyright   Gregory Mage (Aka Mage)
15
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
16
 * @author      Gregory Mage (Aka Mage)
17
 */
18
19
use XoopsModules\Tdmdownloads\Utility;
20
21
/**
22
 * @return bool
23
 */
24
function xoops_module_install_tdmdownloads()
25
{
26
    global $xoopsModule, $xoopsConfig, $xoopsDB;
27
    $moduleDirName = basename(dirname(__DIR__));
28
29
    $namemodule = $moduleDirName;
30
    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
31
        include_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php';
32
    } else {
33
        include_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/english/admin.php';
34
    }
35
    $fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field');
36
    $obj          = $fieldHandler->create();
37
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE);
38
    $obj->setVar('img', 'homepage.png');
39
    $obj->setVar('weight', 1);
40
    $obj->setVar('search', 0);
41
    $obj->setVar('status', 1);
42
    $obj->setVar('status_def', 1);
43
    $fieldHandler->insert($obj);
44
    $obj = $fieldHandler->create();
45
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION);
46
    $obj->setVar('img', 'version.png');
47
    $obj->setVar('weight', 2);
48
    $obj->setVar('search', 0);
49
    $obj->setVar('status', 1);
50
    $obj->setVar('status_def', 1);
51
    $fieldHandler->insert($obj);
52
    $obj = $fieldHandler->create();
53
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE);
54
    $obj->setVar('img', 'size.png');
55
    $obj->setVar('weight', 3);
56
    $obj->setVar('search', 0);
57
    $obj->setVar('status', 1);
58
    $obj->setVar('status_def', 1);
59
    $fieldHandler->insert($obj);
60
    $obj = $fieldHandler->create();
61
    $obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM);
62
    $obj->setVar('img', 'platform.png');
63
    $obj->setVar('weight', 4);
64
    $obj->setVar('search', 0);
65
    $obj->setVar('status', 1);
66
    $obj->setVar('status_def', 1);
67
    $fieldHandler->insert($obj);
68
69
    //Creation du fichier ".$namemodule."/
70
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '';
71
    if (!is_dir($dir)) {
72
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
73
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
74
        }
75
    }
76
    chmod($dir, 0777);
77
78
    //Creation du fichier ".$namemodule."/images/
79
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images';
80
    if (!is_dir($dir)) {
81
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
82
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
83
        }
84
    }
85
    chmod($dir, 0777);
86
87
    //Creation du fichier ".$namemodule."/images/cat
88
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats';
89
    if (!is_dir($dir)) {
90
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
91
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
92
        }
93
    }
94
    chmod($dir, 0777);
95
96
    //Creation du fichier ".$namemodule."/images/shots
97
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots';
98
    if (!is_dir($dir)) {
99
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
100
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
101
        }
102
    }
103
    chmod($dir, 0777);
104
105
    //Creation du fichier ".$namemodule."/images/field
106
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field';
107
    if (!is_dir($dir)) {
108
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
109
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
110
        }
111
    }
112
    chmod($dir, 0777);
113
114
    //Creation du fichier ".$namemodule."/downloads
115
    $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads';
116
    if (!is_dir($dir)) {
117
        if (!mkdir($dir, 0777) && !is_dir($dir)) {
118
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
119
        }
120
    }
121
    chmod($dir, 0777);
122
123
    //Copie des index.html
124
    $indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.html';
125
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.html');
126
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.html');
127
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.html');
128
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.html');
129
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.html');
130
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.html');
131
132
    //Copie des blank.gif
133
    $blankFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/blank.gif';
134
    copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/blank.gif');
135
    copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/blank.gif');
136
    copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/blank.gif');
137
138
    //Copie des images pour les champs
139
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/homepage.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/homepage.png');
140
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/version.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/version.png');
141
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/size.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/size.png');
142
    copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/platform.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/platform.png');
143
144
    return true;
145
}
146