PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | stripe/models/FrmTransLiteDb.php +61 -29 6.5.2 → trunk View file →
@@ -7,9 +7,9 @@
7 7
8 8 /**
9 9 * @var int
10 10 */
11 - public $db_version = 5;
11 + public $db_version = 6;
12 12
13 13 /**
14 14 * @var string
15 15 */
@@ -26,8 +26,9 @@
26 26 public $singular = '';
27 27
28 28 /**
29 29 * @param mixed $old_db_version
30 + *
30 31 * @return void
31 32 */
32 33 public function upgrade( $old_db_version = false ) {
33 34 if ( ! $old_db_version ) {
@@ -33,9 +34,9 @@
33 34 if ( ! $old_db_version ) {
34 35 $old_db_version = get_option( $this->db_opt_name );
35 36 }
36 37
37 - if ( $this->db_version == $old_db_version ) {
38 + if ( $this->db_version === (int) $old_db_version ) {
38 39 return;
39 40 }
40 41
41 42 global $wpdb;
@@ -59,8 +60,9 @@
59 60 begin_date date NOT NULL,
60 61 expire_date date default NULL,
61 62 paysys varchar(100) default NULL,
62 63 created_at datetime NOT NULL,
64 + test TINYINT(1) NULL DEFAULT NULL,
63 65 PRIMARY KEY (id),
64 66 KEY item_id (item_id)
65 67 ) {$charset_collate};";
66 68
@@ -82,8 +84,9 @@
82 84 next_bill_date date default NULL,
83 85 status varchar(100) default NULL,
84 86 paysys varchar(100) default NULL,
85 87 created_at datetime NOT NULL,
88 + test TINYINT(1) NULL DEFAULT NULL,
86 89 PRIMARY KEY (id),
87 90 KEY item_id (item_id)
88 91 ) {$charset_collate};";
89 92
@@ -88,9 +91,9 @@
88 91 ) {$charset_collate};";
89 92
90 93 dbDelta( $sql );
91 94
92 - /***** SAVE DB VERSION *****/
95 + // SAVE DB VERSION.
93 96 update_option( $this->db_opt_name, $this->db_version );
94 97
95 98 $this->migrate_data( $old_db_version );
96 99 }
@@ -96,8 +99,9 @@
96 99 }
97 100
98 101 /**
99 102 * @param array $values
103 + *
100 104 * @return int
101 105 */
102 106 public function create( $values ) {
103 107 global $wpdb;
@@ -102,9 +106,9 @@
102 106 public function create( $values ) {
103 107 global $wpdb;
104 108
105 109 $values['action'] = 'create';
106 - $new_values = array();
110 + $new_values = array();
107 111 $this->fill_values( $values, $new_values );
108 112
109 113 $wpdb->insert( $wpdb->prefix . $this->table_name, $new_values );
110 114
@@ -111,11 +115,12 @@
111 115 return $wpdb->insert_id;
112 116 }
113 117
114 118 /**
115 - * @param string|int $id
119 + * @param int|string $id
116 120 * @param array $values
117 - * @return int|false
121 + *
122 + * @return false|int
118 123 */
119 124 public function update( $id, $values ) {
120 125 global $wpdb;
121 126
@@ -126,12 +131,13 @@
126 131 return $wpdb->update( $wpdb->prefix . $this->table_name, $new_values, compact( 'id' ) );
127 132 }
128 133
129 134 /**
130 - * @param string|int $id
131 - * @return int|bool
135 + * @param int|string $id
136 + *
137 + * @return bool|int
132 138 */
133 - public function &destroy( $id ) {
139 + public function destroy( $id ) {
134 140 FrmAppHelper::permission_check( 'administrator' );
135 141
136 142 global $wpdb;
137 143 $id = absint( $id );
@@ -141,25 +147,20 @@
141 147 */
142 148 do_action( 'frm_before_destroy_' . $this->singular, $id );
143 149
144 150 // @codingStandardsIgnoreStart
145 - $result = $wpdb->query(
146 - $wpdb->prepare(
147 - 'DELETE FROM ' . $wpdb->prefix . $this->table_name . ' WHERE id=%d',
148 - $id
149 - )
150 - );
151 + return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . $this->table_name . ' WHERE id=%d', $id ) );
151 152 // @codingStandardsIgnoreEnd
152 -
153 - return $result;
154 153 }
155 154
156 155 /**
157 - * @param string|int $id
158 - * @return array|object|null|void
156 + * @param int|string $id
157 + *
158 + * @return array|object|null
159 159 */
160 160 public function get_one( $id ) {
161 161 global $wpdb;
162 +
162 163 // @codingStandardsIgnoreStart
163 164 return $wpdb->get_row(
164 165 $wpdb->prepare(
165 166 'SELECT * FROM ' . $wpdb->prefix . $this->table_name . ' WHERE id=%d',
@@ -169,15 +170,16 @@
169 170 // @codingStandardsIgnoreEnd
170 171 }
171 172
172 173 /**
173 - * @param string|int $id
174 + * @param int|string $id
174 175 * @param string $field
176 + *
175 177 * @return object|null
176 178 */
177 179 public function get_one_by( $id, $field = 'receipt_id' ) {
178 180 if ( ! in_array( $field, array( 'receipt_id', 'sub_id', 'item_id' ), true ) ) {
179 - _doing_it_wrong( __FUNCTION__, 'Items can only be retrieved by receipt id or sub id.', 'x.x' );
181 + _doing_it_wrong( __METHOD__, 'Items can only be retrieved by receipt id or sub id.', '6.5' );
180 182 return null;
181 183 }
182 184
183 185 global $wpdb;
@@ -193,8 +195,14 @@
193 195 );
194 196 // @codingStandardsIgnoreEnd
195 197 }
196 198
199 + /**
200 + * @param string $value
201 + * @param string $field
202 + *
203 + * @return array
204 + */
197 205 public function get_all_by( $value, $field = 'item_id' ) {
198 206 if ( ! FrmTransLiteAppHelper::payments_table_exists() ) {
199 207 // If no migrations have run yet return nothing.
200 208 return array();
@@ -202,9 +210,9 @@
202 210
203 211 $field = sanitize_text_field( $field );
204 212
205 213 if ( ! in_array( $field, array( 'receipt_id', 'sub_id', 'item_id' ), true ) ) {
206 - _doing_it_wrong( __FUNCTION__, 'Items can only be retrieved by item id or sub id.', 'x.x' );
214 + _doing_it_wrong( __METHOD__, 'Items can only be retrieved by item id or sub id.', '6.5' );
207 215 return array();
208 216 }
209 217
210 218 global $wpdb;
@@ -218,8 +226,13 @@
218 226 );
219 227 // @codingStandardsIgnoreEnd
220 228 }
221 229
230 + /**
231 + * @param int $user_id
232 + *
233 + * @return array
234 + */
222 235 public function get_all_for_user( $user_id ) {
223 236 global $wpdb;
224 237 // @codingStandardsIgnoreStart
225 238 return $wpdb->get_results(
@@ -237,12 +250,20 @@
237 250 );
238 251 // @codingStandardsIgnoreEnd
239 252 }
240 253
254 + /**
255 + * @param int|string $id
256 + *
257 + * @return array
258 + */
241 259 public function get_all_for_entry( $id ) {
242 - return $this->get_all_by( $id, $field = 'item_id' );
260 + return $this->get_all_by( $id, 'item_id' );
243 261 }
244 262
263 + /**
264 + * @return string
265 + */
245 266 public function get_count() {
246 267 global $wpdb;
247 268 // @codingStandardsIgnoreStart
248 269 return $wpdb->get_var(
@@ -260,13 +281,13 @@
260 281
261 282 /**
262 283 * @param array $values
263 284 * @param array $new_values
285 + *
264 286 * @return void
265 287 */
266 288 private function fill_values( $values, &$new_values ) {
267 - $defaults = $this->get_defaults();
268 - foreach ( $defaults as $val => $default ) {
289 + foreach ( $this->get_defaults() as $val => $default ) {
269 290 if ( isset( $values[ $val ] ) ) {
270 291 if ( $default['sanitize'] === 'float' ) {
271 292 $new_values[ $val ] = (float) $values[ $val ];
272 293 } elseif ( ! empty( $default['sanitize'] ) ) {
@@ -278,27 +299,37 @@
278 299 }
279 300 }
280 301
281 302 /**
303 + * Run database migrations starting from a previous DB version.
304 + *
305 + * @param int $old_db_version Previous database version.
306 + *
282 307 * @return void
283 308 */
284 309 private function migrate_data( $old_db_version ) {
285 310 $migrations = array( 4 );
311 +
286 312 foreach ( $migrations as $migration ) {
287 - if ( $this->db_version >= $migration && $old_db_version < $migration ) {
288 - $function_name = 'migrate_to_' . $migration;
289 - $this->$function_name();
313 + if ( $this->db_version < $migration || $old_db_version >= $migration ) {
314 + continue;
290 315 }
316 +
317 + $function_name = 'migrate_to_' . $migration;
318 + $this->$function_name();
291 319 }
292 320 }
293 321
294 322 /**
323 + * This migration checks for PayPal payments and sets a status value based on the completed status.
324 + *
295 325 * @return void
296 326 */
297 327 private function migrate_to_4() {
298 328 global $wpdb;
299 329 $result = $wpdb->get_results( $wpdb->prepare( 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'frm_payments LIKE %s', 'completed' ) );
300 - if ( empty( $result ) ) {
330 +
331 + if ( ! $result ) {
301 332 return;
302 333 }
303 334
304 335 $payments = $wpdb->get_results(
@@ -303,8 +334,9 @@
303 334
304 335 $payments = $wpdb->get_results(
305 336 "SELECT * FROM {$wpdb->prefix}frm_payments WHERE completed is NOT NULL AND status is NULL"
306 337 );
338 +
307 339 foreach ( $payments as $payment ) {
308 340 $status = $payment->completed ? 'complete' : 'failed';
309 341 $wpdb->update( $wpdb->prefix . 'frm_payments', compact( 'status' ), array( 'id' => $payment->id ) );
310 342 }