Ejemplo n.º 1
0
 /**
  * @covers FrmForm::duplicate
  */
 function test_duplicate()
 {
     $form = $this->factory->form->get_object_by_id('contact');
     $id = FrmForm::duplicate($form->id);
     $this->assertTrue(is_numeric($id));
     $this->assertNotEmpty($id);
     // check the number of form actions
     $original_actions = FrmFormAction::get_action_for_form($form->id);
     $new_actions = FrmFormAction::get_action_for_form($id);
     $this->assertEquals(count($original_actions), count($new_actions));
 }
Ejemplo n.º 2
0
 /**
  * @covers FrmForm::duplicate
  */
 function test_duplicate()
 {
     $form = $this->factory->form->get_object_by_id($this->all_fields_form_key);
     $id = FrmForm::duplicate($form->id);
     $this->assertTrue(is_numeric($id));
     $this->assertNotEmpty($id);
     // check the number of form actions
     $original_actions = FrmFormAction::get_action_for_form($form->id);
     $new_actions = FrmFormAction::get_action_for_form($id);
     $this->assertEquals(count($original_actions), count($new_actions));
     // For repeating sections
     self::_check_if_child_forms_duplicate($form->id, $id);
     self::_check_if_form_select_updates($form->id, $id);
 }
Ejemplo n.º 3
0
 public static function duplicate()
 {
     if (!current_user_can('frm_edit_forms')) {
         global $frm_settings;
         wp_die($frm_settings->admin_permission);
     }
     $frm_form = new FrmForm();
     $params = self::get_params();
     $form = $frm_form->duplicate($params['id'], $params['template'], true);
     $message = $params['template'] ? __('Form template was Successfully Created', 'formidable') : __('Form was Successfully Copied', 'formidable');
     if ($form) {
         return self::get_edit_vars($form, '', $message, true);
     } else {
         return self::display_forms_list($params, __('There was a problem creating new template.', 'formidable'));
     }
 }
Ejemplo n.º 4
0
 public static function duplicate()
 {
     FrmAppHelper::permission_check('frm_edit_forms');
     $params = FrmForm::list_page_params();
     $form = FrmForm::duplicate($params['id'], $params['template'], true);
     $message = $params['template'] ? __('Form template was Successfully Created', 'formidable') : __('Form was Successfully Copied', 'formidable');
     if ($form) {
         return self::get_edit_vars($form, array(), $message, true);
     } else {
         return self::display_forms_list($params, __('There was a problem creating the new template.', 'formidable'));
     }
 }
Ejemplo n.º 5
0
 /**
  * Copy forms that are set to copy from one site to another
  */
 private static function copy_forms($force)
 {
     if (!$force) {
         //don't check on every page load
         $last_checked = get_option('frmpro_copies_checked');
         if (!$last_checked || time() - $last_checked >= 60 * 60) {
             //check every hour
             $force = true;
         }
     }
     if (!$force) {
         return;
     }
     global $wpdb, $blog_id;
     //get all forms to be copied from global table
     $query = $wpdb->prepare('SELECT c.*, p.post_name FROM ' . self::table_name() . ' c LEFT JOIN ' . $wpdb->prefix . 'frm_forms f ON (c.copy_key = f.form_key) LEFT JOIN ' . $wpdb->posts . ' p ON (c.copy_key = p.post_name) WHERE blog_id != %d AND ((type = %s AND f.form_key is NULL) OR (type = %s AND p.post_name is NULL)) ORDER BY type DESC', $blog_id, 'form', 'display');
     $templates = FrmAppHelper::check_cache('all_templates_' . $blog_id, 'frm_copy', $query, 'get_results');
     foreach ($templates as $temp) {
         if ($temp->type == 'form') {
             FrmForm::duplicate($temp->form_id, false, true, $temp->blog_id);
             continue;
         }
         $values = FrmProDisplay::getOne($temp->form_id, $temp->blog_id, true);
         if (!$values || 'trash' == $values->post_status) {
             continue;
         }
         // check if post with slug already exists
         $post_name = wp_unique_post_slug($values->post_name, 0, 'publish', 'frm_display', 0);
         if ($post_name != $values->post_name) {
             continue;
         }
         if ($values->post_name != $temp->copy_key) {
             $wpdb->update(self::table_name(), array('copy_key' => $values->post_name), array('id' => $temp->id));
         }
         FrmProDisplay::duplicate($temp->form_id, true, $temp->blog_id);
         //TODO: replace any ids with field keys in the display before duplicated
         unset($temp);
     }
     update_option('frmpro_copies_checked', time());
 }
Ejemplo n.º 6
0
 function install($force = false)
 {
     $db_version = 1.2;
     // this is the version of the database we're moving to
     $old_db_version = get_site_option('frmpro_copies_db_version');
     global $wpdb, $blog_id;
     if ($db_version != $old_db_version or $force) {
         $force = true;
         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 Display Table */
         $sql = "CREATE TABLE {$this->table_name} (\n                    id int(11) NOT NULL auto_increment,\n                    type varchar(255) default NULL,\n                    copy_key varchar(255) default NULL,\n                    form_id int(11) default NULL,\n                    blog_id int(11) default NULL,\n                    created_at datetime NOT NULL,\n                    PRIMARY KEY id (id),\n                    KEY form_id (form_id),\n                    KEY blog_id (blog_id)\n            ) {$charset_collate};";
         dbDelta($sql);
         update_site_option('frmpro_copies_db_version', $db_version);
     }
     //copy forms
     if (!$force) {
         //don't check on every page load
         $last_checked = get_option('frmpro_copies_checked');
         if (!$last_checked or time() - $last_checked >= 60 * 60) {
             //check every hour
             $force = true;
         }
     }
     if ($force) {
         //get all forms to be copied from global table
         $templates = $wpdb->get_results($wpdb->prepare("SELECT c.*, p.post_name FROM {$this->table_name} c LEFT JOIN {$wpdb->prefix}frm_forms f ON (c.copy_key = f.form_key) LEFT JOIN {$wpdb->posts} p ON (c.copy_key = p.post_name) WHERE blog_id != %d AND ((type = %s AND f.form_key is NULL) OR (type = %s AND p.post_name is NULL)) ORDER BY type DESC", $blog_id, 'form', 'display'));
         foreach ($templates as $temp) {
             if ($temp->type == 'form') {
                 $frm_form = new FrmForm();
                 $frm_form->duplicate($temp->form_id, false, true, $temp->blog_id);
             } else {
                 global $frmpro_display;
                 $values = $frmpro_display->getOne($temp->form_id, $temp->blog_id, true);
                 if (!$values || 'trash' == $values->post_status) {
                     continue;
                 }
                 // check if post with slug already exists
                 $post_name = wp_unique_post_slug($values->post_name, 0, 'publish', 'frm_display', 0);
                 if ($post_name != $values->post_name) {
                     continue;
                 }
                 if ($values->post_name != $temp->copy_key) {
                     $wpdb->update($this->table_name, array('copy_key' => $values->post_name), array('id' => $temp->id));
                 }
                 $frmpro_display->duplicate($temp->form_id, true, $temp->blog_id);
                 //TODO: replace any ids with field keys in the display before duplicated
             }
             unset($temp);
         }
         update_option('frmpro_copies_checked', time());
     }
 }