From 3727f64e692714d8e893d7f50e8c72e210729e55 Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Tue, 19 Jul 2022 13:04:41 +1200 Subject: [PATCH] Add migration dev task for existing Jobs --- docs/en/configuration.md | 13 +++++ src/Tasks/EmbargoExpiryMigrationTask.php | 73 ++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/Tasks/EmbargoExpiryMigrationTask.php diff --git a/docs/en/configuration.md b/docs/en/configuration.md index 7d88e270..420edccc 100644 --- a/docs/en/configuration.md +++ b/docs/en/configuration.md @@ -31,6 +31,19 @@ See the Security section below for more details. You can optionally add the [Embargy & Expiry](https://github.com/silverstripe-terraformers/silverstripe-embargo-expiry) module to your project to allow changes to be published (and/or unpublished) at future dates. +**Note:** You will need to use version 1.2.1 or greater. + +#### Migrating from an older Workflow version + +If you have an existing project which used the `WorkflowEmbargoExpiryExtension`, then you will need to go through a +couple of migration steps. + +1) Update usages of `WorkflowEmbargoExpiryExtension` to `EmbargoExpiryExtension` (from the Terraformers module) +2) Run the `EmbargoExpiryMigrationTask` to migrate over any existing Workflow jobs to the new Terraformers' jobs + * This task will require you to define some basic configuration where you tell us what classes you have applied the + `EmbargoExpiryExtension` to. Other than that, you just need to run it + * See the class for more info + ### Sending reminder emails The workflow engine can send out email reminders if a workflow has been open for longer diff --git a/src/Tasks/EmbargoExpiryMigrationTask.php b/src/Tasks/EmbargoExpiryMigrationTask.php new file mode 100644 index 00000000..6c0a4f9b --- /dev/null +++ b/src/Tasks/EmbargoExpiryMigrationTask.php @@ -0,0 +1,73 @@ +config()->get('classes') as $className) { + if (!DataObject::singleton($className)->hasExtension(EmbargoExpiryExtension::class)) { + continue; + } + + /** @var DataList|DataObject[]|EmbargoExpiryExtension[] $dataObjects */ + $dataObjects = DataObject::get($className); + + foreach ($dataObjects as $dataObject) { + $updated = false; + + if ($dataObject->PublishOnDate) { + $dataObject->createOrUpdatePublishJob(strtotime($dataObject->PublishOnDate)); + + $updated = true; + } + + if ($dataObject->UnPublishOnDate) { + $dataObject->createOrUpdateUnPublishJob(strtotime($dataObject->UnPublishOnDate)); + + $updated = true; + } + + if ($updated) { + $dataObject->write(); + } + } + } + } + +}