From bd37b90a3a5811555248ef616698efbe24466b11 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 28 Sep 2018 13:43:46 +1200 Subject: [PATCH] NEW: Add CMSMain.enable_archive_warning_message config This lets you disable this expensive message generation on larger sites where that is a problem. Speeding it up is obviously a preferred solution (or removing this feature until that is possible), but this config option is a simpler solution to the problem in the short term. --- code/Controllers/CMSMain.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index a21515d5..ffca5757 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -111,6 +111,14 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; + /** + * Should the archive warning message be dynamic based on the specific content? This is slow on larger sites and can be disabled. + * + * @config + * @var bool + */ + private static $enable_dynamic_archive_warning_message = true; + /** * Amount of results showing on a single page. * @@ -1409,6 +1417,14 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr */ protected function getArchiveWarningMessage($record) { + + $defaultMessage = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren', 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'); + + // Option to disable this feature as it is slow on large sites + if (!$this->config()->enable_dynamic_archive_warning_message) { + return $defaultMessage; + } + // Get all page's descendants $record->collateDescendants(true, $descendants); if (!$descendants) { @@ -1434,7 +1450,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr if (count($descendants) > 0 && $inChangeSets->count() > 0) { $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]); } elseif (count($descendants) > 0) { - $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildren', 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'); + $archiveWarningMsg = $defaultMessage; } elseif ($inChangeSets->count() > 0) { $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]); } else {