Commit 9af7082e authored by Simon Gadient's avatar Simon Gadient

[RFT] Label changes and code style

refs KIME-4583
parent 36f56676
......@@ -46,12 +46,12 @@ class SpreadsheetImportCommandController extends CommandController {
protected $settings;
/**
* Import one pending queued spreadsheet into Domain data, and it will import the next one if it is done
* Import next queued spreadsheets into domain objects asynchronously.
*/
public function importCommand() {
$currentImportingCount = $this->spreadsheetImportRepository->countByImportingStatus(SpreadsheetImport::IMPORTING_STATUS_IN_PROGRESS);
if ($currentImportingCount > 0) {
$this->outputFormatted('There is a progressing importing spreadsheet.');
$this->outputFormatted('Previous spreadsheet import is still in progress.');
$this->quit();
}
/** @var SpreadsheetImport $spreadsheetImport */
......@@ -67,25 +67,25 @@ class SpreadsheetImportCommandController extends CommandController {
try {
$this->spreadsheetImportService->import();
$spreadsheetImport->setImportingStatus(SpreadsheetImport::IMPORTING_STATUS_COMPLETED);
$this->outputFormatted('Spreadsheet has been imported. (totalInserted: %d, totalUpdated: %d, totalDeleted: %d, totalSkipped: %d)',
$this->outputFormatted('Spreadsheet has been imported. %d inserted, %d updated, %d deleted, %d skipped',
array($spreadsheetImport->getTotalInserted(), $spreadsheetImport->getTotalUpdated(), $spreadsheetImport->getTotalDeleted(), $spreadsheetImport->getTotalSkipped()));
} catch (Exception $e) {
$spreadsheetImport->setImportingStatus(SpreadsheetImport::IMPORTING_STATUS_FAILED);
$this->outputFormatted('Spreadsheet imported failed.');
$this->outputFormatted('Spreadsheet import failed.');
}
$this->spreadsheetImportRepository->update($spreadsheetImport);
} else {
$this->outputFormatted('There is no spreadsheet importing in queue.');
$this->outputFormatted('No spreadsheet import in queue.');
}
}
/**
* Cleanup previous spreadsheet imports by specific time (defined by settings)
* Cleanup previous spreadsheet imports. Threashold defined in settings.
*/
public function cleanupCommand() {
$cleanupImportFromPreviousDay = $this->settings['cleanupImportFromPreviousDay'];
$cleanupImportsThreasholdDays = intval($this->settings['cleanupImportsThreasholdDays']);
$cleanupFromDate = new \DateTime();
$cleanupFromDate->sub(new \DateInterval('P' . $cleanupImportFromPreviousDay . 'D'));
$cleanupFromDate->sub(new \DateInterval('P' . $cleanupImportsThreasholdDays . 'D'));
$oldSpreadsheetImports = $this->spreadsheetImportRepository->findPreviousImportsBySpecificDate($cleanupFromDate);
if ($oldSpreadsheetImports->count() > 0) {
/** @var SpreadsheetImport $oldSpreadsheetImport */
......
......@@ -137,8 +137,8 @@ class SpreadsheetImportService {
public function getObjectByRow($number) {
$domain = $this->domain;
$newObject = new $domain;
// Plus one to skip the headings
$sheet = $this->getFileActiveSheet();
// Plus one to skip the headings
$row = $sheet->getRowIterator($number + 1, $number + 1)->current();
$this->setObjectPropertiesByRow($newObject, $row);
return $newObject;
......@@ -151,74 +151,62 @@ class SpreadsheetImportService {
$totalInserted = 0;
$totalUpdated = 0;
$totalDeleted = 0;
$totalSkipped = 0;
$objectIds = array();
$domain = $this->domain;
$processedObjectIds = array();
$objectRepository = $this->getDomainRepository();
$objectValidator = $this->validatorResolver->getBaseValidatorConjunction($domain);
$objectValidator = $this->validatorResolver->getBaseValidatorConjunction($this->domain);
$identifierProperties = $this->getDomainMappingIdentifierProperties();
$sheet = $this->getFileActiveSheet();
$numberOfRecordsToPersist = $this->settings['numberOfRecordsToPersist'];
$i = 0;
$persistRecordsChunkSize = intval($this->settings['persistRecordsChunkSize']);
$totalCount = 0;
/** @var \PHPExcel_Worksheet_Row $row */
foreach ($sheet->getRowIterator(2) as $row) {
$totalCount++;
$object = $this->findObjectByIdentifierPropertiesPerRow($identifierProperties, $row);
if (is_object($object)) {
$objectIds[] = $this->persistenceManager->getIdentifierByObject($object);
$processedObjectIds[] = $this->persistenceManager->getIdentifierByObject($object);
if ($this->spreadsheetImport->isUpdating()) {
$this->setObjectPropertiesByRow($object, $row);
$validationResult = $objectValidator->validate($object);
if ($validationResult->hasErrors()) {
$totalSkipped++;
continue;
}
$objectRepository->update($object);
$totalUpdated++;
$i++;
} else {
$totalSkipped++;
continue;
}
} elseif ($this->spreadsheetImport->isInserting()) {
$newObject = new $domain;
$newObject = new $this->domain;
$this->setObjectPropertiesByRow($newObject, $row);
$validationResult = $objectValidator->validate($newObject);
if ($validationResult->hasErrors()) {
$totalSkipped++;
continue;
}
$objectRepository->add($newObject);
$objectIds[] = $this->persistenceManager->getIdentifierByObject($newObject);
$processedObjectIds[] = $this->persistenceManager->getIdentifierByObject($newObject);
$totalInserted++;
$i++;
} else {
$totalSkipped++;
continue;
}
if ($i >= $numberOfRecordsToPersist) {
if ($totalCount % $persistRecordsChunkSize === 0) {
$this->persistenceManager->persistAll();
$i = 0;
}
}
// remove objects which are not exist on the spreadsheet
$deleteCount = 0;
if ($this->spreadsheetImport->isDeleting()) {
$notExistingObjects = $this->findObjectsByExcludedIds($objectIds);
$notExistingObjects = $this->findObjectsByExcludedIds($processedObjectIds);
foreach ($notExistingObjects as $object) {
$objectRepository->remove($object);
$totalDeleted++;
$i++;
if ($i >= $numberOfRecordsToPersist) {
if (++$deleteCount % $persistRecordsChunkSize === 0) {
$this->persistenceManager->persistAll();
$i = 0;
}
}
}
$this->persistenceManager->persistAll();
$this->spreadsheetImport->setTotalInserted($totalInserted);
$this->spreadsheetImport->setTotalUpdated($totalUpdated);
$this->spreadsheetImport->setTotalSkipped($totalCount - $totalInserted - $totalUpdated);
$this->spreadsheetImport->setTotalDeleted($totalDeleted);
$this->spreadsheetImport->setTotalSkipped($totalSkipped);
}
/**
......
WE:
SpreadsheetImport:
cleanupImportFromPreviousDay: 365
numberOfRecordsToPersist: 100
cleanupImportsThreasholdDays: 365
persistRecordsChunkSize: 100
WE:
SpreadsheetImport:
cleanupImportFromPreviousDay: 365
numberOfRecordsToPersist: 100
cleanupImportsThreasholdDays: 365
persistRecordsChunkSize: 100
default:
domain: WE\Sample\Domain\Model\User
arguments:
......
......@@ -44,10 +44,10 @@
<source>Ungültige Daten. Dieser Record wird nicht übersprungen.</source>
</trans-unit>
<trans-unit id="label.spreadsheet_import.preview.record">
<source>Vorschau Zeile</source>
<source>Zeile</source>
</trans-unit>
<trans-unit id="label.spreadsheet_import.list">
<source>Spreadsheet Imports</source>
<source>Importe</source>
</trans-unit>
<!-- Status -->
......
......@@ -44,10 +44,10 @@
<source>Invalid data. This record will be skipped.</source>
</trans-unit>
<trans-unit id="label.spreadsheet_import.preview.record">
<source>Preview record</source>
<source>Record</source>
</trans-unit>
<trans-unit id="label.spreadsheet_import.list">
<source>Spreadsheet Imports</source>
<source>Imports</source>
</trans-unit>
<!-- Status -->
......
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