From 384a4b4359dc9c3d4d412123d247e43a81e970d4 Mon Sep 17 00:00:00 2001 From: Marcel Marnitz Date: Fri, 2 Aug 2024 12:25:08 +0200 Subject: [PATCH 1/3] Adds command to purge all notifications --- src/Command/PurgeNotificationsCommand.php | 35 +++++++++++++++++++ src/Repository/NotificationRepository.php | 7 ++++ .../NotificationRepositoryInterface.php | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 src/Command/PurgeNotificationsCommand.php diff --git a/src/Command/PurgeNotificationsCommand.php b/src/Command/PurgeNotificationsCommand.php new file mode 100644 index 00000000..d50c6cf7 --- /dev/null +++ b/src/Command/PurgeNotificationsCommand.php @@ -0,0 +1,35 @@ +section('Lösche alle Benachrichtigungen'); + + $style->caution('Diese Aktion kann nicht rückgängig gemacht werden'); + if($style->confirm('Sollen wirklich alle Benachrichtigungen gelöscht werden?', false) !== true) { + $style->warning('Abgebrochen, keine Benachrichtigungen gelöscht.'); + return Command::SUCCESS; + } + + $this->repository->removeAll(); + $style->success('Alle Benachrichtigungen gelöscht'); + + return Command::SUCCESS; + } +} \ No newline at end of file diff --git a/src/Repository/NotificationRepository.php b/src/Repository/NotificationRepository.php index 0e2f1b9e..2e443551 100644 --- a/src/Repository/NotificationRepository.php +++ b/src/Repository/NotificationRepository.php @@ -86,6 +86,13 @@ public function remove(Notification $notification): void { $this->em->flush(); } + public function removeAll(): int { + return $this->em->createQueryBuilder() + ->delete(Notification::class, 'n') + ->getQuery() + ->execute(); + } + public function removeBetween(DateTime $start, DateTime $end): int { return $this->em->createQueryBuilder() ->delete(Notification::class, 'n') diff --git a/src/Repository/NotificationRepositoryInterface.php b/src/Repository/NotificationRepositoryInterface.php index 0b1198ae..a6dd3c7b 100644 --- a/src/Repository/NotificationRepositoryInterface.php +++ b/src/Repository/NotificationRepositoryInterface.php @@ -33,5 +33,7 @@ public function persist(Notification $notification): void; public function remove(Notification $notification): void; + public function removeAll(): int; + public function removeBetween(DateTime $start, DateTime $end): int; } \ No newline at end of file From 484ef4ade73539e5267e21e3ae9deb10fbc2cee1 Mon Sep 17 00:00:00 2001 From: Marcel Marnitz Date: Fri, 2 Aug 2024 12:28:09 +0200 Subject: [PATCH 2/3] Rename ClearAuditLogCommand to PurgeAuditLogCommand --- docs/docs/admin/maintenance/new_school_year.md | 2 +- .../{ClearAuditLogCommand.php => PurgeAuditLogCommand.php} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/Command/{ClearAuditLogCommand.php => PurgeAuditLogCommand.php} (89%) diff --git a/docs/docs/admin/maintenance/new_school_year.md b/docs/docs/admin/maintenance/new_school_year.md index 7d3170c3..d0e2281f 100644 --- a/docs/docs/admin/maintenance/new_school_year.md +++ b/docs/docs/admin/maintenance/new_school_year.md @@ -35,7 +35,7 @@ $ php bin/console app:students:remove_orphaned $ # Alle Benutzer löschen, denen kein Schüler/keine Schülerin bzw. Lehrkraft zugeordnet ist $ php bin/console app:user:remove_orphaned $ # Das Audit-Log leeren -$ php bin/console app:clear-audit +$ php bin/console app:audit:purge $ # Datenbanktabellen optimieren $ php bin/console app:db:optimize ``` diff --git a/src/Command/ClearAuditLogCommand.php b/src/Command/PurgeAuditLogCommand.php similarity index 89% rename from src/Command/ClearAuditLogCommand.php rename to src/Command/PurgeAuditLogCommand.php index e5dabd5f..7e59b933 100644 --- a/src/Command/ClearAuditLogCommand.php +++ b/src/Command/PurgeAuditLogCommand.php @@ -11,8 +11,8 @@ use Symfony\Component\Console\Style\SymfonyStyle; use function Symfony\Component\String\u; -#[AsCommand('app:db:clear_audit', 'Leert das Audit-Log.')] -class ClearAuditLogCommand extends Command { +#[AsCommand('app:audit:purge', 'Leert das gesamte Audit-Log.')] +class PurgeAuditLogCommand extends Command { public function __construct(private EntityManagerInterface $em, string $name = null) { parent::__construct($name); @@ -34,6 +34,6 @@ public function execute(InputInterface $input, OutputInterface $output): int { } $style->success('Fertig'); - return 0; + return Command::SUCCESS; } } \ No newline at end of file From 81557c287f9635ec2b85fde22efc171fd0ee8973 Mon Sep 17 00:00:00 2001 From: Marcel Marnitz Date: Sun, 11 Aug 2024 18:17:15 +0200 Subject: [PATCH 3/3] Adds ability to use TRUSTED_PROXIES environment variable (see https://symfony.com/doc/6.4/deployment/proxies.html) --- .env | 3 +-- config/packages/framework.yaml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 9b64d54c..46a2b5fb 100644 --- a/.env +++ b/.env @@ -17,8 +17,7 @@ ###> symfony/framework-bundle ### APP_ENV=prod APP_SECRET=ChangeThisToASecretString -#TRUSTED_PROXIES=127.0.0.1,127.0.0.2 -#TRUSTED_HOSTS=localhost,example.com +TRUSTED_PROXIES=127.0.0.1 ###< symfony/framework-bundle ### ###> schoolit/common-bundle ### diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 91b33a17..1e4b97a6 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -2,6 +2,7 @@ framework: secret: '%env(APP_SECRET)%' #csrf_protection: true http_method_override: false + trusted_proxies: '%env(TRUSTED_PROXIES)%' # Enables session support. Note that the session will ONLY be started if you read or write from it. # Remove or comment this section to explicitly disable session support.