Completed
Push — master ( a1059e...55b12e )
by Michael
01:29
created

update.php ➔ xoops_module_update_marquee()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 40
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 24
nc 3
nop 2
dl 0
loc 40
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * ****************************************************************************
4
 * marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (http://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 (http://www.herve-thouzard.com)
15
 * @license           http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @package           marquee
17
 * @author            Hervé Thouzard (http://www.herve-thouzard.com)
18
 *
19
 * Version :
20
 * ****************************************************************************
21
 *
22
 * @param XoopsModule|\XoopsObject $module
23
 * @param null                    $oldversion
24
 * @return mixed
25
 */
26
27
//function xoops_module_update_marquee()
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
//{
29
//    $db = \XoopsDatabaseFactory::getDatabaseConnection();
30
//    $sql = "ALTER TABLE `" . $db->prefix('marquee') . "` MODIFY `marquee_bgcolor` varchar(7) NOT NULL default '';";
31
//    $db->query($sql);
32
//
33
//    return true;
34
//}
35
36
function xoops_module_update_marquee(XoopsObject $module, $oldversion = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Best Practice introduced by
The function xoops_module_update_marquee() has been defined more than once; this definition is ignored, only the first definition in include/onupdate.php (L67-162) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
37
{
38
    $db  = \XoopsDatabaseFactory::getDatabaseConnection();
39
    $sql = 'ALTER TABLE `' . $db->prefix('marquee') . "` MODIFY `marquee_bgcolor` VARCHAR(7) NOT NULL DEFAULT '';";
40
    $db->query($sql);
41
42
    if ($oldversion < 250) {
43
44
        // delete old block html template files
45
        $templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/blocks/';
46
        $template_list     = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']);
47
        foreach ($template_list as $k => $v) {
48
            $fileinfo = new \SplFileInfo($templateDirectory . $v);
49
            if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) {
50
                // @unlink($templateDirectory . $v);
51
                if (false === @unlink($templateDirectory . $v)) {
52
                    throw new \RuntimeException('The file ' . $templateDirectory . $v . ' could not be deleted.');
53
                }
54
            }
55
        }
56
        // Load class XoopsFile
57
        xoops_load('xoopsfile');
58
        //delete /images directory
59
        $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/images/';
60
        $folderHandler   = XoopsFile::getHandler('folder', $imagesDirectory);
61
        $folderHandler->delete($imagesDirectory);
62
        //delete /js directory
63
        $jsDirectory   = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/js/';
64
        $folderHandler = XoopsFile::getHandler('folder', $jsDirectory);
65
        $folderHandler->delete($jsDirectory);
66
        //delete /templates/style.css file
67
        $deleteFile    = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/admin/marquee.php';
68
        $folderHandler = XoopsFile::getHandler('file', $deleteFile);
69
        $folderHandler->delete($deleteFile);
70
    }
71
72
    $gpermHandler = xoops_getHandler('groupperm');
73
74
    return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read');
75
}
76