예제 #1
0
 /**
  * Is a repeat if the session contains a same logSignature for the same action category.
  */
 public function isARepeat(LogGenericEvent $event)
 {
     if ($this->tokenStorage->getToken() === null) {
         //Only if have a user session;
         return false;
     }
     if ($event instanceof LogNotRepeatableInterface) {
         $request = $this->container->get('request');
         $session = $request->getSession();
         $is = false;
         $pushInSession = true;
         $now = time();
         //if ($session->get($event->getAction()) != null) {
         if ($session->get($event->getLogSignature()) != null) {
             //$oldArray = json_decode($session->get($event->getAction()));
             $oldArray = json_decode($session->get($event->getLogSignature()));
             $oldSignature = $oldArray->logSignature;
             $oldTime = $oldArray->time;
             if ($oldSignature == $event->getLogSignature()) {
                 $diff = $now - $oldTime;
                 $notRepeatableLogTimeInSeconds = $this->container->getParameter('non_repeatable_log_time_in_seconds');
                 if ($event->getIsWorkspaceEnterEvent()) {
                     $notRepeatableLogTimeInSeconds = $notRepeatableLogTimeInSeconds * 3;
                 }
                 if ($diff > $notRepeatableLogTimeInSeconds) {
                     $is = false;
                 } else {
                     $is = true;
                     $pushInSession = false;
                 }
             }
         }
         if ($pushInSession) {
             //Update last logSignature for this event category
             $array = array('logSignature' => $event->getLogSignature(), 'time' => $now);
             //$session->set($event->getAction(), json_encode($array));
             $session->set($event->getLogSignature(), json_encode($array));
         }
         return $is;
     } else {
         return false;
     }
 }