Passed
Push — master ( e12440...7742f2 )
by Michael
02:31
created

xoops_module_pre_install_chess()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 25
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 25
rs 9.6111
1
<?php
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
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
13
/**
14
 * @copyright     {@link https://xoops.org/ XOOPS Project}
15
 * @license       {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
16
 * @package      Chess
17
 * @since        2.01
18
 * @author        XOOPS Development Team
19
 */
20
21
/**
22
 * Prepares system prior to attempting to install module
23
 * @param \XoopsModule $module {@link XoopsModule}
24
 *
25
 * @return bool true if ready to install, false if not
26
 */
27
function xoops_module_pre_install_chess(\XoopsModule $module)
28
{
29
    //    require  dirname(__DIR__) . '/preloads/autoloader.php';
30
31
    require __DIR__ . '/common.php';
32
33
    $utility = new \XoopsModules\Chess\Utility();
34
35
    //check for minimum XOOPS version
36
37
    $xoopsSuccess = $utility::checkVerXoops($module);
38
39
    // check for minimum PHP version
40
41
    $phpSuccess = $utility::checkVerPhp($module);
42
43
    if ($xoopsSuccess && $phpSuccess) {
44
        $moduleTables = &$module->getInfo('tables');
45
46
        foreach ($moduleTables as $table) {
47
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
48
        }
49
    }
50
51
    return $xoopsSuccess && $phpSuccess;
52
}
53
54
/**
55
 * Performs tasks required during installation of the module
56
 * @param \XoopsModule $module {@link XoopsModule}
57
 *
58
 * @return bool true if installation successful, false if not
59
 */
60
function xoops_module_install_chess(\XoopsModule $module)
61
{
62
    require_once dirname(__DIR__) . '/preloads/autoloader.php';
63
64
    $moduleDirName = basename(dirname(__DIR__));
65
66
    /** @var \XoopsModules\Chess\Helper $helper */
67
68
    /** @var \XoopsModules\Chess\Utility $utility */
69
70
    /** @var \XoopsModules\Chess\Common\Configurator $configurator */
71
72
    $helper = \XoopsModules\Chess\Helper::getInstance();
73
74
    $utility = new \XoopsModules\Chess\Utility();
75
76
    $configurator = new \XoopsModules\Chess\Common\Configurator();
77
78
    // Load language files
79
80
    $helper->loadLanguage('admin');
81
82
    $helper->loadLanguage('modinfo');
83
84
    // default Permission Settings ----------------------
85
86
    $moduleId = $module->getVar('mid');
87
88
    //$moduleName = $module->getVar('name');
89
90
    $grouppermHandler = xoops_getHandler('groupperm');
91
92
    // access rights ------------------------------------------
93
94
    $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
0 ignored issues
show
Bug introduced by
The method addRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

94
    $grouppermHandler->/** @scrutinizer ignore-call */ 
95
                       addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
Loading history...
95
96
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
97
98
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
99
100
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
101
102
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
103
104
    //  ---  CREATE FOLDERS ---------------
105
106
    if (count($configurator->uploadFolders) > 0) {
107
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
108
109
        foreach (array_keys($configurator->uploadFolders) as $i) {
110
            $utility::createFolder($configurator->uploadFolders[$i]);
111
        }
112
    }
113
114
    //  ---  COPY blank.png FILES ---------------
115
116
    if (count($configurator->copyBlankFiles) > 0) {
117
        $file = dirname(__DIR__) . '/assets/images/blank.png';
118
119
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
120
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
121
122
            $utility::copyFile($file, $dest);
123
        }
124
    }
125
126
    /*
127
        //  ---  COPY test folder files ---------------
128
    if (count($configurator->copyTestFolders) > 0) {
129
        //        $file =  dirname(__DIR__) . '/testdata/images/';
130
        foreach (array_keys($configurator->copyTestFolders) as $i) {
131
            $src  = $configurator->copyTestFolders[$i][0];
132
            $dest = $configurator->copyTestFolders[$i][1];
133
            $utility::xcopy($src, $dest);
134
        }
135
    }
136
    */
137
138
    //delete .html entries from the tpl table
139
140
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
141
142
    $GLOBALS['xoopsDB']->queryF($sql);
143
144
    return true;
145
}
146