Passed
Push — master ( d1b073...af2052 )
by Michael
32s queued 12s
created

action.module.php ➔ xoops_module_pre_install_xoopspartners()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 8

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 6
nop 1
dl 17
loc 17
rs 9.2
c 0
b 0
f 0
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
 * XOOPS XoopsPartners module
14
 *
15
 * @package      module\Xoopspartners\include
16
 * @author       Taiwen Jiang <[email protected]>
17
 * @author       zyspec <[email protected]>
18
 * @author       XOOPS Module Development Team
19
 * @copyright    {@link https://xoops.org 2001-2016 XOOPS Project}
20
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
21
 * @link         https://xoops.org XOOPS
22
 */
23
24
use XoopsModules\Xoopspartners;
25
use XoopsModules\Xoopspartners\Helper;
26
use XoopsModules\Xoopspartners\Utility;
27
28
/**
29
 * @internal {Make sure you PROTECT THIS FILE}
30
 */
31
if ((!defined('XOOPS_ROOT_PATH'))
32
    || !isset($GLOBALS['xoopsUser'])
33
    || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)
34
    || !$GLOBALS['xoopsUser']->isAdmin()) {
35
    exit('Restricted access' . PHP_EOL);
36
}
37
38
/**
39
 * Prepares system prior to attempting to install module
40
 * @param \XoopsModule $module {@link XoopsModule}
41
 *
42
 * @return bool true if ready to install, false if not
43
 */
44
function xoops_module_pre_install_xoopspartners(\XoopsModule $module)
45
{
46
    //check for minimum XOOPS version
47
    if (!Utility::checkVerXoops($module)) {
48
        return false;
49
    }
50
    // check for minimum PHP version
51
    if (!Utility::checkVerPhp($module)) {
52
        return false;
53
    }
54
55
    return true;
56
}
57
58
/**
59
 * Performs tasks required during installation of the module
60
 * @param \XoopsModule $module {@link XoopsModule}
61
 *
62
 * @return bool true if installation successful, false if not
63
 */
64
function xoops_module_install_xoopspartners(\XoopsModule $module)
65
{
66
    $indexFile = $GLOBALS['xoops']->path('/modules/' . $module->dirname() . '/include/index.html');
67
68
    //Create the "uploads" directory for the module
69
    $module_uploads = $GLOBALS['xoops']->path('/uploads/' . $module->dirname());
70
    if (!is_dir($module_uploads)) {
71
        if (!mkdir($module_uploads, 0777) && !is_dir($module_uploads)) {
72
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $module_uploads));
73
        }
74
    }
75
    chmod($module_uploads, 0777);
76
    //now copy the index file to help prevent 'browsing' the directory
77
    copy($indexFile, $GLOBALS['xoops']->path('/uploads/' . $module->dirname() . '/index.html'));
78
79
    return true;
80
}
81
82
/**
83
 * Prepares system prior to attempting to update module
84
 * @param \XoopsModule $module {@link XoopsModule}
85
 *
86
 * @return bool true if successfully ready to update module, false if not
87
 */
88
function xoops_module_pre_update_xoopspartners(\XoopsModule $module)
89
{
90
    /** @var Helper $helper */
91
    /** @var Utility $utility */
92
    $moduleDirName = basename(dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
93
    $helper        = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
94
    $utility       = new Utility();
95
96
    $xoopsSuccess = $utility::checkVerXoops($module);
97
    $phpSuccess   = $utility::checkVerPhp($module);
98
99
    return $xoopsSuccess && $phpSuccess;
100
}
101
102
/**
103
 * Functions to upgrade from previous version of the module
104
 *
105
 * @param \XoopsModule $module       {@link XoopsModule}
106
 * @param int          $curr_version version number of module currently installed
107
 *
108
 * @return bool true if successfully updated module, false if not
109
 */
110
function xoops_module_update_xoopspartners(\XoopsModule $module, $curr_version = null)
0 ignored issues
show
Unused Code introduced by
The parameter $curr_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

110
function xoops_module_update_xoopspartners(\XoopsModule $module, /** @scrutinizer ignore-unused */ $curr_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...
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

110
function xoops_module_update_xoopspartners(/** @scrutinizer ignore-unused */ \XoopsModule $module, $curr_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...
111
{
112
    return true;
113
}
114
115
/**
116
 * Function to perform before module uninstall
117
 * @param \XoopsModule $module {@link XoopsModule}
118
 *
119
 * @return bool true if successfully executed, false if not
120
 */
121
function xoops_module_pre_uninstall_xoopspartners(\XoopsModule $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

121
function xoops_module_pre_uninstall_xoopspartners(/** @scrutinizer ignore-unused */ \XoopsModule $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...
122
{
123
    return true;
124
}
125
126
/**
127
 * Function to complete upon module uninstall
128
 * @param \XoopsModule $module {@link XoopsModule}
129
 *
130
 * @return bool true if successfully executed uninstall of module, false if not
131
 */
132
function xoops_module_uninstall_xoopspartners(\XoopsModule $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

132
function xoops_module_uninstall_xoopspartners(/** @scrutinizer ignore-unused */ \XoopsModule $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...
133
{
134
    return true;
135
}
136