|
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
|
|
|
for ( $i = 0, $z = count( $sql ); $i < $z; $i ++ ) { |
|
144
|
|
|
$query = trim( $sql[ $i ] ); |
|
145
|
|
|
|
|
146
|
|
|
if ( empty( $query ) ) { |
|
147
|
|
|
continue; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
pods_query( $query, 'Cannot setup SQL tables' ); |
|
151
|
|
|
} |
|
152
|
|
|
}//end if |
|
153
|
|
|
|
|
154
|
|
|
pods_no_conflict_on( 'post' ); |
|
155
|
|
|
|
|
156
|
|
|
// convert field types based on options set |
|
157
|
|
|
$fields = $wpdb->get_results( |
|
|
|
|
|
|
158
|
|
|
" |
|
159
|
|
|
SELECT `p`.`ID` |
|
160
|
|
|
FROM `{$wpdb->posts}` AS `p` |
|
161
|
|
|
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID` |
|
162
|
|
|
WHERE |
|
163
|
|
|
`p`.`post_type` = '_pods_field' |
|
164
|
|
|
AND `pm`.`meta_key` = 'type' |
|
165
|
|
|
AND `pm`.`meta_value` = 'date' |
|
166
|
|
|
" |
|
167
|
|
|
); |
|
168
|
|
|
|
|
169
|
|
|
if ( ! empty( $fields ) ) { |
|
170
|
|
|
foreach ( $fields as $field ) { |
|
171
|
|
|
$new_type = get_post_meta( $field->ID, 'date_format_type', true ); |
|
172
|
|
|
|
|
173
|
|
|
if ( 'datetime' === $new_type ) { |
|
174
|
|
|
$new = array( |
|
175
|
|
|
'date_format' => 'datetime_format', |
|
176
|
|
|
'date_time_type' => 'datetime_time_type', |
|
177
|
|
|
'date_time_format' => 'datetime_time_format', |
|
178
|
|
|
'date_html5' => 'datetime_html5', |
|
179
|
|
|
); |
|
180
|
|
|
|
|
181
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
182
|
|
|
} elseif ( 'time' === $new_type ) { |
|
183
|
|
|
$new = array( |
|
184
|
|
|
'date_time_type' => 'time_type', |
|
185
|
|
|
'date_time_format' => 'time_format', |
|
186
|
|
|
'date_html5' => 'time_html5', |
|
187
|
|
|
); |
|
188
|
|
|
|
|
189
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
190
|
|
|
} |
|
191
|
|
|
}//end foreach |
|
192
|
|
|
}//end if |
|
193
|
|
|
|
|
194
|
|
|
$fields = $wpdb->get_results( |
|
|
|
|
|
|
195
|
|
|
" |
|
196
|
|
|
SELECT `p`.`ID` |
|
197
|
|
|
FROM `{$wpdb->posts}` AS `p` |
|
198
|
|
|
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID` |
|
199
|
|
|
WHERE |
|
200
|
|
|
`p`.`post_type` = '_pods_field' |
|
201
|
|
|
AND `pm`.`meta_key` = 'type' |
|
202
|
|
|
AND `pm`.`meta_value` = 'number' |
|
203
|
|
|
" |
|
204
|
|
|
); |
|
205
|
|
|
|
|
206
|
|
|
if ( ! empty( $fields ) ) { |
|
207
|
|
|
foreach ( $fields as $field ) { |
|
208
|
|
|
$new_type = get_post_meta( $field->ID, 'number_format_type', true ); |
|
209
|
|
|
|
|
210
|
|
|
if ( 'currency' === $new_type ) { |
|
211
|
|
|
$new = array( |
|
212
|
|
|
'number_format_currency_sign' => 'currency_format_sign', |
|
213
|
|
|
'number_format_currency_placement' => 'currency_format_placement', |
|
214
|
|
|
'number_format' => 'currency_format', |
|
215
|
|
|
'number_decimals' => 'currency_decimals', |
|
216
|
|
|
'number_max_length' => 'currency_max_length', |
|
217
|
|
|
'number_size' => 'currency_size', |
|
218
|
|
|
); |
|
219
|
|
|
|
|
220
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
$fields = $wpdb->get_results( |
|
|
|
|
|
|
226
|
|
|
" |
|
227
|
|
|
SELECT `p`.`ID` |
|
228
|
|
|
FROM `{$wpdb->posts}` AS `p` |
|
229
|
|
|
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID` |
|
230
|
|
|
WHERE |
|
231
|
|
|
`p`.`post_type` = '_pods_field' |
|
232
|
|
|
AND `pm`.`meta_key` = 'type' |
|
233
|
|
|
AND `pm`.`meta_value` = 'paragraph' |
|
234
|
|
|
" |
|
235
|
|
|
); |
|
236
|
|
|
|
|
237
|
|
|
if ( ! empty( $fields ) ) { |
|
238
|
|
|
foreach ( $fields as $field ) { |
|
239
|
|
|
$new_type = get_post_meta( $field->ID, 'paragraph_format_type', true ); |
|
240
|
|
|
|
|
241
|
|
|
if ( 'plain' !== $new_type ) { |
|
242
|
|
|
$new_type = 'wysiwyg'; |
|
243
|
|
|
|
|
244
|
|
|
$new = array( |
|
245
|
|
|
'paragraph_format_type' => 'wysiwyg_editor', |
|
246
|
|
|
'paragraph_allow_shortcode' => 'wysiwyg_allow_shortcode', |
|
247
|
|
|
'paragraph_allowed_html_tags' => 'wysiwyg_allowed_html_tags', |
|
248
|
|
|
'paragraph_max_length' => 'wysiwyg_max_length', |
|
249
|
|
|
'paragraph_size' => 'wysiwyg_size', |
|
250
|
|
|
); |
|
251
|
|
|
|
|
252
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
$fields = $wpdb->get_results( |
|
|
|
|
|
|
258
|
|
|
" |
|
259
|
|
|
SELECT `p`.`ID` |
|
260
|
|
|
FROM `{$wpdb->posts}` AS `p` |
|
261
|
|
|
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID` |
|
262
|
|
|
WHERE |
|
263
|
|
|
`p`.`post_type` = '_pods_field' |
|
264
|
|
|
AND `pm`.`meta_key` = 'type' |
|
265
|
|
|
AND `pm`.`meta_value` = 'text' |
|
266
|
|
|
" |
|
267
|
|
|
); |
|
268
|
|
|
|
|
269
|
|
|
if ( ! empty( $fields ) ) { |
|
270
|
|
|
foreach ( $fields as $field ) { |
|
271
|
|
|
$new_type = get_post_meta( $field->ID, 'text_format_type', true ); |
|
272
|
|
|
|
|
273
|
|
|
if ( 'website' === $new_type ) { |
|
274
|
|
|
$new = array( |
|
275
|
|
|
'text_format_website' => 'website_format', |
|
276
|
|
|
'text_max_length' => 'website_max_length', |
|
277
|
|
|
'text_html5' => 'website_html5', |
|
278
|
|
|
'text_size' => 'website_size', |
|
279
|
|
|
); |
|
280
|
|
|
|
|
281
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
282
|
|
|
} elseif ( 'phone' === $new_type ) { |
|
283
|
|
|
$new = array( |
|
284
|
|
|
'text_format_phone' => 'phone_format', |
|
285
|
|
|
'text_max_length' => 'phone_max_length', |
|
286
|
|
|
'text_html5' => 'phone_html5', |
|
287
|
|
|
'text_size' => 'phone_size', |
|
288
|
|
|
); |
|
289
|
|
|
|
|
290
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
291
|
|
|
} elseif ( 'email' === $new_type ) { |
|
292
|
|
|
$new = array( |
|
293
|
|
|
'text_max_length' => 'email_max_length', |
|
294
|
|
|
'text_html5' => 'email_html5', |
|
295
|
|
|
'text_size' => 'email_size', |
|
296
|
|
|
); |
|
297
|
|
|
|
|
298
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
299
|
|
|
} elseif ( 'password' === $new_type ) { |
|
300
|
|
|
$new = array( |
|
301
|
|
|
'text_max_length' => 'password_max_length', |
|
302
|
|
|
'text_size' => 'password_size', |
|
303
|
|
|
); |
|
304
|
|
|
|
|
305
|
|
|
update_post_meta( $field->ID, 'type', $new_type ); |
|
306
|
|
|
}//end if |
|
307
|
|
|
}//end foreach |
|
308
|
|
|
}//end if |
|
309
|
|
|
|
|
310
|
|
|
pods_no_conflict_off( 'post' ); |
|
311
|
|
|
|
|
312
|
|
|
update_option( 'pods_framework_version', '2.0.0-b-14' ); |
|
313
|
|
|
}//end if |
|
314
|
|
|
|
|
315
|
|
|
// Update to 2.0.0-b-15 |
|
316
|
|
|
if ( version_compare( $pods_version, '2.0.0-b-15', '<' ) ) { |
|
317
|
|
|
$helpers = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '_pods_helper'" ); |
|
|
|
|
|
|
318
|
|
|
|
|
319
|
|
|
if ( ! empty( $helpers ) ) { |
|
320
|
|
|
foreach ( $helpers as $helper ) { |
|
321
|
|
|
$wpdb->query( "UPDATE `{$wpdb->postmeta}` SET `meta_key` = 'helper_type' WHERE `meta_key` = 'type' AND `post_id` = {$helper->ID}" ); |
|
|
|
|
|
|
322
|
|
|
} |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
update_option( 'pods_framework_version', '2.0.0-b-15' ); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/* |
|
329
|
|
|
=================================== |
|
330
|
|
|
* |
|
331
|
|
|
* Old upgrade code from Alpha to Beta |
|
332
|
|
|
* |
|
333
|
|
|
* =================================== |
|
334
|
|
|
*/ |
|
335
|
|
|
/** |
|
336
|
|
|
* @param $id |
|
337
|
|
|
* @param $options |
|
338
|
|
|
*/ |
|
339
|
|
|
function pods_2_beta_migrate_type( $id, $options ) { |
|
340
|
|
|
|
|
341
|
|
|
global $wpdb; |
|
|
|
|
|
|
342
|
|
|
|
|
343
|
|
|
foreach ( $options as $old => $new ) { |
|
344
|
|
|
$wpdb->query( |
|
|
|
|
|
|
345
|
|
|
$wpdb->prepare( |
|
346
|
|
|
"UPDATE `{$wpdb->postmeta}` SET `meta_key` = %s WHERE `meta_key` = %s", array( |
|
347
|
|
|
$new, |
|
348
|
|
|
$old, |
|
349
|
|
|
) |
|
350
|
|
|
) |
|
351
|
|
|
); |
|
352
|
|
|
} |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* @return array |
|
357
|
|
|
*/ |
|
358
|
|
|
function pods_2_alpha_migrate_pods() { |
|
359
|
|
|
|
|
360
|
|
|
$api = pods_api(); |
|
361
|
|
|
|
|
362
|
|
|
$api->display_errors = true; |
|
363
|
|
|
|
|
364
|
|
|
$old_pods = pods_query( 'SELECT * FROM `@wp_pods`', false ); |
|
365
|
|
|
|
|
366
|
|
|
$pod_ids = array(); |
|
367
|
|
|
|
|
368
|
|
|
if ( empty( $old_pods ) ) { |
|
369
|
|
|
return $pod_ids; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
foreach ( $old_pods as $pod ) { |
|
373
|
|
|
$api->cache_flush_pods( array( 'name' => $pod->name ) ); |
|
374
|
|
|
|
|
375
|
|
|
$pod_opts = json_decode( $pod->options, true ); |
|
376
|
|
|
|
|
377
|
|
|
$field_rows = pods_query( "SELECT * FROM `@wp_pods_fields` where `pod_id` = {$pod->id}" ); |
|
378
|
|
|
|
|
379
|
|
|
$fields = array(); |
|
380
|
|
|
|
|
381
|
|
|
foreach ( $field_rows as $row ) { |
|
382
|
|
|
$field_opts = json_decode( $row->options, true ); |
|
383
|
|
|
|
|
384
|
|
|
if ( 'permalink' === $row->type ) { |
|
385
|
|
|
$row->type = 'slug'; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
$field_params = array( |
|
389
|
|
|
'name' => $row->name, |
|
390
|
|
|
'label' => $row->label, |
|
391
|
|
|
'type' => $row->type, |
|
392
|
|
|
'pick_object' => $row->pick_object, |
|
393
|
|
|
'pick_val' => $row->pick_val, |
|
394
|
|
|
'sister_field_id' => $row->sister_field_id, |
|
395
|
|
|
'weight' => $row->weight, |
|
396
|
|
|
'options' => $field_opts, |
|
397
|
|
|
); |
|
398
|
|
|
|
|
399
|
|
|
$fields[] = $field_params; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
$pod_params = array( |
|
403
|
|
|
'name' => $pod->name, |
|
404
|
|
|
'type' => $pod->type, |
|
405
|
|
|
'storage' => $pod->storage, |
|
406
|
|
|
'fields' => $fields, |
|
407
|
|
|
'options' => $pod_opts, |
|
408
|
|
|
); |
|
409
|
|
|
|
|
410
|
|
|
$renamed = false; |
|
411
|
|
|
|
|
412
|
|
|
if ( 'table' === $pod->storage ) { |
|
413
|
|
|
try { |
|
414
|
|
|
pods_query( "RENAME TABLE `@wp_pods_tbl_{$pod->name}` TO `@wp_pods_tb_{$pod->name}`" ); |
|
415
|
|
|
$renamed = true; |
|
416
|
|
|
} catch ( Exception $e ) { |
|
417
|
|
|
$renamed = false; |
|
418
|
|
|
} |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
$pod_id = $api->save_pod( $pod_params ); |
|
422
|
|
|
|
|
423
|
|
|
if ( 'table' === $pod->storage && $renamed ) { |
|
424
|
|
|
pods_query( "DROP TABLE `@wp_pods_tbl_{$pod->name}`", false ); |
|
425
|
|
|
pods_query( "RENAME TABLE `@wp_pods_tb_{$pod->name}` TO `@wp_pods_tbl_{$pod->name}`" ); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
$pod_ids[] = $pod_id; |
|
429
|
|
|
}//end foreach |
|
430
|
|
|
|
|
431
|
|
|
return $pod_ids; |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* @return array |
|
436
|
|
|
*/ |
|
437
|
|
|
function pods_2_alpha_migrate_helpers() { |
|
438
|
|
|
|
|
439
|
|
|
$api = pods_api(); |
|
440
|
|
|
|
|
441
|
|
|
$helper_rows = pods_query( "SELECT * FROM `@wp_pods_objects` WHERE `type` = 'helper'", false ); |
|
442
|
|
|
|
|
443
|
|
|
$helper_ids = array(); |
|
444
|
|
|
|
|
445
|
|
|
if ( empty( $helper_rows ) ) { |
|
446
|
|
|
return $helper_ids; |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
foreach ( $helper_rows as $row ) { |
|
450
|
|
|
$opts = json_decode( $row->options ); |
|
451
|
|
|
|
|
452
|
|
|
$helper_params = array( |
|
453
|
|
|
'name' => $row->name, |
|
454
|
|
|
'type' => $opts->type, |
|
455
|
|
|
'phpcode' => $opts->phpcode, |
|
456
|
|
|
); |
|
457
|
|
|
|
|
458
|
|
|
$helper_ids[] = $api->save_helper( $helper_params ); |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
return $helper_ids; |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
/** |
|
465
|
|
|
* @return array |
|
466
|
|
|
*/ |
|
467
|
|
|
function pods_2_alpha_migrate_pages() { |
|
468
|
|
|
|
|
469
|
|
|
$api = pods_api(); |
|
470
|
|
|
|
|
471
|
|
|
$page_rows = pods_query( "SELECT * FROM `@wp_pods_objects` WHERE `type` = 'page'", false ); |
|
472
|
|
|
|
|
473
|
|
|
$page_ids = array(); |
|
474
|
|
|
|
|
475
|
|
|
if ( empty( $page_rows ) ) { |
|
476
|
|
|
return $page_ids; |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
foreach ( $page_rows as $row ) { |
|
480
|
|
|
$opts = json_decode( $row->options ); |
|
481
|
|
|
|
|
482
|
|
|
$page_params = array( |
|
483
|
|
|
'uri' => $row->name, |
|
484
|
|
|
'phpcode' => $opts->phpcode, |
|
485
|
|
|
); |
|
486
|
|
|
|
|
487
|
|
|
$page_ids[] = $api->save_page( $page_params ); |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
return $page_ids; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
/** |
|
494
|
|
|
* @return array |
|
495
|
|
|
*/ |
|
496
|
|
|
function pods_2_alpha_migrate_templates() { |
|
497
|
|
|
|
|
498
|
|
|
$api = pods_api(); |
|
499
|
|
|
|
|
500
|
|
|
$tpl_rows = pods_query( "SELECT * FROM `@wp_pods_objects` WHERE `type` = 'template'", false ); |
|
501
|
|
|
|
|
502
|
|
|
$tpl_ids = array(); |
|
503
|
|
|
|
|
504
|
|
|
if ( empty( $tpl_rows ) ) { |
|
505
|
|
|
return $tpl_ids; |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
foreach ( $tpl_rows as $row ) { |
|
509
|
|
|
$opts = json_decode( $row->options ); |
|
510
|
|
|
|
|
511
|
|
|
$tpl_params = array( |
|
512
|
|
|
'name' => $row->name, |
|
513
|
|
|
'code' => $opts->code, |
|
514
|
|
|
); |
|
515
|
|
|
|
|
516
|
|
|
$tpl_ids[] = $api->save_template( $tpl_params ); |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
return $tpl_ids; |
|
520
|
|
|
} |
|
521
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.