예제 #1
0
 /**
  * @covers FrmForm::destroy
  */
 function test_destroy()
 {
     $forms = FrmForm::getAll();
     $this->assertNotEmpty(count($forms));
     foreach ($forms as $form) {
         if ($form->is_template) {
             continue;
         }
         $id = FrmForm::destroy($form->id);
         $form_exists = FrmForm::getOne($form->id);
         $this->assertEmpty($form_exists, 'Failed to delete form ' . $form->form_key);
         $subforms_exist = FrmForm::getAll(array('parent_form_id' => $form->id));
         $this->assertEmpty($subforms_exist, 'Failed to delete child forms for parent form ' . $form->form_key);
     }
 }
예제 #2
0
 public static function process_bulk_form_actions($errors)
 {
     if (!isset($_POST)) {
         return;
     }
     $bulkaction = FrmAppHelper::get_param('action');
     if ($bulkaction == -1) {
         $bulkaction = FrmAppHelper::get_param('action2');
     }
     if (!empty($bulkaction) && strpos($bulkaction, 'bulk_') === 0) {
         if (isset($_GET) && isset($_GET['action'])) {
             $_SERVER['REQUEST_URI'] = str_replace('&action=' . $_GET['action'], '', $_SERVER['REQUEST_URI']);
         }
         if (isset($_GET) && isset($_GET['action2'])) {
             $_SERVER['REQUEST_URI'] = str_replace('&action=' . $_GET['action2'], '', $_SERVER['REQUEST_URI']);
         }
         $bulkaction = str_replace('bulk_', '', $bulkaction);
     } else {
         $bulkaction = '-1';
         if (isset($_POST['bulkaction']) && $_POST['bulkaction'] != '-1') {
             $bulkaction = $_POST['bulkaction'];
         } else {
             if (isset($_POST['bulkaction2']) && $_POST['bulkaction2'] != '-1') {
                 $bulkaction = $_POST['bulkaction2'];
             }
         }
     }
     $ids = FrmAppHelper::get_param('item-action', '');
     if (empty($ids)) {
         $errors[] = __('No forms were specified', 'formidable');
     } else {
         if ($bulkaction == 'delete') {
             if (!current_user_can('frm_delete_forms')) {
                 global $frm_settings;
                 $errors[] = $frm_settings->admin_permission;
             } else {
                 if (!is_array($ids)) {
                     $ids = explode(',', $ids);
                 }
                 if (is_array($ids)) {
                     if ($bulkaction == 'delete') {
                         $frm_form = new FrmForm();
                         foreach ($ids as $form_id) {
                             $frm_form->destroy($form_id);
                         }
                     }
                 }
             }
         }
     }
     return $errors;
 }
예제 #3
0
 public static function bulk_destroy($ids)
 {
     FrmAppHelper::permission_check('frm_delete_forms');
     $count = 0;
     foreach ($ids as $id) {
         $d = FrmForm::destroy($id);
         if ($d) {
             $count++;
         }
     }
     $message = sprintf(_n('%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable'), $count);
     return $message;
 }
예제 #4
0
 /**
  * Delete entries from repeating sections and transfer first row to parent entries
  */
 private static function move_entries_to_parent_form($args)
 {
     global $wpdb;
     // get the ids of the entries saved in child fields
     $items = FrmDb::get_results($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items i ON i.id=m.item_id', array('field_id' => $args['children']), 'item_id,parent_item_id', array('order_by' => 'i.created_at ASC'));
     $updated_ids = array();
     foreach ($items as $item) {
         $child_id = $item->item_id;
         $parent_id = $item->parent_item_id;
         if (!in_array($parent_id, $updated_ids)) {
             // Change the item_id in frm_item_metas to match the parent item ID
             $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_item_metas SET item_id = %d WHERE item_id = %d', $parent_id, $child_id));
             $updated_ids[] = $parent_id;
         }
         // Delete the child entry
         FrmEntry::destroy($child_id);
     }
     // delete all the metas for the repeat section
     $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $args['field_id']));
     // Delete the child form
     FrmForm::destroy($args['form_id']);
 }
예제 #5
0
 public static function delete_repeat_field($field)
 {
     if (!FrmField::is_repeating_field($field)) {
         return;
     }
     if (isset($field->field_options['form_select']) && is_numeric($field->field_options['form_select']) && $field->field_options['form_select'] != $field->form_id) {
         FrmForm::destroy($field->field_options['form_select']);
     }
 }