xoops_module_update_adslight()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 36
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 36
rs 9.584
cc 4
nc 3
nop 1
1
<?php declare(strict_types=1);
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project (https://xoops.org)
15
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author       XOOPS Development Team
17
 * @author       Pascal Le Boustouller: original author ([email protected])
18
 * @author       Luc Bizet (www.frxoops.org)
19
 * @author       jlm69 (www.jlmzone.com)
20
 * @author       mamba (www.xoops.org)
21
 */
22
23
/**
24
 * @param XoopsObject $xoopsModule
25
 * @return bool
26
 */
27
function xoops_module_update_adslight(\XoopsObject $xoopsModule): bool
28
{
29
    global $xoopsDB;
30
31
    $sql = 'ALTER TABLE `' . $xoopsDB->prefix('adslight_listing') . "` MODIFY `price` DECIMAL(20,2) NOT NULL DEFAULT '0.00' AFTER `tel` ;";
32
    $xoopsDB->query($sql);
33
34
    $sql = 'ALTER TABLE `' . $xoopsDB->prefix('adslight_listing') . "` MODIFY `photo` VARCHAR(100) NOT NULL DEFAULT '0';";
35
    $xoopsDB->query($sql);
36
37
    // remove old html template files
38
    $template_directory = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/templates/';
39
    $template_list      = array_diff(scandir($template_directory, SCANDIR_SORT_NONE), [
40
        '..',
41
        '.',
42
    ]);
43
    foreach ($template_list as $v) {
44
        $fileinfo = new \SplFileInfo($template_directory . $v);
45
        if ('html' === $fileinfo->getExtension()
46
            && 'index.html' !== $fileinfo->getFilename()) {
47
            @unlink($template_directory . $v);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

47
            /** @scrutinizer ignore-unhandled */ @unlink($template_directory . $v);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
48
        }
49
    }
50
51
    xoops_load('xoopsfile');
52
53
    //remove /images directory
54
    $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/images/';
55
    $folderHandler   = XoopsFile::getHandler('folder', $imagesDirectory);
56
    $folderHandler->delete($imagesDirectory);
57
58
    //delete .html entries from the tpl table
59
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
60
    $GLOBALS['xoopsDB']->queryF($sql);
61
62
    return true;
63
}
64