xoops_module_update_marquee()   B
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 23
c 2
b 0
f 0
nc 3
nop 2
dl 0
loc 37
rs 8.9297
1
<?php declare(strict_types=1);
2
/**
3
 * ****************************************************************************
4
 * marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
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         Hervé Thouzard (https://www.herve-thouzard.com)
15
 * @license           GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author            Hervé Thouzard (https://www.herve-thouzard.com)
17
 *
18
 * Version :
19
 * ****************************************************************************
20
 *
21
 * @param \XoopsModule|\XoopsObject $module
22
 * @param null                      $oldversion
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $oldversion is correct as it would always require null to be passed?
Loading history...
23
 * @return mixed
24
 */
25
26
//function xoops_module_update_marquee()
27
//{
28
//    $db = \XoopsDatabaseFactory::getDatabaseConnection();
29
//    $sql = "ALTER TABLE `" . $db->prefix('marquee') . "` MODIFY `marquee_bgcolor` varchar(7) NOT NULL default '';";
30
//    $db->query($sql);
31
//
32
//    return true;
33
//}
34
function xoops_module_update_marquee(\XoopsObject $module, $oldversion = null)
35
{
36
    $db  = \XoopsDatabaseFactory::getDatabaseConnection();
37
    $sql = 'ALTER TABLE `' . $db->prefix('marquee') . "` MODIFY `marquee_bgcolor` VARCHAR(7) NOT NULL DEFAULT '';";
38
    $db->query($sql);
39
    if ($oldversion < 250) {
40
        // delete old block html template files
41
        $templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/blocks/';
42
        $template_list     = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']);
43
        foreach ($template_list as $k => $v) {
44
            $fileinfo = new \SplFileInfo($templateDirectory . $v);
45
            if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) {
46
                // @unlink($templateDirectory . $v);
47
                if (false === @unlink($templateDirectory . $v)) {
48
                    throw new \RuntimeException('The file ' . $templateDirectory . $v . ' could not be deleted.');
49
                }
50
            }
51
        }
52
        // Load class XoopsFile
53
        xoops_load('xoopsfile');
54
        //delete /images directory
55
        $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/images/';
56
        $folderHandler   = XoopsFile::getHandler('folder', $imagesDirectory);
57
        $folderHandler->delete($imagesDirectory);
58
        //delete /js directory
59
        $jsDirectory   = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/js/';
60
        $folderHandler = XoopsFile::getHandler('folder', $jsDirectory);
61
        $folderHandler->delete($jsDirectory);
62
        //delete /templates/style.css file
63
        $deleteFile    = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/admin/marquee.php';
64
        $folderHandler = XoopsFile::getHandler('file', $deleteFile);
65
        $folderHandler->delete($deleteFile);
0 ignored issues
show
Unused Code introduced by
The call to XoopsFileHandler::delete() has too many arguments starting with $deleteFile. ( Ignorable by Annotation )

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

65
        $folderHandler->/** @scrutinizer ignore-call */ 
66
                        delete($deleteFile);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
66
    }
67
    /** @var \XoopsGroupPermHandler $grouppermHandler */
68
    $grouppermHandler = xoops_getHandler('groupperm');
69
70
    return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read');
71
}
72