|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Logs Meta DB class |
|
4
|
|
|
* |
|
5
|
|
|
* @package Give |
|
6
|
|
|
* @subpackage Classes/DB Log Meta |
|
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
|
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
|
9
|
|
|
* @since 2.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Give_DB_Log_Meta |
|
19
|
|
|
* |
|
20
|
|
|
* This class is for interacting with the log meta database table. |
|
21
|
|
|
* |
|
22
|
|
|
* @since 2.0 |
|
23
|
|
|
*/ |
|
24
|
|
|
class Give_DB_Log_Meta extends Give_DB_Meta { |
|
25
|
|
|
/** |
|
26
|
|
|
* Meta supports. |
|
27
|
|
|
* |
|
28
|
|
|
* @since 2.0 |
|
29
|
|
|
* @access protected |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $supports = array( |
|
33
|
|
|
'add_post_metadata', |
|
34
|
|
|
'get_post_metadata', |
|
35
|
|
|
'update_post_metadata', |
|
36
|
|
|
'delete_post_metadata', |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Post type |
|
41
|
|
|
* |
|
42
|
|
|
* @since 2.0 |
|
43
|
|
|
* @access protected |
|
44
|
|
|
* @var bool |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $post_type = 'give_log'; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Meta type |
|
50
|
|
|
* |
|
51
|
|
|
* @since 2.0 |
|
52
|
|
|
* @access protected |
|
53
|
|
|
* @var bool |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $meta_type = 'log'; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Give_DB_Log_Meta constructor. |
|
59
|
|
|
* |
|
60
|
|
|
* @access public |
|
61
|
|
|
* @since 2.0 |
|
62
|
|
|
*/ |
|
63
|
|
View Code Duplication |
public function __construct() { |
|
|
|
|
|
|
64
|
|
|
/* @var WPDB $wpdb */ |
|
65
|
|
|
global $wpdb; |
|
66
|
|
|
|
|
67
|
|
|
$wpdb->logmeta = $this->table_name = $wpdb->prefix . 'give_logmeta'; |
|
68
|
|
|
$this->primary_key = 'meta_id'; |
|
69
|
|
|
$this->version = '1.0'; |
|
70
|
|
|
|
|
71
|
|
|
$this->register_table(); |
|
72
|
|
|
|
|
73
|
|
|
parent::__construct(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get table columns and data types. |
|
78
|
|
|
* |
|
79
|
|
|
* @access public |
|
80
|
|
|
* @since 2.0 |
|
81
|
|
|
* |
|
82
|
|
|
* @return array Columns and formats. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function get_columns() { |
|
85
|
|
|
return array( |
|
86
|
|
|
'meta_id' => '%d', |
|
87
|
|
|
'log_id' => '%d', |
|
88
|
|
|
'meta_key' => '%s', |
|
|
|
|
|
|
89
|
|
|
'meta_value' => '%s', |
|
|
|
|
|
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Delete all log meta |
|
95
|
|
|
* |
|
96
|
|
|
* @since 2.0 |
|
97
|
|
|
* @access public |
|
98
|
|
|
* |
|
99
|
|
|
* @param int $log_id |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
|
View Code Duplication |
public function delete_row( $log_id = 0 ) { |
|
|
|
|
|
|
104
|
|
|
/* @var WPDB $wpdb */ |
|
105
|
|
|
global $wpdb; |
|
106
|
|
|
|
|
107
|
|
|
// Row ID must be positive integer |
|
108
|
|
|
$log_id = absint( $log_id ); |
|
109
|
|
|
|
|
110
|
|
|
if ( empty( $log_id ) ) { |
|
111
|
|
|
return false; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE log_id = %d", $log_id ) ) ) { |
|
|
|
|
|
|
115
|
|
|
return false; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return true; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Create the table |
|
123
|
|
|
* |
|
124
|
|
|
* @access public |
|
125
|
|
|
* @since 2.0 |
|
126
|
|
|
* |
|
127
|
|
|
* @return void |
|
128
|
|
|
*/ |
|
129
|
|
|
public function create_table() { |
|
130
|
|
|
global $wpdb; |
|
131
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
|
132
|
|
|
|
|
133
|
|
|
$sql = "CREATE TABLE {$wpdb->logmeta} ( |
|
134
|
|
|
meta_id bigint(20) NOT NULL AUTO_INCREMENT, |
|
135
|
|
|
log_id bigint(20) NOT NULL, |
|
136
|
|
|
meta_key varchar(255) DEFAULT NULL, |
|
137
|
|
|
meta_value longtext, |
|
138
|
|
|
PRIMARY KEY (meta_id), |
|
139
|
|
|
KEY log_id (log_id), |
|
140
|
|
|
KEY meta_key (meta_key) |
|
141
|
|
|
) {$charset_collate};"; |
|
142
|
|
|
|
|
143
|
|
|
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
144
|
|
|
dbDelta( $sql ); |
|
145
|
|
|
|
|
146
|
|
|
update_option( $this->table_name . '_db_version', $this->version ); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.