Completed
Push — master ( 66731e...5478d6 )
by Michael
02:20
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 : $Id:
20
 * ****************************************************************************
21
 *
22
 * @param      $module
23
 * @param null $oldversion
24
 *
25
 * @return mixed
26
 */
27
28
//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...
29
//{
30
//    $db = XoopsDatabaseFactory::getDatabaseConnection();
31
//    $sql = "ALTER TABLE `" . $db->prefix('marquee') . "` MODIFY `marquee_bgcolor` varchar(7) NOT NULL default '';";
32
//    $db->query($sql);
33
//
34
//    return true;
35
//}
36
37
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...
38
{
39
    $db  = XoopsDatabaseFactory::getDatabaseConnection();
40
    $sql = 'ALTER TABLE `' . $db->prefix('marquee') . "` MODIFY `marquee_bgcolor` varchar(7) NOT NULL default '';";
41
    $db->query($sql);
42
43
    if ($oldversion < 250) {
44
45
        // delete old block html template files
46
        $templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/blocks/';
47
        $template_list     = array_diff(scandir($templateDirectory), array('..', '.'));
48
        foreach ($template_list as $k => $v) {
49
            $fileinfo = new SplFileInfo($templateDirectory . $v);
50
            if ($fileinfo->getExtension() === 'html' && $fileinfo->getFilename() !== 'index.html') {
51
                // @unlink($templateDirectory . $v);
52
                if (false === @unlink($templateDirectory . $v)) {
53
                    throw new \RuntimeException('The file ' . $templateDirectory . $v . ' could not be deleted.');
54
                }
55
            }
56
        }
57
        // Load class XoopsFile
58
        xoops_load('xoopsfile');
59
        //delete /images directory
60
        $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/images/';
61
        $folderHandler   = XoopsFile::getHandler('folder', $imagesDirectory);
62
        $folderHandler->delete($imagesDirectory);
63
        //delete /js directory
64
        $jsDirectory   = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/js/';
65
        $folderHandler = XoopsFile::getHandler('folder', $jsDirectory);
66
        $folderHandler->delete($jsDirectory);
67
        //delete /templates/style.css file
68
        $deleteFile    = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/admin/marquee.php';
69
        $folderHandler = XoopsFile::getHandler('file', $deleteFile);
70
        $folderHandler->delete($deleteFile);
71
    }
72
73
    $gpermHandler = xoops_getHandler('groupperm');
74
75
    return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read');
76
}
77