API Consolidate "Delete from draft" and "Archive" actions into a consistent behaviour (#1653)

API Update to support new versioned dataobject behaviour
This commit is contained in:
Damian Mooyman 2016-10-25 13:22:31 +13:00 committed by Sam Minnée
parent 06c8402f03
commit d54ae8bb26
12 changed files with 225 additions and 391 deletions

View File

@ -74,22 +74,20 @@ onclick:function g(t){var e=this.parents("form:first"),n=e.find(":input[name=Ver
return i=r["default"].sprintf(r["default"]._t("CMSMain.Archive"),n),!!confirm(i)&&this._super(t)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_restore").entwine({onclick:function _(t){var e=this.parents("form:first"),n=e.find(":input[name=Version]").val(),i="",a=this.data("toRoot")
return i=r["default"].sprintf(r["default"]._t(a?"CMSMain.RestoreToRoot":"CMSMain.Restore"),n),!!confirm(i)&&this._super(t)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_delete").entwine({onclick:function b(t){
return i=r["default"].sprintf(r["default"]._t(a?"CMSMain.RestoreToRoot":"CMSMain.Restore"),n),!!confirm(i)&&this._super(t)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_unpublish").entwine({onclick:function b(t){
var e=this.parents("form:first"),n=e.find(":input[name=Version]").val(),i=""
return i=r["default"].sprintf(r["default"]._t("CMSMain.DeleteFromDraft"),n),!!confirm(i)&&this._super(t)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_unpublish").entwine({onclick:function w(t){
var e=this.parents("form:first"),n=e.find(":input[name=Version]").val(),i=""
return i=r["default"].sprintf(r["default"]._t("CMSMain.Unpublish"),n),!!confirm(i)&&this._super(t)}}),t(".cms-edit-form.changed").entwine({onmatch:function C(t){this.find("button[name=action_save]").button("option","showingAlternate",!0),
this.find("button[name=action_publish]").button("option","showingAlternate",!0),this._super(t)},onunmatch:function F(t){var e=this.find("button[name=action_save]")
return i=r["default"].sprintf(r["default"]._t("CMSMain.Unpublish"),n),!!confirm(i)&&this._super(t)}}),t(".cms-edit-form.changed").entwine({onmatch:function w(t){this.find("button[name=action_save]").button("option","showingAlternate",!0),
this.find("button[name=action_publish]").button("option","showingAlternate",!0),this._super(t)},onunmatch:function C(t){var e=this.find("button[name=action_save]")
e.data("button")&&e.button("option","showingAlternate",!1)
var n=this.find("button[name=action_publish]")
n.data("button")&&n.button("option","showingAlternate",!1),this._super(t)}}),t(".cms-edit-form .btn-toolbar button[name=action_publish]").entwine({onbuttonafterrefreshalternate:function P(){this.button("option","showingAlternate")?this.addClass("ss-ui-action-constructive"):this.removeClass("ss-ui-action-constructive")
n.data("button")&&n.button("option","showingAlternate",!1),this._super(t)}}),t(".cms-edit-form .btn-toolbar button[name=action_publish]").entwine({onbuttonafterrefreshalternate:function F(){this.button("option","showingAlternate")?this.addClass("ss-ui-action-constructive"):this.removeClass("ss-ui-action-constructive")
}}),t(".cms-edit-form .btn-toolbar button[name=action_save]").entwine({onbuttonafterrefreshalternate:function T(){this.button("option","showingAlternate")?this.addClass("ss-ui-action-constructive"):this.removeClass("ss-ui-action-constructive")
}}),t(".cms-edit-form .btn-toolbar button[name=action_save]").entwine({onbuttonafterrefreshalternate:function P(){this.button("option","showingAlternate")?this.addClass("ss-ui-action-constructive"):this.removeClass("ss-ui-action-constructive")
}}),t('.cms-edit-form.CMSPageSettingsController input[name="ParentType"]:checked').entwine({onmatch:function S(){this.redraw(),this._super()},onunmatch:function k(){this._super()},redraw:function x(){var e=t(".cms-edit-form.CMSPageSettingsController #Form_EditForm_ParentID_Holder")
}}),t('.cms-edit-form.CMSPageSettingsController input[name="ParentType"]:checked').entwine({onmatch:function T(){this.redraw(),this._super()},onunmatch:function S(){this._super()},redraw:function x(){var e=t(".cms-edit-form.CMSPageSettingsController #Form_EditForm_ParentID_Holder")
"Form_EditForm_ParentType_root"==t(this).attr("id")?e.slideUp():e.slideDown()},onclick:function E(){this.redraw()}}),"Form_EditForm_ParentType_root"==t('.cms-edit-form.CMSPageSettingsController input[name="ParentType"]:checked').attr("id")&&t(".cms-edit-form.CMSPageSettingsController #Form_EditForm_ParentID_Holder").hide()
"Form_EditForm_ParentType_root"==t(this).attr("id")?e.slideUp():e.slideDown()},onclick:function k(){this.redraw()}}),"Form_EditForm_ParentType_root"==t('.cms-edit-form.CMSPageSettingsController input[name="ParentType"]:checked').attr("id")&&t(".cms-edit-form.CMSPageSettingsController #Form_EditForm_ParentID_Holder").hide()
})},function(t,e){t.exports=i18n},function(t,e,n){"use strict"
function i(t){return t&&t.__esModule?t:{"default":t}}var a=n(2),o=i(a)

View File

@ -347,33 +347,6 @@ $.entwine('ss', function($){
}
});
/**
* Class: .cms-edit-form .btn-toolbar #Form_EditForm_action_delete
*
* Informing the user about the delete from draft action while requiring confirmation
*/
$('.cms-edit-form .btn-toolbar #Form_EditForm_action_delete').entwine({
/**
* Function: onclick
*
* Parameters:
* (Event) e
*/
onclick: function(e) {
var form = this.parents('form:first'), version = form.find(':input[name=Version]').val(), message = '';
message = i18n.sprintf(
i18n._t('CMSMain.DeleteFromDraft'),
version
);
if(confirm(message)) {
return this._super(e);
} else {
return false;
}
}
});
/**
* Class: .cms-edit-form .btn-toolbar #Form_EditForm_action_unpublish
* Informing the user about the unpublish action while requiring confirmation

View File

@ -2,30 +2,24 @@
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\Admin\CMSBatchAction;
use SilverStripe\ORM\SS_List;
use SilverStripe\Admin\CMSBatchAction;
/**
* Archives a page, removing it from both live and stage
* Delete items batch action.
*/
class CMSBatchAction_Archive extends CMSBatchAction
{
public function getActionTitle()
{
return _t('CMSBatchActions.ARCHIVE', 'Archive');
class CMSBatchAction_Archive extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchAction_Archive.TITLE', 'Unpublish and archive');
}
public function run(SS_List $pages)
{
public function run(SS_List $pages) {
return $this->batchaction($pages, 'doArchive',
_t('CMSBatchActions.ARCHIVED_PAGES', 'Archived %d pages')
_t('CMSBatchAction_Archive.RESULT', 'Deleted %d pages from draft and live, and sent them to the archive')
);
}
public function applicablePages($ids)
{
return $this->applicablePagesHelper($ids, 'canArchive', true, true);
public function applicablePages($ids) {
return $this->applicablePagesHelper($ids, 'canArchive');
}
}

View File

@ -1,52 +0,0 @@
<?php
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Admin\CMSBatchAction;
/**
* Delete items batch action.
*/
class CMSBatchAction_Delete extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchActions.DELETE_DRAFT_PAGES', 'Delete from draft site');
}
public function run(SS_List $pages) {
$status = array(
'modified'=>array(),
'deleted'=>array(),
'error'=>array()
);
foreach($pages as $page) {
$id = $page->ID;
// Perform the action
if($page->canDelete()) $page->delete();
else $status['error'][$page->ID] = true;
// check to see if the record exists on the live site,
// if it doesn't remove the tree node
$liveRecord = Versioned::get_one_by_stage( 'SilverStripe\\CMS\\Model\\SiteTree', 'Live', array(
'"SiteTree"."ID"' => $id
));
if($liveRecord) {
$status['modified'][$liveRecord->ID] = array(
'TreeTitle' => $liveRecord->TreeTitle,
);
} else {
$status['deleted'][$id] = array();
}
}
return $this->response(_t('CMSBatchActions.DELETED_DRAFT_PAGES', 'Deleted %d pages from draft site, %d failures'), $status);
}
public function applicablePages($ids) {
return $this->applicablePagesHelper($ids, 'canDelete', true, false);
}
}

View File

@ -6,6 +6,10 @@ use SilverStripe\Admin\AdminRootController;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\Admin\CMSPreviewable;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Unpublish;
use SilverStripe\CMS\Model\CurrentPageIdentifier;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
@ -82,9 +86,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
private static $menu_priority = 10;
private static $tree_class = "SilverStripe\\CMS\\Model\\SiteTree";
private static $tree_class = SiteTree::class;
private static $subitem_class = "SilverStripe\\Security\\Member";
private static $subitem_class = Member::class;
private static $session_namespace = 'SilverStripe\\CMS\\Controllers\\CMSMain';
@ -146,11 +150,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
Requirements::customCSS($this->generatePageIconsCss());
Requirements::add_i18n_javascript(CMS_DIR . '/client/lang', false, true);
CMSBatchActionHandler::register('publish', 'SilverStripe\\CMS\\BatchActions\\CMSBatchAction_Publish');
CMSBatchActionHandler::register('unpublish', 'SilverStripe\\CMS\\BatchActions\\CMSBatchAction_Unpublish');
CMSBatchActionHandler::register('delete', 'SilverStripe\\CMS\\BatchActions\\CMSBatchAction_Delete');
CMSBatchActionHandler::register('archive', 'SilverStripe\\CMS\\BatchActions\\CMSBatchAction_Archive');
CMSBatchActionHandler::register('restore', 'SilverStripe\\CMS\\BatchActions\\CMSBatchAction_Restore');
CMSBatchActionHandler::register('restore', CMSBatchAction_Restore::class);
CMSBatchActionHandler::register('archive', CMSBatchAction_Archive::class);
CMSBatchActionHandler::register('unpublish', CMSBatchAction_Unpublish::class);
CMSBatchActionHandler::register('publish', CMSBatchAction_Publish::class);
}
public function index($request) {
@ -324,8 +327,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
*/
public function SiteTreeAsUL() {
// Pre-cache sitetree version numbers for querying efficiency
Versioned::prepopulate_versionnumber_cache("SilverStripe\\CMS\\Model\\SiteTree", "Stage");
Versioned::prepopulate_versionnumber_cache("SilverStripe\\CMS\\Model\\SiteTree", "Live");
Versioned::prepopulate_versionnumber_cache(SiteTree::class, "Stage");
Versioned::prepopulate_versionnumber_cache(SiteTree::class, "Live");
$html = $this->getSiteTreeFor($this->stat('tree_class'));
$this->extend('updateSiteTreeAsUL', $html);
@ -1114,7 +1117,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
$id = (int) $data['ID'];
$restoredPage = Versioned::get_latest_version("SilverStripe\\CMS\\Model\\SiteTree", $id);
$restoredPage = Versioned::get_latest_version(SiteTree::class, $id);
if(!$restoredPage) {
throw new HTTPResponse_Exception("SiteTree #$id not found", 400);
}
@ -1401,7 +1404,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$id = (int)$data['ID'];
/** @var SiteTree $restoredPage */
$restoredPage = Versioned::get_latest_version("SilverStripe\\CMS\\Model\\SiteTree", $id);
$restoredPage = Versioned::get_latest_version(SiteTree::class, $id);
if(!$restoredPage) {
return new HTTPResponse("SiteTree #$id not found", 400);
}

View File

@ -366,7 +366,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
// Traverse down the remaining URL segments and grab the relevant SiteTree objects.
foreach($parts as $segment) {
$next = DataObject::get_one('SilverStripe\\CMS\\Model\\SiteTree', array(
$next = DataObject::get_one(self::class, array(
'"SiteTree"."URLSegment"' => $segment,
'"SiteTree"."ParentID"' => $sitetree->ID
),
@ -1722,7 +1722,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
// Check existence
$existingPage = DataObject::get_one('SilverStripe\\CMS\\Model\\SiteTree', $filter);
$existingPage = DataObject::get_one(self::class, $filter);
if ($existingPage) return false;
return !($existingPage);
@ -1758,7 +1758,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* @return string
*/
public function getStageURLSegment() {
$stageRecord = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', Versioned::DRAFT, array(
$stageRecord = Versioned::get_one_by_stage(self::class, Versioned::DRAFT, array(
'"SiteTree"."ID"' => $this->ID
));
return ($stageRecord) ? $stageRecord->URLSegment : null;
@ -1770,7 +1770,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* @return string
*/
public function getLiveURLSegment() {
$liveRecord = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', Versioned::LIVE, array(
$liveRecord = Versioned::get_one_by_stage(self::class, Versioned::LIVE, array(
'"SiteTree"."ID"' => $this->ID
));
return ($liveRecord) ? $liveRecord->URLSegment : null;
@ -2068,7 +2068,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
"root" => _t("SiteTree.PARENTTYPE_ROOT", "Top-level page"),
"subpage" => _t("SiteTree.PARENTTYPE_SUBPAGE", "Sub-page underneath a parent page"),
)),
$parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SilverStripe\\CMS\\Model\\SiteTree', 'ID', 'MenuTitle')
$parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), self::class, 'ID', 'MenuTitle')
),
$visibility = new FieldGroup(
new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')),
@ -2211,11 +2211,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* @return FieldList The available actions for this page.
*/
public function getCMSActions() {
$existsOnLive = $this->isPublished();
// Get status of page
$isOnDraft = $this->isOnDraft();
$isPublished = $this->isPublished();
$stagesDiffer = $this->stagesDiffer(Versioned::DRAFT, Versioned::LIVE);
// Major actions appear as buttons immediately visible as page actions.
$majorActions = CompositeField::create()
->setName('MajorActions');
$majorActions = CompositeField::create()->setName('MajorActions');
$majorActions->setFieldHolderTemplate(get_class($majorActions) . '_holder_buttongroup');
// Minor options are hidden behind a drop-up and appear as links (although they are still FormActions).
@ -2228,39 +2230,38 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$rootTabSet->addExtraClass('ss-ui-action-tabset action-menus noborder');
// Render page information into the "more-options" drop-up, on the top.
$live = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', Versioned::LIVE, array(
'"SiteTree"."ID"' => $this->ID
));
$liveRecord = Versioned::get_by_stage(self::class, Versioned::LIVE)->byID($this->ID);
$infoTemplate = SSViewer::get_templates_by_class(static::class, '_Information', self::class);
$moreOptions->push(
new LiteralField('Information',
$this->customise(array(
'Live' => $live,
'ExistsOnLive' => $existsOnLive
'Live' => $liveRecord,
'ExistsOnLive' => $isPublished
))->renderWith($infoTemplate)
)
);
$moreOptions->push(AddToCampaignHandler_FormAction::create());
// "readonly"/viewing version that isn't the current version of the record
$stageOrLiveRecord = Versioned::get_one_by_stage(static::class, Versioned::get_stage(), array(
'"SiteTree"."ID"' => $this->ID
));
if($stageOrLiveRecord && $stageOrLiveRecord->Version != $this->Version) {
$moreOptions->push(FormAction::create('email', _t('CMSMain.EMAIL', 'SilverStripe\\Control\\Email\\Email')));
$stageRecord = Versioned::get_by_stage(static::class, Versioned::DRAFT)->byID($this->ID);
/** @skipUpgrade */
if($stageRecord && $stageRecord->Version != $this->Version) {
$moreOptions->push(FormAction::create('email', _t('CMSMain.EMAIL', 'Email')));
$moreOptions->push(FormAction::create('rollback', _t('CMSMain.ROLLBACK', 'Roll back to this version')));
$actions = new FieldList(array($majorActions, $rootTabSet));
// getCMSActions() can be extended with updateCMSActions() on a extension
$this->extend('updateCMSActions', $actions);
return $actions;
}
if($this->isPublished() && $this->canPublish() && $this->isOnDraft() && $this->canUnpublish()) {
// "unpublish"
// Check permissions
$canPublish = $this->canPublish();
$canUnpublish = $this->canUnpublish();
$canEdit = $this->canEdit();
// "unpublish"
if($isPublished && $canPublish && $isOnDraft && $canUnpublish) {
$moreOptions->push(
FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete')
->setDescription(_t('SiteTree.BUTTONUNPUBLISHDESC', 'Remove this page from the published site'))
@ -2268,78 +2269,69 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
);
}
if($this->stagesDiffer(Versioned::DRAFT, Versioned::LIVE) && $this->isOnDraft()) {
if($this->isPublished() && $this->canEdit()) {
// "rollback"
$moreOptions->push(
FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'), 'delete')
->setDescription(_t('SiteTree.BUTTONCANCELDRAFTDESC', 'Delete your draft and revert to the currently published page'))
);
}
// "rollback"
if($isOnDraft && $isPublished && $canEdit && $stagesDiffer) {
$moreOptions->push(
FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'))
->setDescription(_t(
'SiteTree.BUTTONCANCELDRAFTDESC',
'Delete your draft and revert to the currently published page'
))
);
}
if($this->canEdit()) {
if(!$this->isOnDraft()) {
// The usual major actions are not available, so we provide alternatives here.
if($existsOnLive) {
// "restore"
$majorActions->push(FormAction::create('revert',_t('CMSMain.RESTORE','Restore')));
if($this->canDelete() && $this->canUnpublish()) {
// "delete from live"
$majorActions->push(
FormAction::create('deletefromlive',_t('CMSMain.DELETEFP','Delete'))
->addExtraClass('ss-ui-action-destructive')
);
}
} else {
// Determine if we should force a restore to root (where once it was a subpage)
$restoreToRoot = $this->isParentArchived();
// "restore"
$title = $restoreToRoot
? _t('CMSMain.RESTORE_TO_ROOT','Restore draft at top level')
: _t('CMSMain.RESTORE','Restore draft');
$description = $restoreToRoot
? _t('CMSMain.RESTORE_TO_ROOT_DESC','Restore the archived version to draft as a top level page')
: _t('CMSMain.RESTORE_DESC', 'Restore the archived version to draft');
$majorActions->push(
FormAction::create('restore', $title)
->setDescription($description)
->setAttribute('data-to-root', $restoreToRoot)
->setAttribute('data-icon', 'decline')
);
}
} else {
if($this->canDelete()) {
// delete
$moreOptions->push(
FormAction::create('delete',_t('CMSMain.DELETE','Delete draft'))
->addExtraClass('delete ss-ui-action-destructive')
);
}
if($this->canArchive()) {
// "archive"
$moreOptions->push(
FormAction::create('archive',_t('CMSMain.ARCHIVE','Archive'))
->setDescription(_t(
'SiteTree.BUTTONARCHIVEDESC',
'Unpublish and send to archive'
))
->addExtraClass('delete ss-ui-action-destructive')
);
}
// "save", supports an alternate state that is still clickable, but notifies the user that the action is not needed.
$majorActions->push(
FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))
->setAttribute('data-icon', 'accept')
->setAttribute('data-icon-alternate', 'addpage')
->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT','Save draft'))
);
}
// "restore"
if($canEdit && !$isOnDraft && $isPublished) {
$majorActions->push(FormAction::create('revert',_t('CMSMain.RESTORE','Restore')));
}
if($this->canPublish() && $this->isOnDraft()) {
// Check if we can restore a deleted page
// Note: It would be nice to have a canRestore() permission at some point
if($canEdit && !$isOnDraft && !$isPublished) {
// Determine if we should force a restore to root (where once it was a subpage)
$restoreToRoot = $this->isParentArchived();
// "restore"
$title = $restoreToRoot
? _t('CMSMain.RESTORE_TO_ROOT','Restore draft at top level')
: _t('CMSMain.RESTORE','Restore draft');
$description = $restoreToRoot
? _t('CMSMain.RESTORE_TO_ROOT_DESC','Restore the archived version to draft as a top level page')
: _t('CMSMain.RESTORE_DESC', 'Restore the archived version to draft');
$majorActions->push(
FormAction::create('restore', $title)
->setDescription($description)
->setAttribute('data-to-root', $restoreToRoot)
->setAttribute('data-icon', 'decline')
);
}
// If a page is on any stage it can be archived
if (($isOnDraft || $isPublished) && $this->canArchive()) {
$title = $isPublished
? _t('CMSMain.UNPUBLISH_AND_ARCHIVE', 'Unpublish and archive')
: _t('CMSMain.ARCHIVE', 'Archive');
$moreOptions->push(
FormAction::create('archive', $title)
->addExtraClass('delete ss-ui-action-destructive')
->setDescription(_t(
'SiteTree.BUTTONDELETEDESC',
'Remove from draft/live and send to archive'
))
);
}
// "save", supports an alternate state that is still clickable, but notifies the user that the action is not needed.
if ($canEdit && $isOnDraft) {
$majorActions->push(
FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))
->setAttribute('data-icon', 'accept')
->setAttribute('data-icon-alternate', 'addpage')
->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT','Save draft'))
);
}
if($canPublish && $isOnDraft) {
// "publish", as with "save", it supports an alternate state to show when action is needed.
$majorActions->push(
$publish = FormAction::create('publish', _t('SiteTree.BUTTONPUBLISHED', 'Published'))
@ -2349,7 +2341,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
);
// Set up the initial state of the button to reflect the state of the underlying SiteTree object.
if($this->stagesDiffer(Versioned::DRAFT, Versioned::LIVE)) {
if($stagesDiffer) {
$publish->addExtraClass('ss-ui-alternate');
}
}
@ -2377,7 +2369,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
public function onAfterRevertToLive() {
// Use an alias to get the updates made by $this->publish
/** @var SiteTree $stageSelf */
$stageSelf = Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', Versioned::DRAFT)->byID($this->ID);
$stageSelf = Versioned::get_by_stage(self::class, Versioned::DRAFT)->byID($this->ID);
$stageSelf->writeWithoutVersion();
// Need to update pages linking to this one as no longer broken
@ -2420,9 +2412,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
// create an empty record
if(!DB::prepared_query("SELECT \"ID\" FROM \"SiteTree\" WHERE \"ID\" = ?", array($this->ID))->value()) {
$conn = DB::get_conn();
if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('SilverStripe\\CMS\\Model\\SiteTree', true);
if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing(self::class, true);
DB::prepared_query("INSERT INTO \"SiteTree\" (\"ID\") VALUES (?)", array($this->ID));
if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('SilverStripe\\CMS\\Model\\SiteTree', false);
if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing(self::class, false);
}
$oldReadingMode = Versioned::get_reading_mode();

View File

@ -1,53 +0,0 @@
// This file was generated by silverstripe/cow from javascript/lang/src/hr.js.
// See https://github.com/tractorcow/cow for details
if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') {
if (typeof(console) !== 'undefined') { // eslint-disable-line no-console
console.error('Class ss.i18n not defined'); // eslint-disable-line no-console
}
} else {
ss.i18n.addDictionary('hr', {
"AssetAdmin.BATCHACTIONSDELETECONFIRM": "Jeste li sigurni da želite obrisati %s direktorije?",
"AssetAdmin.ConfirmDelete": "Jeste li sigurni da želite obrisati ovaj direktorij i sve datoteke u njemu?",
"AssetTableField.MOVING": "Premještam %s datoteku(e)",
"AssetTableField.REALLYDELETE": "Jeste li sigurni da želite obrisati označene datoteke?",
"CMSMAIN.ALERTCLASSNAME": "Tip stranice će biti osvježen nakon spremanja stranice",
"CMSMAIN.AddSearchCriteria": "Dodaj obilježja",
"CMSMAIN.CANTADDCHILDREN": "Ne možete dodati podstranice za označeni čvor",
"CMSMAIN.DELETINGPAGES": "Brišem stranice...",
"CMSMAIN.ERRORADDINGPAGE": "Greška u dodavanju stranice",
"CMSMAIN.ERRORDELETINGPAGES": "Greška u brisanju stranice",
"CMSMAIN.ERRORFILTERPAGES": "Ne mogu filtrirati stablo za prikaz izmjenjenih stranica<br />%s",
"CMSMAIN.ERRORPUBLISHING": "Greška u objavljivanju stranice",
"CMSMAIN.ERRORREVERTING": "Greška pri vraćanju objavljenog sadržaja",
"CMSMAIN.ERRORUNFILTER": "Nefiltirano stablo",
"CMSMAIN.FILTEREDTREE": "Filtrirano stablo prikazuje samo promjenjene stranice",
"CMSMAIN.PUBLISHING": "Objavljujem...",
"CMSMAIN.PUBLISHINGPAGES": "Objavljujem stranice...",
"CMSMAIN.REALLYDELETEPAGES": "Jeste li sigurni da želite obrisati %s označene stranice?",
"CMSMAIN.RESTORING": "Vraćam...",
"CMSMAIN.SAVING": "spremam...",
"CMSMAIN.SELECTMOREPAGES": "Označili ste %s stranica.\n\nJeste li sigurni da želite izvršiti ovu akciju?",
"CMSMAIN.SELECTONEPAGE": "Molimo odaberite bar 1 stranicu.",
"CMSMAIN.URLSEGMENTVALIDATION": "Linkovi mogu biti sastavljeni samo od slova, brojki i crtica.",
"CMSMAIN.WARNINGSAVEPAGESBEFOREADDING": "Morate spremiti stranicu prije dodavanja podstranica ispod nje",
"CMSMain.Archive": "Jeste li sigurni da želite arhivirati ovu stranicu i sve podstranice?\n\nOva stranica i sve njene podstranice će biti odjavljene i poslane u arhivu.",
"CMSMain.ConfirmRestoreFromLive": "Da li ste sigurni da želite vratiti predložak kada je stranica zadnji put objavljena?",
"CMSMain.DeleteFromDraft": "Jeste li sigurni da želite ukloniti ovu stranicu iz neobjavljene stranice?\n\nOva stranica će ostati na objavljenoj stranici.",
"CMSMain.Restore": "Da li ste sigurni da želite vratiti stranicu iz arhive?",
"CMSMain.RestoreToRoot": "Jeste li sigurni da želite vratiti ovu stranicu iz arhive?\n\nNadstranica neće biti dostupna kada se stranica vrati.",
"CMSMain.RollbackToVersion": "Jeste li sigurni da želite vratiti na verziju #%s ove stranice?",
"CMSMain.Unpublish": "Jeste li sigurni da želite ukloniti ovu stranicu iz objavljene stranice?\n\nOva stranica će ostati dostupna u stablu kao predložak.",
"Folder.Name": "Naziv direktorija",
"Tree.AddSubPage": "Dodaj novu stranicu ovdje",
"Tree.Duplicate": "Dupliciraj",
"Tree.EditPage": "Uredi",
"Tree.ShowAsList": "Prikaži podstranice kao listu",
"Tree.ThisPageAndSubpages": "Ova stranica i podstranice",
"Tree.ThisPageOnly": "Samo ova stranica",
"URLSEGMENT.Cancel": "Odustani",
"URLSEGMENT.Edit": "Uredi",
"URLSEGMENT.OK": "Ok",
"URLSEGMENT.UpdateURL": "Ažuriraj link ",
"WidgetAreaEditor.TOOMANY": "Nažalost, prešli ste maksimalni broj widgeta za ovu zonu"
});
}

View File

@ -1,45 +0,0 @@
{
"AssetAdmin.BATCHACTIONSDELETECONFIRM": "Jeste li sigurni da želite obrisati %s direktorije?",
"AssetAdmin.ConfirmDelete": "Jeste li sigurni da želite obrisati ovaj direktorij i sve datoteke u njemu?",
"AssetTableField.MOVING": "Premještam %s datoteku(e)",
"AssetTableField.REALLYDELETE": "Jeste li sigurni da želite obrisati označene datoteke?",
"CMSMAIN.ALERTCLASSNAME": "Tip stranice će biti osvježen nakon spremanja stranice",
"CMSMAIN.AddSearchCriteria": "Dodaj obilježja",
"CMSMAIN.CANTADDCHILDREN": "Ne možete dodati podstranice za označeni čvor",
"CMSMAIN.DELETINGPAGES": "Brišem stranice...",
"CMSMAIN.ERRORADDINGPAGE": "Greška u dodavanju stranice",
"CMSMAIN.ERRORDELETINGPAGES": "Greška u brisanju stranice",
"CMSMAIN.ERRORFILTERPAGES": "Ne mogu filtrirati stablo za prikaz izmjenjenih stranica<br />%s",
"CMSMAIN.ERRORPUBLISHING": "Greška u objavljivanju stranice",
"CMSMAIN.ERRORREVERTING": "Greška pri vraćanju objavljenog sadržaja",
"CMSMAIN.ERRORUNFILTER": "Nefiltirano stablo",
"CMSMAIN.FILTEREDTREE": "Filtrirano stablo prikazuje samo promjenjene stranice",
"CMSMAIN.PUBLISHING": "Objavljujem...",
"CMSMAIN.PUBLISHINGPAGES": "Objavljujem stranice...",
"CMSMAIN.REALLYDELETEPAGES": "Jeste li sigurni da želite obrisati %s označene stranice?",
"CMSMAIN.RESTORING": "Vraćam...",
"CMSMAIN.SAVING": "spremam...",
"CMSMAIN.SELECTMOREPAGES": "Označili ste %s stranica.\n\nJeste li sigurni da želite izvršiti ovu akciju?",
"CMSMAIN.SELECTONEPAGE": "Molimo odaberite bar 1 stranicu.",
"CMSMAIN.URLSEGMENTVALIDATION": "Linkovi mogu biti sastavljeni samo od slova, brojki i crtica.",
"CMSMAIN.WARNINGSAVEPAGESBEFOREADDING": "Morate spremiti stranicu prije dodavanja podstranica ispod nje",
"CMSMain.Archive": "Jeste li sigurni da želite arhivirati ovu stranicu i sve podstranice?\n\nOva stranica i sve njene podstranice će biti odjavljene i poslane u arhivu.",
"CMSMain.ConfirmRestoreFromLive": "Da li ste sigurni da želite vratiti predložak kada je stranica zadnji put objavljena?",
"CMSMain.DeleteFromDraft": "Jeste li sigurni da želite ukloniti ovu stranicu iz neobjavljene stranice?\n\nOva stranica će ostati na objavljenoj stranici.",
"CMSMain.Restore": "Da li ste sigurni da želite vratiti stranicu iz arhive?",
"CMSMain.RestoreToRoot": "Jeste li sigurni da želite vratiti ovu stranicu iz arhive?\n\nNadstranica neće biti dostupna kada se stranica vrati.",
"CMSMain.RollbackToVersion": "Jeste li sigurni da želite vratiti na verziju #%s ove stranice?",
"CMSMain.Unpublish": "Jeste li sigurni da želite ukloniti ovu stranicu iz objavljene stranice?\n\nOva stranica će ostati dostupna u stablu kao predložak.",
"Folder.Name": "Naziv direktorija",
"Tree.AddSubPage": "Dodaj novu stranicu ovdje",
"Tree.Duplicate": "Dupliciraj",
"Tree.EditPage": "Uredi",
"Tree.ShowAsList": "Prikaži podstranice kao listu",
"Tree.ThisPageAndSubpages": "Ova stranica i podstranice",
"Tree.ThisPageOnly": "Samo ova stranica",
"URLSEGMENT.Cancel": "Odustani",
"URLSEGMENT.Edit": "Uredi",
"URLSEGMENT.OK": "Ok",
"URLSEGMENT.UpdateURL": "Ažuriraj link ",
"WidgetAreaEditor.TOOMANY": "Nažalost, prešli ste maksimalni broj widgeta za ovu zonu"
}

View File

@ -1,15 +1,13 @@
<?php
use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Unpublish;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\SapphireTest;
/**
* Tests CMS Specific subclasses of {@see CMSBatchAction}
*/
@ -23,20 +21,20 @@ class CMSBatchActionsTest extends SapphireTest {
$this->logInWithPermission('ADMIN');
// published page
$published = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'published');
$published = $this->objFromFixture(SiteTree::class, 'published');
$published->publishSingle();
// Deleted / archived page
$archived = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archived');
$archived = $this->objFromFixture(SiteTree::class, 'archived');
$archived->doArchive(); // should archive all children
// Unpublished
$unpublished = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'unpublished');
$unpublished = $this->objFromFixture(SiteTree::class, 'unpublished');
$unpublished->publishSingle();
$unpublished->doUnpublish();
// Modified
$modified = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'modified');
$modified = $this->objFromFixture(SiteTree::class, 'modified');
$modified->publishSingle();
$modified->Title = 'modified2';
$modified->write();
@ -47,18 +45,18 @@ class CMSBatchActionsTest extends SapphireTest {
*/
public function testBatchPublishApplicable() {
$this->logInWithPermission('ADMIN');
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
$pages = Versioned::get_including_deleted(SiteTree::class);
$ids = $pages->column('ID');
$action = new CMSBatchAction_Publish();
// Test applicable pages
$applicable = $action->applicablePages($ids);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'published'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archived'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedx'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedy'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'unpublished'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'modified'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'published'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'archived'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'archivedx'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'archivedy'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'unpublished'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'modified'), $applicable);
}
@ -67,35 +65,35 @@ class CMSBatchActionsTest extends SapphireTest {
*/
public function testBatchUnpublishApplicable() {
$this->logInWithPermission('ADMIN');
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
$pages = Versioned::get_including_deleted(SiteTree::class);
$ids = $pages->column('ID');
$action = new CMSBatchAction_Unpublish();
// Test applicable page
$applicable = $action->applicablePages($ids);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'published'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archived'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedx'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedy'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'unpublished'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'modified'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'published'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'archived'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'archivedx'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'archivedy'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'unpublished'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'modified'), $applicable);
}
/**
* Test which pages can be archived via batch actions
* Test which pages can be archived via delete batch actions
*/
public function testBatchArchiveApplicable() {
public function testBatchDeleteApplicable() {
$this->logInWithPermission('ADMIN');
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
$pages = Versioned::get_including_deleted(SiteTree::class);
$ids = $pages->column('ID');
$action = new CMSBatchAction_Archive();
// Test applicable pages
$applicable = $action->applicablePages($ids);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'published'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archived'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'unpublished'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'modified'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'published'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'archived'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'unpublished'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'modified'), $applicable);
}
/**
@ -103,27 +101,27 @@ class CMSBatchActionsTest extends SapphireTest {
*/
public function testBatchRestoreApplicable() {
$this->logInWithPermission('ADMIN');
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
$pages = Versioned::get_including_deleted(SiteTree::class);
$ids = $pages->column('ID');
$action = new CMSBatchAction_Restore();
// Test applicable pages
$applicable = $action->applicablePages($ids);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'published'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archived'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedx'), $applicable);
$this->assertContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedy'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'unpublished'), $applicable);
$this->assertNotContains($this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'modified'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'published'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'archived'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'archivedx'), $applicable);
$this->assertContains($this->idFromFixture(SiteTree::class, 'archivedy'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'unpublished'), $applicable);
$this->assertNotContains($this->idFromFixture(SiteTree::class, 'modified'), $applicable);
}
public function testBatchRestore() {
$this->logInWithPermission('ADMIN');
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
$pages = Versioned::get_including_deleted(SiteTree::class);
$action = new CMSBatchAction_Restore();
$archivedID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archived');
$archivedxID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedx');
$archivedyID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'archivedy');
$archivedID = $this->idFromFixture(SiteTree::class, 'archived');
$archivedxID = $this->idFromFixture(SiteTree::class, 'archivedx');
$archivedyID = $this->idFromFixture(SiteTree::class, 'archivedy');
// Just restore one child
$list = $pages->filter('RecordID', $archivedxID);

View File

@ -36,7 +36,7 @@ class CMSMainTest extends FunctionalTest {
parent::setUp();
// Clear automatically created siteconfigs (in case one was created outside of the specified fixtures).
$ids = $this->allFixtureIDs('SilverStripe\\SiteConfig\\SiteConfig');
$ids = $this->allFixtureIDs(SiteConfig::class);
if($ids) {
foreach(SiteConfig::get()->exclude('ID', $ids) as $config) {
$config->delete();
@ -120,8 +120,8 @@ class CMSMainTest extends FunctionalTest {
* @todo Test the results of a publication better
*/
public function testPublish() {
$page1 = $this->objFromFixture('Page', "page1");
$page2 = $this->objFromFixture('Page', "page2");
$page1 = $this->objFromFixture(Page::class, "page1");
$page2 = $this->objFromFixture(Page::class, "page2");
$this->session()->inst_set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
$response = $this->get('admin/pages/publishall?confirm=1');
@ -130,8 +130,6 @@ class CMSMainTest extends FunctionalTest {
$response->getBody()
);
$actions = CMSBatchActionHandler::config()->batch_actions;
// Some modules (e.g., cmsworkflow) will remove this action
$actions = CMSBatchActionHandler::config()->batch_actions;
if (isset($actions['publish'])) {
@ -213,8 +211,8 @@ class CMSMainTest extends FunctionalTest {
$this->logInWithPermission('ADMIN');
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', true);
$parentPage = $this->objFromFixture('Page', 'page3');
$childPage = $this->objFromFixture('Page', 'page1');
$parentPage = $this->objFromFixture(Page::class, 'page3');
$childPage = $this->objFromFixture(Page::class, 'page1');
$parentPage->doUnpublish();
$childPage->doUnpublish();
@ -235,7 +233,7 @@ class CMSMainTest extends FunctionalTest {
$this->session()->inst_set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
// Set up a page that is delete from live
$page = $this->objFromFixture('Page', 'page1');
$page = $this->objFromFixture(Page::class, 'page1');
$pageID = $page->ID;
$page->publishRecursive();
$page->delete();
@ -256,8 +254,10 @@ class CMSMainTest extends FunctionalTest {
* Test CMSMain::getRecord()
*/
public function testGetRecord() {
$this->logInWithPermission('ADMIN');
// Set up a page that is delete from live
$page1 = $this->objFromFixture('Page', 'page1');
$page1 = $this->objFromFixture(Page::class, 'page1');
$page1ID = $page1->ID;
$page1->publishRecursive();
$page1->delete();
@ -410,8 +410,8 @@ class CMSMainTest extends FunctionalTest {
}
public function testBreadcrumbs() {
$page3 = $this->objFromFixture('Page', 'page3');
$page31 = $this->objFromFixture('Page', 'page31');
$page3 = $this->objFromFixture(Page::class, 'page3');
$page31 = $this->objFromFixture(Page::class, 'page31');
$adminuser = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
$this->session()->inst_set('loggedInAs', $adminuser->ID);
@ -463,10 +463,10 @@ class CMSMainTest extends FunctionalTest {
);
// Change state of tree
$page1 = $this->objFromFixture('Page', 'page1');
$page3 = $this->objFromFixture('Page', 'page3');
$page11 = $this->objFromFixture('Page', 'page11');
$page12 = $this->objFromFixture('Page', 'page12');
$page1 = $this->objFromFixture(Page::class, 'page1');
$page3 = $this->objFromFixture(Page::class, 'page3');
$page11 = $this->objFromFixture(Page::class, 'page11');
$page12 = $this->objFromFixture(Page::class, 'page12');
// Deleted
$page1->doUnpublish();
$page1->delete();
@ -542,7 +542,7 @@ class CMSMainTest extends FunctionalTest {
$this->loginWithPermission('ADMIN');
// Get a associated with a fixture page.
$page = $this->objFromFixture('Page', 'page1');
$page = $this->objFromFixture(Page::class, 'page1');
$controller = new CMSMain();
$form = $controller->getEditForm($page->ID);
$this->assertInstanceOf("SilverStripe\\Forms\\Form", $form);

View File

@ -93,10 +93,10 @@ class ErrorPageTest extends FunctionalTest {
// Write new 401 page
$page = new ErrorPage();
$page->Title = '401 Error';
$page->ErrorCode = 401;
$page->Title = 'Unauthorised';
$page->write();
$page->copyVersionToStage('Stage', 'Live');
$page->publishRecursive();
// Static cache should now exist

View File

@ -1,7 +1,9 @@
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\ORM\DB;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
@ -13,7 +15,6 @@ use SilverStripe\Dev\TestOnly;
* - action_publish
* - action_unpublish
* - action_archive
* - action_deletefromlive
* - action_rollback
* - action_revert
*
@ -25,29 +26,37 @@ class SiteTreeActionsTest extends FunctionalTest {
protected static $fixture_file = 'SiteTreeActionsTest.yml';
public function testActionsReadonly() {
if(class_exists('SiteTreeCMSWorkflow')) return true;
$readonlyEditor = $this->objFromFixture('SilverStripe\\Security\\Member', 'cmsreadonlyeditor');
$this->session()->inst_set('loggedInAs', $readonlyEditor->ID);
if(class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
// Publish record
$this->logInWithPermission('ADMIN');
$page = new SiteTreeActionsTest_Page();
$page->CanEditType = 'LoggedInUsers';
$page->write();
$page->publishRecursive();
// Log in as another user
$readonlyEditor = $this->objFromFixture(Member::class, 'cmsreadonlyeditor');
$this->session()->inst_set('loggedInAs', $readonlyEditor->ID);
// Reload latest version
$page = Page::get()->byID($page->ID);
$actions = $page->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish'));
$this->assertNull($actions->dataFieldByName('action_delete'));
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNull($actions->dataFieldByName('action_archive'));
$this->assertNull($actions->dataFieldByName('action_rollback'));
$this->assertNull($actions->dataFieldByName('action_revert'));
}
public function testActionsNoDeletePublishedRecord() {
if(class_exists('SiteTreeCMSWorkflow')) return true;
if(class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$this->logInWithPermission('ADMIN');
@ -56,100 +65,118 @@ class SiteTreeActionsTest extends FunctionalTest {
$page->write();
$pageID = $page->ID;
$page->publishRecursive();
$page->deleteFromStage('Stage');
$page->deleteFromStage(Versioned::DRAFT);
// Get the live version of the page
$page = Versioned::get_one_by_stage("SilverStripe\\CMS\\Model\\SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
$this->assertInstanceOf("SilverStripe\\CMS\\Model\\SiteTree", $page);
$page = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $pageID");
$this->assertInstanceOf(SiteTree::class, $page);
// Check that someone without the right permission can't delete the page
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'cmsnodeleteeditor');
$editor = $this->objFromFixture(Member::class, 'cmsnodeleteeditor');
$this->session()->inst_set('loggedInAs', $editor->ID);
$actions = $page->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNull($actions->dataFieldByName('action_archive'));
// Check that someone with the right permission can delete the page
$this->objFromFixture('SilverStripe\\Security\\Member', 'cmseditor')->logIn();
/** @var Member $member */
$member = $this->objFromFixture(Member::class, 'cmseditor');
$member->logIn();
$actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNotNull($actions->dataFieldByName('action_archive'));
}
public function testActionsPublishedRecord() {
if(class_exists('SiteTreeCMSWorkflow')) return true;
if(class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$author = $this->objFromFixture('SilverStripe\\Security\\Member', 'cmseditor');
$author = $this->objFromFixture(Member::class, 'cmseditor');
$this->session()->inst_set('loggedInAs', $author->ID);
/** @var Page $page */
$page = new Page();
$page->CanEditType = 'LoggedInUsers';
$page->write();
$page->publishRecursive();
// Reload latest version
$page = Page::get()->byID($page->ID);
$actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_save'));
$this->assertNotNull($actions->dataFieldByName('action_publish'));
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
$this->assertNotNull($actions->dataFieldByName('action_archive'));
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNull($actions->dataFieldByName('action_rollback'));
$this->assertNull($actions->dataFieldByName('action_revert'));
}
public function testActionsDeletedFromStageRecord() {
if(class_exists('SiteTreeCMSWorkflow')) return true;
if(class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$author = $this->objFromFixture('SilverStripe\\Security\\Member', 'cmseditor');
$author = $this->objFromFixture(Member::class, 'cmseditor');
$this->session()->inst_set('loggedInAs', $author->ID);
$page = new Page();
$page->CanEditType = 'LoggedInUsers';
$page->write();
$this->assertTrue($page->canPublish());
$pageID = $page->ID;
$page->publishRecursive();
$page->deleteFromStage('Stage');
// Get the live version of the page
$page = Versioned::get_one_by_stage("SilverStripe\\CMS\\Model\\SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
$this->assertInstanceOf('SilverStripe\\CMS\\Model\\SiteTree', $page);
$page = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $pageID");
$this->assertInstanceOf(SiteTree::class, $page);
$actions = $page->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish'));
$this->assertNull($actions->dataFieldByName('action_archive'));
$this->assertNotNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNotNull($actions->dataFieldByName('action_archive'));
$this->assertNull($actions->dataFieldByName('action_rollback'));
$this->assertNotNull($actions->dataFieldByName('action_revert'));
}
public function testActionsChangedOnStageRecord() {
if(class_exists('SiteTreeCMSWorkflow')) return true;
if(class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$author = $this->objFromFixture('SilverStripe\\Security\\Member', 'cmseditor');
$author = $this->objFromFixture(Member::class, 'cmseditor');
$this->session()->inst_set('loggedInAs', $author->ID);
$page = new Page();
$page->CanEditType = 'LoggedInUsers';
$page->write();
$this->assertTrue($page->canPublish());
$page->publishRecursive();
$page->Content = 'Changed on Stage';
$page->write();
$page->flushCache();
// Reload latest version
$page = Page::get()->byID($page->ID);
$actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_save'));
$this->assertNotNull($actions->dataFieldByName('action_publish'));
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
$this->assertNotNull($actions->dataFieldByName('action_archive'));
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
$this->assertNull($actions->dataFieldByName('action_revert'));
}
public function testActionsViewingOldVersion() {
if(class_exists('SiteTreeCMSWorkflow')) {
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
}
$p = new Page();
$p->Content = 'test page first version';
$p->write();
@ -163,7 +190,6 @@ class SiteTreeActionsTest extends FunctionalTest {
$this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish'));
$this->assertNull($actions->dataFieldByName('action_archive'));
$this->assertNotNull($actions->dataFieldByName('action_email'));
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
}