diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 702adc7..0098da4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ Next release Features and enhancements - #2516828 - Add mdreg alias for migrate-deregister. - #2504517 - Add timezone handling to timestamp(). +- #2532222 - Allow spreadsheet source data on a row different that 1. Migrate 2.8 =========== diff --git a/plugins/sources/spreadsheet.inc b/plugins/sources/spreadsheet.inc index 81017df..c3ba3b1 100644 --- a/plugins/sources/spreadsheet.inc +++ b/plugins/sources/spreadsheet.inc @@ -71,11 +71,11 @@ class MigrateSourceSpreadsheet extends MigrateSource { protected $columns; /** - * The first row from where the table starts. + * The first row from where the table starts. It's a "zero based" value. * * @var int */ - protected $firstRow; + protected $headerRows = 0; /** * Simple initialization. @@ -86,16 +86,17 @@ class MigrateSourceSpreadsheet extends MigrateSource { * The name of the sheet to be processed. * @param array $options * Options applied to this source. If the source data begins on different - * row than the first row, pass this value as 'first_row' in options, along - * with other options inherited from MigrateSource. + * row than the first row, pass this "zero based" value as 'header_rows' in + * options, along with other options inherited from MigrateSource. */ public function __construct($path, $sheet_name, $columns = array(), array $options = array()) { parent::__construct($options); $this->file = $path; $this->sheetName = $sheet_name; $this->columns = $columns; - $options += array('first_row' => 1); - $this->firstRow = $options['first_row']; + if (!empty($options['header_rows'])) { + $this->headerRows = $options['header_rows']; + } // Load the workbook. if ($this->load()) { @@ -105,7 +106,7 @@ class MigrateSourceSpreadsheet extends MigrateSource { // Map field names to their column index. for ($col = 0; $col < $this->cols; ++$col) { - $this->fields[$col] = trim($this->worksheet->getCellByColumnAndRow($col, $this->firstRow)->getValue()); + $this->fields[$col] = trim($this->worksheet->getCellByColumnAndRow($col, $this->headerRows + 1)->getValue()); } $this->unload(); @@ -201,8 +202,8 @@ class MigrateSourceSpreadsheet extends MigrateSource { * Returns a count of all available source records. */ public function computeCount() { - // Subtract 1 for the header. - return $this->rows - $this->firstRow; + // Subtract the non-data rows (rows before header and the header). + return $this->rows - $this->headerRows + 1; } /** @@ -216,7 +217,7 @@ class MigrateSourceSpreadsheet extends MigrateSource { $this->load(); } - $this->rowNumber = $this->firstRow; + $this->rowNumber = $this->headerRows + 1; } /**