Completed
Push — master ( a3d1c4...a6032a )
by Stephanie
03:05
created
classes/models/FrmMigrate.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@
 block discarded – undo
184 184
 	}
185 185
 
186 186
 	/**
187
-	 * @param int|string $old_db_version
187
+	 * @param boolean $old_db_version
188 188
 	 */
189 189
 	private function migrate_data( $old_db_version ) {
190 190
 		if ( ! $old_db_version ) {
Please login to merge, or discard this patch.
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 		return $charset_collate;
83 83
 	}
84 84
 
85
-    private function create_tables() {
86
-        $charset_collate = $this->collation();
87
-        $sql = array();
85
+	private function create_tables() {
86
+		$charset_collate = $this->collation();
87
+		$sql = array();
88 88
 
89
-        /* Create/Upgrade Fields Table */
89
+		/* Create/Upgrade Fields Table */
90 90
 		$sql[] = 'CREATE TABLE ' . $this->fields . ' (
91 91
 				id BIGINT(20) NOT NULL auto_increment,
92 92
 				field_key varchar(100) default NULL,
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                 UNIQUE KEY field_key (field_key)
106 106
         )';
107 107
 
108
-        /* Create/Upgrade Forms Table */
108
+		/* Create/Upgrade Forms Table */
109 109
 		$sql[] = 'CREATE TABLE ' . $this->forms . ' (
110 110
                 id int(11) NOT NULL auto_increment,
111 111
 				form_key varchar(100) default NULL,
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 UNIQUE KEY form_key (form_key)
124 124
         )';
125 125
 
126
-        /* Create/Upgrade Items Table */
126
+		/* Create/Upgrade Items Table */
127 127
 		$sql[] = 'CREATE TABLE ' . $this->entries . ' (
128 128
 				id BIGINT(20) NOT NULL auto_increment,
129 129
 				item_key varchar(100) default NULL,
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
                 UNIQUE KEY item_key (item_key)
147 147
         )';
148 148
 
149
-        /* Create/Upgrade Meta Table */
149
+		/* Create/Upgrade Meta Table */
150 150
 		$sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
151 151
 				id BIGINT(20) NOT NULL auto_increment,
152 152
 				meta_value longtext default NULL,
@@ -158,16 +158,16 @@  discard block
 block discarded – undo
158 158
                 KEY item_id (item_id)
159 159
         )';
160 160
 
161
-        foreach ( $sql as $q ) {
161
+		foreach ( $sql as $q ) {
162 162
 			if ( function_exists( 'dbDelta' ) ) {
163 163
 				dbDelta( $q . $charset_collate . ';' );
164 164
 			} else {
165 165
 				global $wpdb;
166 166
 				$wpdb->query( $q . $charset_collate );
167 167
 			}
168
-            unset($q);
169
-        }
170
-    }
168
+			unset($q);
169
+		}
170
+	}
171 171
 
172 172
 	private function maybe_create_contact_form() {
173 173
 		$template_id = FrmForm::get_id_by_key( 'contact' );
@@ -209,31 +209,31 @@  discard block
 block discarded – undo
209 209
 		}
210 210
 	}
211 211
 
212
-    public function uninstall() {
212
+	public function uninstall() {
213 213
 		if ( ! current_user_can( 'administrator' ) ) {
214
-            $frm_settings = FrmAppHelper::get_settings();
215
-            wp_die($frm_settings->admin_permission);
216
-        }
214
+			$frm_settings = FrmAppHelper::get_settings();
215
+			wp_die($frm_settings->admin_permission);
216
+		}
217 217
 
218
-        global $wpdb, $wp_roles;
218
+		global $wpdb, $wp_roles;
219 219
 
220 220
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
221 221
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
222 222
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
223 223
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
224 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);
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 237
 		}
238 238
 		unset($roles, $frm_roles);
239 239
 
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
 
258 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 259
 
260
-        do_action('frm_after_uninstall');
261
-        return true;
262
-    }
260
+		do_action('frm_after_uninstall');
261
+		return true;
262
+	}
263 263
 
264 264
 	/**
265 265
 	 * Migrate old styling settings. If sites are using the old
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
 		}
299 299
 	}
300 300
 
301
-    /**
302
-     * Change field size from character to pixel -- Multiply by 9
303
-     */
304
-    private function migrate_to_17() {
305
-        global $wpdb;
301
+	/**
302
+	 * Change field size from character to pixel -- Multiply by 9
303
+	 */
304
+	private function migrate_to_17() {
305
+		global $wpdb;
306 306
 		$pixel_conversion = 9;
307 307
 
308
-        // Get query arguments
308
+		// Get query arguments
309 309
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
310 310
 		$query = array(
311 311
 			'type' => $field_types,
@@ -313,137 +313,137 @@  discard block
 block discarded – undo
313 313
 			'field_options not like' => 's:4:"size";s:0:',
314 314
 		);
315 315
 
316
-        // Get results
316
+		// Get results
317 317
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
318 318
 
319
-        $updated = 0;
320
-        foreach ( $fields as $f ) {
321
-            $f->field_options = maybe_unserialize($f->field_options);
322
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
323
-                continue;
324
-            }
319
+		$updated = 0;
320
+		foreach ( $fields as $f ) {
321
+			$f->field_options = maybe_unserialize($f->field_options);
322
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
323
+				continue;
324
+			}
325 325
 
326 326
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
327
-            $f->field_options['size'] .= 'px';
328
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
329
-            if ( $u ) {
330
-                $updated++;
331
-            }
332
-            unset($f);
333
-        }
334
-
335
-        // Change the characters in widgets to pixels
336
-        $widgets = get_option('widget_frm_show_form');
337
-        if ( empty($widgets) ) {
338
-            return;
339
-        }
340
-
341
-        $widgets = maybe_unserialize($widgets);
342
-        foreach ( $widgets as $k => $widget ) {
343
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
344
-                continue;
345
-            }
327
+			$f->field_options['size'] .= 'px';
328
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
329
+			if ( $u ) {
330
+				$updated++;
331
+			}
332
+			unset($f);
333
+		}
334
+
335
+		// Change the characters in widgets to pixels
336
+		$widgets = get_option('widget_frm_show_form');
337
+		if ( empty($widgets) ) {
338
+			return;
339
+		}
340
+
341
+		$widgets = maybe_unserialize($widgets);
342
+		foreach ( $widgets as $k => $widget ) {
343
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
344
+				continue;
345
+			}
346 346
 			$size = round( $pixel_conversion * (int) $widget['size'] );
347
-            $size .= 'px';
347
+			$size .= 'px';
348 348
 			$widgets[ $k ]['size'] = $size;
349
-        }
350
-        update_option('widget_frm_show_form', $widgets);
351
-    }
352
-
353
-    /**
354
-     * Migrate post and email notification settings into actions
355
-     */
356
-    private function migrate_to_16() {
357
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
358
-
359
-        /**
360
-        * Old email settings format:
361
-        * email_to: Email or field id
362
-        * also_email_to: array of fields ids
363
-        * reply_to: Email, field id, 'custom'
364
-        * cust_reply_to: string
365
-        * reply_to_name: field id, 'custom'
366
-        * cust_reply_to_name: string
367
-        * plain_text: 0|1
368
-        * email_message: string or ''
369
-        * email_subject: string or ''
370
-        * inc_user_info: 0|1
371
-        * update_email: 0, 1, 2
372
-        *
373
-        * Old autoresponder settings format:
374
-        * auto_responder: 0|1
375
-        * ar_email_message: string or ''
376
-        * ar_email_to: field id
377
-        * ar_plain_text: 0|1
378
-        * ar_reply_to_name: string
379
-        * ar_reply_to: string
380
-        * ar_email_subject: string
381
-        * ar_update_email: 0, 1, 2
382
-        *
383
-        * New email settings:
384
-        * post_content: json settings
385
-        * post_title: form id
386
-        * post_excerpt: message
387
-        *
388
-        */
389
-
390
-        foreach ( $forms as $form ) {
349
+		}
350
+		update_option('widget_frm_show_form', $widgets);
351
+	}
352
+
353
+	/**
354
+	 * Migrate post and email notification settings into actions
355
+	 */
356
+	private function migrate_to_16() {
357
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
358
+
359
+		/**
360
+		 * Old email settings format:
361
+		 * email_to: Email or field id
362
+		 * also_email_to: array of fields ids
363
+		 * reply_to: Email, field id, 'custom'
364
+		 * cust_reply_to: string
365
+		 * reply_to_name: field id, 'custom'
366
+		 * cust_reply_to_name: string
367
+		 * plain_text: 0|1
368
+		 * email_message: string or ''
369
+		 * email_subject: string or ''
370
+		 * inc_user_info: 0|1
371
+		 * update_email: 0, 1, 2
372
+		 *
373
+		 * Old autoresponder settings format:
374
+		 * auto_responder: 0|1
375
+		 * ar_email_message: string or ''
376
+		 * ar_email_to: field id
377
+		 * ar_plain_text: 0|1
378
+		 * ar_reply_to_name: string
379
+		 * ar_reply_to: string
380
+		 * ar_email_subject: string
381
+		 * ar_update_email: 0, 1, 2
382
+		 *
383
+		 * New email settings:
384
+		 * post_content: json settings
385
+		 * post_title: form id
386
+		 * post_excerpt: message
387
+		 *
388
+		 */
389
+
390
+		foreach ( $forms as $form ) {
391 391
 			if ( $form->is_template && $form->default_template ) {
392 392
 				// don't migrate the default templates since the email will be added anyway
393 393
 				continue;
394 394
 			}
395 395
 
396
-            // Format form options
397
-            $form_options = maybe_unserialize($form->options);
396
+			// Format form options
397
+			$form_options = maybe_unserialize($form->options);
398 398
 
399
-            // Migrate settings to actions
400
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
401
-        }
402
-    }
399
+			// Migrate settings to actions
400
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
401
+		}
402
+	}
403 403
 
404
-    private function migrate_to_11() {
405
-        global $wpdb;
404
+	private function migrate_to_11() {
405
+		global $wpdb;
406 406
 
407
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
407
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
408 408
 
409
-        $sending = __( 'Sending', 'formidable' );
409
+		$sending = __( 'Sending', 'formidable' );
410 410
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
411
-        $old_default_html = <<<DEFAULT_HTML
411
+		$old_default_html = <<<DEFAULT_HTML
412 412
 <div class="frm_submit">
413 413
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
414 414
 <input type="submit" value="[button_label]" [button_action] />
415 415
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
416 416
 </div>
417 417
 DEFAULT_HTML;
418
-        unset($sending, $img);
418
+		unset($sending, $img);
419 419
 
420
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
421
-        $draft_link = FrmFormsHelper::get_draft_link();
420
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
421
+		$draft_link = FrmFormsHelper::get_draft_link();
422 422
 		foreach ( $forms as $form ) {
423
-            $form->options = maybe_unserialize($form->options);
424
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
425
-                continue;
426
-            }
423
+			$form->options = maybe_unserialize($form->options);
424
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
425
+				continue;
426
+			}
427 427
 
428
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
429
-                $form->options['submit_html'] = $new_default_html;
428
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
429
+				$form->options['submit_html'] = $new_default_html;
430 430
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
431 431
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
432 432
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
433 433
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
434
-            }
435
-            unset($form);
436
-        }
437
-        unset($forms);
438
-    }
434
+			}
435
+			unset($form);
436
+		}
437
+		unset($forms);
438
+	}
439 439
 
440
-    private function migrate_to_6() {
441
-        global $wpdb;
440
+	private function migrate_to_6() {
441
+		global $wpdb;
442 442
 
443 443
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
444 444
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
445 445
 
446
-        $default_html = <<<DEFAULT_HTML
446
+		$default_html = <<<DEFAULT_HTML
447 447
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
448 448
     <label class="frm_pos_[label_position]">[field_name]
449 449
         <span class="frm_required">[required_label]</span>
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 </div>
454 454
 DEFAULT_HTML;
455 455
 
456
-        $old_default_html = <<<DEFAULT_HTML
456
+		$old_default_html = <<<DEFAULT_HTML
457 457
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
458 458
     <label class="frm_pos_[label_position]">[field_name]
459 459
         <span class="frm_required">[required_label]</span>
@@ -463,27 +463,27 @@  discard block
 block discarded – undo
463 463
 </div>
464 464
 DEFAULT_HTML;
465 465
 
466
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
467
-        foreach ( $fields as $field ) {
468
-            $field->field_options = maybe_unserialize($field->field_options);
466
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
467
+		foreach ( $fields as $field ) {
468
+			$field->field_options = maybe_unserialize($field->field_options);
469 469
 			$html = FrmField::get_option( $field, 'custom_html' );
470 470
 			if ( $html == $default_html || $html == $old_default_html ) {
471
-                $field->field_options['custom_html'] = $new_default_html;
471
+				$field->field_options['custom_html'] = $new_default_html;
472 472
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
473
-            }
474
-            unset($field);
475
-        }
476
-        unset($default_html, $old_default_html, $fields);
477
-    }
473
+			}
474
+			unset($field);
475
+		}
476
+		unset($default_html, $old_default_html, $fields);
477
+	}
478 478
 
479 479
 	/**
480 480
 	 * Adds user id to the entry
481 481
 	 */
482
-    private function migrate_to_4() {
483
-        global $wpdb;
482
+	private function migrate_to_4() {
483
+		global $wpdb;
484 484
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
485
-        foreach ( $user_ids as $user_id ) {
485
+		foreach ( $user_ids as $user_id ) {
486 486
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
487
-        }
488
-    }
487
+		}
488
+	}
489 489
 }
Please login to merge, or discard this patch.