Completed
Branch dev (623cfe)
by Greg
03:59
created

classes/DomainMOD/DwServers.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * /classes/DomainMOD/DwServers.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class DwServers
25
{
26
    public $system;
27
28
    public function __construct()
29
    {
30
        $this->system = new System();
31
    }
32
33
    public function get()
34
    {
35
        return $this->system->db()->query("
36
            SELECT id, `host`, protocol, `port`, username, api_token, `hash`
37
            FROM dw_servers
38
            ORDER BY `name`")->fetchAll();
39
    }
40
41
    public function processEachServer($result)
42
    {
43
        $build = new DwBuild();
44
        $accounts = new DwAccounts();
45
        $zones = new DwZones();
46
        $time = new Time();
47
48
        $pdo = $this->system->db();
49
        $stmt = $pdo->prepare("
50
            UPDATE dw_servers
51
            SET build_start_time = :build_start_time,
52
                build_status = '0'
53
            WHERE id = :id");
54
        $stmt->bindParam('build_start_time', $build_start_time, \PDO::PARAM_STR);
55
        $stmt->bindParam('id', $bind_id, \PDO::PARAM_INT);
56
57
        foreach ($result as $row) {
58
59
            $build_start_time = $time->stamp();
60
            $bind_id = $row->id;
1 ignored issue
show
$bind_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
            $stmt->execute();
62
63
            $api_call = $accounts->getApiCall();
64
            $api_results = $build->apiCall($api_call, $row->host, $row->protocol, $row->port, $row->username,
65
                $row->api_token, $row->hash);
66
            $accounts->insertAccounts($api_results, $row->id);
67
68
            $api_call = $zones->getApiCall();
69
            $api_results = $build->apiCall($api_call, $row->host, $row->protocol, $row->port, $row->username,
70
                $row->api_token, $row->hash);
71
            $zones->insertZones($api_results, $row->id);
72
73
            $result_zones = $zones->getInsertedZones($row->id);
74
            $zones->processEachZone($result_zones, $row->id, $row->protocol, $row->host, $row->port, $row->username,
75
                $row->api_token, $row->hash);
76
            $this->serverFinish($row->id, $build_start_time);
77
78
        }
79
    }
80
81
    public function serverFinish($server_id, $build_start_time)
82
    {
83
        $pdo = $this->system->db();
84
85
        $build = new DwBuild();
86
87
        list($build_end_time, $total_build_time) = $build->getBuildTime($build_start_time);
88
89
        $stmt = $pdo->prepare("
90
            UPDATE dw_servers
91
            SET build_status = '1',
92
                build_end_time = :build_end_time,
93
                build_time = :total_build_time,
94
                has_ever_been_built = '1'
95
            WHERE id = :server_id");
96
        $stmt->bindValue('build_end_time', $build_end_time, \PDO::PARAM_STR);
97
        $stmt->bindValue('total_build_time', $total_build_time, \PDO::PARAM_INT);
98
        $stmt->bindValue('server_id', $server_id, \PDO::PARAM_INT);
99
        $stmt->execute();
100
101
    }
102
103
} //@formatter:on
104