From 542ba3bf010430b0505cb73912fec7fc728cc00b Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Mon, 31 Mar 2025 15:49:33 +0200 Subject: [PATCH] #18 Add ignore_missing option on FileFetchTask that allow throwing Exception when file(s) not found. --- docs/reference/tasks/01-FileFetchTask.md | 15 +++++++++------ src/Task/FileFetchTask.php | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/reference/tasks/01-FileFetchTask.md b/docs/reference/tasks/01-FileFetchTask.md index a158c9f..4ad65e3 100644 --- a/docs/reference/tasks/01-FileFetchTask.md +++ b/docs/reference/tasks/01-FileFetchTask.md @@ -27,12 +27,13 @@ Filename of copied file. Options ------- -| Code | Type | Required | Default | Description | -|--------------------------|:----------:|:---------:|:---------:|----------------------------------------------------------------------------------------------------------------------------------------------| -| `source_filesystem` | `string` | **X** | | The source flysystem/storage.
See config/packages/flysystem.yaml to see configured flysystem/storages. | -| `destination_filesystem` | `string` | **X** | | The source flysystem/storage.
See config/packages/flysystem.yaml to see configured flysystem/storages. | -| `file_pattern` | `string` | | null | The file_pattern used in preg_match to match into `source_filesystem` list of files. If not set try to use input as strict filename to match | -| `remove_source` | `bool` | | false | If true delete source file after copy | +| Code | Type | Required | Default | Description | +|--------------------------|:--------:|:--------:|:-------:|----------------------------------------------------------------------------------------------------------------------------------------------| +| `source_filesystem` | `string` | **X** | | The source flysystem/storage.
See config/packages/flysystem.yaml to see configured flysystem/storages. | +| `destination_filesystem` | `string` | **X** | | The source flysystem/storage.
See config/packages/flysystem.yaml to see configured flysystem/storages. | +| `file_pattern` | `string` | | null | The file_pattern used in preg_match to match into `source_filesystem` list of files. If not set try to use input as strict filename to match | +| `remove_source` | `bool` | | false | If true delete source file after copy | +| `ignore_missing` | `bool` | | true | Ignore property accessor errors for this source | Examples @@ -43,6 +44,7 @@ Examples - copy all .csv files from 'storage.source' to 'storage.destination' - remove .csv from 'storage.source' after copy - output will be filename of copied files + - throw Exception when file(s) not found ```yaml # Task configuration level code: @@ -52,6 +54,7 @@ code: destination_filesystem: 'storage.destination' file_pattern: '/.csv$/' remove_source: true + ignore_missing: false ``` * Simple fetch process configuration to cipy a specific file from --input option via
```bin/console cleverage:process:execute my_custom_process --input=foobar.csv -vv``` diff --git a/src/Task/FileFetchTask.php b/src/Task/FileFetchTask.php index b915e67..0a57844 100644 --- a/src/Task/FileFetchTask.php +++ b/src/Task/FileFetchTask.php @@ -127,6 +127,9 @@ protected function findMatchingFiles(ProcessState $state): void $this->matchingFiles[] = $input; } } + if ([] === $this->matchingFiles && !$this->getOption($state, 'ignore_missing')) { + throw new \UnexpectedValueException('File(s) not found in source filesystem'); + } } /** @@ -166,5 +169,8 @@ protected function configureOptions(OptionsResolver $resolver): void $resolver->setDefault('remove_source', false); $resolver->setAllowedTypes('remove_source', 'boolean'); + + $resolver->setDefault('ignore_missing', true); + $resolver->setAllowedTypes('ignore_missing', 'boolean'); } }