|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class FrmMigrate { |
|
4
|
|
|
public $fields; |
|
5
|
|
|
public $forms; |
|
6
|
|
|
public $entries; |
|
7
|
|
|
public $entry_metas; |
|
8
|
|
|
|
|
9
|
|
|
public function __construct() { |
|
10
|
|
|
if ( ! defined('ABSPATH') ) { |
|
11
|
|
|
die('You are not allowed to call this page directly.'); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
global $wpdb; |
|
15
|
|
|
$this->fields = $wpdb->prefix . 'frm_fields'; |
|
16
|
|
|
$this->forms = $wpdb->prefix . 'frm_forms'; |
|
17
|
|
|
$this->entries = $wpdb->prefix . 'frm_items'; |
|
18
|
|
|
$this->entry_metas = $wpdb->prefix . 'frm_item_metas'; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function upgrade( $old_db_version = false ) { |
|
22
|
|
|
do_action( 'frm_before_install' ); |
|
23
|
|
|
|
|
24
|
|
|
global $wpdb, $frm_vars; |
|
25
|
|
|
|
|
26
|
|
|
$frm_vars['doing_upgrade'] = true; |
|
27
|
|
|
|
|
28
|
|
|
$needs_upgrade = FrmAppController::compare_for_update( array( |
|
29
|
|
|
'option' => 'frm_db_version', |
|
30
|
|
|
'new_db_version' => FrmAppHelper::$db_version, |
|
31
|
|
|
'new_plugin_version' => FrmAppHelper::plugin_version(), |
|
32
|
|
|
) ); |
|
33
|
|
|
|
|
34
|
|
|
if ( $needs_upgrade ) { |
|
35
|
|
|
// update rewrite rules for views and other custom post types |
|
36
|
|
|
flush_rewrite_rules(); |
|
37
|
|
|
|
|
38
|
|
|
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
39
|
|
|
|
|
40
|
|
|
$this->create_tables(); |
|
41
|
|
|
$this->migrate_data( $old_db_version ); |
|
42
|
|
|
|
|
43
|
|
|
/***** SAVE DB VERSION *****/ |
|
44
|
|
|
update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version ); |
|
45
|
|
|
|
|
46
|
|
|
/**** ADD/UPDATE DEFAULT TEMPLATES ****/ |
|
47
|
|
|
FrmXMLController::add_default_templates(); |
|
48
|
|
|
|
|
49
|
|
|
if ( ! $old_db_version ) { |
|
50
|
|
|
$this->maybe_create_contact_form(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
do_action('frm_after_install'); |
|
55
|
|
|
|
|
56
|
|
|
$frm_vars['doing_upgrade'] = false; |
|
57
|
|
|
|
|
58
|
|
|
FrmAppHelper::save_combined_js(); |
|
59
|
|
|
|
|
60
|
|
|
/**** update the styling settings ****/ |
|
61
|
|
|
if ( function_exists( 'get_filesystem_method' ) ) { |
|
62
|
|
|
$frm_style = new FrmStyle(); |
|
63
|
|
|
$frm_style->update( 'default' ); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function collation() { |
|
68
|
|
|
global $wpdb; |
|
69
|
|
|
if ( ! $wpdb->has_cap( 'collation' ) ) { |
|
70
|
|
|
return ''; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$charset_collate = ''; |
|
74
|
|
|
if ( ! empty( $wpdb->charset ) ) { |
|
75
|
|
|
$charset_collate .= ' DEFAULT CHARACTER SET ' . $wpdb->charset; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ( ! empty( $wpdb->collate ) ) { |
|
79
|
|
|
$charset_collate .= ' COLLATE ' . $wpdb->collate; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $charset_collate; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
private function create_tables() { |
|
86
|
|
|
$charset_collate = $this->collation(); |
|
87
|
|
|
$sql = array(); |
|
88
|
|
|
|
|
89
|
|
|
/* Create/Upgrade Fields Table */ |
|
90
|
|
|
$sql[] = 'CREATE TABLE ' . $this->fields . ' ( |
|
91
|
|
|
id BIGINT(20) NOT NULL auto_increment, |
|
92
|
|
|
field_key varchar(100) default NULL, |
|
93
|
|
|
name text default NULL, |
|
94
|
|
|
description longtext default NULL, |
|
95
|
|
|
type text default NULL, |
|
96
|
|
|
default_value longtext default NULL, |
|
97
|
|
|
options longtext default NULL, |
|
98
|
|
|
field_order int(11) default 0, |
|
99
|
|
|
required int(1) default NULL, |
|
100
|
|
|
field_options longtext default NULL, |
|
101
|
|
|
form_id int(11) default NULL, |
|
102
|
|
|
created_at datetime NOT NULL, |
|
103
|
|
|
PRIMARY KEY (id), |
|
104
|
|
|
KEY form_id (form_id), |
|
105
|
|
|
UNIQUE KEY field_key (field_key) |
|
106
|
|
|
)'; |
|
107
|
|
|
|
|
108
|
|
|
/* Create/Upgrade Forms Table */ |
|
109
|
|
|
$sql[] = 'CREATE TABLE ' . $this->forms . ' ( |
|
110
|
|
|
id int(11) NOT NULL auto_increment, |
|
111
|
|
|
form_key varchar(100) default NULL, |
|
112
|
|
|
name varchar(255) default NULL, |
|
113
|
|
|
description text default NULL, |
|
114
|
|
|
parent_form_id int(11) default 0, |
|
115
|
|
|
logged_in tinyint(1) default NULL, |
|
116
|
|
|
editable tinyint(1) default NULL, |
|
117
|
|
|
is_template tinyint(1) default 0, |
|
118
|
|
|
default_template tinyint(1) default 0, |
|
119
|
|
|
status varchar(255) default NULL, |
|
120
|
|
|
options longtext default NULL, |
|
121
|
|
|
created_at datetime NOT NULL, |
|
122
|
|
|
PRIMARY KEY (id), |
|
123
|
|
|
UNIQUE KEY form_key (form_key) |
|
124
|
|
|
)'; |
|
125
|
|
|
|
|
126
|
|
|
/* Create/Upgrade Items Table */ |
|
127
|
|
|
$sql[] = 'CREATE TABLE ' . $this->entries . ' ( |
|
128
|
|
|
id BIGINT(20) NOT NULL auto_increment, |
|
129
|
|
|
item_key varchar(100) default NULL, |
|
130
|
|
|
name varchar(255) default NULL, |
|
131
|
|
|
description text default NULL, |
|
132
|
|
|
ip text default NULL, |
|
133
|
|
|
form_id BIGINT(20) default NULL, |
|
134
|
|
|
post_id BIGINT(20) default NULL, |
|
135
|
|
|
user_id BIGINT(20) default NULL, |
|
136
|
|
|
parent_item_id BIGINT(20) default 0, |
|
137
|
|
|
is_draft tinyint(1) default 0, |
|
138
|
|
|
updated_by BIGINT(20) default NULL, |
|
139
|
|
|
created_at datetime NOT NULL, |
|
140
|
|
|
updated_at datetime NOT NULL, |
|
141
|
|
|
PRIMARY KEY (id), |
|
142
|
|
|
KEY form_id (form_id), |
|
143
|
|
|
KEY post_id (post_id), |
|
144
|
|
|
KEY user_id (user_id), |
|
145
|
|
|
KEY parent_item_id (parent_item_id), |
|
146
|
|
|
UNIQUE KEY item_key (item_key) |
|
147
|
|
|
)'; |
|
148
|
|
|
|
|
149
|
|
|
/* Create/Upgrade Meta Table */ |
|
150
|
|
|
$sql[] = 'CREATE TABLE ' . $this->entry_metas . ' ( |
|
151
|
|
|
id BIGINT(20) NOT NULL auto_increment, |
|
152
|
|
|
meta_value longtext default NULL, |
|
153
|
|
|
field_id BIGINT(20) NOT NULL, |
|
154
|
|
|
item_id BIGINT(20) NOT NULL, |
|
155
|
|
|
created_at datetime NOT NULL, |
|
156
|
|
|
PRIMARY KEY (id), |
|
157
|
|
|
KEY field_id (field_id), |
|
158
|
|
|
KEY item_id (item_id) |
|
159
|
|
|
)'; |
|
160
|
|
|
|
|
161
|
|
|
foreach ( $sql as $q ) { |
|
162
|
|
|
if ( function_exists( 'dbDelta' ) ) { |
|
163
|
|
|
dbDelta( $q . $charset_collate . ';' ); |
|
164
|
|
|
} else { |
|
165
|
|
|
global $wpdb; |
|
166
|
|
|
$wpdb->query( $q . $charset_collate ); |
|
167
|
|
|
} |
|
168
|
|
|
unset($q); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
private function maybe_create_contact_form() { |
|
173
|
|
|
$template_id = FrmForm::get_id_by_key( 'contact' ); |
|
174
|
|
|
if ( $template_id ) { |
|
175
|
|
|
$form_id = FrmForm::duplicate( $template_id, false, true ); |
|
176
|
|
|
if ( $form_id ) { |
|
177
|
|
|
$values = array( |
|
178
|
|
|
'status' => 'published', |
|
179
|
|
|
'form_key' => 'contact-form', |
|
180
|
|
|
); |
|
181
|
|
|
FrmForm::update( $form_id, $values ); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param int|string $old_db_version |
|
188
|
|
|
*/ |
|
189
|
|
|
private function migrate_data( $old_db_version ) { |
|
190
|
|
|
if ( ! $old_db_version ) { |
|
191
|
|
|
$old_db_version = get_option( 'frm_db_version' ); |
|
192
|
|
|
} |
|
193
|
|
|
if ( strpos( $old_db_version, '-' ) ) { |
|
194
|
|
|
$last_upgrade = explode( '-', $old_db_version ); |
|
195
|
|
|
$old_db_version = (int) $last_upgrade[1]; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
if ( ! is_numeric( $old_db_version ) ) { |
|
199
|
|
|
// bail if we don't know the previous version |
|
200
|
|
|
return; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
$migrations = array( 4, 6, 11, 16, 17, 23, 25, 86 ); |
|
204
|
|
|
foreach ( $migrations as $migration ) { |
|
205
|
|
|
if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { |
|
206
|
|
|
$function_name = 'migrate_to_' . $migration; |
|
207
|
|
|
$this->$function_name(); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
public function uninstall() { |
|
213
|
|
|
if ( ! current_user_can( 'administrator' ) ) { |
|
214
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
215
|
|
|
wp_die($frm_settings->admin_permission); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
global $wpdb, $wp_roles; |
|
219
|
|
|
|
|
220
|
|
|
$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); |
|
221
|
|
|
$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); |
|
222
|
|
|
$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); |
|
223
|
|
|
$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); |
|
224
|
|
|
|
|
225
|
|
|
delete_option('frm_options'); |
|
226
|
|
|
delete_option('frm_db_version'); |
|
227
|
|
|
|
|
228
|
|
|
//delete roles |
|
229
|
|
|
$frm_roles = FrmAppHelper::frm_capabilities(); |
|
230
|
|
|
$roles = get_editable_roles(); |
|
231
|
|
|
foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
232
|
|
|
foreach ( $roles as $role => $details ) { |
|
233
|
|
|
$wp_roles->remove_cap( $role, $frm_role ); |
|
234
|
|
|
unset($role, $details); |
|
235
|
|
|
} |
|
236
|
|
|
unset($frm_role, $frm_role_description); |
|
237
|
|
|
} |
|
238
|
|
|
unset($roles, $frm_roles); |
|
239
|
|
|
|
|
240
|
|
|
// delete actions, views, and styles |
|
241
|
|
|
|
|
242
|
|
|
// prevent the post deletion from triggering entries to be deleted |
|
243
|
|
|
remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' ); |
|
244
|
|
|
remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' ); |
|
245
|
|
|
|
|
246
|
|
|
$post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) ); |
|
247
|
|
|
foreach ( $post_ids as $post_id ) { |
|
248
|
|
|
// Delete's each post. |
|
249
|
|
|
wp_delete_post( $post_id, true ); |
|
250
|
|
|
} |
|
251
|
|
|
unset( $post_ids ); |
|
252
|
|
|
|
|
253
|
|
|
// delete transients |
|
254
|
|
|
delete_transient( 'frmpro_css' ); |
|
255
|
|
|
delete_transient( 'frm_options' ); |
|
256
|
|
|
delete_transient( 'frmpro_options' ); |
|
257
|
|
|
|
|
258
|
|
|
$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); |
|
259
|
|
|
|
|
260
|
|
|
do_action('frm_after_uninstall'); |
|
261
|
|
|
return true; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Reverse migration 17 -- Divide by 9 |
|
266
|
|
|
*/ |
|
267
|
|
|
private function migrate_to_86() { |
|
268
|
|
|
|
|
269
|
|
|
$fields = $this->get_fields_with_size(); |
|
270
|
|
|
|
|
271
|
|
|
foreach ( (array) $fields as $f ) { |
|
272
|
|
|
$f->field_options = maybe_unserialize( $f->field_options ); |
|
273
|
|
|
$size = $f->field_options['size']; |
|
274
|
|
|
$this->maybe_convert_migrated_size( $size ); |
|
275
|
|
|
|
|
276
|
|
|
if ( $size === $f->field_options['size'] ) { |
|
277
|
|
|
continue; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
$f->field_options['size'] = $size; |
|
281
|
|
|
FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
|
282
|
|
|
unset( $f ); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
// reverse the extra size changes in widgets |
|
286
|
|
|
$widgets = get_option( 'widget_frm_show_form' ); |
|
287
|
|
|
if ( empty( $widgets ) ) { |
|
288
|
|
|
return; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
$this->revert_widget_field_size(); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
private function get_fields_with_size() { |
|
295
|
|
|
$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' ); |
|
296
|
|
|
$query = array( |
|
297
|
|
|
'type' => $field_types, |
|
298
|
|
|
'field_options like' => 's:4:"size";', |
|
299
|
|
|
'field_options not like' => 's:4:"size";s:0:', |
|
300
|
|
|
); |
|
301
|
|
|
|
|
302
|
|
|
return FrmDb::get_results( $this->fields, $query, 'id, field_options' ); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* reverse the extra size changes in widgets |
|
307
|
|
|
*/ |
|
308
|
|
|
private function revert_widget_field_size() { |
|
309
|
|
|
$widgets = get_option( 'widget_frm_show_form' ); |
|
310
|
|
|
if ( empty( $widgets ) ) { |
|
311
|
|
|
return; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
$widgets = maybe_unserialize( $widgets ); |
|
315
|
|
|
foreach ( $widgets as $k => $widget ) { |
|
316
|
|
|
if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
|
317
|
|
|
continue; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
$size = $widget['size']; |
|
321
|
|
|
$this->maybe_convert_migrated_size( $size ); |
|
322
|
|
|
if ( $size === $widget['size'] ) { |
|
323
|
|
|
continue; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
$widgets[ $k ]['size'] = $size; |
|
327
|
|
|
} |
|
328
|
|
|
update_option( 'widget_frm_show_form', $widgets ); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** |
|
332
|
|
|
* Divide by 9 to reverse the multiplication |
|
333
|
|
|
* @since 3.0.05 |
|
334
|
|
|
*/ |
|
335
|
|
|
private function maybe_convert_migrated_size( &$size ) { |
|
336
|
|
|
$has_px_size = ! empty( $size ) && strpos( $size, 'px' ); |
|
337
|
|
|
if ( ! $has_px_size ) { |
|
338
|
|
|
return; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
$int_size = str_replace( 'px', '', $size ); |
|
342
|
|
|
if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) { |
|
343
|
|
|
return; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
$pixel_conversion = 9; |
|
347
|
|
|
$size = round( (int) $int_size / $pixel_conversion ); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* Migrate old styling settings. If sites are using the old |
|
352
|
|
|
* default 400px field width, switch it to 100% |
|
353
|
|
|
* |
|
354
|
|
|
* @since 2.0.4 |
|
355
|
|
|
*/ |
|
356
|
|
|
private function migrate_to_25() { |
|
357
|
|
|
// get the style that was created with the style migration |
|
358
|
|
|
$frm_style = new FrmStyle(); |
|
359
|
|
|
$styles = $frm_style->get_all( 'post_date', 'ASC', 1 ); |
|
360
|
|
|
if ( empty( $styles ) ) { |
|
361
|
|
|
return; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
foreach ( $styles as $style ) { |
|
365
|
|
|
if ( $style->post_content['field_width'] == '400px' ) { |
|
366
|
|
|
$style->post_content['field_width'] = '100%'; |
|
367
|
|
|
$frm_style->save( (array) $style ); |
|
368
|
|
|
return; |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* Check if the parent_form_id columns exists. |
|
375
|
|
|
* If not, try and add it again |
|
376
|
|
|
* |
|
377
|
|
|
* @since 2.0.2 |
|
378
|
|
|
*/ |
|
379
|
|
|
private function migrate_to_23() { |
|
380
|
|
|
global $wpdb; |
|
381
|
|
|
$exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); |
|
382
|
|
|
if ( empty( $exists ) ) { |
|
383
|
|
|
$wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); |
|
384
|
|
|
} |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* Change field size from character to pixel -- Multiply by 9 |
|
389
|
|
|
*/ |
|
390
|
|
|
private function migrate_to_17() { |
|
391
|
|
|
$pixel_conversion = 9; |
|
392
|
|
|
|
|
393
|
|
|
$fields = $this->get_fields_with_size(); |
|
394
|
|
|
|
|
395
|
|
|
foreach ( $fields as $f ) { |
|
|
|
|
|
|
396
|
|
|
$f->field_options = maybe_unserialize($f->field_options); |
|
397
|
|
|
if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) { |
|
398
|
|
|
continue; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] ); |
|
402
|
|
|
$f->field_options['size'] .= 'px'; |
|
403
|
|
|
FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
|
404
|
|
|
unset($f); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
// Change the characters in widgets to pixels |
|
408
|
|
|
$widgets = get_option('widget_frm_show_form'); |
|
409
|
|
|
if ( empty($widgets) ) { |
|
410
|
|
|
return; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
$widgets = maybe_unserialize($widgets); |
|
414
|
|
|
foreach ( $widgets as $k => $widget ) { |
|
415
|
|
|
if ( ! is_array($widget) || ! isset($widget['size']) ) { |
|
416
|
|
|
continue; |
|
417
|
|
|
} |
|
418
|
|
|
$size = round( $pixel_conversion * (int) $widget['size'] ); |
|
419
|
|
|
$size .= 'px'; |
|
420
|
|
|
$widgets[ $k ]['size'] = $size; |
|
421
|
|
|
} |
|
422
|
|
|
update_option('widget_frm_show_form', $widgets); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* Migrate post and email notification settings into actions |
|
427
|
|
|
*/ |
|
428
|
|
|
private function migrate_to_16() { |
|
429
|
|
|
$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* Old email settings format: |
|
433
|
|
|
* email_to: Email or field id |
|
434
|
|
|
* also_email_to: array of fields ids |
|
435
|
|
|
* reply_to: Email, field id, 'custom' |
|
436
|
|
|
* cust_reply_to: string |
|
437
|
|
|
* reply_to_name: field id, 'custom' |
|
438
|
|
|
* cust_reply_to_name: string |
|
439
|
|
|
* plain_text: 0|1 |
|
440
|
|
|
* email_message: string or '' |
|
441
|
|
|
* email_subject: string or '' |
|
442
|
|
|
* inc_user_info: 0|1 |
|
443
|
|
|
* update_email: 0, 1, 2 |
|
444
|
|
|
* |
|
445
|
|
|
* Old autoresponder settings format: |
|
446
|
|
|
* auto_responder: 0|1 |
|
447
|
|
|
* ar_email_message: string or '' |
|
448
|
|
|
* ar_email_to: field id |
|
449
|
|
|
* ar_plain_text: 0|1 |
|
450
|
|
|
* ar_reply_to_name: string |
|
451
|
|
|
* ar_reply_to: string |
|
452
|
|
|
* ar_email_subject: string |
|
453
|
|
|
* ar_update_email: 0, 1, 2 |
|
454
|
|
|
* |
|
455
|
|
|
* New email settings: |
|
456
|
|
|
* post_content: json settings |
|
457
|
|
|
* post_title: form id |
|
458
|
|
|
* post_excerpt: message |
|
459
|
|
|
* |
|
460
|
|
|
*/ |
|
461
|
|
|
|
|
462
|
|
|
foreach ( $forms as $form ) { |
|
|
|
|
|
|
463
|
|
|
if ( $form->is_template && $form->default_template ) { |
|
464
|
|
|
// don't migrate the default templates since the email will be added anyway |
|
465
|
|
|
continue; |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
// Format form options |
|
469
|
|
|
$form_options = maybe_unserialize($form->options); |
|
470
|
|
|
|
|
471
|
|
|
// Migrate settings to actions |
|
472
|
|
|
FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
473
|
|
|
} |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
private function migrate_to_11() { |
|
477
|
|
|
global $wpdb; |
|
478
|
|
|
|
|
479
|
|
|
$forms = FrmDb::get_results( $this->forms, array(), 'id, options'); |
|
480
|
|
|
|
|
481
|
|
|
$sending = __( 'Sending', 'formidable' ); |
|
482
|
|
|
$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
|
483
|
|
|
$old_default_html = <<<DEFAULT_HTML |
|
484
|
|
|
<div class="frm_submit"> |
|
485
|
|
|
[if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button] |
|
486
|
|
|
<input type="submit" value="[button_label]" [button_action] /> |
|
487
|
|
|
<img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" /> |
|
488
|
|
|
</div> |
|
489
|
|
|
DEFAULT_HTML; |
|
490
|
|
|
unset($sending, $img); |
|
491
|
|
|
|
|
492
|
|
|
$new_default_html = FrmFormsHelper::get_default_html('submit'); |
|
493
|
|
|
$draft_link = FrmFormsHelper::get_draft_link(); |
|
494
|
|
|
foreach ( $forms as $form ) { |
|
|
|
|
|
|
495
|
|
|
$form->options = maybe_unserialize($form->options); |
|
496
|
|
|
if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) { |
|
497
|
|
|
continue; |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
501
|
|
|
$form->options['submit_html'] = $new_default_html; |
|
502
|
|
|
$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
|
503
|
|
|
} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { |
|
504
|
|
|
$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
|
505
|
|
|
$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
|
506
|
|
|
} |
|
507
|
|
|
unset($form); |
|
508
|
|
|
} |
|
509
|
|
|
unset($forms); |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
private function migrate_to_6() { |
|
513
|
|
|
global $wpdb; |
|
514
|
|
|
|
|
515
|
|
|
$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) ); |
|
516
|
|
|
$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' ); |
|
517
|
|
|
|
|
518
|
|
|
$default_html = <<<DEFAULT_HTML |
|
519
|
|
|
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> |
|
520
|
|
|
<label class="frm_pos_[label_position]">[field_name] |
|
521
|
|
|
<span class="frm_required">[required_label]</span> |
|
522
|
|
|
</label> |
|
523
|
|
|
[input] |
|
524
|
|
|
[if description]<div class="frm_description">[description]</div>[/if description] |
|
525
|
|
|
</div> |
|
526
|
|
|
DEFAULT_HTML; |
|
527
|
|
|
|
|
528
|
|
|
$old_default_html = <<<DEFAULT_HTML |
|
529
|
|
|
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> |
|
530
|
|
|
<label class="frm_pos_[label_position]">[field_name] |
|
531
|
|
|
<span class="frm_required">[required_label]</span> |
|
532
|
|
|
</label> |
|
533
|
|
|
[input] |
|
534
|
|
|
[if description]<p class="frm_description">[description]</p>[/if description] |
|
535
|
|
|
</div> |
|
536
|
|
|
DEFAULT_HTML; |
|
537
|
|
|
|
|
538
|
|
|
$new_default_html = FrmFieldsHelper::get_default_html('text'); |
|
539
|
|
|
foreach ( $fields as $field ) { |
|
|
|
|
|
|
540
|
|
|
$field->field_options = maybe_unserialize($field->field_options); |
|
541
|
|
|
$html = FrmField::get_option( $field, 'custom_html' ); |
|
542
|
|
|
if ( $html == $default_html || $html == $old_default_html ) { |
|
543
|
|
|
$field->field_options['custom_html'] = $new_default_html; |
|
544
|
|
|
$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) ); |
|
545
|
|
|
} |
|
546
|
|
|
unset($field); |
|
547
|
|
|
} |
|
548
|
|
|
unset($default_html, $old_default_html, $fields); |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
/** |
|
552
|
|
|
* Adds user id to the entry |
|
553
|
|
|
*/ |
|
554
|
|
|
private function migrate_to_4() { |
|
555
|
|
|
global $wpdb; |
|
556
|
|
|
$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) ); |
|
557
|
|
|
foreach ( $user_ids as $user_id ) { |
|
558
|
|
|
$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) ); |
|
559
|
|
|
} |
|
560
|
|
|
} |
|
561
|
|
|
} |
|
562
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.