Passed
Branch master (1b1cd9)
by Michael
03:24
created

xoops_module_pre_install_publisher()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 1
dl 0
loc 19
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
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
9
 This program is distributed in the hope that it will be useful,
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 */
13
14
/**
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @author          luciorota <[email protected]>
18
 */
19
20
use XoopsModules\Publisher\{Common\Configurator,
21
    Helper,
22
    Utility
23
};
24
25
/** @var Helper $helper */
26
/** @var Utility $utility */
27
/** @var Common\Configurator $configurator */
28
29
/**
30
 * @param \XoopsModule $module
31
 * @return bool
32
 */
33
function xoops_module_pre_install_publisher(\XoopsModule $module)
34
{
35
    require dirname(__DIR__) . '/preloads/autoloader.php';
36
    $utility = new Utility();
37
38
    //check for minimum XOOPS version
39
    $xoopsSuccess = $utility::checkVerXoops($module);
40
41
    // check for minimum PHP version
42
    $phpSuccess = $utility::checkVerPhp($module);
43
44
    if ($xoopsSuccess && $phpSuccess) {
45
        $moduleTables = &$module->getInfo('tables');
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
 * @param \XoopsModule $module
56
 * @return bool|string
57
 */
58
function xoops_module_install_publisher(\XoopsModule $module)
59
{
60
    require dirname(__DIR__) . '/preloads/autoloader.php';
61
62
    $helper       = Helper::getInstance();
63
    $utility      = new Utility();
64
    $configurator = new Common\Configurator();
0 ignored issues
show
Bug introduced by
The type Common\Configurator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
65
66
    // Load language files
67
    $helper->loadLanguage('admin');
68
    $helper->loadLanguage('modinfo');
69
70
    //  ---  CREATE FOLDERS ---------------
71
    if ($configurator->uploadFolders && is_array($configurator->uploadFolders)) {
72
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
73
        foreach (array_keys($configurator->uploadFolders) as $i) {
74
            $utility::createFolder($configurator->uploadFolders[$i]);
75
        }
76
    }
77
78
    //  ---  COPY blank.png FILES ---------------
79
    if ($configurator->copyBlankFiles && is_array($configurator->copyBlankFiles)) {
80
        $file = dirname(__DIR__) . '/assets/images/blank.png';
81
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
82
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
83
            $utility::copyFile($file, $dest);
84
        }
85
    }
86
87
    //  ---  COPY test folder files ---------------
88
    if ($configurator->copyTestFolders && is_array($configurator->copyTestFolders)) {
89
        //        $file =  dirname(__DIR__) . '/testdata/images/';
90
        foreach (array_keys($configurator->copyTestFolders) as $i) {
91
            $src  = $configurator->copyTestFolders[$i][0];
92
            $dest = $configurator->copyTestFolders[$i][1];
93
            $utility::rcopy($src, $dest);
94
        }
95
    }
96
97
    //delete .html entries from the tpl table
98
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
99
    $GLOBALS['xoopsDB']->queryF($sql);
100
101
    return true;
102
}
103