Completed
Push — master ( 4b4f1d...42f486 )
by Michael
24s queued 20s
created

Upgrade_2511::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
use Xmf\Database\Tables;
4
5
/**
6
 * Upgrade from 2.5.10 to 2.5.11
7
 *
8
 * See the enclosed file license.txt for licensing information.
9
 * If you did not receive this file, get it at https://www.gnu.org/licenses/gpl-2.0.html
10
 *
11
 * @copyright    (c) 2000-2019 XOOPS Project (https://xoops.org)
12
 * @license          GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
13
 * @package          Upgrade
14
 * @since            2.5.11
15
 * @author           XOOPS Team
16
 */
17
class Upgrade_2511 extends XoopsUpgrade
18
{
19
    /**
20
     * __construct
21
     */
22
    public function __construct()
23
    {
24
        parent::__construct(basename(__DIR__));
25
        $this->tasks = array('qmail');
26
        $this->usedFiles = array();
27
    }
28
29
    /**
30
     * Add qmail as valid mailmethod
31
     *
32
     * @return bool
33
     */
34
    public function check_qmail()
35
    {
36
        /* @var XoopsMySQLDatabase $db */
37
        $db = XoopsDatabaseFactory::getDatabaseConnection();
38
39
        $table = $db->prefix('configoption');
40
41
        $sql = sprintf(
42
            'SELECT count(*) FROM `%s` '
43
            . "WHERE `conf_id` = 64 AND `confop_name` = 'qmail'",
44
            $db->escape($table)
45
        );
46
47
        /** @var mysqli_result $result */
48
        $result = $db->query($sql);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $db->query($sql) targeting XoopsMySQLDatabase::query() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
49
        if ($result) {
0 ignored issues
show
introduced by
$result is of type mysqli_result, thus it always evaluated to true.
Loading history...
50
            $row = $db->fetchRow($result);
51
            if ($row) {
52
                $count = $row[0];
53
                return (0 === (int) $count) ? false : true;
54
            }
55
        }
56
        return false;
57
    }
58
59
    /**
60
     * Add qmail as valid mailmethod
61
     *
62
     * phpMailer has qmail support, similar to but slightly different than sendmail
63
     * This will allow webmasters to utilize qmail if it is provisioned on server.
64
     *
65
     * @return bool
66
     */
67
    public function apply_qmail()
68
    {
69
        $migrate = new Tables();
70
        $migrate->useTable('configoption');
71
        $migrate->insert('configoption',
72
            array('confop_name' => 'qmail', 'confop_value' => 'qmail', 'conf_id' => 64));
73
        return $migrate->executeQueue(true);
74
    }
75
}
76
77
$upg = new Upgrade_2511();
78
return $upg;
79