Part-DB-server/src/Entity/LogSystem/ElementDeletedLogEntry.php

117 lines
3.1 KiB
PHP
Raw Normal View History

<?php
2020-02-22 18:14:36 +01:00
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
2022-11-29 22:28:53 +01:00
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
2020-02-22 18:14:36 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-02-01 16:17:20 +01:00
declare(strict_types=1);
namespace App\Entity\LogSystem;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Contracts\LogWithCommentInterface;
2020-03-01 19:46:48 +01:00
use App\Entity\Contracts\LogWithEventUndoInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\TimeTravelInterface;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
2020-03-01 19:46:48 +01:00
class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface, LogWithEventUndoInterface
{
2022-09-18 22:59:31 +02:00
protected string $typeString = 'element_deleted';
2023-06-18 21:26:28 +02:00
use LogWithEventUndoTrait;
public function __construct(AbstractDBElement $deleted_element)
{
parent::__construct();
2023-06-18 17:25:55 +02:00
$this->level = LogLevel::INFO;
$this->setTargetElement($deleted_element);
//Deletion of a user is maybe more interesting...
if ($deleted_element instanceof User || $deleted_element instanceof Group) {
2023-06-18 17:25:55 +02:00
$this->level = LogLevel::NOTICE;
}
}
/**
* @return $this
*/
public function setTargetElement(?AbstractDBElement $element): AbstractLogEntry
{
parent::setTargetElement($element);
if ($element instanceof NamedElementInterface) {
$this->setOldName($element->getName());
}
2020-03-15 13:56:31 +01:00
return $this;
}
public function setOldName(string $old_name): self
{
$this->extra['n'] = $old_name;
2020-03-15 13:56:31 +01:00
return $this;
}
2020-02-06 14:03:25 +01:00
public function getOldName(): ?string
{
2020-02-06 14:03:25 +01:00
return $this->extra['n'] ?? null;
}
/**
* Sets the old data for this entry.
2020-03-15 13:56:31 +01:00
*
* @return $this
*/
public function setOldData(array $old_data): self
{
$this->extra['o'] = $old_data;
2020-03-15 13:56:31 +01:00
return $this;
}
public function hasOldDataInformation(): bool
{
2020-08-21 21:36:22 +02:00
return !empty($this->extra['o']);
}
public function getOldData(): array
{
return $this->extra['o'] ?? [];
}
public function hasComment(): bool
{
return isset($this->extra['m']);
}
public function getComment(): ?string
{
return $this->extra['m'] ?? null;
}
public function setComment(?string $new_comment): LogWithCommentInterface
{
$this->extra['m'] = $new_comment;
2020-03-15 13:56:31 +01:00
return $this;
}
2020-02-01 16:17:20 +01:00
}