@@ -12,38 +12,38 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | private $user; |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * CreateUpdateAwareListener constructor. |
|
| 17 | - * @param TokenStorage $tokenStorage |
|
| 18 | - */ |
|
| 19 | - public function __construct(TokenStorage $tokenStorage) |
|
| 15 | + /** |
|
| 16 | + * CreateUpdateAwareListener constructor. |
|
| 17 | + * @param TokenStorage $tokenStorage |
|
| 18 | + */ |
|
| 19 | + public function __construct(TokenStorage $tokenStorage) |
|
| 20 | 20 | { |
| 21 | - if ($tokenStorage->getToken() && is_object($tokenStorage->getToken()->getUser()) && $tokenStorage->getToken()->getUser()->getUser()) { |
|
| 22 | - $this->user = $tokenStorage->getToken()->getUser()->getUser(); |
|
| 23 | - } else { |
|
| 24 | - $this->user = null; |
|
| 25 | - } |
|
| 21 | + if ($tokenStorage->getToken() && is_object($tokenStorage->getToken()->getUser()) && $tokenStorage->getToken()->getUser()->getUser()) { |
|
| 22 | + $this->user = $tokenStorage->getToken()->getUser()->getUser(); |
|
| 23 | + } else { |
|
| 24 | + $this->user = null; |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function prePersist($entity) |
| 29 | 29 | { |
| 30 | - if ($this->user) { |
|
| 31 | - if ($entity->getCreatedBy() === null) { |
|
| 32 | - $entity->setCreatedAt(new \DateTime()); |
|
| 33 | - $entity->setCreatedBy($this->user); |
|
| 34 | - } |
|
| 35 | - if ($entity->getUpdatedBy() === null) { |
|
| 36 | - $entity->setUpdatedAt(new \DateTime()); |
|
| 37 | - $entity->setUpdatedBy($this->user); |
|
| 38 | - } |
|
| 39 | - } |
|
| 30 | + if ($this->user) { |
|
| 31 | + if ($entity->getCreatedBy() === null) { |
|
| 32 | + $entity->setCreatedAt(new \DateTime()); |
|
| 33 | + $entity->setCreatedBy($this->user); |
|
| 34 | + } |
|
| 35 | + if ($entity->getUpdatedBy() === null) { |
|
| 36 | + $entity->setUpdatedAt(new \DateTime()); |
|
| 37 | + $entity->setUpdatedBy($this->user); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function preUpdate($entity) |
|
| 43 | - { |
|
| 44 | - if ($this->user) { |
|
| 45 | - $entity->setUpdatedAt(new \DateTime()); |
|
| 46 | - $entity->setUpdatedBy($this->user); |
|
| 47 | - } |
|
| 48 | - } |
|
| 42 | + public function preUpdate($entity) |
|
| 43 | + { |
|
| 44 | + if ($this->user) { |
|
| 45 | + $entity->setUpdatedAt(new \DateTime()); |
|
| 46 | + $entity->setUpdatedBy($this->user); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -13,129 +13,129 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class UserLogs |
| 15 | 15 | { |
| 16 | - use CreatedUpdatedTrait; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var integer |
|
| 20 | - * |
|
| 21 | - * @ORM\Column(name="id", type="integer", nullable=false) |
|
| 22 | - * @ORM\Id |
|
| 23 | - * @ORM\GeneratedValue(strategy="IDENTITY") |
|
| 24 | - */ |
|
| 25 | - private $id; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User") |
|
| 29 | - * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) |
|
| 30 | - */ |
|
| 31 | - private $user; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - * |
|
| 36 | - * @ORM\Column(name="method", type="string", length=255, nullable=false) |
|
| 37 | - */ |
|
| 38 | - private $method; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - * |
|
| 43 | - * @ORM\Column(name="url", type="string", length=255, nullable=false) |
|
| 44 | - */ |
|
| 45 | - private $url; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - * |
|
| 50 | - * @ORM\Column(name="equest_parameters", type="json", nullable=true) |
|
| 51 | - */ |
|
| 52 | - private $request_parameters; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @return int |
|
| 56 | - */ |
|
| 57 | - public function getId() |
|
| 58 | - { |
|
| 59 | - return $this->id; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param int $id |
|
| 64 | - */ |
|
| 65 | - public function setId($id) |
|
| 66 | - { |
|
| 67 | - $this->id = $id; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return User |
|
| 72 | - */ |
|
| 73 | - public function getUser(): User |
|
| 74 | - { |
|
| 75 | - return $this->user; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param \User $user |
|
| 80 | - */ |
|
| 81 | - public function setUser($user) |
|
| 82 | - { |
|
| 83 | - $this->user = $user; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function getMethod(): string |
|
| 90 | - { |
|
| 91 | - return $this->method; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $method |
|
| 96 | - * @return UserLogs |
|
| 97 | - */ |
|
| 98 | - public function setMethod(string $method): UserLogs |
|
| 99 | - { |
|
| 100 | - $this->method = $method; |
|
| 101 | - |
|
| 102 | - return $this; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function getUrl(): string |
|
| 109 | - { |
|
| 110 | - return $this->url; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param string $url |
|
| 115 | - * @return UserLogs |
|
| 116 | - */ |
|
| 117 | - public function setUrl(string $url): UserLogs |
|
| 118 | - { |
|
| 119 | - $this->url = $url; |
|
| 120 | - |
|
| 121 | - return $this; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - public function getRequestParameters() |
|
| 126 | - { |
|
| 127 | - return $this->request_parameters; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @param $request_parameters |
|
| 132 | - * @return UserLogs |
|
| 133 | - */ |
|
| 134 | - public function setRequestParameters($request_parameters): UserLogs |
|
| 135 | - { |
|
| 136 | - $this->request_parameters = $request_parameters; |
|
| 137 | - |
|
| 138 | - return $this; |
|
| 139 | - } |
|
| 16 | + use CreatedUpdatedTrait; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var integer |
|
| 20 | + * |
|
| 21 | + * @ORM\Column(name="id", type="integer", nullable=false) |
|
| 22 | + * @ORM\Id |
|
| 23 | + * @ORM\GeneratedValue(strategy="IDENTITY") |
|
| 24 | + */ |
|
| 25 | + private $id; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User") |
|
| 29 | + * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) |
|
| 30 | + */ |
|
| 31 | + private $user; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + * |
|
| 36 | + * @ORM\Column(name="method", type="string", length=255, nullable=false) |
|
| 37 | + */ |
|
| 38 | + private $method; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + * |
|
| 43 | + * @ORM\Column(name="url", type="string", length=255, nullable=false) |
|
| 44 | + */ |
|
| 45 | + private $url; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + * |
|
| 50 | + * @ORM\Column(name="equest_parameters", type="json", nullable=true) |
|
| 51 | + */ |
|
| 52 | + private $request_parameters; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @return int |
|
| 56 | + */ |
|
| 57 | + public function getId() |
|
| 58 | + { |
|
| 59 | + return $this->id; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param int $id |
|
| 64 | + */ |
|
| 65 | + public function setId($id) |
|
| 66 | + { |
|
| 67 | + $this->id = $id; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return User |
|
| 72 | + */ |
|
| 73 | + public function getUser(): User |
|
| 74 | + { |
|
| 75 | + return $this->user; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param \User $user |
|
| 80 | + */ |
|
| 81 | + public function setUser($user) |
|
| 82 | + { |
|
| 83 | + $this->user = $user; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function getMethod(): string |
|
| 90 | + { |
|
| 91 | + return $this->method; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $method |
|
| 96 | + * @return UserLogs |
|
| 97 | + */ |
|
| 98 | + public function setMethod(string $method): UserLogs |
|
| 99 | + { |
|
| 100 | + $this->method = $method; |
|
| 101 | + |
|
| 102 | + return $this; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function getUrl(): string |
|
| 109 | + { |
|
| 110 | + return $this->url; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param string $url |
|
| 115 | + * @return UserLogs |
|
| 116 | + */ |
|
| 117 | + public function setUrl(string $url): UserLogs |
|
| 118 | + { |
|
| 119 | + $this->url = $url; |
|
| 120 | + |
|
| 121 | + return $this; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + public function getRequestParameters() |
|
| 126 | + { |
|
| 127 | + return $this->request_parameters; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @param $request_parameters |
|
| 132 | + * @return UserLogs |
|
| 133 | + */ |
|
| 134 | + public function setRequestParameters($request_parameters): UserLogs |
|
| 135 | + { |
|
| 136 | + $this->request_parameters = $request_parameters; |
|
| 137 | + |
|
| 138 | + return $this; |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | |
@@ -9,43 +9,43 @@ |
||
| 9 | 9 | |
| 10 | 10 | class UserLog |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var TokenStorageInterface |
|
| 14 | - */ |
|
| 15 | - private $token_storage; |
|
| 12 | + /** |
|
| 13 | + * @var TokenStorageInterface |
|
| 14 | + */ |
|
| 15 | + private $token_storage; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var EntityManagerInterface a |
|
| 19 | - */ |
|
| 20 | - private $em; |
|
| 17 | + /** |
|
| 18 | + * @var EntityManagerInterface a |
|
| 19 | + */ |
|
| 20 | + private $em; |
|
| 21 | 21 | |
| 22 | - public function __construct(TokenStorageInterface $token_storage, EntityManagerInterface $em) |
|
| 23 | - { |
|
| 24 | - $this->token_storage = $token_storage; |
|
| 25 | - $this->em = $em; |
|
| 26 | - } |
|
| 22 | + public function __construct(TokenStorageInterface $token_storage, EntityManagerInterface $em) |
|
| 23 | + { |
|
| 24 | + $this->token_storage = $token_storage; |
|
| 25 | + $this->em = $em; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param RequestEvent $request_event |
|
| 30 | - */ |
|
| 31 | - public function onKernelRequest(RequestEvent $request_event) |
|
| 32 | - { |
|
| 33 | - if ($request_event->isMasterRequest()) { |
|
| 34 | - $user = null; |
|
| 35 | - if ($this->token_storage->getToken() && is_object($this->token_storage->getToken()->getUser()) && $this->token_storage->getToken()->getUser()->getUser()) { |
|
| 36 | - $user = $this->token_storage->getToken()->getUser()->getUser(); |
|
| 37 | - } |
|
| 38 | - $request = $request_event->getRequest(); |
|
| 28 | + /** |
|
| 29 | + * @param RequestEvent $request_event |
|
| 30 | + */ |
|
| 31 | + public function onKernelRequest(RequestEvent $request_event) |
|
| 32 | + { |
|
| 33 | + if ($request_event->isMasterRequest()) { |
|
| 34 | + $user = null; |
|
| 35 | + if ($this->token_storage->getToken() && is_object($this->token_storage->getToken()->getUser()) && $this->token_storage->getToken()->getUser()->getUser()) { |
|
| 36 | + $user = $this->token_storage->getToken()->getUser()->getUser(); |
|
| 37 | + } |
|
| 38 | + $request = $request_event->getRequest(); |
|
| 39 | 39 | |
| 40 | - if ($user) { |
|
| 41 | - $user_log = new UserLogs(); |
|
| 42 | - $user_log->setMethod($request->getMethod()); |
|
| 43 | - $user_log->setUser($user); |
|
| 44 | - $user_log->setUrl($request->get("_route")); |
|
| 45 | - $user_log->setRequestParameters($request->request->all()); |
|
| 46 | - $this->em->persist($user_log); |
|
| 47 | - $this->em->flush(); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } |
|
| 40 | + if ($user) { |
|
| 41 | + $user_log = new UserLogs(); |
|
| 42 | + $user_log->setMethod($request->getMethod()); |
|
| 43 | + $user_log->setUser($user); |
|
| 44 | + $user_log->setUrl($request->get("_route")); |
|
| 45 | + $user_log->setRequestParameters($request->request->all()); |
|
| 46 | + $this->em->persist($user_log); |
|
| 47 | + $this->em->flush(); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | } |