events/Classes/Service/CleanupService.php
Daniel Siepmann f618536ff9 Add PHPStan
In order to static analyze code and prevent bugs when changing code.
Fix issues in most of the files.
2021-09-07 11:07:55 +02:00

49 lines
1.3 KiB
PHP

<?php
namespace Wrm\Events\Service;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Wrm\Events\Service\Cleanup\Database;
use Wrm\Events\Service\Cleanup\Files;
class CleanupService
{
/**
* @var Database
*/
private $database;
/**
* @var Files
*/
private $files;
public function __construct(Database $database, Files $files)
{
$this->database = $database;
$this->files = $files;
}
public function deleteAllData(): void
{
$this->database->truncateTables(...[Database::DATE_TABLE, Database::ORGANIZER_TABLE]);
$this->removeViaDataHandler($this->database->getDeletionStructureForEvents());
$this->files->deleteAll();
}
public function deletePastData(): void
{
$this->database->deleteDates(...$this->database->getPastDates());
$this->removeViaDataHandler($this->database->getDeletionStructureForEventsWithoutDates());
$this->files->deleteDangling();
}
private function removeViaDataHandler(array $structure): void
{
/* @var DataHandler $dataHandler */
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start([], $structure);
$dataHandler->process_cmdmap();
}
}