Skip to content

Commit

Permalink
Merge pull request #58 from H2-invent/feature/add_comand_to_send_remi…
Browse files Browse the repository at this point in the history
…nder

add command to send reminder
  • Loading branch information
holzi1005 authored Feb 6, 2021
2 parents e61e450 + 26347f2 commit 263cedd
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 22 deletions.
Binary file modified docs/images/dashboard-heading.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/join.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/joint-internal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/server.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions src/Command/CronSendReminderCommand.php
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;
}



}
}
24 changes: 3 additions & 21 deletions src/Controller/CronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use App\Entity\Rooms;
use App\Service\ReminderService;
use App\Service\UserService;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -16,32 +17,13 @@ class CronController extends AbstractController
/**
* @Route("/cron/remember", name="cron_remember")
*/
public function updateCronAkademie(Request $request, LoggerInterface $logger, UserService $userService)
public function updateCronAkademie(Request $request, LoggerInterface $logger, UserService $userService, ReminderService $reminderService)
{
if ($request->get('token') !== $this->getParameter('cronToken')) {
$message = ['error' => true, 'hinweis' => 'Token fehlerhaft', 'token' => $request->get('token'), 'ip' => $request->getClientIp()];
$logger->error($message['hinweis'], $message);
return new JsonResponse($message);
}
$now10 = new \DateTime();
$now10->modify('+ 10 minutes');

$qb = $this->getDoctrine()->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) {
$userService->notifyUser($data,$room);
++ $emails;
}
}

$message = ['error' => false, 'hinweis' => 'Cron ok', 'Konferenzen'=>count($rooms), 'Emails' => $emails];
return new JsonResponse($message);
return new JsonResponse($reminderService->sendReminder());
}
}
1 change: 0 additions & 1 deletion src/Service/PexelService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function getImageFromPexels()
$image = null;
try {
$cache = new FilesystemAdapter();
$cache->delete('pexels_image');
$value = $cache->get('pexels_image', function (ItemInterface $item) {
$item->expiresAfter(intval($this->parameterBag->get('laF_pexel_refresh_time')));

Expand Down
47 changes: 47 additions & 0 deletions src/Service/ReminderService.php
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;
}

}

0 comments on commit 263cedd

Please sign in to comment.