-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
101 additions
and
22 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Service\ReminderService; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class CronSendReminderCommand extends Command | ||
{ | ||
protected static $defaultName = 'app:cron:sendReminder'; | ||
private $reminderService; | ||
public function __construct(string $name = null, ReminderService $reminderService) | ||
{ | ||
parent::__construct($name); | ||
$this->reminderService = $reminderService; | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Send a reminder to all users which are in a room in the next 10 min') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
$res = $this->reminderService->sendReminder(); | ||
|
||
$io->writeln('Hinweis: '. $res['hinweis']); | ||
$io->writeln('Konferenzen: '.$res['Konferenzen']); | ||
$io->writeln('Emails: '.$res['Emails']); | ||
$io->writeln('Datum: '.(new \DateTime())->format('d.m.Y')); | ||
$io->writeln('Zeit: '.(new \DateTime())->format('H:i')); | ||
if(!$res['error']){ | ||
$io->success('Erfolgreich versandt'); | ||
return Command::SUCCESS; | ||
}else{ | ||
$io->error('Fehler'); | ||
return Command::FAILURE; | ||
} | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
|
||
namespace App\Service; | ||
|
||
|
||
use App\Entity\Rooms; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
class ReminderService | ||
{ | ||
private $em; | ||
private $parameterBag; | ||
private $userService; | ||
public function __construct(EntityManagerInterface $entityManager, ParameterBagInterface $parameterBag,UserService $userService) | ||
{ | ||
$this->em = $entityManager; | ||
$this->parameterBag = $parameterBag; | ||
$this->userService = $userService; | ||
} | ||
|
||
public function sendReminder(){ | ||
set_time_limit(600); | ||
$now10 = new \DateTime(); | ||
$now10->modify('+ 10 minutes'); | ||
|
||
$qb = $this->em->getRepository(Rooms::class)->createQueryBuilder('rooms'); | ||
$qb->where('rooms.start > :now') | ||
->andWhere('rooms.start < :now10') | ||
->setParameter('now10', $now10) | ||
->setParameter('now', new \DateTime()); | ||
$query = $qb->getQuery(); | ||
$rooms = $query->getResult(); | ||
$emails = 0; | ||
foreach ($rooms as $room) { | ||
foreach ($room->getUser() as $data) { | ||
$this->userService->notifyUser($data,$room); | ||
++ $emails; | ||
} | ||
} | ||
$message = ['error' => false, 'hinweis' => 'Cron ok', 'Konferenzen'=>count($rooms), 'Emails' => $emails]; | ||
return $message; | ||
} | ||
|
||
} |