Allow to show collection elements that were deleted before by timetravel

This commit is contained in:
Jan Böhmer 2020-02-29 22:53:53 +01:00
parent b5bc096972
commit f604022e49
9 changed files with 386 additions and 78 deletions

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Services\LogSystem;
use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\LogSystem\CollectionElementDeleted;
use App\Entity\LogSystem\DatabaseUpdatedLogEntry;
use App\Entity\LogSystem\ElementCreatedLogEntry;
use App\Entity\LogSystem\ElementDeletedLogEntry;
@ -52,6 +53,8 @@ use App\Entity\LogSystem\InstockChangedLogEntry;
use App\Entity\LogSystem\UserLoginLogEntry;
use App\Entity\LogSystem\UserLogoutLogEntry;
use App\Entity\LogSystem\UserNotAllowedLogEntry;
use App\Services\ElementTypeNameGenerator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
@ -60,10 +63,12 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class LogEntryExtraFormatter
{
protected $translator;
protected $elementTypeNameGenerator;
public function __construct(TranslatorInterface $translator)
public function __construct(TranslatorInterface $translator, ElementTypeNameGenerator $elementTypeNameGenerator)
{
$this->translator = $translator;
$this->elementTypeNameGenerator = $elementTypeNameGenerator;
}
/**
@ -174,6 +179,15 @@ class LogEntryExtraFormatter
);
}
if ($context instanceof CollectionElementDeleted) {
return sprintf('<i>%s</i>: %s: %s (%s)',
$this->translator->trans('log.collection_deleted.deleted'),
$this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getDeletedElementClass()),
$context->getOldName() ?? $context->getDeletedElementID(),
$context->getCollectionName()
);
}
if ($context instanceof UserNotAllowedLogEntry) {
return htmlspecialchars($context->getMessage());
}