2019-08-12 07:43:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wrm\Events\Service;
|
|
|
|
|
2019-09-17 17:14:28 +02:00
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
2019-08-12 07:43:37 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
2019-09-19 12:11:21 +02:00
|
|
|
use Wrm\Events\Service\Cleanup\Database;
|
|
|
|
use Wrm\Events\Service\Cleanup\Files;
|
2019-09-17 17:14:28 +02:00
|
|
|
|
|
|
|
class CleanupService
|
|
|
|
{
|
2019-09-19 12:11:21 +02:00
|
|
|
/**
|
|
|
|
* @var Database
|
|
|
|
*/
|
|
|
|
private $database;
|
2019-09-19 09:09:42 +02:00
|
|
|
|
2019-09-19 12:11:21 +02:00
|
|
|
/**
|
|
|
|
* @var Files
|
|
|
|
*/
|
|
|
|
private $files;
|
2019-09-19 10:47:37 +02:00
|
|
|
|
2019-09-19 12:11:21 +02:00
|
|
|
public function __construct(Database $database, Files $files)
|
2019-09-17 17:14:28 +02:00
|
|
|
{
|
2019-09-19 12:11:21 +02:00
|
|
|
$this->database = $database;
|
|
|
|
$this->files = $files;
|
2019-09-17 17:14:28 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 12:11:21 +02:00
|
|
|
public function deleteAllData()
|
2019-09-19 10:47:37 +02:00
|
|
|
{
|
2019-09-19 12:11:21 +02:00
|
|
|
$this->database->truncateTables(... [Database::DATE_TABLE, Database::ORGANIZER_TABLE]);
|
|
|
|
$this->removeViaDataHandler($this->database->getDeletionStructureForEvents());
|
|
|
|
$this->files->deleteAll();
|
2019-09-19 10:47:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 12:11:21 +02:00
|
|
|
public function deletePastData()
|
2019-09-19 10:47:37 +02:00
|
|
|
{
|
2019-09-19 12:11:21 +02:00
|
|
|
$this->database->deleteDates(... $this->database->getPastDates());
|
|
|
|
$this->removeViaDataHandler($this->database->getDeletionStructureForEventsWithoutDates());
|
|
|
|
$this->files->deleteDangling();
|
2019-09-19 10:47:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 12:11:21 +02:00
|
|
|
private function removeViaDataHandler(array $structure)
|
2019-09-19 10:47:37 +02:00
|
|
|
{
|
2019-09-19 12:11:21 +02:00
|
|
|
/* @var DataHandler $dataHandler */
|
|
|
|
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
|
|
|
|
$dataHandler->start([], $structure);
|
|
|
|
$dataHandler->process_cmdmap();
|
2019-09-19 10:47:37 +02:00
|
|
|
}
|
2019-09-17 17:14:28 +02:00
|
|
|
}
|