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