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
parent a04ac5ebbe
commit 509d32e58f

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);
} }