From 9b68d41b9ef65c48915f819f9f448a1871b46232 Mon Sep 17 00:00:00 2001 From: deqngeorgiev Date: Fri, 20 Oct 2017 16:18:05 +0300 Subject: [PATCH 1/4] Fix using first row as header --- src/Import_Page.php | 3 ++- src/Import_Process.php | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Import_Page.php b/src/Import_Page.php index ff96801..d68f98a 100644 --- a/src/Import_Page.php +++ b/src/Import_Page.php @@ -151,6 +151,7 @@ public function process_form() { $csv = new CsvFile( $file['file'] ); $this->import_process->set_csv($csv); + // dd($this->import_process); $this->import_process->will_start(); $return['status'] = 'success'; @@ -221,8 +222,8 @@ public function start() { $imported_rows = []; - $start_row = ( $this->step - 1 ) * $this->settings['rows_per_request']; $csv = $this->import_process->get_csv(); + $start_row = ( intval( $this->step ) === 1 && $this->import_process->first_row_header ) ? 1 : ( $this->step - 1 ) * $this->settings['rows_per_request']; $csv->skip_to_row( $start_row ); $row_number = 0; diff --git a/src/Import_Process.php b/src/Import_Process.php index a57c91a..50d3ecc 100644 --- a/src/Import_Process.php +++ b/src/Import_Process.php @@ -7,6 +7,7 @@ abstract class Import_Process { protected $csv; + public $first_row_header = false; public function set_csv(CsvFile $csv) { $this->csv = $csv; @@ -30,4 +31,9 @@ public function will_start() { public function ended() { } + + public function use_first_row_as_header() { + $this->csv->use_first_row_as_header(); + $this->first_row_header = true; + } } From c6ee2ab79b98ca896a0deadecd8a9523bd18e382 Mon Sep 17 00:00:00 2001 From: deqngeorgiev Date: Fri, 20 Oct 2017 16:20:21 +0300 Subject: [PATCH 2/4] Remove debug code --- src/Import_Page.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Import_Page.php b/src/Import_Page.php index d68f98a..711d67a 100644 --- a/src/Import_Page.php +++ b/src/Import_Page.php @@ -151,7 +151,6 @@ public function process_form() { $csv = new CsvFile( $file['file'] ); $this->import_process->set_csv($csv); - // dd($this->import_process); $this->import_process->will_start(); $return['status'] = 'success'; From 424d4f729d7868fca3027ee2db5f99bee85d14d5 Mon Sep 17 00:00:00 2001 From: deqngeorgiev Date: Fri, 20 Oct 2017 16:25:17 +0300 Subject: [PATCH 3/4] Fix loading bar --- src/Import_Page.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Import_Page.php b/src/Import_Page.php index 711d67a..d2410f9 100644 --- a/src/Import_Page.php +++ b/src/Import_Page.php @@ -259,7 +259,7 @@ public function start() { $return['step'] = $this->step += 1; $return['next_action'] = $next_action; - $return['progress_bar']['current'] = $this->step; + $return['progress_bar']['current'] = ( $this->step * $this->settings['rows_per_request'] - $this->settings['rows_per_request'] ); $return['token'] = $this->token; wp_send_json( $return ); From 64ef59cdca89170a21f464ef562b62d62c9e82f4 Mon Sep 17 00:00:00 2001 From: deqngeorgiev Date: Fri, 20 Oct 2017 17:18:01 +0300 Subject: [PATCH 4/4] Change examples to use new method for header row --- _examples/01.menu-page/csv-importer.php | 2 +- _examples/02.submenu-page/csv-importer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_examples/01.menu-page/csv-importer.php b/_examples/01.menu-page/csv-importer.php index b620be0..6b8cd72 100644 --- a/_examples/01.menu-page/csv-importer.php +++ b/_examples/01.menu-page/csv-importer.php @@ -39,7 +39,7 @@ public function ended() { * See https://github.com/htmlburger/carbon-csv/blob/master/README.md */ public function setup_csv() { - $this->csv->use_first_row_as_header(); + $this->use_first_row_as_header(); } } diff --git a/_examples/02.submenu-page/csv-importer.php b/_examples/02.submenu-page/csv-importer.php index 309f70f..901e3a4 100644 --- a/_examples/02.submenu-page/csv-importer.php +++ b/_examples/02.submenu-page/csv-importer.php @@ -23,7 +23,7 @@ public function ended() { } public function setup_csv() { - $this->csv->use_first_row_as_header(); + $this->use_first_row_as_header(); } }