mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fixed broken link correction when a page is deleted. (from r89989)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96731 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
18a71a3fdb
commit
8a0302d2ac
@ -1356,6 +1356,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
// Need to flush cache to avoid outdated versionnumber references
|
||||
$this->flushCache();
|
||||
|
||||
// Need to mark pages linking to this one as broken
|
||||
foreach($this->BackLinkTracking() as $page) {
|
||||
// $page->write() calls syncLinkTracking, which does all the hard work for us.
|
||||
$page->write();
|
||||
}
|
||||
|
||||
parent::onAfterDelete();
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,69 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
|
||||
$this->assertFalse($obj->HasBrokenFile, 'Page does NOT have a broken file');
|
||||
}
|
||||
|
||||
function testDeletingMarksBackLinkedPagesAsBroken() {
|
||||
$this->logInWithPermssion('ADMIN');
|
||||
|
||||
// Set up two published pages with a link from content -> about
|
||||
$linkDest = $this->objFromFixture('Page','about');
|
||||
$linkDest->doPublish();
|
||||
|
||||
$linkSrc = $this->objFromFixture('Page','content');
|
||||
$linkSrc->Content = "<p><a href=\"" . $linkDest->URLSegment . "/\">about us</a></p>";
|
||||
$linkSrc->write();
|
||||
$linkSrc->doPublish();
|
||||
|
||||
// Confirm no broken link
|
||||
$this->assertEquals(0, (int)$linkSrc->HasBrokenLink);
|
||||
$this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
|
||||
WHERE \"ID\" = $linkSrc->ID")->value());
|
||||
|
||||
// Delete page from draft
|
||||
$linkDestID = $linkDest->ID;
|
||||
$linkDest->delete();
|
||||
|
||||
// Confirm draft has broken link, and published doesn't
|
||||
$linkSrc->flushCache();
|
||||
$linkSrc = $this->objFromFixture('Page', 'content');
|
||||
|
||||
$this->assertEquals(1, (int)$linkSrc->HasBrokenLink);
|
||||
$this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
|
||||
WHERE \"ID\" = $linkSrc->ID")->value());
|
||||
|
||||
// Delete from live
|
||||
$linkDest = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $linkDestID");
|
||||
$linkDest->doDeleteFromLive();
|
||||
|
||||
// Confirm both draft and published have broken link
|
||||
$linkSrc->flushCache();
|
||||
$linkSrc = $this->objFromFixture('Page', 'content');
|
||||
|
||||
$this->assertEquals(1, (int)$linkSrc->HasBrokenLink);
|
||||
$this->assertEquals(1, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
|
||||
WHERE \"ID\" = $linkSrc->ID")->value());
|
||||
}
|
||||
|
||||
function testPublishingSourceBeforeDestHasBrokenLink() {
|
||||
$this->logInWithPermssion('ADMIN');
|
||||
|
||||
// Set up two draft pages with a link from content -> about
|
||||
$linkDest = $this->objFromFixture('Page','about');
|
||||
// Ensure that it's not on the published site
|
||||
$linkDest->doDeleteFromLive();
|
||||
|
||||
$linkSrc = $this->objFromFixture('Page','content');
|
||||
$linkSrc->Content = "<p><a href=\"" . $linkDest->URLSegment . "/\">about us</a></p>";
|
||||
$linkSrc->write();
|
||||
|
||||
// Publish the source of the link, while the dest is still unpublished.
|
||||
$linkSrc->doPublish();
|
||||
|
||||
// Verify that the link isn't broken on draft but is broken on published
|
||||
$this->assertEquals(0, (int)$linkSrc->HasBrokenLink);
|
||||
$this->assertEquals(1, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
|
||||
WHERE \"ID\" = $linkSrc->ID")->value());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user