diff --git a/api/src/Logger/SessionDataProcessor.php b/api/src/Logger/SessionDataProcessor.php index 537753cba..0ce8592c2 100644 --- a/api/src/Logger/SessionDataProcessor.php +++ b/api/src/Logger/SessionDataProcessor.php @@ -38,26 +38,43 @@ public function __construct( $this->entityManager = $entityManager; } - public function __invoke(array $record): array + /** + * Update the context with data from the session and the request stack. + * + * @param array $context The context to update. + * + * @return array The updated context. + */ + public function updateContext($context): array { + $context['session'] = $this->session->getId(); + $context['process'] = $this->session->has('process') ? $this->session->get('process') : ''; + $context['endpoint'] = $this->session->has('endpoint') ? $this->session->get('endpoint') : ''; + $context['schema'] = $this->session->has('schema') ? $this->session->get('schema') : ''; + $context['object'] = $this->session->has('object') === true ? $this->session->get('object') : ''; + $context['cronjob'] = $this->session->has('cronjob') ? $this->session->get('cronjob') : ''; + $context['action'] = $this->session->has('cronjob') ? $this->session->get('action') : ''; + $context['mapping'] = $this->session->has('mapping') ? $this->session->get('mapping') : ''; + $context['source'] = $this->session->has('source') ? $this->session->get('source') : ''; + $context['plugin'] = isset($record['data']['plugin']) === true ? $record['data']['plugin'] : ''; + $context['user'] = $this->session->has('user') ? $this->session->get('user') : ''; + $context['organization'] = $this->session->has('organization') ? $this->session->get('organization') : ''; + $context['application'] = $this->session->has('application') ? $this->session->get('application') : ''; + $context['host'] = $this->requestStack->getMainRequest() ? $this->requestStack->getMainRequest()->getHost() : ''; + $context['ip'] = $this->requestStack->getMainRequest() ? $this->requestStack->getMainRequest()->getClientIp() : ''; - $record['context']['session'] = $this->session->getId(); - $record['context']['process'] = $this->session->has('process') ? $this->session->get('process') : ''; - $record['context']['endpoint'] = $this->session->has('endpoint') ? $this->session->get('endpoint') : ''; - $record['context']['schema'] = $this->session->has('schema') ? $this->session->get('schema') : ''; - $record['context']['object'] = $this->session->has('object') === true ? $this->session->get('object') : ''; - $record['context']['cronjob'] = $this->session->has('cronjob') ? $this->session->get('cronjob') : ''; - $record['context']['action'] = $this->session->has('cronjob') ? $this->session->get('action') : ''; - $record['context']['mapping'] = $this->session->has('mapping') ? $this->session->get('mapping') : ''; - $record['context']['source'] = $this->session->has('source') ? $this->session->get('source') : ''; - $record['context']['plugin'] = isset($record['data']['plugin']) === true ? $record['data']['plugin'] : ''; - $record['context']['user'] = $this->session->has('user') ? $this->session->get('user') : ''; - $record['context']['organization'] = $this->session->has('organization') ? $this->session->get('organization') : ''; - $record['context']['application'] = $this->session->has('application') ? $this->session->get('application') : ''; - $record['context']['host'] = $this->requestStack->getMainRequest() ? $this->requestStack->getMainRequest()->getHost() : ''; - $record['context']['ip'] = $this->requestStack->getMainRequest() ? $this->requestStack->getMainRequest()->getClientIp() : ''; - + return $context; + } + /** + * Dispatches a log create action. + * + * @param array $record The log record that is created. + * + * @return array The resulting log record after the action. + */ + public function dispatchLogCreateAction(array $record): array + { if ($this->entityManager->getConnection()->isConnected() === true && in_array( $this->entityManager->getConnection()->getDatabase(), @@ -74,4 +91,18 @@ public function __invoke(array $record): array return $record; } + + /** + * Updates the log record with data from the session, request and from actions. + * + * @param array $record The log record. + * + * @return array The updated log record. + */ + public function __invoke(array $record): array + { + $record['context'] = $this->updateContext($record['context']); + + return $this->dispatchLogCreateAction($record); + } }