Skip to content

Commit b853f94

Browse files
committed
More stuff
1 parent 8ccec62 commit b853f94

12 files changed

Lines changed: 216 additions & 24 deletions

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,53 @@
1212
Note: The "SFTP private key" key must be passwordless.
1313

1414
2. Go to `/admin/os2forms_fordelingskomponent/settings` and configure the Fordelingskomponent module.
15+
16+
## Console commands
17+
18+
``` shell
19+
drush os2forms-fordelingskomponent:sftp:ls
20+
```
21+
22+
---
23+
24+
``` shell name=key-create-sf2900_certificate
25+
drush config:set --input-format=yaml key.key.sf2900_certificate '?' - <<'EOF'
26+
langcode: da
27+
status: true
28+
dependencies:
29+
module:
30+
- os2web_key
31+
id: sf2900_certificate
32+
label: 'SF2900 Certificate'
33+
description: ''
34+
key_type: os2web_key_certificate
35+
key_type_settings:
36+
passphrase: …
37+
input_format: pfx
38+
output_format: pem
39+
key_provider: file
40+
key_provider_settings:
41+
file_location: /app/cert/OS2Forms_FordelingUdvikling.p12
42+
strip_line_breaks: false
43+
key_input: none
44+
key_input_settings: { }
45+
EOF
46+
```
47+
48+
``` shell name=key-create-sf2900_sftp_private_key
49+
drush config:set --input-format=yaml key.key.sf2900_sftp_private_key '?' - <<'EOF'
50+
langcode: da
51+
status: true
52+
dependencies: { }
53+
id: sf2900_sftp_private_key
54+
label: 'SF2900 SFTP private key'
55+
description: ''
56+
key_type: authentication
57+
key_type_settings: { }
58+
key_provider: file
59+
key_provider_settings:
60+
file_location: /app/cert/OS2Forms_FordelingUdvikling-sftp-nopass
61+
strip_line_breaks: false
62+
key_input: none
63+
key_input_settings: { }
64+
```

drush.services.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
os2forms_fordelingskomponent.sftp.ls:
3+
class: Drupal\os2forms_fordelingskomponent\Drush\Commands\SftpLsCommand
4+
arguments:
5+
- '@Drupal\os2forms_fordelingskomponent\Helper\FordelingskomponentHelper'
6+
tags:
7+
- { name: console.command }
8+
9+
os2forms_fordelingskomponent.sned.journalnotat:
10+
class: Drupal\os2forms_fordelingskomponent\Drush\Commands\SendJournalnotat
11+
arguments:
12+
- '@Drupal\os2forms_fordelingskomponent\Helper\FordelingskomponentHelper'
13+
tags:
14+
- { name: console.command }

modules/os2forms_fordelingskomponent_examples/config/install/webform.webform.os2_fdk_kp_anmoding.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ handlers:
271271
titel: "Your document"
272272
beskrivelse: "This is a very important document"
273273

274+
distribution_type: DISTRIBUTION_DOKUMENT_TYPE
275+
# DISTRIBUTION_JOURNAL_POST_TYPE
276+
# DISTRIBUTION_FORMULAR_TYPE
277+
274278
xml_template: |
275279
<?xml version="1.0" encoding="UTF-8"?>
276280
<Anmodning xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

os2forms_fordelingskomponent.routing.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,19 @@ os2forms_fordelingskomponent.routing_info:
1919
_permission: "administer site configuration"
2020

2121
os2forms_fordelingskomponent.fordelingskomponent_payload.preview:
22-
path: "/admin/structure/webform/manage/{webform}/os2forms_fordelingskomponent/payload/{handler}/preview"
22+
path: "/admin/structure/webform/manage/{webform}/os2forms_fordelingskomponent/payload/{webform_handler}/preview"
2323
defaults:
2424
_controller: '\Drupal\os2forms_fordelingskomponent\Controller\Os2formsFordelingskomponentPayloadPreviewController'
2525
_title: "Fordelingskomponent payload preview"
2626
options:
2727
parameters:
2828
webform:
2929
type: "entity:webform"
30-
handler:
31-
type: "entity:webform_handler"
3230
requirements:
3331
_permission: "view any webform submission"
3432

3533
os2forms_fordelingskomponent.fordelingskomponent_payload.preview_render:
36-
path: "/admin/structure/webform/manage/{webform}/os2forms_fordelingskomponent/payload/{handler}/preview/render/{submission}"
34+
path: "/admin/structure/webform/manage/{webform}/os2forms_fordelingskomponent/payload/{webform_handler}/preview/render/{submission}"
3735
defaults:
3836
_controller: '\Drupal\os2forms_fordelingskomponent\Controller\Os2formsFordelingskomponentPayloadPreviewRenderController'
3937
_title: "Fordelingskomponent payload preview"

src/Controller/Os2formsFordelingskomponentPayloadPreviewController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function __construct(
3131
/**
3232
* Builds the response.
3333
*/
34-
public function __invoke(Request $request, WebformInterface $webform, string $handler): array|Response {
35-
$handler = $webform->getHandler($handler);
34+
public function __invoke(Request $request, WebformInterface $webform, string $webform_handler): array|Response {
35+
$handler = $webform->getHandler($webform_handler);
3636
$submissionIds = array_keys($this->submissionStorage->getQuery()
3737
->accessCheck()
3838
->condition('webform_id', $webform->id())
@@ -48,7 +48,7 @@ public function __invoke(Request $request, WebformInterface $webform, string $ha
4848
$previewUrls = array_map(
4949
static fn($submission) => Url::fromRoute('os2forms_fordelingskomponent.fordelingskomponent_payload.preview', [
5050
'webform' => $webform->id(),
51-
'handler' => $handler->getHandlerId(),
51+
'webform_handler' => $handler->getHandlerId(),
5252
'submission' => $submission,
5353
]),
5454
array_filter([
@@ -61,7 +61,7 @@ public function __invoke(Request $request, WebformInterface $webform, string $ha
6161
$renderUrl = NULL !== $currentSubmission
6262
? Url::fromRoute('os2forms_fordelingskomponent.fordelingskomponent_payload.preview_render', [
6363
'webform' => $webform->id(),
64-
'handler' => $handler->getHandlerId(),
64+
'webform_handler' => $handler->getHandlerId(),
6565
'submission' => $currentSubmission,
6666
])
6767
: NULL;

src/Controller/Os2formsFordelingskomponentPayloadPreviewRenderController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function __construct(
2626
/**
2727
* Builds the response.
2828
*/
29-
public function __invoke(WebformInterface $webform, string $handler, WebformSubmissionInterface $submission): Response {
30-
$handler = $webform->getHandler($handler);
29+
public function __invoke(WebformInterface $webform, string $webform_handler, WebformSubmissionInterface $submission): Response {
30+
$handler = $webform->getHandler($webform_handler);
3131
$handlerSettings = $handler->getSetting('sf2900');
3232

3333
$exceptions = [];
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\os2forms_fordelingskomponent\Drush\Commands;
6+
7+
use SF2900\SftpHelper;
8+
use Drupal\os2forms_fordelingskomponent\Helper\FordelingskomponentHelper;
9+
use Symfony\Component\Console\Attribute\AsCommand;
10+
use Symfony\Component\Console\Command\Command;
11+
use Symfony\Component\Console\Input\InputArgument;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
use Symfony\Component\Console\Style\SymfonyStyle;
15+
16+
// phpcs:disable Drupal.Commenting.ClassComment.Missing
17+
#[AsCommand(
18+
name: 'os2forms-fordelingskomponent:send:journalnotat',
19+
description: 'Send journalnotat',
20+
)]
21+
final class SendJournalnotatCommand extends Command {
22+
23+
public function __construct(
24+
private readonly FordelingskomponentHelper $helper,
25+
) {
26+
parent::__construct();
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*
32+
* @see https://www.drush.org/13.x/commands/
33+
*/
34+
protected function configure(): void {
35+
$this
36+
->addArgument('dir', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'List of directory paths', [SftpHelper::INCOMING_FOLDER]);
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
protected function execute(InputInterface $input, OutputInterface $output): int {
43+
$io = new SymfonyStyle($input, $output);
44+
$sftp = $this->helper->sf2900()->sftp();
45+
$dirs = (array) $input->getArgument('dir');
46+
foreach ($dirs as $dir) {
47+
// @todo getFiles does not complain when using an invalid directory …
48+
$files = $sftp->getFiles($dir);
49+
$files = array_filter($files, fn (string $file) => !preg_match('/^[.]+$/', $file));
50+
$io->section($dir);
51+
foreach ($files as $file) {
52+
$io->writeln($file);
53+
}
54+
}
55+
56+
return self::SUCCESS;
57+
}
58+
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\os2forms_fordelingskomponent\Drush\Commands;
6+
7+
use SF2900\SftpHelper;
8+
use Drupal\os2forms_fordelingskomponent\Helper\FordelingskomponentHelper;
9+
use Symfony\Component\Console\Attribute\AsCommand;
10+
use Symfony\Component\Console\Command\Command;
11+
use Symfony\Component\Console\Input\InputArgument;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
use Symfony\Component\Console\Style\SymfonyStyle;
15+
16+
// phpcs:disable Drupal.Commenting.ClassComment.Missing
17+
#[AsCommand(
18+
name: 'os2forms-fordelingskomponent:sftp:ls',
19+
description: 'List files on SFTP server',
20+
)]
21+
final class SftpLsCommand extends Command {
22+
23+
public function __construct(
24+
private readonly FordelingskomponentHelper $helper,
25+
) {
26+
parent::__construct();
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*
32+
* @see https://www.drush.org/13.x/commands/
33+
*/
34+
protected function configure(): void {
35+
$this
36+
->addArgument('dir', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'List of directory paths', [SftpHelper::INCOMING_FOLDER]);
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
protected function execute(InputInterface $input, OutputInterface $output): int {
43+
$io = new SymfonyStyle($input, $output);
44+
$sftp = $this->helper->sf2900()->sftp();
45+
$dirs = (array) $input->getArgument('dir');
46+
foreach ($dirs as $dir) {
47+
// @todo getFiles does not complain when using an invalid directory …
48+
$files = $sftp->getFiles($dir);
49+
$files = array_filter($files, fn (string $file) => !preg_match('/^[.]+$/', $file));
50+
$io->section($dir);
51+
foreach ($files as $file) {
52+
$io->writeln($file);
53+
}
54+
}
55+
56+
return self::SUCCESS;
57+
}
58+
59+
}

src/Helper/FordelingskomponentHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public static function isValidUuid(string $value): bool {
261261
/**
262262
* Get a singleton instance of SF2900.
263263
*/
264-
private function sf2900(): SF2900 {
264+
public function sf2900(): SF2900 {
265265
if (!isset($this->sf2900)) {
266266
$options = $this->getModuleConfig()->get('sf2900');
267267
$certificateKey = $this->keyRepository->getKey($options['certificate']);

src/Hook/Hooks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Hooks {
1010
/**
1111
* Implements hook_theme().
1212
*/
13-
public function theme(array $existing, string $type, string $theme, string $path) : array {
13+
public function theme(array $existing, string $type, string $theme, string $path): array {
1414
{
1515
return [
1616
'os2forms_fordelingskomponent_payload_preview' => [

0 commit comments

Comments
 (0)