Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalized white space in filenames #20

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"itk-dev/getorganized-api-client-php": "^1.2",
"itk-dev/getorganized-api-client-php": "^1.2.2",
"drupal/webform": "^6.2",
"drupal/advancedqueue": "^1.2",
"symfony/options-resolver": "^5.4 || ^6.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;

/**
* OS2Forms archive command.
*/
class ArchiveCommands extends DrushCommands {

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

/**
* A Drush command for archiving submission in GetOrganized.
*
* @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:]]/', ' ', trim($filename));
}

/**
Expand Down
Loading