diff --git a/docs/migration-v3.md b/docs/migration-v3.md index b428defeb..a3fa39321 100644 --- a/docs/migration-v3.md +++ b/docs/migration-v3.md @@ -241,3 +241,66 @@ For example: } } ``` + +## Consume Script Positional Arguments Removed + +Pre- and post-consumption scripts no longer receive positional arguments. All information is +now passed exclusively via environment variables, which have been available since earlier versions. + +### Pre-consumption script + +Previously, the original file path was passed as `$1`. It is now only available as +`DOCUMENT_SOURCE_PATH`. + +**Before:** + +```bash +#!/usr/bin/env bash +# $1 was the original file path +process_document "$1" +``` + +**After:** + +```bash +#!/usr/bin/env bash +process_document "${DOCUMENT_SOURCE_PATH}" +``` + +### Post-consumption script + +Previously, document metadata was passed as positional arguments `$1` through `$8`: + +| Argument | Environment Variable Equivalent | +| -------- | ------------------------------- | +| `$1` | `DOCUMENT_ID` | +| `$2` | `DOCUMENT_FILE_NAME` | +| `$3` | `DOCUMENT_SOURCE_PATH` | +| `$4` | `DOCUMENT_THUMBNAIL_PATH` | +| `$5` | `DOCUMENT_DOWNLOAD_URL` | +| `$6` | `DOCUMENT_THUMBNAIL_URL` | +| `$7` | `DOCUMENT_CORRESPONDENT` | +| `$8` | `DOCUMENT_TAGS` | + +**Before:** + +```bash +#!/usr/bin/env bash +DOCUMENT_ID=$1 +CORRESPONDENT=$7 +TAGS=$8 +``` + +**After:** + +```bash +#!/usr/bin/env bash +# Use environment variables directly +echo "Document ${DOCUMENT_ID} from ${DOCUMENT_CORRESPONDENT} tagged: ${DOCUMENT_TAGS}" +``` + +### Action Required + +Update any pre- or post-consumption scripts that read `$1`, `$2`, etc. to use the +corresponding environment variables instead. Environment variables have been the preferred +option since v1.8.0. diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 6656a3d96..83bc832ce 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -313,7 +313,6 @@ class ConsumerPlugin( run_subprocess( [ settings.PRE_CONSUME_SCRIPT, - original_file_path, ], script_env, self.log, @@ -383,14 +382,6 @@ class ConsumerPlugin( run_subprocess( [ settings.POST_CONSUME_SCRIPT, - str(document.pk), - document.get_public_filename(), - os.path.normpath(document.source_path), - os.path.normpath(document.thumbnail_path), - reverse("document-download", kwargs={"pk": document.pk}), - reverse("document-thumb", kwargs={"pk": document.pk}), - str(document.correspondent), - str(",".join(document.tags.all().values_list("name", flat=True))), ], script_env, self.log, diff --git a/src/documents/tests/test_consumer.py b/src/documents/tests/test_consumer.py index 0ff415a5f..0ea714fc1 100644 --- a/src/documents/tests/test_consumer.py +++ b/src/documents/tests/test_consumer.py @@ -1328,7 +1328,7 @@ class PreConsumeTestCase(DirectoriesMixin, GetConsumerMixin, TestCase): environment = args[1] self.assertEqual(command[0], script.name) - self.assertEqual(command[1], str(self.test_file)) + self.assertEqual(len(command), 1) subset = { "DOCUMENT_SOURCE_PATH": str(c.input_doc.original_file), @@ -1478,11 +1478,7 @@ class PostConsumeTestCase(DirectoriesMixin, GetConsumerMixin, TestCase): environment = args[1] self.assertEqual(command[0], script.name) - self.assertEqual(command[1], str(doc.pk)) - self.assertEqual(command[5], f"/api/documents/{doc.pk}/download/") - self.assertEqual(command[6], f"/api/documents/{doc.pk}/thumb/") - self.assertEqual(command[7], "my_bank") - self.assertCountEqual(command[8].split(","), ["a", "b"]) + self.assertEqual(len(command), 1) subset = { "DOCUMENT_ID": str(doc.pk),