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. * Updates link tracking.
*/ */
function onAfterDelete() { function onAfterDelete() {
$brokenPages = $this->owner->BackLinkTracking(); // We query the explicit ID list, because BackLinkTracking will get modified after the stage
if($brokenPages) { // site does its thing
$brokenPageIDs = $this->owner->BackLinkTracking()->column("ID");
if($brokenPageIDs) {
$origStage = Versioned::current_stage(); $origStage = Versioned::current_stage();
// This will syncLinkTracking on draft // This will syncLinkTracking on draft
Versioned::reading_stage('Stage'); Versioned::reading_stage('Stage');
$brokenPages = DataObject::get('SiteTree')->byIDs($brokenPageIDs);
foreach($brokenPages as $brokenPage) $brokenPage->write(); foreach($brokenPages as $brokenPage) $brokenPage->write();
// This will syncLinkTracking on published // This will syncLinkTracking on published
Versioned::reading_stage('Live'); 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); Versioned::reading_stage($origStage);
} }