Skip to content

Commit

Permalink
Merge branch 'SchulIT:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrank14 committed Aug 11, 2024
2 parents 8e63c14 + 81557c2 commit 44932de
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down
1 change: 1 addition & 0 deletions config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/admin/maintenance/new_school_year.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,6 +34,6 @@ public function execute(InputInterface $input, OutputInterface $output): int {
}

$style->success('Fertig');
return 0;
return Command::SUCCESS;
}
}
35 changes: 35 additions & 0 deletions src/Command/PurgeNotificationsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Command;

use App\Chat\Cleaner;
use App\Repository\NotificationRepositoryInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand('app:notifications:purge', description: 'Löscht alle Benachrichtigungen.')]
class PurgeNotificationsCommand extends Command {
public function __construct(private readonly NotificationRepositoryInterface $repository, string $name = null) {
parent::__construct($name);
}

public function execute(InputInterface $input, OutputInterface $output): int {
$style = new SymfonyStyle($input, $output);

$style->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;
}
}
7 changes: 7 additions & 0 deletions src/Repository/NotificationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions src/Repository/NotificationRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 44932de

Please sign in to comment.