Skip to content

Commit

Permalink
Merge pull request #4 from deqngeorgiev/master
Browse files Browse the repository at this point in the history
Fix using first row from CSV as header. Fix loading bar issues
  • Loading branch information
emohamed authored Oct 20, 2017
2 parents 2a5db80 + 64ef59c commit 91838e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _examples/01.menu-page/csv-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion _examples/02.submenu-page/csv-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function ended() {
}

public function setup_csv() {
$this->csv->use_first_row_as_header();
$this->use_first_row_as_header();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Import_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,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;
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/Import_Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
abstract class Import_Process {

protected $csv;
public $first_row_header = false;

public function set_csv(CsvFile $csv) {
$this->csv = $csv;
Expand All @@ -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;
}
}

0 comments on commit 91838e9

Please sign in to comment.