remove date diff

This commit is contained in:
tykayn 2020-04-14 18:16:09 +02:00
parent 81b27811c2
commit 00fe90b66b
1 changed files with 23 additions and 33 deletions

View File

@ -6,7 +6,6 @@ namespace App\Service;
use App\Entity\Owner;
use App\Entity\Poll;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Swift_Message;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
@ -24,8 +23,8 @@ class MailService {
*/
private $mailer;
public function __construct(EntityManagerInterface $entityManager, \Swift_Mailer $mailer) {
$this->em = $entityManager;
public function __construct( EntityManagerInterface $entityManager, \Swift_Mailer $mailer ) {
$this->em = $entityManager;
$this->mailer = $mailer;
}
@ -35,17 +34,7 @@ class MailService {
$poll = $newpoll;
// anti spam , limit to every minute
$lastSend = $admin_user->getRequestedPollsDate();
$now = new \DateTime();
if ( date_diff( $lastSend, $now ) < 60 ) {
// too soon!
die( 'too soon!' );
}
$admin_user->setRequestedPollsDate( $now );
$em->persist( $admin_user );
$em->flush();
// anti spam , limit to every minute TODO
$templateVars = [
'owner' => $admin_user,
@ -56,11 +45,11 @@ class MailService {
$message = ( new Swift_Message( 'Framadate - mes sondages' ) )
->setFrom( 'ne-pas-repondre@framadate-api.cipherbliss.com' )
->setContentType('text/html')
->setCharset('UTF-8')
->setContentType( 'text/html' )
->setCharset( 'UTF-8' )
->setTo( $admin_user->getEmail() )
->htmlTemplate($templateVars[ 'email_template' ])
->context( $templateVars);
->htmlTemplate( $templateVars[ 'email_template' ] )
->context( $templateVars );
// send email
return $mailer->send( $message );
@ -69,6 +58,7 @@ class MailService {
/**
* send created polls to an owner
*
* @param Owner $foundOwner
*
* @return int
@ -79,17 +69,17 @@ class MailService {
$admin_user = $foundOwner;
// anti spam , limit to every minute
$lastSend = $admin_user->getRequestedPollsDate();
$now = new \DateTime();
// anti spam , limit to every minute TODO
// $lastSend = $admin_user->getRequestedPollsDate();
// $now = new \DateTime();
if ( date_diff( $lastSend, $now ) < 60 ) {
// too soon!
die( 'too soon!' );
}
$admin_user->setRequestedPollsDate( $now );
$em->persist( $admin_user );
$em->flush();
// if ( date_diff( $lastSend, $now ) < 60 ) {
// // too soon!
// die( 'too soon!' );
// }
// $admin_user->setRequestedPollsDate( $now );
// $em->persist( $admin_user );
// $em->flush();
$titleEmail = 'Framadate | Mes sondages';
$templateVars = [
@ -98,12 +88,12 @@ class MailService {
'email_template' => 'emails/owner-polls.html.twig',
];
$email = ( new TemplatedEmail( ) )
$email = ( new TemplatedEmail() )
->from( 'ne-pas-repondre@framadate-api.cipherbliss.com' )
->to( new Address($admin_user->getEmail() ) )
->subject($titleEmail)
->htmlTemplate($templateVars[ 'email_template' ])
->context( $templateVars);
->to( new Address( $admin_user->getEmail() ) )
->subject( $titleEmail )
->htmlTemplate( $templateVars[ 'email_template' ] )
->context( $templateVars );
// send email
return $this->mailer->send( $email );