Skip to content
This repository
Browse code

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 authored March 14, 2012
17  code/controllers/RootURLController.php
@@ -28,17 +28,20 @@ class RootURLController extends Controller {
28 28
 	 */
29 29
 	public static function get_homepage_link() {
30 30
 		if(!self::$cached_homepage_link) {
31  
-			$host       = str_replace('www.', null, $_SERVER['HTTP_HOST']);
32  
-			$SQL_host   = Convert::raw2sql($host);
33  
-			$candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%$SQL_host%'");
34  
-			
35  
-			if($candidates) foreach($candidates as $candidate) {
36  
-				if(preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
37  
-					self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
  31
+			// TODO Move to 'homepagefordomain' module
  32
+			if(class_exists('HomepageForDomainExtension')) {
  33
+				$host       = str_replace('www.', null, $_SERVER['HTTP_HOST']);
  34
+				$SQL_host   = Convert::raw2sql($host);
  35
+				$candidates = DataObject::get('SiteTree', "\"HomepageForDomain\" LIKE '%$SQL_host%'");
  36
+				if($candidates) foreach($candidates as $candidate) {
  37
+					if(preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
  38
+						self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
  39
+					}
38 40
 				}
39 41
 			}
40 42
 			
41 43
 			if(!self::$cached_homepage_link) {
  44
+				// TODO Move to 'translatable' module
42 45
 				if (
43 46
 					class_exists('Translatable')
44 47
 					&& Object::has_extension('SiteTree', 'Translatable')
43  code/model/SiteTree.php
@@ -71,7 +71,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
71 71
 		"ExtraMeta" => "HTMLText",
72 72
 		"ShowInMenus" => "Boolean",
73 73
 		"ShowInSearch" => "Boolean",
74  
-		"HomepageForDomain" => "Varchar(100)",
75 74
 		"Sort" => "Int",
76 75
 		"HasBrokenFile" => "Boolean",
77 76
 		"HasBrokenLink" => "Boolean",
@@ -154,11 +153,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
154 153
 		"Versioned('Stage', 'Live')",
155 154
 	);
156 155
 	
157  
-	/**
158  
-	 * Whether or not to write the homepage map for static publisher
159  
-	 */
160  
-	public static $write_homepage_map = true;
161  
-	
162 156
 	static $searchable_fields = array(
163 157
 		'Title',
164 158
 		'Content',
@@ -1908,19 +1902,7 @@ function getSettingsFields() {
1908 1902
 						$parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SiteTree', 'ID', 'MenuTitle')
1909 1903
 					),
1910 1904
 					new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')),
1911  
-					new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch')),
1912  
-					new LiteralField(
1913  
-						"HomepageForDomainInfo", 
1914  
-						"<p>" . 
1915  
-							_t('SiteTree.NOTEUSEASHOMEPAGE', 
1916  
-							"Use this page as the 'home page' for the following domains: 
1917  
-							(separate multiple domains with commas)") .
1918  
-						"</p>"
1919  
-					),
1920  
-					new TextField(
1921  
-						"HomepageForDomain",
1922  
-						_t('SiteTree.HOMEPAGEFORDOMAIN', "Domain(s)", PR_MEDIUM, 'Listing domains that should be used as homepage')
1923  
-					)
  1905
+					new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch'))
1924 1906
 				),
1925 1907
 				$tabAccess = new Tab('Access',
1926 1908
 					$viewersOptionsField = new OptionsetField(
@@ -2019,7 +2001,6 @@ function fieldLabels($includerelations = true) {
2019 2001
 		$labels['EditorGroups'] = _t('SiteTree.EDITORGROUPS', "Editor Groups");
2020 2002
 		$labels['URLSegment'] = _t('SiteTree.URLSegment', 'URL Segment', PR_MEDIUM, 'URL for this page');
2021 2003
 		$labels['Content'] = _t('SiteTree.Content', 'Content', PR_MEDIUM, 'Main HTML Content for a page');
2022  
-		$labels['HomepageForDomain'] = _t('SiteTree.HomepageForDomain', 'Hompage for this domain');
2023 2004
 		$labels['CanViewType'] = _t('SiteTree.Viewers', 'Viewers Groups');
2024 2005
 		$labels['CanEditType'] = _t('SiteTree.Editors', 'Editors Groups');
2025 2006
 		$labels['Comments'] = _t('SiteTree.Comments', 'Comments');
@@ -2165,34 +2146,12 @@ function doPublish() {
2165 2146
 		}
2166 2147
 		Versioned::set_reading_mode($origMode);
2167 2148
 		
2168  
-		// Check to write CMS homepage map.
2169  
-		$usingStaticPublishing = false;
2170  
-		foreach(ClassInfo::subclassesFor('StaticPublisher') as $class) if ($this->hasExtension($class)) $usingStaticPublishing = true;
2171  
-
2172  
-		// NOTE: if you change the path here, you must also change it in sapphire/static-main.php
2173  
-		if (self::$write_homepage_map) {
2174  
-			if ($usingStaticPublishing && $map = SiteTree::generate_homepage_domain_map()) {
2175  
-				@file_put_contents(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php', "<?php\n\$homepageMap = ".var_export($map, true)."; ?>");
2176  
-			} else { if (file_exists(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php')) unlink(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php'); }
2177  
-		}
2178  
-		
2179 2149
 		// Handle activities undertaken by extensions
2180 2150
 		$this->invokeWithExtensions('onAfterPublish', $original);
2181 2151
 		
2182 2152
 		return true;
2183 2153
 	}
2184 2154
 	
2185  
-	static function generate_homepage_domain_map() {
2186  
-		$domainSpecificHomepages = Versioned::get_by_stage('Page', 'Live', "\"HomepageForDomain\" != ''", "\"URLSegment\" ASC");
2187  
-		if (!$domainSpecificHomepages) return false;
2188  
-		
2189  
-		$map = array();
2190  
-		foreach($domainSpecificHomepages->map('URLSegment', 'HomepageForDomain') as $url => $domains) {
2191  
-			foreach(explode(',', $domains) as $domain) $map[$domain] = $url;
2192  
-		}
2193  
-		return $map;
2194  
-	}
2195  
-	
2196 2155
 	/**
2197 2156
 	 * Unpublish this page - remove it from the live site
2198 2157
 	 * 
6  lang/en_US.php
@@ -360,17 +360,11 @@
360 360
 $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';
361 361
 $lang['en_US']['SiteTree']['Editors'] = 'Editors Groups';
362 362
 $lang['en_US']['SiteTree']['HASBROKENLINKS'] = 'This page has broken links.';
363  
-$lang['en_US']['SiteTree']['HOMEPAGEFORDOMAIN'] = array(
364  
-	'Domain(s)',
365  
-	PR_MEDIUM,
366  
-	'Listing domains that should be used as homepage'
367  
-);
368 363
 $lang['en_US']['SiteTree']['HTMLEDITORTITLE'] = array(
369 364
 	'Content',
370 365
 	PR_MEDIUM,
371 366
 	'HTML editor title'
372 367
 );
373  
-$lang['en_US']['SiteTree']['HomepageForDomain'] = 'Hompage for this domain';
374 368
 $lang['en_US']['SiteTree']['INHERIT'] = 'Inherit from parent page';
375 369
 $lang['en_US']['SiteTree']['LINKCHANGENOTE'] = 'Changing this page\'s link will also affect the links of all child pages.';
376 370
 $lang['en_US']['SiteTree']['MENUTITLE'] = 'Navigation label';
58  tests/controller/RootURLControllerTest.php
@@ -6,71 +6,13 @@
6 6
 class RootURLControllerTest extends SapphireTest {
7 7
 	static $fixture_file = 'RootURLControllerTest.yml';
8 8
 	
9  
-	function testHomepageForDomain() {
10  
-		$originalHost = $_SERVER['HTTP_HOST'];
11  
-
12  
-		// Tests matching an HTTP_HOST value to URLSegment homepage values
13  
-		$tests = array(
14  
-			'page.co.nz' => 'page1',
15  
-			'www.page.co.nz' => 'page1',
16  
-			'help.com' => 'page1',
17  
-			'www.help.com' => 'page1',
18  
-			'something.com' => 'page1',
19  
-			'www.something.com' => 'page1',
20  
-
21  
-	 		'other.co.nz' => 'page2',
22  
-	 		'www.other.co.nz' => 'page2',
23  
-			'right' => 'page2',
24  
-			'www. right' => 'page2',
25  
-
26  
-			'only.com' => 'page3',
27  
-			'www.only.com' => 'page3',
28  
-			
29  
-			'www.somethingelse.com' => 'home',
30  
-			'somethingelse.com' => 'home',
31  
-			
32  
-			// Test some potential false matches to page2 and page3
33  
-			'alternate.only.com' => 'home',
34  
-			'www.alternate.only.com' => 'home',
35  
-			'alternate.something.com' => 'home',
36  
-		);
37  
-		
38  
-		foreach($tests as $domain => $urlSegment) {
39  
-			RootURLController::reset();
40  
-			$_SERVER['HTTP_HOST'] = $domain;
41  
-			
42  
-			$this->assertEquals(
43  
-				$urlSegment, 
44  
-				RootURLController::get_homepage_link(), 
45  
-				"Testing $domain matches $urlSegment"
46  
-			);
47  
-		}
48  
-		
49  
-		$_SERVER['HTTP_HOST'] = $originalHost;
50  
-	}
51  
-	
52 9
 	public function testGetHomepageLink() {
53 10
 		$default = $this->objFromFixture('Page', 'home');
54  
-		$nested  = $this->objFromFixture('Page', 'nested');
55 11
 		
56 12
 		SiteTree::disable_nested_urls();
57 13
 		$this->assertEquals('home', RootURLController::get_homepage_link());
58 14
 		SiteTree::enable_nested_urls();
59 15
 		$this->assertEquals('home', RootURLController::get_homepage_link());
60  
-		
61  
-		$nested->HomepageForDomain = str_replace('www.', null, $_SERVER['HTTP_HOST']);
62  
-		$nested->write();
63  
-		
64  
-		RootURLController::reset();
65  
-		SiteTree::disable_nested_urls();
66  
-		$this->assertEquals('nested-home', RootURLController::get_homepage_link());
67  
-		
68  
-		RootURLController::reset();
69  
-		SiteTree::enable_nested_urls();
70  
-		$this->assertEquals('home/nested-home', RootURLController::get_homepage_link());
71  
-		
72  
-		$nested->HomepageForDomain = null;
73  
-		$nested->write();
74 16
 	}
75 17
 	
76 18
 }
34  tests/staticpublisher/FilesystemPublisherTest.php
@@ -15,7 +15,6 @@ function setUp() {
15 15
 		parent::setUp();
16 16
 		
17 17
 		Object::add_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
18  
-		SiteTree::$write_homepage_map = false;
19 18
 		
20 19
 		$this->orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching;
21 20
 		FilesystemPublisher::$domain_based_caching = false;
@@ -25,7 +24,6 @@ function tearDown() {
25 24
 		parent::tearDown();
26 25
 
27 26
 		Object::remove_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
28  
-		SiteTree::$write_homepage_map = true;
29 27
 
30 28
 		FilesystemPublisher::$domain_based_caching = $this->orig['domain_based_caching'];
31 29
 
@@ -127,38 +125,6 @@ function testHasCalledParentConstructor() {
127 125
 		$this->assertEquals($fsp->class, 'FilesystemPublisher');
128 126
 	}
129 127
 	
130  
-	function testHomepageMapIsWithStaticPublishing() {
131  
-		$this->logInWithPermission('ADMIN');
132  
-		
133  
-		$p1 = new Page();
134  
-		$p1->URLSegment = strtolower(__CLASS__).'-page-1';
135  
-		$p1->HomepageForDomain = '';
136  
-		$p1->write();
137  
-		$p1->doPublish();
138  
-		$p2 = new Page();
139  
-		$p2->URLSegment = strtolower(__CLASS__).'-page-2';
140  
-		$p2->HomepageForDomain = 'domain1';
141  
-		$p2->write();
142  
-		$p2->doPublish();
143  
-		$p3 = new Page();
144  
-		$p3->URLSegment = strtolower(__CLASS__).'-page-3';
145  
-		$p3->HomepageForDomain = 'domain2,domain3';
146  
-		$p3->write();
147  
-		$p3->doPublish();
148  
-		
149  
-		$map = SiteTree::generate_homepage_domain_map();
150  
-		
151  
-		$this->assertEquals(
152  
-			$map, 
153  
-			array(
154  
-				'domain1' => strtolower(__CLASS__).'-page-2',
155  
-				'domain2' => strtolower(__CLASS__).'-page-3',
156  
-				'domain3' => strtolower(__CLASS__).'-page-3',
157  
-			), 
158  
-			'Homepage/domain map is correct when static publishing is enabled'
159  
-		);
160  
-	}
161  
-	
162 128
 	/*
163 129
 	 * These are a few simple tests to check that we will be retrieving the correct theme when we need it
164 130
 	 * StaticPublishing needs to be able to retrieve a non-null theme at the time publishPages() is called.

0 notes on commit 1827dc6

Please sign in to comment.
Something went wrong with that request. Please try again.