Commit 82eeab63 authored by Chivy Lim's avatar Chivy Lim

[TASK] Add spreadsheet import cleanup command

refs KIME-4682
parent 28a8edde
......@@ -38,6 +38,12 @@ class SpreadsheetImportCommandController extends CommandController {
*/
protected $persistenceManager;
/**
* @Flow\InjectConfiguration
* @var array
*/
protected $settings;
/**
* Import one pending queued spreadsheet into Domain data, and it will import the next one if it is done
*/
......@@ -70,4 +76,23 @@ class SpreadsheetImportCommandController extends CommandController {
}
}
/**
* Cleanup previous spreadsheet imports by specific time (defined by settings)
*/
public function cleanupCommand() {
$cleanupImportFromPreviousDay = $this->settings['cleanupImportFromPreviousDay'];
$cleanupFromDate = new \DateTime();
$cleanupFromDate->sub(new \DateInterval('P' . $cleanupImportFromPreviousDay . 'D'));
$oldSpreadsheetImports = $this->spreadsheetImportRepository->findPreviousImportsBySpecificDate($cleanupFromDate);
if ($oldSpreadsheetImports->count() > 0) {
/** @var SpreadsheetImport $oldSpreadsheetImport */
foreach ($oldSpreadsheetImports as $oldSpreadsheetImport) {
$this->spreadsheetImportRepository->remove($oldSpreadsheetImport);
}
$this->outputLine('%d spreadsheet imports were removed.', array($oldSpreadsheetImports->count()));
} else {
$this->outputLine('There is no spreadsheet import in queue to remove.');
}
}
}
......@@ -31,7 +31,7 @@ class SpreadsheetImport {
protected $context;
/**
* @ORM\OneToOne(cascade={"persist"})
* @ORM\OneToOne(cascade={"persist", "remove"})
* @var \TYPO3\Flow\Resource\Resource
*/
protected $file;
......
......@@ -24,4 +24,15 @@ class SpreadsheetImportRepository extends Repository {
*/
protected $defaultOrderings = array('scheduleDate' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING);
/**
* @param \DateTime $dateTime
*
* @return \TYPO3\Flow\Persistence\QueryResultInterface
*/
public function findPreviousImportsBySpecificDate(\DateTime $dateTime) {
$query = $this->createQuery();
$constraint = $query->lessThanOrEqual('scheduleDate', $dateTime);
return $query->matching($constraint)->execute();
}
}
WE:
SpreadsheetImport:
cleanupImportFromPreviousDay: 5
swisscomGrb:
domain: WE\KIME\Domain\Model\User
Configuration:
......
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