V5000.php
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace ACP\Plugin\Update;
use AC\Plugin\Update;
use AC\Plugin\Version;
use ACP\Type\Activation\Status;
use DateTime;
use DateTimeZone;
use Exception;
/**
* Migrate license settings per site
*/
class V5000 extends Update {
const LICENSE_OPTION_KEY = 'cpupdate_cac-pro';
public function __construct() {
parent::__construct( new Version( '5.0.0' ) );
}
/**
* @throws Exception
*/
public function apply_update() {
$this->migrate_license();
}
private function migrate_license() {
$license_key_value = defined( 'ACP_LICENCE' ) && ACP_LICENCE
? ACP_LICENCE
: (string) $this->get_license_option();
if ( ! $license_key_value ) {
return;
}
$status = $this->get_license_option( '_sts' );
if ( ! Status::is_valid( $status ) ) {
return;
}
$expiry_date = null;
$expiry_date_raw = $this->get_license_option( '_expiry_date' );
if ( $expiry_date_raw ) {
$expiry_date = is_numeric( $expiry_date_raw )
? DateTime::createFromFormat( 'U', $expiry_date_raw, new DateTimeZone( 'Europe/Amsterdam' ) )
: DateTime::createFromFormat( 'Y-m-d H:i:s', $expiry_date_raw, new DateTimeZone( 'Europe/Amsterdam' ) );
}
if ( $expiry_date === false ) {
return;
}
$renewal_method = $this->get_license_option( '_renewal_method' );
if ( $renewal_method !== 'manual' ) {
$renewal_method = 'auto';
}
$this->update_option( 'acp_subscription_key', $license_key_value );
$this->update_option( 'acp_subscription_details_key', $license_key_value );
$this->update_option( 'acp_subscription_details', [
'status' => $status,
'renewal_method' => $renewal_method,
'expiry_date' => $expiry_date ? $expiry_date->getTimestamp() : null,
] );
}
protected function get_license_option( $key = '' ) {
return $this->get_option( self::LICENSE_OPTION_KEY . $key );
}
protected function get_option( $key ) {
return get_option( $key );
}
protected function update_option( $key, $value ) {
return update_option( $key, $value );
}
}