Last active
January 30, 2018 22:38
-
-
Save sunnysideup/df819d1103d785941942b35e871cbfbd to your computer and use it in GitHub Desktop.
Delete a Silverstripe Page for both STAGE and LIVE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyExampleDeleteAllForPage extends Object | |
{ | |
private static function delete_page($idOrPage) | |
{ | |
if($idOrPage instanceof SiteTree) { | |
$id = $idOrStage->ID; | |
}elseif(intval($idOrPage)) { | |
$id = $idOrStage; | |
//do nothing | |
} else { | |
user_error('idOrPage parameter can not be parsed: '.print_r($idOrPage, 1)); | |
} | |
$stageRecord = Versioned::get_one_by_stage('SiteTree', 'Stage', "\"SiteTree\".\"ID\" = $id"); | |
if ($stageRecord) { | |
$stageRecord->deleteFromStage('Stage'); | |
} | |
if ($stageRecord) { | |
$stageRecord->delete(); | |
} | |
$liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = $id"); | |
if ($liveRecord) { | |
$stageRecord->deleteFromStage('Live'); | |
} | |
if ($liveRecord) { | |
$stageRecord->delete(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment