mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
API CHANGE Removed SiteTree->HomepageForDomain and related functionality ($write_homepage_map and generate_homepage_domain_map()), use new 'homepagefordomain' module instead (fixes #6902)
This commit is contained in:
parent
c6b259e856
commit
1827dc6727
@ -28,17 +28,20 @@ class RootURLController extends Controller {
|
|||||||
*/
|
*/
|
||||||
public static function get_homepage_link() {
|
public static function get_homepage_link() {
|
||||||
if(!self::$cached_homepage_link) {
|
if(!self::$cached_homepage_link) {
|
||||||
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
|
// TODO Move to 'homepagefordomain' module
|
||||||
$SQL_host = Convert::raw2sql($host);
|
if(class_exists('HomepageForDomainExtension')) {
|
||||||
$candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%$SQL_host%'");
|
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
|
||||||
|
$SQL_host = Convert::raw2sql($host);
|
||||||
if($candidates) foreach($candidates as $candidate) {
|
$candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%$SQL_host%'");
|
||||||
if(preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
|
if($candidates) foreach($candidates as $candidate) {
|
||||||
self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
|
if(preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
|
||||||
|
self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!self::$cached_homepage_link) {
|
if(!self::$cached_homepage_link) {
|
||||||
|
// TODO Move to 'translatable' module
|
||||||
if (
|
if (
|
||||||
class_exists('Translatable')
|
class_exists('Translatable')
|
||||||
&& Object::has_extension('SiteTree', 'Translatable')
|
&& Object::has_extension('SiteTree', 'Translatable')
|
||||||
|
@ -71,7 +71,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
"ExtraMeta" => "HTMLText",
|
"ExtraMeta" => "HTMLText",
|
||||||
"ShowInMenus" => "Boolean",
|
"ShowInMenus" => "Boolean",
|
||||||
"ShowInSearch" => "Boolean",
|
"ShowInSearch" => "Boolean",
|
||||||
"HomepageForDomain" => "Varchar(100)",
|
|
||||||
"Sort" => "Int",
|
"Sort" => "Int",
|
||||||
"HasBrokenFile" => "Boolean",
|
"HasBrokenFile" => "Boolean",
|
||||||
"HasBrokenLink" => "Boolean",
|
"HasBrokenLink" => "Boolean",
|
||||||
@ -154,11 +153,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
"Versioned('Stage', 'Live')",
|
"Versioned('Stage', 'Live')",
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not to write the homepage map for static publisher
|
|
||||||
*/
|
|
||||||
public static $write_homepage_map = true;
|
|
||||||
|
|
||||||
static $searchable_fields = array(
|
static $searchable_fields = array(
|
||||||
'Title',
|
'Title',
|
||||||
'Content',
|
'Content',
|
||||||
@ -1908,19 +1902,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
$parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SiteTree', 'ID', 'MenuTitle')
|
$parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SiteTree', 'ID', 'MenuTitle')
|
||||||
),
|
),
|
||||||
new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')),
|
new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')),
|
||||||
new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch')),
|
new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch'))
|
||||||
new LiteralField(
|
|
||||||
"HomepageForDomainInfo",
|
|
||||||
"<p>" .
|
|
||||||
_t('SiteTree.NOTEUSEASHOMEPAGE',
|
|
||||||
"Use this page as the 'home page' for the following domains:
|
|
||||||
(separate multiple domains with commas)") .
|
|
||||||
"</p>"
|
|
||||||
),
|
|
||||||
new TextField(
|
|
||||||
"HomepageForDomain",
|
|
||||||
_t('SiteTree.HOMEPAGEFORDOMAIN', "Domain(s)", PR_MEDIUM, 'Listing domains that should be used as homepage')
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
$tabAccess = new Tab('Access',
|
$tabAccess = new Tab('Access',
|
||||||
$viewersOptionsField = new OptionsetField(
|
$viewersOptionsField = new OptionsetField(
|
||||||
@ -2019,7 +2001,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
$labels['EditorGroups'] = _t('SiteTree.EDITORGROUPS', "Editor Groups");
|
$labels['EditorGroups'] = _t('SiteTree.EDITORGROUPS', "Editor Groups");
|
||||||
$labels['URLSegment'] = _t('SiteTree.URLSegment', 'URL Segment', PR_MEDIUM, 'URL for this page');
|
$labels['URLSegment'] = _t('SiteTree.URLSegment', 'URL Segment', PR_MEDIUM, 'URL for this page');
|
||||||
$labels['Content'] = _t('SiteTree.Content', 'Content', PR_MEDIUM, 'Main HTML Content for a page');
|
$labels['Content'] = _t('SiteTree.Content', 'Content', PR_MEDIUM, 'Main HTML Content for a page');
|
||||||
$labels['HomepageForDomain'] = _t('SiteTree.HomepageForDomain', 'Hompage for this domain');
|
|
||||||
$labels['CanViewType'] = _t('SiteTree.Viewers', 'Viewers Groups');
|
$labels['CanViewType'] = _t('SiteTree.Viewers', 'Viewers Groups');
|
||||||
$labels['CanEditType'] = _t('SiteTree.Editors', 'Editors Groups');
|
$labels['CanEditType'] = _t('SiteTree.Editors', 'Editors Groups');
|
||||||
$labels['Comments'] = _t('SiteTree.Comments', 'Comments');
|
$labels['Comments'] = _t('SiteTree.Comments', 'Comments');
|
||||||
@ -2165,34 +2146,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
}
|
}
|
||||||
Versioned::set_reading_mode($origMode);
|
Versioned::set_reading_mode($origMode);
|
||||||
|
|
||||||
// Check to write CMS homepage map.
|
|
||||||
$usingStaticPublishing = false;
|
|
||||||
foreach(ClassInfo::subclassesFor('StaticPublisher') as $class) if ($this->hasExtension($class)) $usingStaticPublishing = true;
|
|
||||||
|
|
||||||
// NOTE: if you change the path here, you must also change it in sapphire/static-main.php
|
|
||||||
if (self::$write_homepage_map) {
|
|
||||||
if ($usingStaticPublishing && $map = SiteTree::generate_homepage_domain_map()) {
|
|
||||||
@file_put_contents(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php', "<?php\n\$homepageMap = ".var_export($map, true)."; ?>");
|
|
||||||
} else { if (file_exists(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php')) unlink(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php'); }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle activities undertaken by extensions
|
// Handle activities undertaken by extensions
|
||||||
$this->invokeWithExtensions('onAfterPublish', $original);
|
$this->invokeWithExtensions('onAfterPublish', $original);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function generate_homepage_domain_map() {
|
|
||||||
$domainSpecificHomepages = Versioned::get_by_stage('Page', 'Live', "\"HomepageForDomain\" != ''", "\"URLSegment\" ASC");
|
|
||||||
if (!$domainSpecificHomepages) return false;
|
|
||||||
|
|
||||||
$map = array();
|
|
||||||
foreach($domainSpecificHomepages->map('URLSegment', 'HomepageForDomain') as $url => $domains) {
|
|
||||||
foreach(explode(',', $domains) as $domain) $map[$domain] = $url;
|
|
||||||
}
|
|
||||||
return $map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unpublish this page - remove it from the live site
|
* Unpublish this page - remove it from the live site
|
||||||
*
|
*
|
||||||
|
@ -360,17 +360,11 @@ $lang['en_US']['SiteTree']['EDIT_ALL_DESCRIPTION'] = 'Edit any page';
|
|||||||
$lang['en_US']['SiteTree']['EDIT_ALL_HELP'] = 'Ability to edit any page on the site, regardless of the settings on the Access tab. Requires the "Access to \'Pages\' section" permission';
|
$lang['en_US']['SiteTree']['EDIT_ALL_HELP'] = 'Ability to edit any page on the site, regardless of the settings on the Access tab. Requires the "Access to \'Pages\' section" permission';
|
||||||
$lang['en_US']['SiteTree']['Editors'] = 'Editors Groups';
|
$lang['en_US']['SiteTree']['Editors'] = 'Editors Groups';
|
||||||
$lang['en_US']['SiteTree']['HASBROKENLINKS'] = 'This page has broken links.';
|
$lang['en_US']['SiteTree']['HASBROKENLINKS'] = 'This page has broken links.';
|
||||||
$lang['en_US']['SiteTree']['HOMEPAGEFORDOMAIN'] = array(
|
|
||||||
'Domain(s)',
|
|
||||||
PR_MEDIUM,
|
|
||||||
'Listing domains that should be used as homepage'
|
|
||||||
);
|
|
||||||
$lang['en_US']['SiteTree']['HTMLEDITORTITLE'] = array(
|
$lang['en_US']['SiteTree']['HTMLEDITORTITLE'] = array(
|
||||||
'Content',
|
'Content',
|
||||||
PR_MEDIUM,
|
PR_MEDIUM,
|
||||||
'HTML editor title'
|
'HTML editor title'
|
||||||
);
|
);
|
||||||
$lang['en_US']['SiteTree']['HomepageForDomain'] = 'Hompage for this domain';
|
|
||||||
$lang['en_US']['SiteTree']['INHERIT'] = 'Inherit from parent page';
|
$lang['en_US']['SiteTree']['INHERIT'] = 'Inherit from parent page';
|
||||||
$lang['en_US']['SiteTree']['LINKCHANGENOTE'] = 'Changing this page\'s link will also affect the links of all child pages.';
|
$lang['en_US']['SiteTree']['LINKCHANGENOTE'] = 'Changing this page\'s link will also affect the links of all child pages.';
|
||||||
$lang['en_US']['SiteTree']['MENUTITLE'] = 'Navigation label';
|
$lang['en_US']['SiteTree']['MENUTITLE'] = 'Navigation label';
|
||||||
|
@ -6,71 +6,13 @@
|
|||||||
class RootURLControllerTest extends SapphireTest {
|
class RootURLControllerTest extends SapphireTest {
|
||||||
static $fixture_file = 'RootURLControllerTest.yml';
|
static $fixture_file = 'RootURLControllerTest.yml';
|
||||||
|
|
||||||
function testHomepageForDomain() {
|
|
||||||
$originalHost = $_SERVER['HTTP_HOST'];
|
|
||||||
|
|
||||||
// Tests matching an HTTP_HOST value to URLSegment homepage values
|
|
||||||
$tests = array(
|
|
||||||
'page.co.nz' => 'page1',
|
|
||||||
'www.page.co.nz' => 'page1',
|
|
||||||
'help.com' => 'page1',
|
|
||||||
'www.help.com' => 'page1',
|
|
||||||
'something.com' => 'page1',
|
|
||||||
'www.something.com' => 'page1',
|
|
||||||
|
|
||||||
'other.co.nz' => 'page2',
|
|
||||||
'www.other.co.nz' => 'page2',
|
|
||||||
'right' => 'page2',
|
|
||||||
'www. right' => 'page2',
|
|
||||||
|
|
||||||
'only.com' => 'page3',
|
|
||||||
'www.only.com' => 'page3',
|
|
||||||
|
|
||||||
'www.somethingelse.com' => 'home',
|
|
||||||
'somethingelse.com' => 'home',
|
|
||||||
|
|
||||||
// Test some potential false matches to page2 and page3
|
|
||||||
'alternate.only.com' => 'home',
|
|
||||||
'www.alternate.only.com' => 'home',
|
|
||||||
'alternate.something.com' => 'home',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach($tests as $domain => $urlSegment) {
|
|
||||||
RootURLController::reset();
|
|
||||||
$_SERVER['HTTP_HOST'] = $domain;
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$urlSegment,
|
|
||||||
RootURLController::get_homepage_link(),
|
|
||||||
"Testing $domain matches $urlSegment"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$_SERVER['HTTP_HOST'] = $originalHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetHomepageLink() {
|
public function testGetHomepageLink() {
|
||||||
$default = $this->objFromFixture('Page', 'home');
|
$default = $this->objFromFixture('Page', 'home');
|
||||||
$nested = $this->objFromFixture('Page', 'nested');
|
|
||||||
|
|
||||||
SiteTree::disable_nested_urls();
|
SiteTree::disable_nested_urls();
|
||||||
$this->assertEquals('home', RootURLController::get_homepage_link());
|
$this->assertEquals('home', RootURLController::get_homepage_link());
|
||||||
SiteTree::enable_nested_urls();
|
SiteTree::enable_nested_urls();
|
||||||
$this->assertEquals('home', RootURLController::get_homepage_link());
|
$this->assertEquals('home', RootURLController::get_homepage_link());
|
||||||
|
|
||||||
$nested->HomepageForDomain = str_replace('www.', null, $_SERVER['HTTP_HOST']);
|
|
||||||
$nested->write();
|
|
||||||
|
|
||||||
RootURLController::reset();
|
|
||||||
SiteTree::disable_nested_urls();
|
|
||||||
$this->assertEquals('nested-home', RootURLController::get_homepage_link());
|
|
||||||
|
|
||||||
RootURLController::reset();
|
|
||||||
SiteTree::enable_nested_urls();
|
|
||||||
$this->assertEquals('home/nested-home', RootURLController::get_homepage_link());
|
|
||||||
|
|
||||||
$nested->HomepageForDomain = null;
|
|
||||||
$nested->write();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -15,7 +15,6 @@ class FilesystemPublisherTest extends SapphireTest {
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Object::add_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
|
Object::add_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
|
||||||
SiteTree::$write_homepage_map = false;
|
|
||||||
|
|
||||||
$this->orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching;
|
$this->orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching;
|
||||||
FilesystemPublisher::$domain_based_caching = false;
|
FilesystemPublisher::$domain_based_caching = false;
|
||||||
@ -25,7 +24,6 @@ class FilesystemPublisherTest extends SapphireTest {
|
|||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
|
|
||||||
Object::remove_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
|
Object::remove_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
|
||||||
SiteTree::$write_homepage_map = true;
|
|
||||||
|
|
||||||
FilesystemPublisher::$domain_based_caching = $this->orig['domain_based_caching'];
|
FilesystemPublisher::$domain_based_caching = $this->orig['domain_based_caching'];
|
||||||
|
|
||||||
@ -127,38 +125,6 @@ class FilesystemPublisherTest extends SapphireTest {
|
|||||||
$this->assertEquals($fsp->class, 'FilesystemPublisher');
|
$this->assertEquals($fsp->class, 'FilesystemPublisher');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testHomepageMapIsWithStaticPublishing() {
|
|
||||||
$this->logInWithPermission('ADMIN');
|
|
||||||
|
|
||||||
$p1 = new Page();
|
|
||||||
$p1->URLSegment = strtolower(__CLASS__).'-page-1';
|
|
||||||
$p1->HomepageForDomain = '';
|
|
||||||
$p1->write();
|
|
||||||
$p1->doPublish();
|
|
||||||
$p2 = new Page();
|
|
||||||
$p2->URLSegment = strtolower(__CLASS__).'-page-2';
|
|
||||||
$p2->HomepageForDomain = 'domain1';
|
|
||||||
$p2->write();
|
|
||||||
$p2->doPublish();
|
|
||||||
$p3 = new Page();
|
|
||||||
$p3->URLSegment = strtolower(__CLASS__).'-page-3';
|
|
||||||
$p3->HomepageForDomain = 'domain2,domain3';
|
|
||||||
$p3->write();
|
|
||||||
$p3->doPublish();
|
|
||||||
|
|
||||||
$map = SiteTree::generate_homepage_domain_map();
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$map,
|
|
||||||
array(
|
|
||||||
'domain1' => strtolower(__CLASS__).'-page-2',
|
|
||||||
'domain2' => strtolower(__CLASS__).'-page-3',
|
|
||||||
'domain3' => strtolower(__CLASS__).'-page-3',
|
|
||||||
),
|
|
||||||
'Homepage/domain map is correct when static publishing is enabled'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These are a few simple tests to check that we will be retrieving the correct theme when we need it
|
* These are a few simple tests to check that we will be retrieving the correct theme when we need it
|
||||||
* StaticPublishing needs to be able to retrieve a non-null theme at the time publishPages() is called.
|
* StaticPublishing needs to be able to retrieve a non-null theme at the time publishPages() is called.
|
||||||
|
Loading…
Reference in New Issue
Block a user