events/Classes/Service/CleanupService.php
Daniel Siepmann 6aa4681cb9 Delete files which were referenced by events objects
Adjust existing code base to not use hardcoded file path.
Instead use info from database and check all files which have references
to event objects.

Also add test to cover feature.
2021-12-16 14:07:32 +01:00

38 lines
766 B
PHP

<?php
namespace Wrm\Events\Service;
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();
$this->files->deleteDangling();
}
public function deletePastData(): void
{
$this->database->deleteDates(...$this->database->getPastDates());
$this->database->deleteEventsWithoutDates();
$this->files->deleteDangling();
}
}