Commit 8c556c12 authored by KR Moorhouse's avatar KR Moorhouse

Corrected some errors in our import process. Added an additional error...

Corrected some errors in our import process. Added an additional error response code for if a form ID cannot be generated.
parent 7fc8a9b4
Pipeline #2834 passed with stages
in 6 minutes and 17 seconds
......@@ -145,7 +145,7 @@ class NF_Admin_Processes_ImportForm extends NF_Abstracts_BatchProcess
public function restart()
{
// Get our remaining fields from the database.
$this->form = get_option( 'nf_import_form', $this->form, array() );
$this->form = get_option( 'nf_import_form', array() );
}
/**
......@@ -169,7 +169,7 @@ class NF_Admin_Processes_ImportForm extends NF_Abstracts_BatchProcess
* Save our processing option.
* Move on to the next step.
*/
if ( ! isset ( $this->form[ 'ID' ] ) ) {
if ( ! isset( $this->form[ 'ID' ] ) ) {
$this->insert_form();
} else { // We have a form ID set.
$this->insert_fields();
......@@ -239,6 +239,8 @@ class NF_Admin_Processes_ImportForm extends NF_Abstracts_BatchProcess
$insert_columns = array();
$insert_columns_types = array();
foreach ( $this->forms_db_columns as $column_name => $setting_name ) {
// Make sure we don't try to set created_at to NULL.
if( 'created_at' === $column_name && is_null( $this->form[ 'settings' ][ $setting_name ] ) ) continue;
$insert_columns[ $column_name ] = $this->form[ 'settings' ][ $setting_name ];
if ( is_numeric( $this->form[ 'settings' ][ $setting_name ] ) ) {
array_push( $insert_columns_types, '%d' );
......@@ -252,6 +254,11 @@ class NF_Admin_Processes_ImportForm extends NF_Abstracts_BatchProcess
// Update our form ID with the newly inserted row ID.
$this->form[ 'ID' ] = $this->_db->insert_id;
if ( 0 === $this->form[ 'ID' ] ) {
$this->add_error( 'insert_failed', __( 'Failed to insert new form.', 'ninja-forms' ), 'fatal' );
$this->batch_complete();
}
$this->insert_form_meta();
$this->insert_actions();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment