Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Upgrader | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
do_upgrade | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
v1_2_0 | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace BrianHenryIE\WC_Address_Validation; |
4 | |
5 | use BrianHenryIE\WC_Address_Validation\API\Settings; |
6 | use Psr\Log\LoggerAwareTrait; |
7 | use Psr\Log\LoggerInterface; |
8 | |
9 | class Upgrader { |
10 | use LoggerAwareTrait; |
11 | |
12 | protected Settings_Interface $settings; |
13 | |
14 | public function __construct( Settings_Interface $settings, LoggerInterface $logger ) { |
15 | $this->setLogger( $logger ); |
16 | $this->settings = $settings; |
17 | } |
18 | |
19 | public function do_upgrade(): void { |
20 | |
21 | $old_version = get_option( 'bh_wc_address_validation_version', '0.0.0' ); |
22 | |
23 | if ( 1 === version_compare( '1.2.0', $old_version ) ) { |
24 | $this->v1_2_0(); |
25 | } |
26 | |
27 | update_option( 'bh_wc_address_validation_version', $this->settings->get_plugin_version() ); |
28 | } |
29 | |
30 | /** |
31 | * Rename options so they use the conventional underscores rather than hyphens. |
32 | */ |
33 | public function v1_2_0() { |
34 | |
35 | $option_name_changes = array( |
36 | 'bh-wc-address-validation-usps-username' => Settings::USPS_USERNAME_OPTION, |
37 | 'bh-wc-address-validation-is-admin-email-enabled' => Settings::IS_ADMIN_EMAIL_ENABLED_OPTION, |
38 | ); |
39 | |
40 | foreach ( $option_name_changes as $from => $to ) { |
41 | |
42 | $value = get_option( $from, null ); |
43 | |
44 | if ( ! empty( $value ) ) { |
45 | update_option( $to, $value ); |
46 | delete_option( $from ); |
47 | } |
48 | } |
49 | } |
50 | } |