Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

API CHANGE Removed SiteTree->HomepageForDomain and related functional…

…ity ($write_homepage_map and generate_homepage_domain_map()), use new 'homepagefordomain' module instead (fixes #6902)
  • Loading branch information...
commit 1827dc6727b6957fdddbbdbbe46dba4287ab2b9e 1 parent c6b259e
Ingo Schommer chillu authored
17 code/controllers/RootURLController.php
View
@@ -28,17 +28,20 @@ class RootURLController extends Controller {
*/
public static function get_homepage_link() {
if(!self::$cached_homepage_link) {
- $host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
- $SQL_host = Convert::raw2sql($host);
- $candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%$SQL_host%'");
-
- if($candidates) foreach($candidates as $candidate) {
- if(preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
- self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
+ // TODO Move to 'homepagefordomain' module
+ if(class_exists('HomepageForDomainExtension')) {
+ $host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
+ $SQL_host = Convert::raw2sql($host);
+ $candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%$SQL_host%'");
+ if($candidates) foreach($candidates as $candidate) {
+ if(preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
+ self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
+ }
}
}
if(!self::$cached_homepage_link) {
+ // TODO Move to 'translatable' module
if (
class_exists('Translatable')
&& Object::has_extension('SiteTree', 'Translatable')
43 code/model/SiteTree.php
View
@@ -71,7 +71,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
"ExtraMeta" => "HTMLText",
"ShowInMenus" => "Boolean",
"ShowInSearch" => "Boolean",
- "HomepageForDomain" => "Varchar(100)",
"Sort" => "Int",
"HasBrokenFile" => "Boolean",
"HasBrokenLink" => "Boolean",
@@ -154,11 +153,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
"Versioned('Stage', 'Live')",
);
- /**
- * Whether or not to write the homepage map for static publisher
- */
- public static $write_homepage_map = true;
-
static $searchable_fields = array(
'Title',
'Content',
@@ -1908,19 +1902,7 @@ function getSettingsFields() {
$parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SiteTree', 'ID', 'MenuTitle')
),
new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')),
- 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')
- )
+ new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch'))
),
$tabAccess = new Tab('Access',
$viewersOptionsField = new OptionsetField(
@@ -2019,7 +2001,6 @@ function fieldLabels($includerelations = true) {
$labels['EditorGroups'] = _t('SiteTree.EDITORGROUPS', "Editor Groups");
$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['HomepageForDomain'] = _t('SiteTree.HomepageForDomain', 'Hompage for this domain');
$labels['CanViewType'] = _t('SiteTree.Viewers', 'Viewers Groups');
$labels['CanEditType'] = _t('SiteTree.Editors', 'Editors Groups');
$labels['Comments'] = _t('SiteTree.Comments', 'Comments');
@@ -2165,34 +2146,12 @@ function doPublish() {
}
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
$this->invokeWithExtensions('onAfterPublish', $original);
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
*
6 lang/en_US.php
View
@@ -360,17 +360,11 @@
$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']['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(
'Content',
PR_MEDIUM,
'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']['LINKCHANGENOTE'] = 'Changing this page\'s link will also affect the links of all child pages.';
$lang['en_US']['SiteTree']['MENUTITLE'] = 'Navigation label';
58 tests/controller/RootURLControllerTest.php
View
@@ -6,71 +6,13 @@
class RootURLControllerTest extends SapphireTest {
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() {
$default = $this->objFromFixture('Page', 'home');
- $nested = $this->objFromFixture('Page', 'nested');
SiteTree::disable_nested_urls();
$this->assertEquals('home', RootURLController::get_homepage_link());
SiteTree::enable_nested_urls();
$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();
}
}
34 tests/staticpublisher/FilesystemPublisherTest.php
View
@@ -15,7 +15,6 @@ function setUp() {
parent::setUp();
Object::add_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
- SiteTree::$write_homepage_map = false;
$this->orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching;
FilesystemPublisher::$domain_based_caching = false;
@@ -25,7 +24,6 @@ function tearDown() {
parent::tearDown();
Object::remove_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
- SiteTree::$write_homepage_map = true;
FilesystemPublisher::$domain_based_caching = $this->orig['domain_based_caching'];
@@ -127,38 +125,6 @@ function testHasCalledParentConstructor() {
$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
* StaticPublishing needs to be able to retrieve a non-null theme at the time publishPages() is called.
Please sign in to comment.
Something went wrong with that request. Please try again.