PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / sql / update-2.0-beta.php
pods / sql Last commit date
upgrade 3 days ago dump.sql 3 days ago update-1.x.php 3 days ago update-2.0-beta.php 3 days ago update.php 3 days ago
update-2.0-beta.php
522 lines
1 <?php
2 /**
3 * @package Pods\Upgrade
4 */
5
6 /**
7 * @var $wpdb WPDB
8 */
9 global $wpdb;
10
11 // Update to 2.0.0-a-31
12 if ( version_compare( $pods_version, '2.0.0-a-31', '<' ) ) {
13 $pages = pods_2_alpha_migrate_pages();
14 $helpers = pods_2_alpha_migrate_helpers();
15 $templates = pods_2_alpha_migrate_templates();
16 $pod_ids = pods_2_alpha_migrate_pods();
17
18 pods_query( 'DROP TABLE @wp_pods', false );
19 pods_query( 'DROP TABLE @wp_pods_fields', false );
20 pods_query( 'DROP TABLE @wp_pods_objects', false );
21
22 update_option( 'pods_framework_version', '2.0.0-a-31' );
23 }
24
25 // Update to 2.0.0-b-10
26 if ( version_compare( $pods_version, '2.0.0-b-10', '<' ) ) {
27 $author_fields = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_name` = 'author' AND `post_type` = '_pods_field'" );
28
29 if ( ! empty( $author_fields ) ) {
30 foreach ( $author_fields as $author ) {
31 update_post_meta( $author->ID, 'pick_format_type', 'single' );
32 update_post_meta( $author->ID, 'pick_format_single', 'autocomplete' );
33 update_post_meta( $author->ID, 'default_value', '{@user.ID}' );
34 }
35 }
36
37 update_option( 'pods_framework_version', '2.0.0-b-10' );
38 }
39
40 // Update to 2.0.0-b-11
41 if ( version_compare( $pods_version, '2.0.0-b-11', '<' ) ) {
42 $date_fields = $wpdb->get_results(
43 "
44 SELECT `ID`
45 FROM `{$wpdb->posts}`
46 WHERE ( `post_name` = 'created' OR `post_name` = 'modified' ) AND `post_type` = '_pods_field'
47 "
48 );
49
50 if ( ! empty( $date_fields ) ) {
51 foreach ( $date_fields as $date ) {
52 update_post_meta( $date->ID, 'date_format_type', 'datetime' );
53 update_post_meta( $date->ID, 'date_format', 'ymd_slash' );
54 update_post_meta( $date->ID, 'date_time_type', '12' );
55 update_post_meta( $date->ID, 'date_time_format', 'h_mm_ss_A' );
56 }
57 }
58
59 update_option( 'pods_framework_version', '2.0.0-b-11' );
60 }
61
62 // Update to 2.0.0-b-12
63 if ( version_compare( $pods_version, '2.0.0-b-12', '<' ) ) {
64 $oldget = $_GET;
65
66 $_GET['toggle'] = 1;
67
68 PodsInit::$components->toggle( 'templates' );
69 PodsInit::$components->toggle( 'pages' );
70 PodsInit::$components->toggle( 'helpers' );
71
72 $_GET = $oldget;
73
74 $number_fields = $wpdb->get_results(
75 "
76 SELECT `p`.`ID`
77 FROM `{$wpdb->posts}` AS `p`
78 LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
79 WHERE
80 `p`.`post_type` = '_pods_field'
81 AND `pm`.`meta_key` = 'type'
82 AND `pm`.`meta_value` = 'number'
83 "
84 );
85
86 if ( ! empty( $number_fields ) ) {
87 foreach ( $number_fields as $number ) {
88 update_post_meta( $number->ID, 'number_max_length', '12' );
89 }
90 }
91
92 update_option( 'pods_framework_version', '2.0.0-b-12' );
93 }//end if
94
95 // Update to 2.0.0-b-14
96 if ( version_compare( $pods_version, '2.0.0-b-14', '<' ) ) {
97 $tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pods%'", ARRAY_N );
98
99 $podsrel_found = false;
100
101 if ( ! empty( $tables ) ) {
102 foreach ( $tables as &$table ) {
103 $table = $table[0];
104 $new_table = $table;
105
106 if ( "{$wpdb->prefix}pods_rel" === $table ) {
107 $new_table = "{$wpdb->prefix}podsrel";
108
109 $podsrel_found = true;
110 } elseif ( "{$wpdb->prefix}podsrel" === $table ) {
111 $podsrel_found = true;
112 } else {
113 $new_table = str_replace( 'pods_tbl_', 'pods_', $table );
114 }
115
116 if ( $table !== $new_table ) {
117 $wpdb->query( "ALTER TABLE `{$table}` RENAME `{$new_table}`" );
118 }
119 }
120 }
121
122 if ( ! $podsrel_found ) {
123 // rerun install for any bugged versions
124 $sql = file_get_contents( PODS_DIR . 'sql/dump.sql' );
125 $sql = apply_filters( 'pods_install_sql', $sql, PODS_VERSION, $pods_version, $_blog_id );
126
127 $charset_collate = 'DEFAULT CHARSET utf8';
128
129 if ( ! empty( $wpdb->charset ) ) {
130 $charset_collate = "DEFAULT CHARSET {$wpdb->charset}";
131 }
132
133 if ( ! empty( $wpdb->collate ) ) {
134 $charset_collate .= " COLLATE {$wpdb->collate}";
135 }
136
137 if ( 'DEFAULT CHARSET utf8' !== $charset_collate ) {
138 $sql = str_replace( 'DEFAULT CHARSET utf8', $charset_collate, $sql );
139 }
140
141 $sql = explode( ";\n", str_replace( array( "\r", 'wp_' ), array( "\n", $wpdb->prefix ), $sql ) );
142
143 $z = count( $sql );
144 for ( $i = 0; $i < $z; $i ++ ) {
145 $query = trim( $sql[ $i ] );
146
147 if ( empty( $query ) ) {
148 continue;
149 }
150
151 pods_query( $query, 'Cannot setup SQL tables' );
152 }
153 }//end if
154
155 pods_no_conflict_on( 'post' );
156
157 // convert field types based on options set
158 $fields = $wpdb->get_results(
159 "
160 SELECT `p`.`ID`
161 FROM `{$wpdb->posts}` AS `p`
162 LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
163 WHERE
164 `p`.`post_type` = '_pods_field'
165 AND `pm`.`meta_key` = 'type'
166 AND `pm`.`meta_value` = 'date'
167 "
168 );
169
170 if ( ! empty( $fields ) ) {
171 foreach ( $fields as $field ) {
172 $new_type = get_post_meta( $field->ID, 'date_format_type', true );
173
174 if ( 'datetime' === $new_type ) {
175 $new = array(
176 'date_format' => 'datetime_format',
177 'date_time_type' => 'datetime_time_type',
178 'date_time_format' => 'datetime_time_format',
179 'date_html5' => 'datetime_html5',
180 );
181
182 update_post_meta( $field->ID, 'type', $new_type );
183 } elseif ( 'time' === $new_type ) {
184 $new = array(
185 'date_time_type' => 'time_type',
186 'date_time_format' => 'time_format',
187 'date_html5' => 'time_html5',
188 );
189
190 update_post_meta( $field->ID, 'type', $new_type );
191 }
192 }//end foreach
193 }//end if
194
195 $fields = $wpdb->get_results(
196 "
197 SELECT `p`.`ID`
198 FROM `{$wpdb->posts}` AS `p`
199 LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
200 WHERE
201 `p`.`post_type` = '_pods_field'
202 AND `pm`.`meta_key` = 'type'
203 AND `pm`.`meta_value` = 'number'
204 "
205 );
206
207 if ( ! empty( $fields ) ) {
208 foreach ( $fields as $field ) {
209 $new_type = get_post_meta( $field->ID, 'number_format_type', true );
210
211 if ( 'currency' === $new_type ) {
212 $new = array(
213 'number_format_currency_sign' => 'currency_format_sign',
214 'number_format_currency_placement' => 'currency_format_placement',
215 'number_format' => 'currency_format',
216 'number_decimals' => 'currency_decimals',
217 'number_max_length' => 'currency_max_length',
218 'number_size' => 'currency_size',
219 );
220
221 update_post_meta( $field->ID, 'type', $new_type );
222 }
223 }
224 }
225
226 $fields = $wpdb->get_results(
227 "
228 SELECT `p`.`ID`
229 FROM `{$wpdb->posts}` AS `p`
230 LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
231 WHERE
232 `p`.`post_type` = '_pods_field'
233 AND `pm`.`meta_key` = 'type'
234 AND `pm`.`meta_value` = 'paragraph'
235 "
236 );
237
238 if ( ! empty( $fields ) ) {
239 foreach ( $fields as $field ) {
240 $new_type = get_post_meta( $field->ID, 'paragraph_format_type', true );
241
242 if ( 'plain' !== $new_type ) {
243 $new_type = 'wysiwyg';
244
245 $new = array(
246 'paragraph_format_type' => 'wysiwyg_editor',
247 'paragraph_allow_shortcode' => 'wysiwyg_allow_shortcode',
248 'paragraph_allowed_html_tags' => 'wysiwyg_allowed_html_tags',
249 'paragraph_max_length' => 'wysiwyg_max_length',
250 'paragraph_size' => 'wysiwyg_size',
251 );
252
253 update_post_meta( $field->ID, 'type', $new_type );
254 }
255 }
256 }
257
258 $fields = $wpdb->get_results(
259 "
260 SELECT `p`.`ID`
261 FROM `{$wpdb->posts}` AS `p`
262 LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
263 WHERE
264 `p`.`post_type` = '_pods_field'
265 AND `pm`.`meta_key` = 'type'
266 AND `pm`.`meta_value` = 'text'
267 "
268 );
269
270 if ( ! empty( $fields ) ) {
271 foreach ( $fields as $field ) {
272 $new_type = get_post_meta( $field->ID, 'text_format_type', true );
273
274 if ( 'website' === $new_type ) {
275 $new = array(
276 'text_format_website' => 'website_format',
277 'text_max_length' => 'website_max_length',
278 'text_html5' => 'website_html5',
279 'text_size' => 'website_size',
280 );
281
282 update_post_meta( $field->ID, 'type', $new_type );
283 } elseif ( 'phone' === $new_type ) {
284 $new = array(
285 'text_format_phone' => 'phone_format',
286 'text_max_length' => 'phone_max_length',
287 'text_html5' => 'phone_html5',
288 'text_size' => 'phone_size',
289 );
290
291 update_post_meta( $field->ID, 'type', $new_type );
292 } elseif ( 'email' === $new_type ) {
293 $new = array(
294 'text_max_length' => 'email_max_length',
295 'text_html5' => 'email_html5',
296 'text_size' => 'email_size',
297 );
298
299 update_post_meta( $field->ID, 'type', $new_type );
300 } elseif ( 'password' === $new_type ) {
301 $new = array(
302 'text_max_length' => 'password_max_length',
303 'text_size' => 'password_size',
304 );
305
306 update_post_meta( $field->ID, 'type', $new_type );
307 }//end if
308 }//end foreach
309 }//end if
310
311 pods_no_conflict_off( 'post' );
312
313 update_option( 'pods_framework_version', '2.0.0-b-14' );
314 }//end if
315
316 // Update to 2.0.0-b-15
317 if ( version_compare( $pods_version, '2.0.0-b-15', '<' ) ) {
318 $helpers = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '_pods_helper'" );
319
320 if ( ! empty( $helpers ) ) {
321 foreach ( $helpers as $helper ) {
322 $wpdb->query( "UPDATE `{$wpdb->postmeta}` SET `meta_key` = 'helper_type' WHERE `meta_key` = 'type' AND `post_id` = {$helper->ID}" );
323 }
324 }
325
326 update_option( 'pods_framework_version', '2.0.0-b-15' );
327 }
328
329 /*
330 ===================================
331
332 Old upgrade code from Alpha to Beta
333
334 ===================================
335 */
336 /**
337 * @param $id
338 * @param $options
339 */
340 function pods_2_beta_migrate_type( $id, $options ) {
341
342 global $wpdb;
343
344 foreach ( $options as $old => $new ) {
345 $wpdb->query(
346 $wpdb->prepare(
347 "UPDATE `{$wpdb->postmeta}` SET `meta_key` = %s WHERE `meta_key` = %s", array(
348 $new,
349 $old,
350 )
351 )
352 );
353 }
354 }
355
356 /**
357 * @return array
358 */
359 function pods_2_alpha_migrate_pods() {
360
361 $api = pods_api();
362
363 $api->display_errors = true;
364
365 $old_pods = pods_query( 'SELECT * FROM `@wp_pods`', false );
366
367 $pod_ids = array();
368
369 if ( empty( $old_pods ) ) {
370 return $pod_ids;
371 }
372
373 foreach ( $old_pods as $pod ) {
374 $api->cache_flush_pods( array( 'name' => $pod->name ) );
375
376 $pod_opts = json_decode( $pod->options, true );
377
378 $field_rows = pods_query( "SELECT * FROM `@wp_pods_fields` where `pod_id` = {$pod->id}" );
379
380 $fields = array();
381
382 foreach ( $field_rows as $row ) {
383 $field_opts = json_decode( $row->options, true );
384
385 if ( 'permalink' === $row->type ) {
386 $row->type = 'slug';
387 }
388
389 $field_params = array(
390 'name' => $row->name,
391 'label' => $row->label,
392 'type' => $row->type,
393 'pick_object' => $row->pick_object,
394 'pick_val' => $row->pick_val,
395 'sister_field_id' => $row->sister_field_id,
396 'weight' => $row->weight,
397 'options' => $field_opts,
398 );
399
400 $fields[] = $field_params;
401 }
402
403 $pod_params = array(
404 'name' => $pod->name,
405 'type' => $pod->type,
406 'storage' => $pod->storage,
407 'fields' => $fields,
408 'options' => $pod_opts,
409 );
410
411 $renamed = false;
412
413 if ( 'table' === $pod->storage ) {
414 try {
415 pods_query( "RENAME TABLE `@wp_pods_tbl_{$pod->name}` TO `@wp_pods_tb_{$pod->name}`" );
416 $renamed = true;
417 } catch ( Exception $e ) {
418 $renamed = false;
419 }
420 }
421
422 $pod_id = $api->save_pod( $pod_params );
423
424 if ( 'table' === $pod->storage && $renamed ) {
425 pods_query( "DROP TABLE `@wp_pods_tbl_{$pod->name}`", false );
426 pods_query( "RENAME TABLE `@wp_pods_tb_{$pod->name}` TO `@wp_pods_tbl_{$pod->name}`" );
427 }
428
429 $pod_ids[] = $pod_id;
430 }//end foreach
431
432 return $pod_ids;
433 }
434
435 /**
436 * @return array
437 */
438 function pods_2_alpha_migrate_helpers() {
439
440 $api = pods_api();
441
442 $helper_rows = pods_query( "SELECT * FROM `@wp_pods_objects` WHERE `type` = 'helper'", false );
443
444 $helper_ids = array();
445
446 if ( empty( $helper_rows ) ) {
447 return $helper_ids;
448 }
449
450 foreach ( $helper_rows as $row ) {
451 $opts = json_decode( $row->options );
452
453 $helper_params = array(
454 'name' => $row->name,
455 'type' => $opts->type,
456 'phpcode' => $opts->phpcode,
457 );
458
459 $helper_ids[] = $api->save_helper( $helper_params );
460 }
461
462 return $helper_ids;
463 }
464
465 /**
466 * @return array
467 */
468 function pods_2_alpha_migrate_pages() {
469
470 $api = pods_api();
471
472 $page_rows = pods_query( "SELECT * FROM `@wp_pods_objects` WHERE `type` = 'page'", false );
473
474 $page_ids = array();
475
476 if ( empty( $page_rows ) ) {
477 return $page_ids;
478 }
479
480 foreach ( $page_rows as $row ) {
481 $opts = json_decode( $row->options );
482
483 $page_params = array(
484 'uri' => $row->name,
485 'phpcode' => $opts->phpcode,
486 );
487
488 $page_ids[] = $api->save_page( $page_params );
489 }
490
491 return $page_ids;
492 }
493
494 /**
495 * @return array
496 */
497 function pods_2_alpha_migrate_templates() {
498
499 $api = pods_api();
500
501 $tpl_rows = pods_query( "SELECT * FROM `@wp_pods_objects` WHERE `type` = 'template'", false );
502
503 $tpl_ids = array();
504
505 if ( empty( $tpl_rows ) ) {
506 return $tpl_ids;
507 }
508
509 foreach ( $tpl_rows as $row ) {
510 $opts = json_decode( $row->options );
511
512 $tpl_params = array(
513 'name' => $row->name,
514 'code' => $opts->code,
515 );
516
517 $tpl_ids[] = $api->save_template( $tpl_params );
518 }
519
520 return $tpl_ids;
521 }
522