BUGFIX: Better handling of non-existent records in delete calls (if button is clicked twice) (by sminnee, merged from r100473)

This commit is contained in:
Sam Minnee 2011-09-22 18:15:04 +02:00 committed by Ingo Schommer
parent 1499a3c13a
commit 74f9649ac9
2 changed files with 9 additions and 1 deletions

View File

@ -617,6 +617,8 @@ JS;
$id = $_REQUEST['ID'];
Versioned::reading_stage('Live');
$record = DataObject::get_by_id("SiteTree", $id);
if(!$record || !$record->ID) throw new HTTPResponse_Exception("Bad record ID #$id", 404);
if($record && !($record->canDelete() && $record->canDeleteFromLive())) return Security::permissionFailure($this);
$descRemoved = '';
@ -697,7 +699,10 @@ JS;
"SiteTree",
sprintf("\"SiteTree\".\"ID\" = %d", Convert::raw2sql($data['ID']))
);
if(!$record) return $this->httpError(400);
// Non-existent record
if(!$record || !$record->ID) throw new HTTPResponse_Exception("Bad record ID #$id", 404);
if(!$record->canDelete()) return Security::permissionFailure();
// save ID and delete record

View File

@ -847,6 +847,9 @@ JS;
* @return string
*/
public function deleteTreeNodeJS($page) {
// Silently skip if $page isn't a record
if (!$page || (!isset($page->ID) && !isset($page->OldID))) return false;
$id = $page->ID ? $page->ID : $page->OldID;
$response = <<<JS
var node = $('sitetree').getTreeNodeByIdx($id);