Skip to content

Commit

Permalink
Merge pull request #123 from itk-dev/feature/FORMS-622-log-get-organized
Browse files Browse the repository at this point in the history
Feature/forms 622 log get organized
  • Loading branch information
martinyde authored Jan 23, 2023
2 parents 97097ad + df469d8 commit e9057ec
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Nedenfor ses dato for release og beskrivelse af opgaver som er implementeret.
* Tilføjet Book aarhus.
* Tilføj conditions til "Mere"-element
* Tilføjet Api request handler logging.
* Tilføjet get organized handler logging.

### Fix

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function postSave(WebformSubmissionInterface $submission, $update = TRUE)
$logger_context = [
'channel' => 'webform_submission',
'webform_submission' => $submission,
'operation' => 'submission queued',
'operation' => 'submission queued (api request handler)',
];

$this->submissionLogger->notice($this->t('Added submission #@serial to queue for processing', ['@serial' => $submission->serial()]), $logger_context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
use Drupal\advancedqueue\Job;
use Drupal\advancedqueue\JobResult;
use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\os2forms_get_organized\Helper\ArchiveHelper;
use Drupal\webform\Entity\WebformSubmission;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -25,6 +28,13 @@ class ArchiveDocument extends JobTypeBase implements ContainerFactoryPluginInter
*/
private ArchiveHelper $helper;

/**
* The submission logger.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected LoggerChannelInterface $submissionLogger;

/**
* {@inheritdoc}
*/
Expand All @@ -33,7 +43,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('os2forms_get_organized.archive_helper')
$container->get('os2forms_get_organized.archive_helper'),
$container->get('logger.factory')
);
}

Expand All @@ -44,22 +55,43 @@ public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
ArchiveHelper $helper
ArchiveHelper $helper,
LoggerChannelFactoryInterface $loggerFactory
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->helper = $helper;
$this->submissionLogger = $loggerFactory->get('webform_submission');
}

/**
* Processes the ArchiveDocument job.
*/
public function process(Job $job): JobResult {
$payload = $job->getPayload();

try {
$this->helper->archive($payload['submissionId'], $payload['handlerConfiguration']);
$payload = $job->getPayload();

/** @var \Drupal\webform\WebformSubmissionInterface $webformSubmission */
$webformSubmission = WebformSubmission::load($payload['submissionId']);
$logger_context = [
'channel' => 'webform_submission',
'webform_submission' => $webformSubmission,
'operation' => 'response from queue (get organized handler)',
];

try {
$this->helper->archive($payload['submissionId'], $payload['handlerConfiguration']);
$this->submissionLogger->notice($this->t('The submission #@serial was successfully delivered', ['@serial' => $webformSubmission->serial()]), $logger_context);

return JobResult::success();
}
catch (\Exception $e) {
$this->submissionLogger->error($this->t('The submission #@serial failed (@message)', [
'@serial' => $webformSubmission->serial(),
'@message' => $e->getMessage(),
]), $logger_context);

return JobResult::success();
return JobResult::failure($e->getMessage());
}
}
catch (\Exception $e) {
return JobResult::failure($e->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\os2forms_get_organized\Plugin\AdvancedQueue\JobType\ArchiveDocument;
use Drupal\webform\Plugin\WebformHandlerBase;
Expand All @@ -29,6 +30,12 @@
* )
*/
class GetOrganizedWebformHandler extends WebformHandlerBase {
/**
* The submission logger.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected LoggerChannelInterface $submissionLogger;

/**
* Constructs a GetOrganizedWebformHandler object.
Expand All @@ -42,6 +49,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$this->entityTypeManager = $entityTypeManager;
$this->conditionsValidator = $conditionsValidator;
$this->tokenManager = $tokenManager;
$this->submissionLogger = $loggerFactory->get('webform_submission');
}

/**
Expand Down Expand Up @@ -236,6 +244,14 @@ public function postSave(WebformSubmissionInterface $webform_submission, $update
'handlerConfiguration' => $this->configuration,
]);
$queue->enqueueJob($job);

$logger_context = [
'channel' => 'webform_submission',
'webform_submission' => $webform_submission,
'operation' => 'submission queued (get organized handler)',
];

$this->submissionLogger->notice($this->t('Added submission #@serial to queue for processing', ['@serial' => $webform_submission->serial()]), $logger_context);
}

/**
Expand Down

0 comments on commit e9057ec

Please sign in to comment.