mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
BUGFIX CMSMain->delete()/deletefromlive() consistently show page in "archive mode", rather than empty form (or 404 response) (fixes #6973)
This commit is contained in:
parent
3248da02ce
commit
6876c9a802
@ -443,6 +443,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
$actions = $form->Actions();
|
$actions = $form->Actions();
|
||||||
|
|
||||||
if($record) {
|
if($record) {
|
||||||
|
$deletedFromStage = $record->IsDeletedFromStage;
|
||||||
|
$deleteFromLive = !$record->ExistsOnLive;
|
||||||
|
|
||||||
$fields->push($idField = new HiddenField("ID", false, $id));
|
$fields->push($idField = new HiddenField("ID", false, $id));
|
||||||
// Necessary for different subsites
|
// Necessary for different subsites
|
||||||
$fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink()));
|
$fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink()));
|
||||||
@ -457,7 +460,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
if($liveRecord) $liveURLField->setValue($liveRecord->AbsoluteLink());
|
if($liveRecord) $liveURLField->setValue($liveRecord->AbsoluteLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$record->IsDeletedFromStage) {
|
if(!$deletedFromStage) {
|
||||||
$stageURLField->setValue(Controller::join_links($record->AbsoluteLink(), '?stage=Stage'));
|
$stageURLField->setValue(Controller::join_links($record->AbsoluteLink(), '?stage=Stage'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +498,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
$form->addExtraClass('center ss-tabset ' . $this->BaseCSSClasses());
|
$form->addExtraClass('center ss-tabset ' . $this->BaseCSSClasses());
|
||||||
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
||||||
|
|
||||||
if(!$record->canEdit() || $record->IsDeletedFromStage) {
|
if(!$record->canEdit() || $deletedFromStage) {
|
||||||
$readonlyFields = $form->Fields()->makeReadonly();
|
$readonlyFields = $form->Fields()->makeReadonly();
|
||||||
$form->setFields($readonlyFields);
|
$form->setFields($readonlyFields);
|
||||||
}
|
}
|
||||||
@ -652,6 +655,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
|
|
||||||
$descRemoved = '';
|
$descRemoved = '';
|
||||||
$descendantsRemoved = 0;
|
$descendantsRemoved = 0;
|
||||||
|
$recordTitle = $record->Title;
|
||||||
|
$recordID = $record->ID;
|
||||||
|
|
||||||
// before deleting the records, get the descendants of this tree
|
// before deleting the records, get the descendants of this tree
|
||||||
if($record) {
|
if($record) {
|
||||||
@ -678,17 +683,17 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
$descRemoved = '';
|
$descRemoved = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response->addHeader(
|
$form->sessionMessage(
|
||||||
'X-Status',
|
|
||||||
sprintf(
|
sprintf(
|
||||||
_t('CMSMain.REMOVED', 'Deleted \'%s\'%s from live site'),
|
_t('CMSMain.REMOVED', 'Deleted \'%s\'%s from live site'),
|
||||||
$record->Title,
|
$recordTitle,
|
||||||
$descRemoved
|
$descRemoved
|
||||||
)
|
),
|
||||||
|
'good'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Redirect to pages overview
|
// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
|
||||||
return $this->redirect(singleton('CMSPagesController')->Link());
|
return $this->redirect(Controller::join_links($this->Link('show'), $recordID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -756,31 +761,17 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
// save ID and delete record
|
// save ID and delete record
|
||||||
$recordID = $record->ID;
|
$recordID = $record->ID;
|
||||||
$record->delete();
|
$record->delete();
|
||||||
|
|
||||||
$this->response->addHeader(
|
$form->sessionMessage(
|
||||||
'X-Status',
|
|
||||||
sprintf(
|
sprintf(
|
||||||
_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"),
|
_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"),
|
||||||
$record->Title
|
$record->Title
|
||||||
)
|
),
|
||||||
|
'good'
|
||||||
);
|
);
|
||||||
|
|
||||||
// need a valid ID value even if the record doesn't have one in the database
|
// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
|
||||||
// (its still present in the live tables)
|
return $this->redirect(Controller::join_links($this->Link('show'), $recordID));
|
||||||
$liveRecord = Versioned::get_one_by_stage(
|
|
||||||
'SiteTree',
|
|
||||||
'Live',
|
|
||||||
"\"SiteTree_Live\".\"ID\" = $recordID"
|
|
||||||
);
|
|
||||||
// If no live record exists, redirect to pages list
|
|
||||||
if(!$liveRecord) return $this->redirect(singleton('CMSPagesController')->Link());
|
|
||||||
|
|
||||||
if($this->isAjax()) {
|
|
||||||
$form = $this->getEditForm($liveRecord->ID);
|
|
||||||
return $form->forTemplate();
|
|
||||||
} else {
|
|
||||||
$this->redirectBack();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function publish($data, $form) {
|
function publish($data, $form) {
|
||||||
|
Loading…
Reference in New Issue
Block a user