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 +46 -18 6.25.1 → trunk View file →
@@ -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;
@@ -98,8 +99,9 @@
98 99 }
99 100
100 101 /**
101 102 * @param array $values
103 + *
102 104 * @return int
103 105 */
104 106 public function create( $values ) {
105 107 global $wpdb;
@@ -115,8 +117,9 @@
115 117
116 118 /**
117 119 * @param int|string $id
118 120 * @param array $values
121 + *
119 122 * @return false|int
120 123 */
121 124 public function update( $id, $values ) {
122 125 global $wpdb;
@@ -129,11 +132,12 @@
129 132 }
130 133
131 134 /**
132 135 * @param int|string $id
136 + *
133 137 * @return bool|int
134 138 */
135 - public function &destroy( $id ) {
139 + public function destroy( $id ) {
136 140 FrmAppHelper::permission_check( 'administrator' );
137 141
138 142 global $wpdb;
139 143 $id = absint( $id );
@@ -143,25 +147,20 @@
143 147 */
144 148 do_action( 'frm_before_destroy_' . $this->singular, $id );
145 149
146 150 // @codingStandardsIgnoreStart
147 - $result = $wpdb->query(
148 - $wpdb->prepare(
149 - 'DELETE FROM ' . $wpdb->prefix . $this->table_name . ' WHERE id=%d',
150 - $id
151 - )
152 - );
151 + return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . $this->table_name . ' WHERE id=%d', $id ) );
153 152 // @codingStandardsIgnoreEnd
154 -
155 - return $result;
156 153 }
157 154
158 155 /**
159 156 * @param int|string $id
160 - * @return array|object|void|null
157 + *
158 + * @return array|object|null
161 159 */
162 160 public function get_one( $id ) {
163 161 global $wpdb;
162 +
164 163 // @codingStandardsIgnoreStart
165 164 return $wpdb->get_row(
166 165 $wpdb->prepare(
167 166 'SELECT * FROM ' . $wpdb->prefix . $this->table_name . ' WHERE id=%d',
@@ -173,8 +172,9 @@
173 172
174 173 /**
175 174 * @param int|string $id
176 175 * @param string $field
176 + *
177 177 * @return object|null
178 178 */
179 179 public function get_one_by( $id, $field = 'receipt_id' ) {
180 180 if ( ! in_array( $field, array( 'receipt_id', 'sub_id', 'item_id' ), true ) ) {
@@ -195,8 +195,14 @@
195 195 );
196 196 // @codingStandardsIgnoreEnd
197 197 }
198 198
199 + /**
200 + * @param string $value
201 + * @param string $field
202 + *
203 + * @return array
204 + */
199 205 public function get_all_by( $value, $field = 'item_id' ) {
200 206 if ( ! FrmTransLiteAppHelper::payments_table_exists() ) {
201 207 // If no migrations have run yet return nothing.
202 208 return array();
@@ -220,8 +226,13 @@
220 226 );
221 227 // @codingStandardsIgnoreEnd
222 228 }
223 229
230 + /**
231 + * @param int $user_id
232 + *
233 + * @return array
234 + */
224 235 public function get_all_for_user( $user_id ) {
225 236 global $wpdb;
226 237 // @codingStandardsIgnoreStart
227 238 return $wpdb->get_results(
@@ -239,12 +250,20 @@
239 250 );
240 251 // @codingStandardsIgnoreEnd
241 252 }
242 253
254 + /**
255 + * @param int|string $id
256 + *
257 + * @return array
258 + */
243 259 public function get_all_for_entry( $id ) {
244 - return $this->get_all_by( $id, $field = 'item_id' );
260 + return $this->get_all_by( $id, 'item_id' );
245 261 }
246 262
263 + /**
264 + * @return string
265 + */
247 266 public function get_count() {
248 267 global $wpdb;
249 268 // @codingStandardsIgnoreStart
250 269 return $wpdb->get_var(
@@ -262,13 +281,13 @@
262 281
263 282 /**
264 283 * @param array $values
265 284 * @param array $new_values
285 + *
266 286 * @return void
267 287 */
268 288 private function fill_values( $values, &$new_values ) {
269 - $defaults = $this->get_defaults();
270 - foreach ( $defaults as $val => $default ) {
289 + foreach ( $this->get_defaults() as $val => $default ) {
271 290 if ( isset( $values[ $val ] ) ) {
272 291 if ( $default['sanitize'] === 'float' ) {
273 292 $new_values[ $val ] = (float) $values[ $val ];
274 293 } elseif ( ! empty( $default['sanitize'] ) ) {
@@ -280,17 +299,24 @@
280 299 }
281 300 }
282 301
283 302 /**
303 + * Run database migrations starting from a previous DB version.
304 + *
305 + * @param int $old_db_version Previous database version.
306 + *
284 307 * @return void
285 308 */
286 309 private function migrate_data( $old_db_version ) {
287 310 $migrations = array( 4 );
311 +
288 312 foreach ( $migrations as $migration ) {
289 - if ( $this->db_version >= $migration && $old_db_version < $migration ) {
290 - $function_name = 'migrate_to_' . $migration;
291 - $this->$function_name();
313 + if ( $this->db_version < $migration || $old_db_version >= $migration ) {
314 + continue;
292 315 }
316 +
317 + $function_name = 'migrate_to_' . $migration;
318 + $this->$function_name();
293 319 }
294 320 }
295 321
296 322 /**
@@ -300,9 +326,10 @@
300 326 */
301 327 private function migrate_to_4() {
302 328 global $wpdb;
303 329 $result = $wpdb->get_results( $wpdb->prepare( 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'frm_payments LIKE %s', 'completed' ) );
304 - if ( empty( $result ) ) {
330 +
331 + if ( ! $result ) {
305 332 return;
306 333 }
307 334
308 335 $payments = $wpdb->get_results(
@@ -307,8 +334,9 @@
307 334
308 335 $payments = $wpdb->get_results(
309 336 "SELECT * FROM {$wpdb->prefix}frm_payments WHERE completed is NOT NULL AND status is NULL"
310 337 );
338 +
311 339 foreach ( $payments as $payment ) {
312 340 $status = $payment->completed ? 'complete' : 'failed';
313 341 $wpdb->update( $wpdb->prefix . 'frm_payments', compact( 'status' ), array( 'id' => $payment->id ) );
314 342 }