diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 553418b2d3..44efeeaf1a 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -1479,28 +1479,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 fb9e95b96b..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\ORM\FieldType\DBHTMLText; -use SilverStripe\Core\Validation\ValidationResult; /** * @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,81 +34,4 @@ public function getClientConfig(): array ], ]); } - - /** - * Action handler for adding pages to a campaign - */ - public function addtocampaign(array $data, Form $form): HTTPResponse - { - $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 - */ - public function AddToCampaignForm($request) - { - // 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 - */ - public function getAddToCampaignForm($id) - { - // 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 29476014fb..9d1af1e877 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -1885,10 +1885,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' @@ -1922,10 +1918,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' @@ -1953,10 +1945,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' @@ -1983,10 +1971,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' @@ -2016,10 +2000,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 @@ -2030,10 +2010,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 @@ -2057,10 +2033,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