|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Upgrade 3.0.0 |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2020 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\Mollie |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
|
12
|
|
|
|
|
13
|
|
|
use Pronamic\WordPress\Pay\Upgrades\Upgrade; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Upgrade 3.0.0 |
|
17
|
|
|
* |
|
18
|
|
|
* @author Remco Tolsma |
|
19
|
|
|
* @version 3.0.0 |
|
20
|
|
|
* @since 3.0.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
class Upgrade300 extends Upgrade { |
|
23
|
|
|
/** |
|
24
|
|
|
* Construct 3.0.0 upgrade. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct() { |
|
27
|
|
|
parent::__construct( '3.0.0' ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Execute. |
|
32
|
|
|
* |
|
33
|
|
|
* @link https://github.com/WordPress/WordPress/blob/5.3/wp-includes/wp-db.php#L992-L1072 |
|
34
|
|
|
* @link https://github.com/WordPress/WordPress/blob/5.3/wp-admin/includes/schema.php#L25-L344 |
|
35
|
|
|
* @link https://developer.wordpress.org/reference/functions/dbdelta/ |
|
36
|
|
|
* @link https://github.com/wp-premium/gravityforms/blob/2.4.16/includes/class-gf-upgrade.php#L518-L531 |
|
37
|
|
|
*/ |
|
38
|
|
|
public function execute() { |
|
39
|
|
|
global $wpdb; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Requirements. |
|
43
|
|
|
*/ |
|
44
|
|
|
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Other. |
|
48
|
|
|
*/ |
|
49
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Queries. |
|
53
|
|
|
*/ |
|
54
|
|
|
$queries = " |
|
55
|
|
|
CREATE TABLE $wpdb->pronamic_pay_mollie_organisations ( |
|
56
|
|
|
id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
57
|
|
|
mollie_id VARCHAR( 16 ) NOT NULL, |
|
58
|
|
|
|
|
59
|
|
|
PRIMARY KEY ( id ), |
|
60
|
|
|
UNIQUE KEY mollie_id ( mollie_id ) |
|
61
|
|
|
) $charset_collate; |
|
62
|
|
|
|
|
63
|
|
|
CREATE TABLE $wpdb->pronamic_pay_mollie_customers ( |
|
64
|
|
|
id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
65
|
|
|
mollie_id VARCHAR( 16 ) NOT NULL, |
|
66
|
|
|
organisation_id BIGINT( 20 ) NOT NULL, |
|
67
|
|
|
test_mode BOOL NOT NULL, |
|
68
|
|
|
email VARCHAR( 100 ) DEFAULT NULL, |
|
69
|
|
|
|
|
70
|
|
|
PRIMARY KEY ( id ), |
|
71
|
|
|
UNIQUE KEY mollie_id ( mollie_id ), |
|
72
|
|
|
KEY organisation_id ( organisation_id ), |
|
73
|
|
|
KEY test_mode ( test_mode ), |
|
74
|
|
|
KEY email ( email ) |
|
75
|
|
|
) $charset_collate; |
|
76
|
|
|
|
|
77
|
|
|
CREATE TABLE $wpdb->pronamic_pay_mollie_customer_users ( |
|
78
|
|
|
id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
79
|
|
|
customer_id BIGINT( 20 ) UNSIGNED NOT NULL, |
|
80
|
|
|
user_id BIGINT( 20 ) UNSIGNED NOT NULL, |
|
81
|
|
|
|
|
82
|
|
|
PRIMARY KEY ( id ), |
|
83
|
|
|
UNIQUE KEY customer_user ( customer_id, user_id ) |
|
84
|
|
|
) $charset_collate; |
|
85
|
|
|
"; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Execute. |
|
89
|
|
|
*/ |
|
90
|
|
|
\dbDelta( $queries ); |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Foreign keys. |
|
94
|
|
|
* |
|
95
|
|
|
* @link https://core.trac.wordpress.org/ticket/19207 |
|
96
|
|
|
*/ |
|
97
|
|
|
$wpdb->query( " |
|
98
|
|
|
ALTER TABLE $wpdb->pronamic_pay_mollie_customers |
|
99
|
|
|
ADD FOREIGN KEY ( organisation_id ) |
|
100
|
|
|
REFERENCES $wpdb->pronamic_pay_mollie_organisations ( id ) |
|
101
|
|
|
ON DELETE RESTRICT |
|
102
|
|
|
ON UPDATE RESTRICT |
|
103
|
|
|
; |
|
104
|
|
|
" ); |
|
105
|
|
|
|
|
106
|
|
|
$wpdb->query( " |
|
107
|
|
|
ALTER TABLE $wpdb->pronamic_pay_mollie_customer_users |
|
108
|
|
|
ADD FOREIGN KEY ( customer_id ) |
|
109
|
|
|
REFERENCES $wpdb->pronamic_pay_mollie_customers ( id ) |
|
110
|
|
|
ON DELETE RESTRICT |
|
111
|
|
|
ON UPDATE RESTRICT |
|
112
|
|
|
; |
|
113
|
|
|
" ); |
|
114
|
|
|
|
|
115
|
|
|
$wpdb->query( " |
|
116
|
|
|
ALTER TABLE $wpdb->pronamic_pay_mollie_customer_users |
|
117
|
|
|
ADD FOREIGN KEY ( user_id ) |
|
118
|
|
|
REFERENCES $wpdb->users ( id ) |
|
119
|
|
|
ON DELETE RESTRICT |
|
120
|
|
|
ON UPDATE RESTRICT |
|
121
|
|
|
; |
|
122
|
|
|
" ); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|