|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Installs: Install Service. |
|
4
|
|
|
* |
|
5
|
|
|
* The Installation Service. |
|
6
|
|
|
* |
|
7
|
|
|
* @since 3.18.0 |
|
8
|
|
|
* @package Wordlift |
|
9
|
|
|
* @subpackage Wordlift/install |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Define the {@link Wordlift_Install_Service} interface. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 3.18.0 |
|
16
|
|
|
* @package Wordlift |
|
17
|
|
|
* @subpackage Wordlift/install |
|
18
|
|
|
*/ |
|
19
|
|
|
class Wordlift_Install_Service { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The singleton instance. |
|
23
|
|
|
* |
|
24
|
|
|
* @since 3.18.0 |
|
25
|
|
|
* @access private |
|
26
|
|
|
* @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance. |
|
27
|
|
|
*/ |
|
28
|
|
|
private static $instance; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Wordlift_Install_Service constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* @since 3.18.0 |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct() { |
|
37
|
|
|
|
|
38
|
|
|
self::$instance = $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get the singleton instance. |
|
43
|
|
|
* |
|
44
|
|
|
* @since 3.18.0 |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function get_instance() { |
|
47
|
|
|
|
|
48
|
|
|
return self::$instance; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Loop thought all versions and install the updates. |
|
53
|
|
|
* |
|
54
|
|
|
* @since 3.18.0 |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
public function install() { |
|
59
|
|
|
|
|
60
|
|
|
// Get the install services. |
|
61
|
|
|
$installs = array( |
|
62
|
|
|
new Wordlift_Install_1_0_0(), |
|
63
|
|
|
new Wordlift_Install_3_10_0(), |
|
64
|
|
|
new Wordlift_Install_3_12_0(), |
|
65
|
|
|
new Wordlift_Install_3_14_0(), |
|
66
|
|
|
new Wordlift_Install_3_15_0(), |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
/** @var Wordlift_Install $install */ |
|
70
|
|
|
foreach ( $installs as $install ) { |
|
71
|
|
|
// Get the install version. |
|
72
|
|
|
$version = $install->get_version(); |
|
73
|
|
|
|
|
74
|
|
|
if ( version_compare( $version, $this->get_current_version(), '>=' ) ) { |
|
75
|
|
|
// Install version. |
|
76
|
|
|
$install->install(); |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// Bump the `wl_db_version`. |
|
82
|
|
|
update_option( 'wl_db_version', $version ); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Retrieve the current db version. |
|
87
|
|
|
* |
|
88
|
|
|
* @return type |
|
89
|
|
|
*/ |
|
90
|
|
|
private function get_current_version() { |
|
91
|
|
|
return get_option( 'wl_db_version', '0.0.0' ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: