From cca9225cfe4c6b1968e149b771e98ef2fa41d5a7 Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Tue, 12 Nov 2024 16:59:31 -0500 Subject: [PATCH] pkp/pkp-lib#10571 Move migration into v3.6 folder --- classes/emailTemplate/maps/Schema.php | 14 ----- .../I10403_EmailTemplateUserGroupAccess.php | 4 +- .../V3_6_0/PreflightCheckMigration.php | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+), 16 deletions(-) rename classes/migration/upgrade/{v3_5_0 => V3_6_0}/I10403_EmailTemplateUserGroupAccess.php (96%) create mode 100644 classes/migration/upgrade/V3_6_0/PreflightCheckMigration.php diff --git a/classes/emailTemplate/maps/Schema.php b/classes/emailTemplate/maps/Schema.php index 87e3024286f..d4e7688cf83 100644 --- a/classes/emailTemplate/maps/Schema.php +++ b/classes/emailTemplate/maps/Schema.php @@ -84,20 +84,6 @@ protected function mapByProperties(array $props, EmailTemplate $item, string $ma $output = []; $mailableClass = $mailableClass ?? Repo::mailable()->getMailableByEmailTemplate($item); - $assignedUserGroupsIds = []; - // some mailable are not found during some operations such as performing a search for templates. So ensure mailable exist before using - // if ($mailableClass) { - // $isUserGroupsAssignable = Repo::mailable()->isGroupsAssignableToTemplates($mailableClass); - // $assignedUserGroupsIds = Repo::emailTemplate()->getUserGroupsIdsAssignedToTemplate($item->getData('key'), Application::get()->getRequest()->getContext()->getId()); - // if (!$isUserGroupsAssignable) { - // $output['assignedUserGroupIds'] = []; - // } else { - // // Get the current user groups assigned to the template - // $output['assignedUserGroupIds'] = $assignedUserGroupsIds; - // } - // } - - foreach ($props as $prop) { switch ($prop) { case '_href': diff --git a/classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.php b/classes/migration/upgrade/V3_6_0/I10403_EmailTemplateUserGroupAccess.php similarity index 96% rename from classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.php rename to classes/migration/upgrade/V3_6_0/I10403_EmailTemplateUserGroupAccess.php index fb4b75a2e55..2c06d112c3d 100644 --- a/classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.php +++ b/classes/migration/upgrade/V3_6_0/I10403_EmailTemplateUserGroupAccess.php @@ -1,6 +1,6 @@ setFallbackVersion()) { + $this->_installer->log("A pre-flight check failed. The software was successfully upgraded to {$fallbackVersion} but could not be upgraded further (to " . $this->_installer->newVersion->getVersionString() . '). Check and correct the error, then try again.'); + } + throw $e; + } + } + + /** + * Rollback the migrations. + */ + public function down(): void + { + if ($fallbackVersion = $this->setFallbackVersion()) { + $this->_installer->log("An upgrade step failed! Fallback set to {$fallbackVersion}. Check and correct the error and try the upgrade again. We recommend restoring from backup, though you may be able to continue without doing so."); + // Prevent further downgrade migrations from executing. + $this->_installer->migrations = []; + } + } + + /** + * Store the fallback version in the database, permitting resumption of partial upgrades. + * + * @return ?string Fallback version, if one was identified + */ + protected function setFallbackVersion(): ?string + { + if ($fallbackVersion = $this->_attributes['fallback'] ?? null) { + $versionDao = DAORegistry::getDAO('VersionDAO'); /** @var \PKP\site\VersionDAO $versionDao */ + $versionDao->insertVersion(\PKP\site\Version::fromString($fallbackVersion)); + return $fallbackVersion; + } + return null; + } +}