/** * @depends testGetLogClassByName * * @param LogClass $logClass */ public function testSave(LogClass $logClass) { $log = new Log(); $log->setAccountId(1); $log->setAction('add'); $log->setApplicationContext(1); $log->setLogClass($logClass); $log->setObjectId(1); $this->assertEquals(0, $log->getId()); $this->service->save($log); $this->assertGreaterThan(0, $log->getId()); }
/** * Common BaseEvent listener. This will create a new log of the event and persist it to the database. * * @param BaseEvent $event */ public function onCommonLogAction(BaseEvent $event) { // event data is expected to be an instance of LogEventData $eventData = $event->getData(); $logAction = $this->getLogActionOfEventName($event->getName()); $log = new Log(); $log->setAccountId($this->loggedAccountId); $log->setAction($logAction); $log->setApplicationContext($this->applicationContext); if ($eventData instanceof LogEventData) { $log->setMessage($eventData->getMessage()); $log->setData(\json_encode($eventData->getData())); // quick fix for login since no logged accountId is set yet $dataArr = $eventData->getData(); if (isset($dataArr['accountId']) && $dataArr['accountId']) { $log->setAccountId($dataArr['accountId']); } // we only cater those with LogEventData $this->logService->save($log); } else { // for BC } }