public function upgrade($old_db_version = false) { global $wpdb; //$frm_db_version is the version of the database we're moving to $frm_db_version = FrmAppHelper::$db_version; $old_db_version = (double) $old_db_version; if (!$old_db_version) { $old_db_version = get_option('frm_db_version'); } if ($frm_db_version != $old_db_version) { // update rewrite rules for views and other custom post types flush_rewrite_rules(); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $this->create_tables(); $this->migrate_data($frm_db_version, $old_db_version); /***** SAVE DB VERSION *****/ update_option('frm_db_version', $frm_db_version); /**** ADD/UPDATE DEFAULT TEMPLATES ****/ FrmXMLController::add_default_templates(); } do_action('frm_after_install'); /**** update the styling settings ****/ if (is_admin() && function_exists('get_filesystem_method')) { $frm_style = new FrmStyle(); $frm_style->update('default'); } }
function import_xml() { // install test data in older format add_filter('frm_default_templates_files', 'FrmUnitTest::install_data'); FrmXMLController::add_default_templates(); $form = FrmForm::getOne('contact-db12'); $this->assertEquals($form->form_key, 'contact-db12'); }
public static function upgrade() { global $wpdb; $db_version = FrmAppHelper::$pro_db_version; // this is the version of the database we're moving to $old_db_version = get_option('frmpro_db_version'); if ($db_version == $old_db_version) { return; } if ($old_db_version) { if ($db_version >= 16 && $old_db_version < 16) { self::migrate_to_16(); } if ($db_version >= 17 && $old_db_version < 17) { self::migrate_to_17(); } if ($db_version >= 25 && $old_db_version < 25) { // let's remove the old displays now $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'frm_display'); } if ($db_version >= 27 && $old_db_version < 27) { self::migrate_to_27(); } if ($db_version >= 28 && $old_db_version < 28) { self::migrate_to_28(); } if ($db_version >= 29 && $old_db_version < 29) { self::migrate_to_29(); } if ($db_version >= 30 && $old_db_version < 30) { self::migrate_to_30(); } } update_option('frmpro_db_version', $db_version); /**** ADD DEFAULT TEMPLATES ****/ if (class_exists('FrmXMLController')) { FrmXMLController::add_default_templates(); } }
function upgrade() { global $wpdb, $frmdb; $db_version = FrmAppHelper::$pro_db_version; // this is the version of the database we're moving to $old_db_version = get_option('frmpro_db_version'); if ($db_version == $old_db_version) { return; } // update rewrite rules for views flush_rewrite_rules(); if ($old_db_version) { if ($db_version >= 3 && $old_db_version < 3) { //migrate hidden field data into the parent field global $frm_field; $wpdb->update($frmdb->fields, array('type' => 'scale'), array('type' => '10radio')); $fields = $frm_field->getAll(); foreach ($fields as $field) { $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['hide_field']) and is_numeric($field->field_options['hide_field']) and (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt']) or isset($field->field_options['form_select']) and !empty($field->field_options['form_select']))) { global $frm_field; //save hidden fields to parent field $parent_field = $frm_field->getOne($field->field_options['hide_field']); if ($parent_field) { $parent_options = maybe_unserialize($parent_field->field_options); if (!isset($parent_options['dependent_fields'])) { $parent_options['dependent_fields'] = array(); } else { foreach ($parent_options['dependent_fields'] as $child_id => $child_opt) { if (empty($child_opt) or $child_opt == '') { unset($parent_options['dependent_fields'][$child_id]); } else { if ($child_id != $field->id) { //check to make sure this field is still dependent $check_field = $frm_field->getOne($child_id); $check_options = maybe_unserialize($check_field->field_options); if (!is_numeric($check_options['hide_field']) or $check_options['hide_field'] != $parent_field->id or empty($check_options['hide_opt']) and empty($check_options['form_select'])) { unset($parent_options['dependent_fields'][$child_id]); } } } } } $dep_fields = array(); if ($field->type == 'data' and isset($field->field_options['form_select']) and is_numeric($field_options['form_select'])) { $dep_fields[] = $field->field_options['form_select']; $dep_fields[] = $field->field_options['data_type']; } else { if (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt'])) { $dep_fields[] = $field->field_options['hide_opt']; } } if (!empty($dep_fields)) { $parent_options['dependent_fields'][$field->id] = $dep_fields; } $frm_field->update($parent_field->id, array('field_options' => $parent_options)); } } } } if ($db_version >= 16 and $old_db_version < 16) { //migrate table into wp_posts $display_posts = array(); if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}frm_display'")) { //only migrate if table exists $dis = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}frm_display"); } else { $dis = array(); } foreach ($dis as $d) { $post = array('post_title' => $d->name, 'post_content' => $d->content, 'post_date' => $d->created_at, 'post_excerpt' => $d->description, 'post_name' => $d->display_key, 'post_status' => 'publish', 'post_type' => 'frm_display'); $post_ID = wp_insert_post($post); unset($post); update_post_meta($post_ID, 'frm_old_id', $d->id); if (!isset($d->show_count) or empty($d->show_count)) { $d->show_count = 'none'; } foreach (array('dyncontent', 'param', 'form_id', 'post_id', 'entry_id', 'param', 'type', 'show_count', 'insert_loc') as $f) { update_post_meta($post_ID, 'frm_' . $f, $d->{$f}); unset($f); } $d->options = maybe_unserialize($d->options); update_post_meta($post_ID, 'frm_options', $d->options); if (isset($d->options['insert_loc']) and $d->options['insert_loc'] != 'none' and is_numeric($d->options['post_id']) and !isset($display_posts[$d->options['post_id']])) { $display_posts[$d->options['post_id']] = $post_ID; } unset($d); unset($post_ID); } unset($dis); global $frmdb, $frmpro_display; //get all post_ids from frm_entries $entry_posts = $wpdb->get_results("SELECT id, post_id, form_id FROM {$frmdb->entries} WHERE post_id > 0"); $form_display = array(); foreach ($entry_posts as $ep) { if (isset($form_display[$ep->form_id])) { $display_posts[$ep->post_id] = $form_display[$ep->form_id]; } else { $d = $frmpro_display->get_auto_custom_display(array('post_id' => $ep->post_id, 'form_id' => $ep->form_id, 'entry_id' => $ep->id)); $display_posts[$ep->post_id] = $form_display[$ep->form_id] = $d ? $d->ID : 0; unset($d); } unset($ep); } unset($form_display); foreach ($display_posts as $post_ID => $d) { if ($d) { update_post_meta($post_ID, 'frm_display_id', $d); } unset($d); unset($post_ID); } unset($display_posts); } if ($db_version >= 17 && $old_db_version < 17) { $frm_form = new FrmForm(); //migrate "allow one per field" into "unique" $form = $frm_form->getAll(); $field_ids = array(); foreach ($form as $f) { if (isset($f->options['single_entry']) and $f->options['single_entry'] and is_numeric($f->options['single_entry_type'])) { $f->options['single_entry'] = 0; $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => serialize($f->options)), array('id' => $f->id)); $field_ids[] = $f->options['single_entry_type']; } unset($f); } if (!empty($field_ids)) { $fields = $wpdb->get_results("SELECT id, field_options FROM {$frmdb->fields} WHERE id in (" . implode(',', $field_ids) . ")"); foreach ($fields as $f) { $opts = maybe_unserialize($f->field_options); $opts['unique'] = 1; $wpdb->update($frmdb->fields, array('field_options' => serialize($opts)), array('id' => $f->id)); unset($f); } } } if ($db_version >= 25 && $old_db_version < 25) { // let's remove the old displays now $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}frm_display"); } } /**** ADD DEFAULT TEMPLATES ****/ if (class_exists('FrmXMLController')) { FrmXMLController::add_default_templates(); } update_option('frmpro_db_version', $db_version); global $frmpro_settings; $frmpro_settings->store(); //update the styling settings }
public static function map_csv_fields() { $name = 'frm_import_file'; if (!isset($_FILES) || !isset($_FILES[$name]) || empty($_FILES[$name]['name']) || (int) $_FILES[$name]['size'] < 1) { return; } $file = $_FILES[$name]['tmp_name']; // check if file was uploaded if (!is_uploaded_file($file)) { return; } if (empty($_POST['form_id'])) { $errors = array(__('All Fields are required', 'formidable')); FrmXMLController::form($errors); return; } //upload $media_id = isset($_POST[$name]) && !empty($_POST[$name]) && is_numeric($_POST[$name]) ? $_POST[$name] : FrmProAppHelper::upload_file($name); if ($media_id && !is_wp_error($media_id)) { $filename = get_attached_file($media_id); } if (empty($filename)) { $errors = array(__('That CSV was not uploaded. Are CSV files allowed on your site?', 'formidable')); FrmXMLController::form($errors); return; } $row = 1; $headers = $example = ''; $csv_del = FrmAppHelper::get_param('csv_del', ','); $form_id = FrmAppHelper::get_param('form_id'); setlocale(LC_ALL, get_locale()); if (($f = fopen($filename, "r")) !== FALSE) { $row = 0; while (($data = fgetcsv($f, 100000, $csv_del)) !== FALSE) { //while (($raw_data = fgets($f, 100000))){ $row++; if ($row == 1) { $headers = $data; } else { if ($row == 2) { $example = $data; } else { continue; } } } fclose($f); } else { $errors = array(__('CSV cannot be opened.', 'formidable')); FrmXMLController::form($errors); return; } $frm_field = new FrmField(); $fields = $frm_field->getAll(array('fi.form_id' => (int) $form_id), 'field_order'); include FrmAppHelper::plugin_path() . '/pro/classes/views/xml/map_csv_fields.php'; }
$frm_field = new FrmField(); $frm_form = new FrmForm(); $frm_entry = new FrmEntry(); $frm_entry_meta = new FrmEntryMeta(); $obj = new FrmNotification(); // Instansiate Controllers require_once $frm_path . '/classes/controllers/FrmAppController.php'; require_once $frm_path . '/classes/controllers/FrmFieldsController.php'; require_once $frm_path . '/classes/controllers/FrmFormsController.php'; require_once $frm_path . '/classes/controllers/FrmEntriesController.php'; FrmAppController::load_hooks(); FrmEntriesController::load_hooks(); FrmFieldsController::load_hooks(); FrmFormsController::load_hooks(); if (is_admin()) { require_once $frm_path . '/classes/controllers/FrmSettingsController.php'; FrmSettingsController::load_hooks(); require_once $frm_path . '/classes/controllers/FrmStatisticsController.php'; FrmStatisticsController::load_hooks(); require_once $frm_path . '/classes/controllers/FrmXMLController.php'; FrmXMLController::load_hooks(); } // Instansiate Helpers require_once $frm_path . '/classes/helpers/FrmEntriesHelper.php'; require_once $frm_path . '/classes/helpers/FrmFieldsHelper.php'; require_once $frm_path . '/classes/helpers/FrmFormsHelper.php'; if (file_exists($frm_path . '/pro/formidable-pro.php')) { require_once $frm_path . '/pro/formidable-pro.php'; } include_once $frm_path . '/deprecated.php'; unset($frm_path);
function upgrade($old_db_version = false) { global $wpdb; //$frm_db_version is the version of the database we're moving to $frm_db_version = FrmAppHelper::$db_version; $old_db_version = (double) $old_db_version; if (!$old_db_version) { $old_db_version = get_option('frm_db_version'); } if ($frm_db_version != $old_db_version) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset_collate = ''; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } /* Create/Upgrade Fields Table */ $sql = "CREATE TABLE {$this->fields} (\n id int(11) NOT NULL auto_increment,\n field_key varchar(255) default NULL,\n name text default NULL,\n description text default NULL,\n type text default NULL,\n default_value longtext default NULL,\n options longtext default NULL,\n field_order int(11) default 0,\n required int(1) default NULL,\n field_options longtext default NULL,\n form_id int(11) default NULL,\n created_at datetime NOT NULL,\n PRIMARY KEY (id),\n KEY form_id (form_id),\n UNIQUE KEY field_key (field_key)\n ) {$charset_collate};"; dbDelta($sql); /* Create/Upgrade Forms Table */ $sql = "CREATE TABLE {$this->forms} (\n id int(11) NOT NULL auto_increment,\n form_key varchar(255) default NULL,\n name varchar(255) default NULL,\n description text default NULL,\n parent_form_id int(11) default NULL,\n logged_in tinyint(1) default NULL,\n editable tinyint(1) default NULL,\n is_template tinyint(1) default 0,\n default_template tinyint(1) default 0,\n status varchar(255) default NULL,\n prli_link_id int(11) default NULL,\n options longtext default NULL,\n created_at datetime NOT NULL,\n PRIMARY KEY (id),\n UNIQUE KEY form_key (form_key)\n ) {$charset_collate};"; dbDelta($sql); /* Create/Upgrade Items Table */ $sql = "CREATE TABLE {$this->entries} (\n id int(11) NOT NULL auto_increment,\n item_key varchar(255) default NULL,\n name varchar(255) default NULL,\n description text default NULL,\n ip text default NULL,\n form_id int(11) default NULL,\n post_id int(11) default NULL,\n user_id int(11) default NULL,\n parent_item_id int(11) default NULL,\n is_draft tinyint(1) default 0,\n updated_by int(11) default NULL,\n created_at datetime NOT NULL,\n updated_at datetime NOT NULL,\n PRIMARY KEY (id),\n KEY form_id (form_id),\n KEY post_id (post_id),\n KEY user_id (user_id),\n KEY parent_item_id (parent_item_id),\n UNIQUE KEY item_key (item_key)\n ) {$charset_collate};"; dbDelta($sql); /* Create/Upgrade Meta Table */ $sql = "CREATE TABLE {$this->entry_metas} (\n id int(11) NOT NULL auto_increment,\n meta_value longtext default NULL,\n field_id int(11) NOT NULL,\n item_id int(11) NOT NULL,\n created_at datetime NOT NULL,\n PRIMARY KEY (id),\n KEY field_id (field_id),\n KEY item_id (item_id)\n ) {$charset_collate};"; dbDelta($sql); /**** MIGRATE DATA ****/ if ($frm_db_version >= 1.03 and $old_db_version < 1.03) { global $frm_entry; $all_entries = $frm_entry->getAll(); foreach ($all_entries as $ent) { $opts = maybe_unserialize($ent->description); if (is_array($opts) and in_array($opts['ip'])) { $wpdb->update($this->entries, array('ip' => $opts['ip']), array('id' => $ent->id)); } } } if ($frm_db_version >= 4 and $old_db_version < 4) { global $frm_entry_meta; $user_ids = $frm_entry_meta->getAll("fi.type='user_id'"); foreach ($user_ids as $user_id) { $wpdb->update($this->entries, array('user_id' => $user_id->meta_value), array('id' => $user_id->item_id)); } } if ($frm_db_version >= 6 and $old_db_version < 6) { $fields = $wpdb->get_results("SELECT id, field_options FROM {$this->fields} WHERE type not in ('hidden', 'user_id', 'break', 'divider', 'html', 'captcha', 'form')"); $default_html = <<<DEFAULT_HTML <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> <label class="frm_pos_[label_position]">[field_name] <span class="frm_required">[required_label]</span> </label> [input] [if description]<div class="frm_description">[description]</div>[/if description] </div> DEFAULT_HTML; $old_default_html = <<<DEFAULT_HTML <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> <label class="frm_pos_[label_position]">[field_name] <span class="frm_required">[required_label]</span> </label> [input] [if description]<p class="frm_description">[description]</p>[/if description] </div> DEFAULT_HTML; $new_default_html = FrmFieldsHelper::get_default_html('text'); foreach ($fields as $field) { $field->field_options = maybe_unserialize($field->field_options); if (!isset($field->field_options['custom_html']) || empty($field->field_options['custom_html']) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html) { $field->field_options['custom_html'] = $new_default_html; $wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array('id' => $field->id)); } unset($field); } unset($default_html); unset($old_default_html); unset($fields); } if ($frm_db_version >= 11 and $old_db_version < 11) { $forms = $wpdb->get_results("SELECT id, options FROM {$this->forms}"); $sending = __('Sending', 'formidable'); $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; $old_default_html = <<<DEFAULT_HTML <div class="frm_submit"> [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button] <input type="submit" value="[button_label]" [button_action] /> <img class="frm_ajax_loading" src="{$img}" alt="{$sending}" style="visibility:hidden;" /> </div> DEFAULT_HTML; unset($sending); unset($img); $new_default_html = FrmFormsHelper::get_default_html('submit'); $draft_link = FrmFormsHelper::get_draft_link(); foreach ($forms as $form) { $form->options = maybe_unserialize($form->options); if (!isset($form->options['submit_html']) or empty($form->options['submit_html'])) { continue; } if ($form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html) { $form->options['submit_html'] = $new_default_html; $wpdb->update($this->forms, array('options' => serialize($form->options)), array('id' => $form->id)); } else { if (!strpos($form->options['submit_html'], 'save_draft')) { $form->options['submit_html'] = preg_replace('~\\<\\/div\\>(?!.*\\<\\/div\\>)~', $draft_link . "\r\n</div>", $form->options['submit_html']); $wpdb->update($this->forms, array('options' => serialize($form->options)), array('id' => $form->id)); } } unset($form); } unset($forms); } /**** ADD/UPDATE DEFAULT TEMPLATES ****/ if (class_exists('FrmXMLController')) { FrmXMLController::add_default_templates(); } /***** SAVE DB VERSION *****/ update_option('frm_db_version', $frm_db_version); } do_action('frm_after_install'); }