Skip to content

Commit

Permalink
API Remove silverstripe/campaign-admin integration support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 27, 2024
1 parent 7c5e243 commit c217d1b
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 161 deletions.
21 changes: 1 addition & 20 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?');
}
Expand Down
112 changes: 0 additions & 112 deletions code/Controllers/CMSPageEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@

namespace SilverStripe\CMS\Controllers;

use Page;
use SilverStripe\Admin\LeftAndMain;
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';
Expand All @@ -29,103 +16,4 @@ class CMSPageEditController extends CMSMain
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';

private static $ignore_menuitem = true;

private static $allowed_actions = [
'AddToCampaignForm',
];

public function getClientConfig(): array
{
return ArrayLib::array_merge_recursive(parent::getClientConfig(), [
'form' => [
'AddToCampaignForm' => [
'schemaUrl' => $this->Link('schema/AddToCampaignForm'),
],
],
]);
}

/**
* 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;
}
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"require": {
"php": "^8.3",
"silverstripe/admin": "^3",
"silverstripe/campaign-admin": "^3",
"silverstripe/framework": "^6",
"silverstripe/reports": "^6",
"silverstripe/siteconfig": "^6",
Expand Down
28 changes: 0 additions & 28 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c217d1b

Please sign in to comment.