/** * Update form settings to the new storage system when the form is viewed for the first time. * * @since 2.9 * @return void */ function nf_29_update_form_settings($form_id) { global $wpdb; // Check to see if an object exists with our form id. $type = nf_get_object_type($form_id); if ('form' != $type) { // We have an object with our form id. // Insert a new object. $next_id = nf_insert_object($type); // Replace all instances of the object ID with our new one. $wpdb->update(NF_OBJECT_META_TABLE_NAME, array('object_id' => $next_id), array('object_id' => $form_id)); $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('parent_id' => $next_id), array('parent_type' => $type, 'parent_id' => $form_id)); $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('child_id' => $next_id), array('child_type' => $type, 'child_id' => $form_id)); // Delete the original object $wpdb->query('DELETE FROM ' . NF_OBJECTS_TABLE_NAME . ' WHERE id = ' . $form_id); } $form = $wpdb->get_row('SELECT * FROM ' . NINJA_FORMS_TABLE_NAME . ' WHERE id = ' . $form_id, ARRAY_A); $settings = maybe_unserialize($form['data']); $settings['date_updated'] = $form['date_updated']; $f_id = nf_insert_object('form', $form['id']); foreach ($settings as $meta_key => $value) { nf_update_object_meta($f_id, $meta_key, $value); } nf_update_object_meta($f_id, 'status', ''); }
/** * Update form settings to the new storage system when the form is viewed for the first time. * * @since 2.9 * @return void */ function nf_29_update_form_settings($form_id) { global $wpdb; // Check to see if the conversion has been reset. $is_reset = get_option('nf_converted_form_reset', 0); // Check to see if an object exists with our form id. $type = nf_get_object_type($form_id); if ($type) { // We have an object with our form id. if ($is_reset and 'form' == $type) { // Give precedence to the most recent form. // Set a new ID for the form being converted. $f_id = nf_insert_object('form'); $fields = $wpdb->get_results("SELECT * FROM " . NINJA_FORMS_FIELDS_TABLE_NAME . " WHERE form_id = " . $form_id, ARRAY_A); foreach ($fields as $field) { unset($field['id']); $field['form_id'] = $f_id; // Copy the Fields to the new ID. $wpdb->insert(NINJA_FORMS_FIELDS_TABLE_NAME, $field); } $relationships = $wpdb->get_results("SELECT * FROM " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " WHERE parent_id = " . $form_id, ARRAY_A); foreach ($relationships as $relationship) { unset($relationship['id']); // Copy the object related to the form. $object = $wpdb->get_results("SELECT * FROM " . NF_OBJECTS_TABLE_NAME . " WHERE id = " . $relationship['child_id'], ARRAY_A); unset($object['id']); $wpdb->insert(NF_OBJECTS_TABLE_NAME, $object); $relationship['child_id'] = $wpdb->insert_id; $relationship['parent_id'] = $f_id; // Copy the Relationships to the new ID. $wpdb->insert(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, $relationship); } } else { // Give precedence to the converting form. // Insert a new object. $next_id = nf_insert_object($type); // Replace all instances of the conflicting object ID with our new one. $wpdb->update(NF_OBJECT_META_TABLE_NAME, array('object_id' => $next_id), array('object_id' => $form_id)); $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('parent_id' => $next_id), array('parent_type' => $type, 'parent_id' => $form_id)); $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('child_id' => $next_id), array('child_type' => $type, 'child_id' => $form_id)); // Delete the original (conflicting) object $wpdb->query('DELETE FROM ' . NF_OBJECTS_TABLE_NAME . ' WHERE id = ' . $form_id); } } // Get the form from the old table. $form = $wpdb->get_row('SELECT * FROM ' . NINJA_FORMS_TABLE_NAME . ' WHERE id = ' . $form_id, ARRAY_A); // Set the insert form ID, if not already set. $f_id = isset($f_id) ? $f_id : nf_insert_object('form', $form['id']); // Unpack the converted form's settings $settings = maybe_unserialize($form['data']); $settings['date_updated'] = $form['date_updated']; foreach ($settings as $meta_key => $value) { nf_update_object_meta($f_id, $meta_key, $value); } nf_update_object_meta($f_id, 'status', ''); }
/** * Add a condition to an object * * @param $object_id * @since 1.2.8 * @return object id */ function nf_cl_insert_condition($parent_id) { // Insert our new condition object. $cond_id = nf_insert_object('condition'); // Get our parent type. $parent_type = nf_get_object_type($parent_id); // Create a relationship between this condition and its parent object. nf_add_relationship($cond_id, 'condition', $parent_id, $parent_type); return $cond_id; }
/** * Add a form * * @access public * @since 2.9 * @return int $form_id */ public function create($defaults = array()) { $form_id = nf_insert_object('form'); $date_updated = date('Y-m-d', current_time('timestamp')); nf_update_object_meta($form_id, 'date_updated', $date_updated); foreach ($defaults as $meta_key => $meta_value) { nf_update_object_meta($form_id, $meta_key, $meta_value); } // Add a single event hook that will check to see if this is an orphaned function. $timestamp = strtotime('+24 hours', time()); $args = array('form_id' => $form_id); wp_schedule_single_event($timestamp, 'nf_maybe_delete_form', $args); return $form_id; }
/** * Insert a notification into the database. * * Calls nf_insert_object() * Calls nf_add_relationship() * Calls nf_update_object_meta() * * @since 2.8 * @param int $form_id * @return int $n_id */ function nf_insert_notification($form_id = '') { if (empty($form_id)) { return false; } $n_id = nf_insert_object('notification'); nf_add_relationship($n_id, 'notification', $form_id, 'form'); $date_updated = date('Y-m-d', current_time('timestamp')); nf_update_object_meta($n_id, 'date_updated', $date_updated); return $n_id; }
/** * Save admin edit screen * * @access public * @since 1.0 * @return void */ public function save_admin($id = '', $data) { if (isset($data['wh_args']) && is_array($data['wh_args'])) { $args = nf_get_object_children($id, 'wh_args'); foreach ($args as $object_id => $vars) { if (!isset($data['wh_args'][$object_id])) { nf_delete_object($object_id); } } if (isset($data['wh_args']['new'])) { foreach ($data['wh_args']['new'] as $vars) { $object_id = nf_insert_object('wh_args'); nf_update_object_meta($object_id, 'key', $vars['key']); nf_update_object_meta($object_id, 'field', $vars['field']); nf_add_relationship($object_id, 'wh_args', $id, 'notification'); } unset($data['wh_args']['new']); } foreach ($data['wh_args'] as $object_id => $vars) { if (!empty($object_id)) { nf_update_object_meta($object_id, 'key', $vars['key']); nf_update_object_meta($object_id, 'field', $vars['field']); } } unset($data['wh_args']); } return $data; }