BUGFIX: Fix SiteTree broken link correction to handle the fact that relations aren't cached.

This commit is contained in:
Sam Minnee 2011-03-30 18:57:50 +13:00 committed by Ingo Schommer
parent 1821ccbb7d
commit 9398fcaaa1

View File

@ -31,17 +31,23 @@ class SiteTreeFileExtension extends DataExtension {
* Updates link tracking.
*/
function onAfterDelete() {
$brokenPages = $this->owner->BackLinkTracking();
if($brokenPages) {
// We query the explicit ID list, because BackLinkTracking will get modified after the stage
// site does its thing
$brokenPageIDs = $this->owner->BackLinkTracking()->column("ID");
if($brokenPageIDs) {
$origStage = Versioned::current_stage();
// This will syncLinkTracking on draft
Versioned::reading_stage('Stage');
$brokenPages = DataObject::get('SiteTree')->byIDs($brokenPageIDs);
foreach($brokenPages as $brokenPage) $brokenPage->write();
// This will syncLinkTracking on published
Versioned::reading_stage('Live');
foreach($brokenPages as $brokenPage) $brokenPage->write();
$liveBrokenPages = DataObject::get('SiteTree')->byIDs($brokenPageIDs);
foreach($liveBrokenPages as $brokenPage) {
$brokenPage->write();
}
Versioned::reading_stage($origStage);
}