From 950f87a01113e383beb14716297cb5bb2b5df66b Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 3 Oct 2023 12:54:56 +0200 Subject: [PATCH] Added Digital post module --- modules/os2forms_digital_post/README.md | 74 +++++-------------- .../BeskedfordelerEventSubscriber.php | 30 ++------ .../src/Form/SettingsForm.php | 28 ++----- .../src/Helper/BeskedfordelerHelper.php | 21 +----- 4 files changed, 34 insertions(+), 119 deletions(-) diff --git a/modules/os2forms_digital_post/README.md b/modules/os2forms_digital_post/README.md index 020eb66f..04747c94 100644 --- a/modules/os2forms_digital_post/README.md +++ b/modules/os2forms_digital_post/README.md @@ -13,24 +13,9 @@ This module provides functionality for sending digital post to danish citizens. A WebformHandler is provided that you can add to your webform, and if configured it will send the submitted data as digital post. -## Beskedfordeler endpoint - -This module provides an endpoint, -`/os2forms_digital_post/PostStatusBeskedModtag`, for -“[PostStatusBeskedModtag](https://digitaliseringskataloget.dk/integration/sf1601)” -to get information on how or why not a digital post has been delivered. See -“PostStatusBeskedHent” on - for details. - ## Installation -Require it with composer: - -```shell -composer require "os2forms/os2forms_digital_post" -``` - -Enable it with drush: +Enable the module with [`drush`](https://drush.org/) ```shell drush pm:enable os2forms_digital_post @@ -46,24 +31,17 @@ examples](modules/os2forms_digital_post_examples/README.md). Go to `/admin/os2forms_digital_post/settings` to set up global settings for digital post. -## Drush commands - -```sh -drush --uri=$(itkdev-docker-compose url) os2forms_digital_post:digital-post:send --help - -drush --uri=$(itkdev-docker-compose url) os2forms_digital_post:digital-post:memo-show --help -``` +### Queue -## Queue +The actual sending of digital post is handled by jobs in an [Advanced +Queue](https://www.drupal.org/project/advancedqueue) queue. -Digital post is sent via jobs via an [Advanced -Queue](https://www.drupal.org/project/advancedqueue) called -`os2forms_digital_post`. +The default queue, OSForms digital post (`os2forms_digital_post`), must be +processed by a server `cron` job (cf. +`/admin/config/system/queues/manage/os2forms_digital_post?destination=/en/admin/config/system/queues`), +but this can be changed or a completely diffent queue can be used if nedd be. -The queue is processed via [Drupal's cron -run](https://www.drupal.org/docs/administering-a-drupal-site/cron-automated-tasks/cron-automated-tasks-overview), -but you can manually process the queue with `drush` if you want to process it -more often than other Drupal cron jobs: +If using the default queue, it can be processed by running the command ```sh drush advancedqueue:queue:process os2forms_digital_post @@ -78,31 +56,13 @@ drush advancedqueue:queue:list or go to `/admin/config/system/queues/jobs/os2forms_digital_post` for a graphical overview of jobs in the queue. - - - - - -## Coding standards +## Beskedfordeler -All coding standards are checked with [GitHub -Actions](https://github.com/features/actions) when a pull request is made (cf. -<.github/workflows/pr.yaml>). +Thie digital post module depends on [Beskedfordeler for +Drupal](https://github.com/itk-dev/beskedfordeler-drupalon) to get get +information on how or why not a digital post has been delivered (cf. +[BeskedfordelerEventSubscriber](src/EventSubscriber/BeskedfordelerEventSubscriber.php)). -Check coding standards: - -```sh -docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer install -docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-check - -docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app install -docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app coding-standards-check -``` - -Apply coding standards: - -```shell -docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-apply - -docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app coding-standards-apply -``` +See the [documentation for Beskedfordeler for +Drupal](https://github.com/itk-dev/beskedfordeler-drupal#beskedfordeler) for +details on how to set up the Beskedfordeler module. diff --git a/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php b/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php index 05e9be63..0ebbc4ef 100644 --- a/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php +++ b/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php @@ -16,35 +16,15 @@ final class BeskedfordelerEventSubscriber extends AbstractBeskedfordelerEventSub private const KANAL_KODE = 'Digital Post'; private const MESSAGE_UUID_KEY = 'MessageUUID'; - /** - * The Beskedfordeler helper. - * - * @var \Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper - */ - private BeskedfordelerHelper $beskedfordelerHelper; - - /** - * The message helper. - * - * @var \Drupal\beskedfordeler\Helper\MessageHelper - */ - private MessageHelper $messageHelper; - - /** - * The webform helper. - * - * @var \Drupal\os2forms_digital_post\Helper\WebformHelperSF1601 - */ - private WebformHelperSF1601 $webformHelper; - /** * Constructor. */ - public function __construct(BeskedfordelerHelper $beskedfordelerHelper, MessageHelper $messageHelper, WebformHelperSF1601 $webformHelper, LoggerInterface $logger) { + public function __construct( + private readonly BeskedfordelerHelper $beskedfordelerHelper, + private readonly MessageHelper $messageHelper, + private readonly WebformHelperSF1601 $webformHelper, + LoggerInterface $logger) { parent::__construct($logger); - $this->beskedfordelerHelper = $beskedfordelerHelper; - $this->messageHelper = $messageHelper; - $this->webformHelper = $webformHelper; } /** diff --git a/modules/os2forms_digital_post/src/Form/SettingsForm.php b/modules/os2forms_digital_post/src/Form/SettingsForm.php index 8031040a..0d968590 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -19,34 +19,22 @@ final class SettingsForm extends FormBase { use StringTranslationTrait; - /** - * The settings. - * - * @var \Drupal\os2forms_digital_post\Helper\Settings - */ - private Settings $settings; - /** * The queue storage. * * @var \Drupal\Core\Entity\EntityStorageInterface */ - protected EntityStorageInterface $queueStorage; - - /** - * The certificate locator helper. - * - * @var \Drupal\os2forms_digital_post\Helper\CertificateLocatorHelper - */ - private CertificateLocatorHelper $certificateLocatorHelper; + private readonly EntityStorageInterface $queueStorage; /** * Constructor. */ - public function __construct(Settings $settings, EntityTypeManagerInterface $entityTypeManager, CertificateLocatorHelper $certificateLocatorHelper) { - $this->settings = $settings; + public function __construct( + private readonly Settings $settings, + private readonly CertificateLocatorHelper $certificateLocatorHelper, + EntityTypeManagerInterface $entityTypeManager + ) { $this->queueStorage = $entityTypeManager->getStorage('advancedqueue_queue'); - $this->certificateLocatorHelper = $certificateLocatorHelper; } /** @@ -57,8 +45,8 @@ public function __construct(Settings $settings, EntityTypeManagerInterface $enti public static function create(ContainerInterface $container) { return new static( $container->get(Settings::class), - $container->get('entity_type.manager'), - $container->get(CertificateLocatorHelper::class) + $container->get(CertificateLocatorHelper::class), + $container->get('entity_type.manager') ); } diff --git a/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php b/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php index ddb82061..ba8bc480 100644 --- a/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php +++ b/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php @@ -18,26 +18,13 @@ class BeskedfordelerHelper { private const TABLE_NAME = 'os2forms_digital_post_beskedfordeler'; - /** - * The database. - * - * @var \Drupal\Core\Database\Connection - */ - private Connection $database; - - /** - * The MeMo helper. - * - * @var MeMoHelper - */ - private MeMoHelper $meMoHelper; - /** * Constructor. */ - public function __construct(Connection $database, MeMoHelper $meMoHelper, LoggerInterface $logger) { - $this->database = $database; - $this->meMoHelper = $meMoHelper; + public function __construct( + private readonly Connection $database, + private readonly MeMoHelper $meMoHelper, + LoggerInterface $logger) { $this->setLogger($logger); }