Commit ecb96f98 authored by Simon Gadient's avatar Simon Gadient

[IMP] Max records limitation for preview

refs KIME-4583
parent f95f2ec3
...@@ -99,6 +99,7 @@ class FrontendMappingService { ...@@ -99,6 +99,7 @@ class FrontendMappingService {
* @return array * @return array
*/ */
public function getMappingPreview($mapping, $record) { public function getMappingPreview($mapping, $record) {
$record = max($record, 1);
$previewObject = $this->spreadsheetImportService->getObjectByRow($record); $previewObject = $this->spreadsheetImportService->getObjectByRow($record);
$preview = array(); $preview = array();
foreach ($mapping as $property => $columnMapping) { foreach ($mapping as $property => $columnMapping) {
......
...@@ -99,14 +99,22 @@ class SpreadsheetImportService { ...@@ -99,14 +99,22 @@ class SpreadsheetImportService {
return $mappingPropertyAnnotations; return $mappingPropertyAnnotations;
} }
/**
* @return array
*/
public function getTotalRecords() {
$sheet = $this->getFileActiveSheet();
$highestColumn = $sheet->getHighestDataRow();
return $highestColumn - 1;
}
/** /**
* @return array * @return array
*/ */
public function getSpreadsheetColumns() { public function getSpreadsheetColumns() {
$columns = array(); $columns = array();
$file = $this->spreadsheetImport->getFile()->createTemporaryLocalCopy(); $sheet = $this->getFileActiveSheet();
$reader = \PHPExcel_IOFactory::load($file);
$sheet = $reader->getActiveSheet();
$highestColumn = $sheet->getHighestDataColumn(); $highestColumn = $sheet->getHighestDataColumn();
$row = $sheet->getRowIterator(1, 1)->current(); $row = $sheet->getRowIterator(1, 1)->current();
$cellIterator = $row->getCellIterator(); $cellIterator = $row->getCellIterator();
...@@ -130,9 +138,8 @@ class SpreadsheetImportService { ...@@ -130,9 +138,8 @@ class SpreadsheetImportService {
$domain = $this->domain; $domain = $this->domain;
$newObject = new $domain; $newObject = new $domain;
// Plus one to skip the headings // Plus one to skip the headings
$file = $this->spreadsheetImport->getFile()->createTemporaryLocalCopy(); $sheet = $this->getFileActiveSheet();
$reader = \PHPExcel_IOFactory::load($file); $row = $sheet->getRowIterator($number + 1, $number + 1)->current();
$row = $reader->getActiveSheet()->getRowIterator($number + 1, $number + 1)->current();
$this->setObjectPropertiesByRow($newObject, $row); $this->setObjectPropertiesByRow($newObject, $row);
return $newObject; return $newObject;
} }
...@@ -150,12 +157,11 @@ class SpreadsheetImportService { ...@@ -150,12 +157,11 @@ class SpreadsheetImportService {
$objectRepository = $this->getDomainRepository(); $objectRepository = $this->getDomainRepository();
$objectValidator = $this->validatorResolver->getBaseValidatorConjunction($domain); $objectValidator = $this->validatorResolver->getBaseValidatorConjunction($domain);
$identifierProperties = $this->getDomainMappingIdentifierProperties(); $identifierProperties = $this->getDomainMappingIdentifierProperties();
$file = $this->spreadsheetImport->getFile()->createTemporaryLocalCopy(); $sheet = $this->getFileActiveSheet();
$reader = \PHPExcel_IOFactory::load($file);
$numberOfRecordsToPersist = $this->settings['numberOfRecordsToPersist']; $numberOfRecordsToPersist = $this->settings['numberOfRecordsToPersist'];
$i = 0; $i = 0;
/** @var \PHPExcel_Worksheet_Row $row */ /** @var \PHPExcel_Worksheet_Row $row */
foreach ($reader->getActiveSheet()->getRowIterator(2) as $row) { foreach ($sheet->getRowIterator(2) as $row) {
$object = $this->findObjectByIdentifierPropertiesPerRow($identifierProperties, $row); $object = $this->findObjectByIdentifierPropertiesPerRow($identifierProperties, $row);
if (is_object($object)) { if (is_object($object)) {
$objectIds[] = $this->persistenceManager->getIdentifierByObject($object); $objectIds[] = $this->persistenceManager->getIdentifierByObject($object);
...@@ -215,6 +221,16 @@ class SpreadsheetImportService { ...@@ -215,6 +221,16 @@ class SpreadsheetImportService {
$this->spreadsheetImport->setTotalSkipped($totalSkipped); $this->spreadsheetImport->setTotalSkipped($totalSkipped);
} }
/**
* @return \PHPExcel_Worksheet
*/
private function getFileActiveSheet() {
$file = $this->spreadsheetImport->getFile()->createTemporaryLocalCopy();
$reader = \PHPExcel_IOFactory::load($file);
$sheet = $reader->getActiveSheet();
return $sheet;
}
/** /**
* @return \TYPO3\Flow\Persistence\RepositoryInterface * @return \TYPO3\Flow\Persistence\RepositoryInterface
*/ */
......
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