Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1' ]
php-versions: [ '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1' ]
php-versions: [ '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1' ]
php-versions: [ '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ about writing changes to this log.

## [Unreleased]

## [1.4.0] 18.12.2024

* Normalized white space in filename.
* Added command for archiving submission.

## [1.3.1] 09.12.2024

* Added webform ID to audit logging messages.
Expand Down Expand Up @@ -51,7 +56,8 @@ about writing changes to this log.

## [1.0.0] 29.03.2023

[Unreleased]: https://github.com/OS2Forms/os2forms_get_organized/compare/1.3.1...HEAD
[Unreleased]: https://github.com/OS2Forms/os2forms_get_organized/compare/1.4.0...HEAD
[1.4.0]: https://github.com/OS2Forms/os2forms_get_organized/compare/1.3.1...1.4.0
[1.3.1]: https://github.com/OS2Forms/os2forms_get_organized/compare/1.3.0...1.3.1
[1.3.0]: https://github.com/OS2Forms/os2forms_get_organized/compare/1.2.0...1.3.0
[1.2.0]: https://github.com/OS2Forms/os2forms_get_organized/compare/1.1.5...1.2.0
Expand Down
7 changes: 7 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
drush_command_example.commands:
class: \Drupal\os2forms_get_organized\Commands\ArchiveCommands
tags:
- { name: drush.command }
arguments:
- '@Drupal\os2forms_get_organized\Helper\ArchiveHelper'
60 changes: 60 additions & 0 deletions src/Commands/ArchiveCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Drupal\os2forms_get_organized\Commands;

use Drupal\os2forms_get_organized\Helper\ArchiveHelper;
use Drupal\webform\Entity\WebformSubmission;
use Drush\Commands\DrushCommands;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* Drush command file.
*/
class ArchiveCommands extends DrushCommands {

public function __construct(
private readonly ArchiveHelper $archiveHelper,
) {
parent::__construct();
}

/**
* A custom Drush command to displays the given text.
*
* @param string $submissionId
* The submission id.
* @param string $handlerId
* The handler id.
*
* @command os2forms:get-organized:archive
*/
public function archive(string $submissionId, string $handlerId): void {

$io = new SymfonyStyle($this->input(), $this->output());

/** @var \Drupal\webform\WebformSubmissionInterface|null $submission */
$submission = WebformSubmission::load($submissionId);

if (!$submission) {
$io->error(sprintf('Webform submission with id %s could not be found.', $submissionId));

return;
}

try {
$handler = $submission->getWebform()->getHandler($handlerId);
}
catch (\Exception $e) {
$io->error($e->getMessage());

return;
}

$handlerConfig = $handler->getConfiguration();

$this->archiveHelper->archive($submissionId, $handlerConfig['settings']);

$io->success(sprintf('Successfully archived webform submission with id %s ', $submissionId));
}

}
5 changes: 4 additions & 1 deletion src/Helper/ArchiveHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,10 @@ private function computeGetOrganizedFilename(string $filename, WebformSubmission
$position = strrpos($filename, '.' . $fileExtension);

// Inject the webform label and submission number at found position.
return substr_replace($filename, '-' . $webformLabel . '-' . $submissionNumber, $position, 0);
$filename = substr_replace($filename, '-' . $webformLabel . '-' . $submissionNumber, $position, 0);

// Normalize white space.
return preg_replace('/[[:space:]]/', ' ', $filename);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be worth trimming the value to get rid of any leading and trailing whitespace.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed in a384e2a!

}

/**
Expand Down
Loading