-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathclass-give-db-sequential-ordering.php
More file actions
145 lines (128 loc) · 2.75 KB
/
Copy pathclass-give-db-sequential-ordering.php
File metadata and controls
145 lines (128 loc) · 2.75 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Sequential Donation DB
*
* @package Give
* @subpackage Classes/Give_DB_Sequential_Ordering
* @copyright Copyright (c) 2018, GiveWP
* @license https://opensource.org/licenses/gpl-license GNU Public License
* @since 2.1.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Give_DB_Sequential_Ordering Class
*
* This class is for interacting with the sequential donation database table.
*
* @since 2.1.0
*/
class Give_DB_Sequential_Ordering extends Give_DB {
/**
* Give_DB_Sequential_Ordering constructor.
*
* Set up the Give DB Donor class.
*
* @since 2.1.0
* @access public
*/
public function __construct() {
/* @var WPDB $wpdb */
global $wpdb;
$this->table_name = $wpdb->prefix . 'give_sequential_ordering';
$this->primary_key = 'id';
$this->version = '1.0';
parent::__construct();
}
/**
* Get columns and formats
*
* @since 2.1.0
* @access public
*
* @return array Columns and formats.
*/
public function get_columns() {
return array(
'id' => '%d',
'payment_id' => '%s',
);
}
/**
* Get default column values
*
* @since 2.1.0
* @access public
*
* @return array Default column values.
*/
public function get_column_defaults() {
return array(
'id' => 0,
'payment_id' => '',
);
}
/**
* Create the table
*
* @since 2.1.0
* @access public
*
* @return void
*/
public function create_table() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
// Calculate auto increment number.
$payment_ID = $wpdb->get_var(
$wpdb->prepare(
"
SELECT ID
FROM $wpdb->posts
WHERE post_type=%s
ORDER By ID desc
LIMIT 1
",
'give_payment'
)
);
$sql = "CREATE TABLE {$this->table_name} (
id bigint(20) NOT NULL AUTO_INCREMENT,
payment_id bigint(20) NOT NULL,
PRIMARY KEY (id)
) {$charset_collate};";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
if ( ! empty( $payment_ID ) ) {
$auto_increment = $payment_ID + 1;
$wpdb->query( "ALTER TABLE {$this->table_name} AUTO_INCREMENT={$auto_increment};" );
give_update_option( 'sequential-ordering_number', $auto_increment );
} else {
give_update_option( 'sequential-ordering_number', 1 );
}
update_option( $this->table_name . '_db_version', $this->version, false );
}
/**
* Get id auto increment next value.
*
* @since 2.1.0
* @return null|string
*/
public function get_id_auto_increment_val() {
global $wpdb;
return $wpdb->get_var(
$wpdb->prepare(
'
SELECT AUTO_INCREMENT
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA=%s
AND TABLE_NAME=%s
',
DB_NAME,
$this->table_name
)
);
}
}