DatabaseUpdate   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
c 0
b 0
f 0
dl 0
loc 104
rs 10
wmc 15

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 2 1
A hasAdditionScript() 0 2 1
A getFilename() 0 2 1
A getDisableForeignKeyChecks() 0 2 1
A getCondition() 0 2 1
B __construct() 0 42 6
A getAutoExecute() 0 2 1
A getSql() 0 2 1
A getExecuteOn() 0 2 1
A getDescription() 0 2 1
1
<?php
2
namespace AL\Admin\Common;
3
4
/** A database update script to execute */
5
class DatabaseUpdate {
6
    const EXECUTE_ON_SUCCESS = "success";
7
    const EXECUTE_ON_FAILURE = "failure";
8
9
    /** Permitted values for 'execute_on' */
10
    const EXECUTE_ON = array(DatabaseUpdate::EXECUTE_ON_SUCCESS, DatabaseUpdate::EXECUTE_ON_FAILURE);
11
12
    private $id;
13
14
    /** Path to the INI file */
15
    private $filename;
16
17
    private $description;
18
19
    /** SQL Condition to check */
20
    private $condition;
21
22
    /** Wether to execute on success or failure */
23
    private $execute_on;
24
    private $sql;
25
    private $autoexecute;
26
    private $disable_fk;
27
28
    /** Wether there's an additional PHP script to run */
29
    private $has_addition_script;
30
31
    public function __construct(
32
        $db_name,
33
        $id,
34
        $filename,
35
        $description,
36
        $condition,
37
        $execute_on,
38
        $sql,
39
        $autoexecute,
40
        $disable_fk,
41
        $has_addition_script
42
    ) {
43
        if (!is_int($id)) {
44
            die("id must be an integer, but was: '$id'");
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
45
        }
46
        $this->id = $id;
47
        $this->filename = $filename;
48
        $this->description = $description;
49
50
        if (!in_array($execute_on, DatabaseUpdate::EXECUTE_ON)) {
51
            die("Invalid value '$execute_on' for 'execute_on'. Only "
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
52
                .join(", ", DatabaseUpdate::EXECUTE_ON)." are supported");
53
        }
54
        $this->execute_on = $execute_on;
55
        $this->condition = str_replace("__DBNAME__", $db_name, $condition);
56
        ;
57
        $this->sql = $sql;
58
59
        if (!is_bool($autoexecute)) {
60
            die("autoexecute must be a boolean, but was: '$autoexecute'");
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
61
        }
62
        $this->autoexecute = $autoexecute;
63
64
        if (!is_bool($disable_fk)) {
65
            die("disable_fk must be a boolean, but was: '$disable_fk'");
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
66
        }
67
        $this->disable_fk = $disable_fk;
68
69
        if (!is_bool($has_addition_script)) {
70
            die("has_addition_script must be a boolean, but was: '$has_addition_script'");
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
71
        }
72
        $this->has_addition_script = $has_addition_script;
73
    }
74
75
    public function getId() {
76
        return $this->id;
77
    }
78
79
    public function getFilename() {
80
        return $this->filename;
81
    }
82
83
    public function getDescription() {
84
        return $this->description;
85
    }
86
87
    public function getCondition() {
88
        return $this->condition;
89
    }
90
91
    public function getExecuteOn() {
92
        return $this->execute_on;
93
    }
94
95
    public function getSql() {
96
        return $this->sql;
97
    }
98
99
    public function getAutoExecute() {
100
        return $this->autoexecute;
101
    }
102
103
    public function getDisableForeignKeyChecks() {
104
        return $this->disable_fk;
105
    }
106
107
    public function hasAdditionScript() {
108
        return $this->has_addition_script;
109
    }
110
}
111