Passed
Push — master ( fb46c9...e4f11c )
by Michael
17:52 queued 15:44
created

tableExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
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
 * @package      XoopsModules\Tag
14
 * @copyright    XOOPS Project (https://xoops.org)
15
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author       XOOPS Development Team
17
 */
18
19
use XoopsModules\Tag;
20
21
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)
22
    || !$GLOBALS['xoopsUser']->isAdmin()) {
23
    exit('Restricted access' . PHP_EOL);
24
}
25
26
$moduleDirName      = \basename(\dirname(__DIR__, 2));
27
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
28
xoops_loadLanguage('common', $moduleDirName);
29
30
/**
31
 * Prepares system prior to attempting to install module
32
 * @param \XoopsModule $module {@link XoopsModule}
33
 *
34
 * @return bool true if ready to install, false if not
35
 */
36
function xoops_module_pre_update_tag(\XoopsModule $module)
37
{
38
    /** @var Tag\Helper $helper */
39
    /** @var Tag\Utility $utility */
40
    $moduleDirName = \basename(\dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
41
    $helper        = Tag\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
42
    $utility       = new Tag\Utility();
43
44
    $xoopsSuccess = $utility::checkVerXoops($module);
45
    $phpSuccess   = $utility::checkVerPhp($module);
46
47
    return $xoopsSuccess && $phpSuccess;
48
}
49
50
/**
51
 * Performs tasks required during update of the module
52
 * @param \XoopsModule $module {@link XoopsModule}
53
 * @param null         $previousVersion
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $previousVersion is correct as it would always require null to be passed?
Loading history...
54
 *
55
 * @return bool true if update successful, false if not
56
 */
57
function xoops_module_update_tag(\XoopsModule $module, $previousVersion = null)
58
{
59
    global $xoopsDB;
60
    $moduleDirName = \basename(\dirname(__DIR__));
61
62
    /** @var Tag\Helper $helper */ 
63
    /** @var Tag\Utility $utility */
64
    /** @var Tag\Common\Configurator $configurator */
65
    $helper       = Tag\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
66
    $utility      = new Tag\Utility();
67
    $configurator = new Tag\Common\Configurator();
68
69
    if ($previousVersion < 235) {
70
        //delete old HTML templates
71
        if (count($configurator->templateFolders) > 0) {
72
            foreach ($configurator->templateFolders as $folder) {
73
                $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder);
74
                if (is_dir($templateFolder)) {
75
                    $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']);
76
                    foreach ($templateList as $k => $v) {
77
                        $fileInfo = new \SplFileInfo($templateFolder . $v);
78
                        if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) {
79
                            if (is_file($templateFolder . $v)) {
80
                                unlink($templateFolder . $v);
81
                            }
82
                        }
83
                    }
84
                }
85
            }
86
        }
87
88
        //  ---  DELETE OLD FILES ---------------
89
        if (count($configurator->oldFiles) > 0) {
90
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
91
            foreach (array_keys($configurator->oldFiles) as $i) {
92
                $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]);
93
                if (is_file($tempFile)) {
94
                    unlink($tempFile);
95
                }
96
            }
97
        }
98
99
        //  ---  DELETE OLD FOLDERS ---------------
100
        xoops_load('XoopsFile');
101
        if (count($configurator->oldFolders) > 0) {
102
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
103
            foreach (array_keys($configurator->oldFolders) as $i) {
104
                $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]);
105
                /* @var XoopsObjectHandler $folderHandler */
106
                $folderHandler = XoopsFile::getHandler('folder', $tempFolder);
107
                $folderHandler->delete($tempFolder);
108
            }
109
        }
110
111
        //  ---  CREATE FOLDERS ---------------
112
        if (count($configurator->uploadFolders) > 0) {
113
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
114
            foreach (array_keys($configurator->uploadFolders) as $i) {
115
                $utility::createFolder($configurator->uploadFolders[$i]);
116
            }
117
        }
118
119
        //  ---  COPY blank.png FILES ---------------
120
        if (count($configurator->copyBlankFiles) > 0) {
121
            $file = \dirname(__DIR__) . '/assets/images/blank.png';
122
            foreach (array_keys($configurator->copyBlankFiles) as $i) {
123
                $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
124
                $utility::copyFile($file, $dest);
125
            }
126
        }
127
128
        //delete .html entries from the tpl table
129
        $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\'';
130
        $GLOBALS['xoopsDB']->queryF($sql);
131
132
        /** @var \XoopsGroupPermHandler $grouppermHandler */
133
        $grouppermHandler = xoops_getHandler('groupperm');
134
135
        return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read');
136
    }
137
138
    return true;
139
}
140