mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
BUG Fix issue with children of unpublished pages appearing in sitemap as apparent root pages
This commit is contained in:
parent
a2297c43ef
commit
5f06483b73
@ -56,11 +56,33 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension {
|
|||||||
|
|
||||||
$labels['Priority'] = _t('GoogleSitemaps.METAPAGEPRIO', "Page Priority");
|
$labels['Priority'] = _t('GoogleSitemaps.METAPAGEPRIO', "Page Priority");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that all parent pages of this page (if any) are published
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function hasPublishedParent() {
|
||||||
|
|
||||||
|
// Skip root pages
|
||||||
|
if(empty($this->owner->ParentID)) return true;
|
||||||
|
|
||||||
|
// Ensure direct parent exists
|
||||||
|
$parent = $this->owner->Parent();
|
||||||
|
if(empty($parent) || !$parent->exists()) return false;
|
||||||
|
|
||||||
|
// Check ancestry
|
||||||
|
return $parent->hasPublishedParent();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function canIncludeInGoogleSitemap() {
|
public function canIncludeInGoogleSitemap() {
|
||||||
|
|
||||||
|
// Check that parent page is published
|
||||||
|
if(!$this->owner->hasPublishedParent()) return false;
|
||||||
|
|
||||||
$result = parent::canIncludeInGoogleSitemap();
|
$result = parent::canIncludeInGoogleSitemap();
|
||||||
$result = ($this->owner instanceof ErrorPage) ? false : $result;
|
$result = ($this->owner instanceof ErrorPage) ? false : $result;
|
||||||
|
|
||||||
|
@ -232,6 +232,38 @@ class GoogleSitemapTest extends FunctionalTest {
|
|||||||
$page->Priority = -1;
|
$page->Priority = -1;
|
||||||
$this->assertFalse($page->getGooglePriority());
|
$this->assertFalse($page->getGooglePriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUnpublishedPage() {
|
||||||
|
|
||||||
|
if(!class_exists('SiteTree')) {
|
||||||
|
$this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage');
|
||||||
|
}
|
||||||
|
|
||||||
|
$orphanedPage = new SiteTree();
|
||||||
|
$orphanedPage->ParentID = 999999; // missing parent id
|
||||||
|
$orphanedPage->write();
|
||||||
|
$orphanedPage->publish("Stage", "Live");
|
||||||
|
|
||||||
|
$rootPage = new SiteTree();
|
||||||
|
$rootPage->ParentID = 0;
|
||||||
|
$rootPage->write();
|
||||||
|
$rootPage->publish("Stage", "Live");
|
||||||
|
|
||||||
|
$oldMode = Versioned::get_reading_mode();
|
||||||
|
Versioned::reading_stage('Live');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->assertEmpty($orphanedPage->hasPublishedParent());
|
||||||
|
$this->assertEmpty($orphanedPage->canIncludeInGoogleSitemap());
|
||||||
|
$this->assertNotEmpty($rootPage->hasPublishedParent());
|
||||||
|
$this->assertNotEmpty($rootPage->canIncludeInGoogleSitemap());
|
||||||
|
} catch(Exception $ex) {
|
||||||
|
Versioned::set_reading_mode($oldMode);
|
||||||
|
throw $ex;
|
||||||
|
} // finally {
|
||||||
|
Versioned::set_reading_mode($oldMode);
|
||||||
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user