From 91e153492b507690af524ccf179f6c9e63e52588 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 21 Nov 2024 11:26:53 +1300 Subject: [PATCH] API Remove silverstripe/campaign-admin integration support --- code/Controllers/CMSMain.php | 21 +---- code/Controllers/CMSPageEditController.php | 102 --------------------- composer.json | 1 - tests/php/Model/SiteTreeTest.php | 28 ------ 4 files changed, 1 insertion(+), 151 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 644b3ec05c..a63fcdd807 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -1481,28 +1481,9 @@ protected function getArchiveWarningMessage($record) // Get the IDs of all changeset including at least one of the pages. $descendants[] = $record->ID; - $inChangeSetIDs = ChangeSetItem::get()->filter([ - 'ObjectID' => $descendants, - 'ObjectClass' => SiteTree::class - ])->column('ChangeSetID'); - // Count number of affected change set - $affectedChangeSetCount = 0; - if (count($inChangeSetIDs ?? []) > 0) { - $affectedChangeSetCount = ChangeSet::get() - ->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN]) - ->count(); - } - - $numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount); - $numCampaigns = mb_strtolower($numCampaigns ?? ''); - - if (count($descendants ?? []) > 0 && $affectedChangeSetCount > 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) { + if (count($descendants ?? []) > 0) { $archiveWarningMsg = $defaultMessage; - } elseif ($affectedChangeSetCount > 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 { $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarning', 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'); } diff --git a/code/Controllers/CMSPageEditController.php b/code/Controllers/CMSPageEditController.php index 2573f70678..5c523bd32a 100644 --- a/code/Controllers/CMSPageEditController.php +++ b/code/Controllers/CMSPageEditController.php @@ -2,25 +2,14 @@ namespace SilverStripe\CMS\Controllers; -use Page; -use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\ModalController; -use SilverStripe\CampaignAdmin\AddToCampaignHandler; -use SilverStripe\CMS\Model\SiteTree; -use SilverStripe\Control\Controller; -use SilverStripe\Control\HTTPRequest; -use SilverStripe\Control\HTTPResponse; -use SilverStripe\Forms\Form; use SilverStripe\Core\ArrayLib; -use SilverStripe\Core\Validation\ValidationResult; -use SilverStripe\Dev\Deprecation; /** * @package cms */ class CMSPageEditController extends CMSMain { - private static $url_segment = 'pages/edit'; private static $url_rule = '/$Action/$ID/$OtherID'; @@ -31,18 +20,11 @@ class CMSPageEditController extends CMSMain private static $ignore_menuitem = true; - private static $allowed_actions = [ - 'AddToCampaignForm', - ]; - public function getClientConfig(): array { $modalController = ModalController::singleton(); return ArrayLib::array_merge_recursive(parent::getClientConfig(), [ 'form' => [ - 'AddToCampaignForm' => [ - 'schemaUrl' => $this->Link('schema/AddToCampaignForm'), - ], 'editorInternalLink' => [ 'schemaUrl' => $modalController->Link('schema/editorInternalLink'), ], @@ -52,88 +34,4 @@ public function getClientConfig(): array ], ]); } - - /** - * Action handler for adding pages to a campaign - * - * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it - */ - public function addtocampaign(array $data, Form $form): HTTPResponse - { - Deprecation::noticeWithNoReplacment('5.4.0'); - $id = $data['ID']; - $record = \Page::get()->byID($id); - - $handler = AddToCampaignHandler::create($this, $record); - $response = $handler->addToCampaign($record, $data); - $message = $response->getBody(); - if (empty($message)) { - return $response; - } - - if ($this->getSchemaRequested()) { - // Send extra "message" data with schema response - $extraData = ['message' => $message]; - $schemaId = Controller::join_links($this->Link('schema/AddToCampaignForm'), $id); - return $this->getSchemaResponse($schemaId, $form, null, $extraData); - } - - return $response; - } - - /** - * Url handler for add to campaign form - * - * @param HTTPRequest $request - * @return Form - * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it - */ - public function AddToCampaignForm($request) - { - Deprecation::noticeWithNoReplacment('5.4.0'); - // Get ID either from posted back value, or url parameter - $id = $request->param('ID') ?: $request->postVar('ID'); - return $this->getAddToCampaignForm($id); - } - - /** - * @param int $id - * @return Form - * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it - */ - public function getAddToCampaignForm($id) - { - Deprecation::noticeWithNoReplacment('5.4.0'); - // Get record-specific fields - $record = SiteTree::get()->byID($id); - - if (!$record) { - $this->httpError(404, _t( - __CLASS__ . '.ErrorNotFound', - 'That {Type} couldn\'t be found', - '', - ['Type' => Page::singleton()->i18n_singular_name()] - )); - return null; - } - if (!$record->canView()) { - $this->httpError(403, _t( - __CLASS__.'.ErrorItemPermissionDenied', - 'It seems you don\'t have the necessary permissions to add {ObjectTitle} to a campaign', - '', - ['ObjectTitle' => Page::singleton()->i18n_singular_name()] - )); - return null; - } - - $handler = AddToCampaignHandler::create($this, $record); - $form = $handler->Form($record); - - $form->setValidationResponseCallback(function (ValidationResult $errors) use ($form, $id) { - $schemaId = Controller::join_links($this->Link('schema/AddToCampaignForm'), $id); - return $this->getSchemaResponse($schemaId, $form, $errors); - }); - - return $form; - } } diff --git a/composer.json b/composer.json index 2b49f8d0d9..fb220d11d0 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "require": { "php": "^8.3", "silverstripe/admin": "^3", - "silverstripe/campaign-admin": "^3", "silverstripe/framework": "^6", "silverstripe/reports": "^6", "silverstripe/siteconfig": "^6", diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index ef8c92859e..1de289eee4 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -1763,10 +1763,6 @@ public function testGetCMSActions() $actions->fieldByName('ActionMenus.MoreOptions.action_archive'), 'archive action present for a saved draft page' ); - $this->assertNotNull( - $actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'), - 'addtocampaign action present for a saved draft page' - ); $this->assertNull( $actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'), 'no unpublish action present for a saved draft page' @@ -1800,10 +1796,6 @@ public function testGetCMSActions() $actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'), 'no unpublish action present for a published page' ); - $this->assertNotNull( - $actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'), - 'addtocampaign action present for a published page' - ); $this->assertNull( $actions->fieldByName('MajorActions.action_restore'), 'no restore action present for a published page' @@ -1831,10 +1823,6 @@ public function testGetCMSActions() $actions->fieldByName('ActionMenus.MoreOptions.action_rollback'), 'rollback action present for a changed published page' ); - $this->assertNotNull( - $actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'), - 'addtocampaign action present for a changed published page' - ); $this->assertNull( $actions->fieldByName('MajorActions.action_restore'), 'no restore action present for a changed published page' @@ -1861,10 +1849,6 @@ public function testGetCMSActions() $actions->fieldByName('ActionMenus.MoreOptions.action_rollback'), 'no rollback action present for a archived page' ); - $this->assertNull( - $actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'), - 'no addtocampaign action present for a archived page' - ); $this->assertNotNull( $actions->fieldByName('MajorActions.action_restore'), 'restore action present for a archived page' @@ -1894,10 +1878,6 @@ public function testGetCMSActionsWithoutForms() $actions->fieldByName('ActionMenus.MoreOptions.action_archive')->getForm(), 'archive action has no form when page is draft' ); - $this->assertEmpty( - $actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(), - 'addtocampaign action has no form when page is draft' - ); // END DRAFT // BEGIN PUBLISHED @@ -1908,10 +1888,6 @@ public function testGetCMSActionsWithoutForms() $actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(), 'rollback action has no form when page is published' ); - $this->assertEmpty( - $actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(), - 'addtocampaign action has no form when page is published' - ); // END PUBLISHED // BEGIN DRAFT AFTER PUBLISHED @@ -1935,10 +1911,6 @@ public function testGetCMSActionsWithoutForms() $actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(), 'rollback action has no form when page is draft after published' ); - $this->assertEmpty( - $actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(), - 'addtocampaign action has no form when page is draft after published' - ); // END DRAFT AFTER PUBLISHED // BEGIN ARCHIVED