Commit 70f31a75 authored by Chhengleap Soem's avatar Chhengleap Soem

Merge branch 'KIME-4682' into 'master'

[TASK] Add spreadsheet import cleanup command

refs KIME-4682

See merge request !4
parents 28a8edde 82eeab63
...@@ -38,6 +38,12 @@ class SpreadsheetImportCommandController extends CommandController { ...@@ -38,6 +38,12 @@ class SpreadsheetImportCommandController extends CommandController {
*/ */
protected $persistenceManager; 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 * 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 { ...@@ -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 { ...@@ -31,7 +31,7 @@ class SpreadsheetImport {
protected $context; protected $context;
/** /**
* @ORM\OneToOne(cascade={"persist"}) * @ORM\OneToOne(cascade={"persist", "remove"})
* @var \TYPO3\Flow\Resource\Resource * @var \TYPO3\Flow\Resource\Resource
*/ */
protected $file; protected $file;
......
...@@ -24,4 +24,15 @@ class SpreadsheetImportRepository extends Repository { ...@@ -24,4 +24,15 @@ class SpreadsheetImportRepository extends Repository {
*/ */
protected $defaultOrderings = array('scheduleDate' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING); 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: WE:
SpreadsheetImport: SpreadsheetImport:
cleanupImportFromPreviousDay: 5
swisscomGrb: swisscomGrb:
domain: WE\KIME\Domain\Model\User domain: WE\KIME\Domain\Model\User
Configuration: 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