This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace HM\BackUpWordPress; |
||
4 | |||
5 | /** |
||
6 | * The Database Backup Engine type |
||
7 | * |
||
8 | * All Database Backup Engine implementations should extend this class |
||
9 | */ |
||
10 | abstract class Database_Backup_Engine extends Backup_Engine { |
||
11 | |||
12 | /** |
||
13 | * The filename for the resulting Backup |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | public $backup_filename = ''; |
||
18 | |||
19 | /** |
||
20 | * The database host string, typically the value of |
||
21 | * the `DB_HOST` Constant. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $host = ''; |
||
26 | |||
27 | /** |
||
28 | * The database socket, if it's using a socket connection |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $socket = ''; |
||
33 | |||
34 | /** |
||
35 | * The database port, if a custom one is set |
||
36 | * |
||
37 | * @var integer |
||
38 | */ |
||
39 | private $port = 0; |
||
40 | |||
41 | /** |
||
42 | * Individual Database Backup Engine implementations must include |
||
43 | * a backup method at a minimum. |
||
44 | * |
||
45 | * @return [type] [description] |
||
0 ignored issues
–
show
|
|||
46 | */ |
||
47 | abstract public function backup(); |
||
48 | |||
49 | /** |
||
50 | * Setup some general database backup settings |
||
51 | * |
||
52 | * Child classes must call `parent::__construct` in their own constructor. |
||
53 | */ |
||
54 | public function __construct() { |
||
55 | |||
56 | parent::__construct(); |
||
57 | |||
58 | $this->parse_db_host_constant(); |
||
59 | |||
60 | // Set a default backup filename |
||
61 | $this->set_backup_filename( 'database-' . $this->get_name() . '.sql' ); |
||
62 | |||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get the database charset setting. |
||
67 | * |
||
68 | * @return [string The database charset. |
||
0 ignored issues
–
show
The doc-type
string">[string could not be parsed: Unknown type name "[" at position 0. [(view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
69 | */ |
||
70 | public function get_charset() { |
||
0 ignored issues
–
show
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 ![]() |
|||
71 | global $wpdb; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
72 | return $wpdb->charset; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Get the database collate setting. |
||
77 | * |
||
78 | * @return string The database collage setting. |
||
79 | */ |
||
80 | public function get_collate() { |
||
81 | global $wpdb; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
82 | return $wpdb->collate; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Get the database name. |
||
87 | * |
||
88 | * @return string The database name. |
||
89 | */ |
||
90 | public function get_name() { |
||
91 | global $wpdb; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
92 | return $wpdb->dbname; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Get the database user. |
||
97 | * |
||
98 | * @return string The database user. |
||
99 | */ |
||
100 | public function get_user() { |
||
101 | global $wpdb; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
102 | return $wpdb->dbuser; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Get the database password. |
||
107 | * |
||
108 | * @return string The database password. |
||
109 | */ |
||
110 | public function get_password() { |
||
111 | global $wpdb; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
112 | return $wpdb->dbpassword; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Get the database hostname. |
||
117 | * |
||
118 | * @return string The database hostname. |
||
119 | */ |
||
120 | public function get_host() { |
||
121 | return $this->host; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Get the database port. |
||
126 | * |
||
127 | * @return int The database port. |
||
128 | */ |
||
129 | public function get_port() { |
||
130 | return $this->port; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Get the database socket. |
||
135 | * |
||
136 | * @return string The database socket. |
||
137 | */ |
||
138 | public function get_socket() { |
||
139 | return $this->socket; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Parse the `DB_HOST` constant. |
||
144 | * |
||
145 | * The `DB_HOST` constant potentially contains the hostname, port or socket. |
||
146 | * We need to parse it to figure out the type of mysql connection to make. |
||
147 | * |
||
148 | * @param string $constant The Constant to parse. If the string isn't a |
||
149 | * defined Constant then it will be parsed directly. |
||
150 | */ |
||
151 | public function parse_db_host_constant( $constant = 'DB_HOST' ) { |
||
152 | |||
153 | // If we've been passed a Constant then grab it's contents |
||
154 | if ( defined( $constant ) ) { |
||
155 | $constant = constant( $constant ); |
||
156 | } |
||
157 | |||
158 | // If we weren't passed a Constant then just parse the string directly. |
||
159 | $this->host = (string) $constant; |
||
160 | |||
161 | // Grab the part after :, it could either be a port or a socket |
||
162 | $port_or_socket = strstr( $constant, ':' ); |
||
163 | |||
164 | if ( $port_or_socket ) { |
||
165 | |||
166 | // The host is the bit up to the : |
||
167 | $this->host = substr( $constant, 0, strpos( $constant, ':' ) ); |
||
168 | |||
169 | // Strip the : |
||
170 | $port_or_socket = substr( $port_or_socket, 1 ); |
||
171 | |||
172 | if ( 0 !== strpos( $port_or_socket, '/' ) ) { |
||
173 | |||
174 | $this->port = intval( $port_or_socket ); |
||
175 | $maybe_socket = strstr( $port_or_socket, ':' ); |
||
176 | |||
177 | if ( ! empty( $maybe_socket ) ) { |
||
178 | $this->socket = substr( $maybe_socket, 1 ); |
||
179 | } |
||
180 | } else { |
||
181 | $this->socket = $port_or_socket; |
||
182 | } |
||
183 | } |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Verify that the database backup was successful. |
||
188 | * |
||
189 | * It's important this function is performant as it's called after every |
||
190 | * backup. |
||
191 | * |
||
192 | * @return bool Whether the backup completed successfully |
||
193 | */ |
||
194 | public function verify_backup() { |
||
195 | |||
196 | // If there are errors delete the database dump file |
||
197 | if ( $this->get_errors( get_called_class() ) && file_exists( $this->get_backup_filepath() ) ) { |
||
198 | unlink( $this->get_backup_filepath() ); |
||
199 | } |
||
200 | |||
201 | // If we have an empty file delete it |
||
202 | if ( @filesize( $this->get_backup_filepath() ) === 0 ) { |
||
203 | unlink( $this->get_backup_filepath() ); |
||
204 | } |
||
205 | |||
206 | // If the database backup doesn't exist then the backup must have failed |
||
207 | if ( ! file_exists( $this->get_backup_filepath() ) ) { |
||
208 | return false; |
||
209 | } |
||
210 | |||
211 | return true; |
||
212 | |||
213 | } |
||
214 | } |
||
215 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.