mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-30 21:44:28 +02:00
Applied rector with PHP8.1 migration rules
This commit is contained in:
parent
dc6a67c2f0
commit
7ee01d9a05
303 changed files with 1228 additions and 3465 deletions
|
@ -70,30 +70,12 @@ class EventLoggerSubscriber implements EventSubscriber
|
|||
];
|
||||
|
||||
protected const MAX_STRING_LENGTH = 2000;
|
||||
|
||||
protected EventLogger $logger;
|
||||
protected SerializerInterface $serializer;
|
||||
protected EventCommentHelper $eventCommentHelper;
|
||||
protected EventUndoHelper $eventUndoHelper;
|
||||
protected bool $save_changed_fields;
|
||||
protected bool $save_changed_data;
|
||||
protected bool $save_removed_data;
|
||||
protected bool $save_new_data;
|
||||
protected PropertyAccessorInterface $propertyAccessor;
|
||||
|
||||
public function __construct(EventLogger $logger, SerializerInterface $serializer, EventCommentHelper $commentHelper,
|
||||
bool $save_changed_fields, bool $save_changed_data, bool $save_removed_data, bool $save_new_data,
|
||||
PropertyAccessorInterface $propertyAccessor, EventUndoHelper $eventUndoHelper)
|
||||
public function __construct(protected EventLogger $logger, protected SerializerInterface $serializer, protected EventCommentHelper $eventCommentHelper,
|
||||
protected bool $save_changed_fields, protected bool $save_changed_data, protected bool $save_removed_data, bool $save_new_data,
|
||||
protected PropertyAccessorInterface $propertyAccessor, protected EventUndoHelper $eventUndoHelper)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->serializer = $serializer;
|
||||
$this->eventCommentHelper = $commentHelper;
|
||||
$this->propertyAccessor = $propertyAccessor;
|
||||
$this->eventUndoHelper = $eventUndoHelper;
|
||||
|
||||
$this->save_changed_fields = $save_changed_fields;
|
||||
$this->save_changed_data = $save_changed_data;
|
||||
$this->save_removed_data = $save_removed_data;
|
||||
//This option only makes sense if save_changed_data is true
|
||||
$this->save_new_data = $save_new_data && $save_changed_data;
|
||||
}
|
||||
|
@ -181,7 +163,7 @@ class EventLoggerSubscriber implements EventSubscriber
|
|||
public function hasFieldRestrictions(AbstractDBElement $element): bool
|
||||
{
|
||||
foreach (array_keys(static::FIELD_BLACKLIST) as $class) {
|
||||
if (is_a($element, $class)) {
|
||||
if ($element instanceof $class) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +177,7 @@ class EventLoggerSubscriber implements EventSubscriber
|
|||
public function shouldFieldBeSaved(AbstractDBElement $element, string $field_name): bool
|
||||
{
|
||||
foreach (static::FIELD_BLACKLIST as $class => $blacklist) {
|
||||
if (is_a($element, $class) && in_array($field_name, $blacklist, true)) {
|
||||
if ($element instanceof $class && in_array($field_name, $blacklist, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -231,11 +213,11 @@ class EventLoggerSubscriber implements EventSubscriber
|
|||
|
||||
//Check if we have to log CollectionElementDeleted entries
|
||||
if ($this->save_changed_data) {
|
||||
$metadata = $em->getClassMetadata(get_class($entity));
|
||||
$metadata = $em->getClassMetadata($entity::class);
|
||||
$mappings = $metadata->getAssociationMappings();
|
||||
//Check if class is whitelisted for CollectionElementDeleted entry
|
||||
foreach (static::TRIGGER_ASSOCIATION_LOG_WHITELIST as $class => $whitelist) {
|
||||
if (is_a($entity, $class)) {
|
||||
if ($entity instanceof $class) {
|
||||
//Check names
|
||||
foreach ($mappings as $field => $mapping) {
|
||||
if (in_array($field, $whitelist, true)) {
|
||||
|
@ -308,8 +290,6 @@ class EventLoggerSubscriber implements EventSubscriber
|
|||
/**
|
||||
* Restrict the length of every string in the given array to MAX_STRING_LENGTH, to save memory in the case of very
|
||||
* long strings (e.g. images in notes)
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
protected function fieldLengthRestrict(array $fields): array
|
||||
{
|
||||
|
@ -325,6 +305,7 @@ class EventLoggerSubscriber implements EventSubscriber
|
|||
|
||||
protected function saveChangeSet(AbstractDBElement $entity, AbstractLogEntry $logEntry, EntityManagerInterface $em, bool $element_deleted = false): void
|
||||
{
|
||||
$new_data = null;
|
||||
$uow = $em->getUnitOfWork();
|
||||
|
||||
if (!$logEntry instanceof ElementEditedLogEntry && !$logEntry instanceof ElementDeletedLogEntry) {
|
||||
|
@ -348,7 +329,7 @@ class EventLoggerSubscriber implements EventSubscriber
|
|||
|
||||
$logEntry->setOldData($old_data);
|
||||
|
||||
if (!empty($new_data)) {
|
||||
if ($new_data !== []) {
|
||||
$new_data = $this->filterFieldRestrictions($entity, $new_data);
|
||||
$new_data = $this->fieldLengthRestrict($new_data);
|
||||
|
||||
|
|
|
@ -53,11 +53,8 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|||
*/
|
||||
class LogAccessDeniedSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private EventLogger $logger;
|
||||
|
||||
public function __construct(EventLogger $logger)
|
||||
public function __construct(private readonly EventLogger $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function onKernelException(ExceptionEvent $event): void
|
||||
|
|
|
@ -37,13 +37,8 @@ class LogDBMigrationSubscriber implements EventSubscriber
|
|||
protected ?string $old_version = null;
|
||||
protected ?string $new_version = null;
|
||||
|
||||
protected EventLogger $eventLogger;
|
||||
protected DependencyFactory $dependencyFactory;
|
||||
|
||||
public function __construct(EventLogger $eventLogger, DependencyFactory $dependencyFactory)
|
||||
public function __construct(protected EventLogger $eventLogger, protected DependencyFactory $dependencyFactory)
|
||||
{
|
||||
$this->eventLogger = $eventLogger;
|
||||
$this->dependencyFactory = $dependencyFactory;
|
||||
}
|
||||
|
||||
public function onMigrationsMigrated(MigrationsEventArgs $args): void
|
||||
|
@ -66,7 +61,7 @@ class LogDBMigrationSubscriber implements EventSubscriber
|
|||
try {
|
||||
$log = new DatabaseUpdatedLogEntry($this->old_version, $this->new_version);
|
||||
$this->eventLogger->logAndFlush($log);
|
||||
} catch (\Throwable $exception) {
|
||||
} catch (\Throwable) {
|
||||
//Ignore any exception occuring here...
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,10 @@ use Symfony\Component\Security\Http\Event\LogoutEvent;
|
|||
* This handler logs to event log, if a user logs out.
|
||||
*/
|
||||
#[AsEventListener]
|
||||
final class LogLogoutEventListener
|
||||
final class LogLogoutEventEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
|
||||
{
|
||||
protected EventLogger $logger;
|
||||
protected bool $gpdr_compliance;
|
||||
|
||||
public function __construct(EventLogger $logger, bool $gpdr_compliance)
|
||||
public function __construct(protected EventLogger $logger, protected bool $gpdr_compliance)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->gpdr_compliance = $gpdr_compliance;
|
||||
}
|
||||
|
||||
public function __invoke(LogoutEvent $event): void
|
||||
|
@ -48,7 +43,7 @@ final class LogLogoutEventListener
|
|||
$request = $event->getRequest();
|
||||
$token = $event->getToken();
|
||||
|
||||
if (null === $token) {
|
||||
if (!$token instanceof \Symfony\Component\Security\Core\Authentication\Token\TokenInterface) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -60,4 +55,11 @@ final class LogLogoutEventListener
|
|||
|
||||
$this->logger->logAndFlush($log);
|
||||
}
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return ['' => ''];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,15 +53,8 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||
*/
|
||||
final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private RequestStack $requestStack;
|
||||
private bool $gpdr_compliant;
|
||||
private EventLogger $eventLogger;
|
||||
|
||||
public function __construct(RequestStack $requestStack, EventLogger $eventLogger, bool $gpdr_compliance)
|
||||
public function __construct(private readonly RequestStack $requestStack, private readonly EventLogger $eventLogger, private readonly bool $gpdr_compliant)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
$this->gpdr_compliant = $gpdr_compliance;
|
||||
$this->eventLogger = $eventLogger;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
|
@ -129,7 +122,7 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
|
|||
$anonymize = $this->gpdr_compliant;
|
||||
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
if (null !== $request) {
|
||||
if ($request instanceof \Symfony\Component\HttpFoundation\Request) {
|
||||
$ip = $request->getClientIp() ?? 'unknown';
|
||||
} else {
|
||||
$ip = 'Console';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue