PluginProbe
PayPlug for WooCommerce (Official) / 2.9.0
PayPlug for WooCommerce (Official) v2.9.0
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
← All changes | src/Model/Lock.php +101 -125 3.0.02.9.0 View file →
@@ -3,155 +3,131 @@
3 3 namespace Payplug\PayplugWoocommerce\Model;
4 4
5 5 class Lock
6 6 {
7 - /**
8 - * create Lock table
9 - */
10 - public static function create_lock_table(): void
11 - {
12 - global $wpdb;
13 7
14 - $sql = 'CREATE TABLE IF NOT EXISTS `' . $wpdb->base_prefix . 'woocommerce_payplug_lock` (';
15 - $sql .= ' `payment_id` VARCHAR(50) NOT NULL,';
16 - $sql .= ' `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,';
17 - $sql .= ' PRIMARY KEY (`payment_id`));';
8 + /**
9 + * create Lock table
10 + */
11 + static function create_lock_table(){
12 + global $wpdb;
18 13
19 - $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
20 - require_once ABSPATH . 'wp-admin/includes/upgrade.php';
21 - maybe_create_table($table_name, $sql);
14 + $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->base_prefix}woocommerce_payplug_lock` (";
15 + $sql .= " `payment_id` VARCHAR(50) NOT NULL,";
16 + $sql .= " `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,";
17 + $sql .= " PRIMARY KEY (`payment_id`));";
22 18
23 - $result = $wpdb->get_row(
24 - $wpdb->prepare(
25 - "SELECT count(column_name) as column_exists FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->base_prefix}woocommerce_payplug_lock' AND column_name = %s ",
26 - ['id']
27 - )
28 - );
19 + $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
20 + require_once ABSPATH . 'wp-admin/includes/upgrade.php';
21 + maybe_create_table( $table_name, $sql);
29 22
30 - if (!empty($result) && !$result->column_exists) {
31 - static::update_lock_table();
32 - }
33 - }
23 + $result = $wpdb->get_row(
24 + $wpdb->prepare(
25 + "SELECT count(column_name) as column_exists FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->base_prefix}woocommerce_payplug_lock' AND column_name = %s ", ['id']
26 + )
27 + );
34 28
35 - /**
36 - * update table
37 - */
38 - public static function update_lock_table(): void
39 - {
40 - global $wpdb;
29 + if( !empty($result) && !$result->column_exists){
30 + static::update_lock_table();
31 + }
41 32
42 - $sql = "ALTER TABLE `{$wpdb->base_prefix}woocommerce_payplug_lock` ";
43 - $sql .= ' ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST,';
44 - $sql .= ' DROP PRIMARY KEY,';
45 - $sql .= ' ADD PRIMARY KEY (`id`);';
46 - $wpdb->query($sql);
47 - }
33 + }
48 34
49 - /**
50 - * @param $payment_id
51 - *
52 - * @return bool|int
53 - */
54 - public static function insert_lock($payment_id)
55 - {
56 - global $wpdb;
57 - $wpdb->hide_errors();
58 - $lock_table_exists = self::check_table_exists();
59 - if (!$lock_table_exists) {
60 - self::create_lock_table();
61 - }
62 - $wpdb->insert($wpdb->base_prefix . 'woocommerce_payplug_lock', ['payment_id' => $payment_id]);
35 + /**
36 + * update table
37 + */
38 + static function update_lock_table(){
39 + global $wpdb;
63 40
64 - return $wpdb->insert_id;
65 - }
41 + $sql = "ALTER TABLE `{$wpdb->base_prefix}woocommerce_payplug_lock` ";
42 + $sql .= " ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST,";
43 + $sql .= " DROP PRIMARY KEY,";
44 + $sql .= " ADD PRIMARY KEY (`id`);";
45 + $wpdb->query($sql);
66 46
67 - /**
68 - * @param $id
69 - *
70 - * @return bool
71 - */
72 - public static function delete_lock($id)
73 - {
74 - global $wpdb;
75 - $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
76 - $wpdb->query($wpdb->prepare("DELETE FROM {$table_name} WHERE id = %s OR created < NOW() - INTERVAL 1 DAY;", [$id]));
47 + }
77 48
78 - return true;
79 - }
49 + /**
50 + * @param $payment_id
51 + * @return bool|int
52 + */
53 + static function insert_lock($payment_id){
54 + global $wpdb;
55 + $wpdb->hide_errors();
56 + $wpdb->insert($wpdb->base_prefix . 'woocommerce_payplug_lock', array("payment_id" => $payment_id));
57 + return $wpdb->insert_id;
58 + }
80 59
81 - /**
82 - * @param $payment_id
83 - *
84 - * @return bool
85 - */
86 - public static function delete_lock_by_payment_id($payment_id)
87 - {
88 - global $wpdb;
89 - $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
90 - $wpdb->query($wpdb->prepare("DELETE FROM {$table_name} WHERE payment_id = %s OR created < NOW() - INTERVAL 1 DAY;", [$payment_id]));
60 + /**
61 + * @param $id
62 + * @return bool
63 + */
64 + static function delete_lock($id){
65 + global $wpdb;
66 + $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
67 + $wpdb->query( $wpdb->prepare("DELETE FROM {$table_name} WHERE id = %s OR created < NOW() - INTERVAL 1 DAY;", [$id] ));
68 + return true;
69 + }
91 70
92 - return true;
93 - }
71 + /**
72 + * @param $payment_id
73 + * @return bool
74 + */
75 + static function delete_lock_by_payment_id($payment_id){
76 + global $wpdb;
77 + $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
78 + $wpdb->query( $wpdb->prepare("DELETE FROM {$table_name} WHERE payment_id = %s OR created < NOW() - INTERVAL 1 DAY;", [$payment_id] ));
79 + return true;
80 + }
94 81
95 - /**
96 - * @param $payment_id
97 - * @param $id
98 - *
99 - * @return bool
100 - */
101 - public static function locked($payment_id, $id)
102 - {
103 - global $wpdb;
104 82
105 - $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
83 + /**
84 + * @param $payment_id
85 + * @param $id
86 + * @return bool
87 + */
88 + static function locked($payment_id, $id){
89 + global $wpdb;
106 90
107 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
108 - $result = $wpdb->get_row($wpdb->prepare("SELECT id FROM {$table_name} WHERE `payment_id` = %s AND `id` <> %s ", [$payment_id, $id]));
91 + $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
109 92
110 - if (empty($result)) {
111 - return false;
112 - }
93 + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
94 + $result = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE `payment_id` = %s AND `id` <> %s ", array( $payment_id, $id ) ) );
113 95
114 - return true;
115 - }
96 + if ( empty($result) ) {
97 + return false;
98 + }
116 99
117 - /**
118 - * @param $id
119 - *
120 - * @return bool|int
121 - */
122 - public static function get_lock_by_payment_id($payment_id)
123 - {
124 - global $wpdb;
100 + return true;
125 101
126 - $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
102 + }
127 103
128 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
129 - $result = $wpdb->get_row($wpdb->prepare("SELECT id FROM {$table_name} WHERE payment_id = %s", [$payment_id]));
130 - if (!$result) {
131 - return false;
132 - }
104 + /**
105 + * @param $id
106 + * @return bool|int
107 + */
108 + static function get_lock_by_payment_id($payment_id){
109 + global $wpdb;
133 110
134 - return $result;
135 - }
111 + $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
136 112
137 - public static function delete_lock_table(): void
138 - {
139 - global $wpdb;
113 + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
114 + $result = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE payment_id = %s", array( $payment_id ) ) );
115 + if ( !$result ) {
116 + return false;
117 + }
140 118
141 - $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
142 - $sql = "DROP TABLE IF EXISTS $table_name;";
143 - $wpdb->query($sql);
144 - }
119 + return $result;
145 120
146 - public static function check_table_exists()
147 - {
148 - global $wpdb;
149 - $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
150 - $table_exists = $wpdb->get_var($wpdb->prepare(
151 - 'SHOW TABLES LIKE %s',
152 - $table_name
153 - ));
121 + }
154 122
155 - return $table_exists === $table_name;
156 - }
123 + static function delete_lock_table(){
124 + global $wpdb;
125 +
126 + $table_name = $wpdb->base_prefix . 'woocommerce_payplug_lock';
127 + $sql = "DROP TABLE IF EXISTS $table_name;";
128 + $wpdb->query($sql);
129 +
130 + }
131 +
132 +
157 133 }