Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

StaticPublisher giving out only Page Not Found pages


Go to End


6 Posts   2123 Views

Avatar
ronaan

Community Member, 9 Posts

9 May 2012 at 9:56pm

Hello everyone,

since Silverstripe is holding our ISO9001 documentation, our QM requested to have a static copy of the site on hand.

So after some looking, I stumbled across Staticpublisher. Took some looking around, but in the end I got it to run without error messages. The list I get when I do a /mysite/dev/buildcache/?flush=1 looks exactly like my sitemap,

but

every page has the same contents - the default "Page not found" page.

What did I do wrong?

I did add this code to page.php:

// page classes for static publisher added by t 

/** 
* Return a list of all the pages to cache 
*/ 
function allPagesToCache() { 
// Get each page type to define its sub-urls 
$urls = array(); 

// memory intensive depending on number of pages 
$pages = DataObject::get("Page");  

foreach($pages as $page) { 
$urls = array_merge($urls, (array)$page->subPagesToCache()); 
} 

// add any custom URLs which are not SiteTree instances 
$urls[] = "sitemap.xml"; 

return $urls; 
} 

/** 
* Get a list of URLs to cache related to this page 
*/ 
function subPagesToCache() { 
$urls = array(); 

// add current page 
$urls[] = $this->Link(); 

// cache the RSS feed if comments are enabled 
if ($this->ProvideComments) { 
$urls[] = Director::absoluteBaseURL() . "pagecomment/rss/" . $this->ID; 
} 

return $urls; 
} 

function pagesAffectedByChanges() { 
$urls = $this->subPagesToCache(); 
if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
 return $urls; 
} 

I also modified .htaccess like this:

### SILVERSTRIPE START ### 
<Files *.ss> 
Order deny,allow 
Deny from all 
Allow from 127.0.0.1 
</Files> 

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase / 

## CONFIG FOR TEST/LIVE ENVIRONMENTS 

# Cached content - live webserver 
RewriteCond %{REQUEST_METHOD} ^GET$ 
RewriteCond %{QUERY_STRING} ^$ 
RewriteCond %{REQUEST_URI} /(.*[^/])/?$ 
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .* /cache/%1.html [L] 

# Cached content - homepage 
RewriteCond %{REQUEST_METHOD} ^GET$ 
RewriteCond %{QUERY_STRING} ^$ 
RewriteCond %{REQUEST_URI} ^/?$ 
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .* /cache/index.html [L] 

### Dynamic ### 
RewriteCond %{REQUEST_URI} !(\.gif$)|(\.jpg$)|(\.png$)|(\.css$)|(\.js$)|(\.php$)
 
RewriteCond %{REQUEST_URI} ^(.*)$ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L] 
</IfModule> 
### SILVERSTRIPE END ###

and I added to _config.php

// StaticPublisher
Object::add_extension("SiteTree", "FilesystemPublisher('cache/', 'html')"); 

Where did I take a wrong turn?

In the end, it's only 86 pages so I could basically print everyone to pdfcreator once a year but... why bother when there's a really smooth solution available, right?

Thanks in advance for any comments.

Avatar
Willr

Forum Moderator, 5523 Posts

13 May 2012 at 6:31pm

$urls[] = $this->Link();

Perhaps try AbsoluteLink rather than link? If you look at the base tag in that HTML generated does it match your sites domain?

Avatar
ronaan

Community Member, 9 Posts

16 May 2012 at 7:53pm

AbsoluteLink didn't change anything, sorry.
The source code of every page in the cache directory basically looks like this

<!DOCTYPE html>

<html lang="en-US">
  <head>
		<base href="http://10.22.140.204/QM/"><!--[if lte IE 6]></base><![endif]-->
		<title>Page not found &raquo; Lebenshilfe Werkstätten QMS</title>
		<meta name="generator" content="SilverStripe - http://silverstripe.org" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />

		<link rel="shortcut icon" href="/favicon.ico" />
		
		 
		 
		 
		
		<!--[if IE 6]>
			<style type="text/css">
			 @import url(themes/blackcandy/css/ie6.css);
			</style> 
		<![endif]-->
	<link rel="stylesheet" type="text/css" href="http://10.22.140.204/QM/themes/blackcandy/css/layout.css?m=1335254291" />
<link rel="stylesheet" type="text/css" href="http://10.22.140.204/QM/themes/blackcandy/css/typography.css?m=1333542189" />
<link rel="stylesheet" type="text/css" href="http://10.22.140.204/QM/themes/blackcandy/css/form.css?m=1279014110" />
</head>
<body>
	<div id="BgContainer">
		<div id="Container">
			<div id="Header">
				
		   		<h1>Lebenshilfe Werkstätten QMS</h1>
		    	<p></p>
			</div>
		
			<div id="Navigation">
				<ul>
 		  
  		<li><a href="/QM/index-2/" title="Wechseln zu Übersicht" class="link"><span>Übersicht</span></a></li>
   		  
  		<li><a href="/QM/qm-handbuch/" title="Wechseln zu QM-Handbuch" class="link"><span>QM-Handbuch</span></a></li>
   		  
  		<li><a href="/QM/haccp-handbuch/" title="Wechseln zu HACCP-Handbuch" class="link"><span>HACCP-Handbuch</span></a></li>
   		  
  		<li><a href="/QM/kontakt/" title="Wechseln zu Kontakt" class="link"><span>Kontakt</span></a></li>
   	
 </ul>
		  	</div>
	  	
		  	<div class="clear"><!-- --></div>
		
			<div id="Layout">
			  <div class="typography">
	

	
	
		<h2>Page not found</h2>
	
		<p>Die Seite konnte nicht aufgerufen werden. Bitte informieren Sie den Administrator.</p>
		
		
	
</div>
			</div>
		
		   <div class="clear"><!-- --></div>
		</div>
		<div id="Footer">
			<div class="footerTop">
	<!-- -->
</div>
<p>Copyright &copy; 2007-2012 Lebenshilfe Werkstätten Forchheim gGmbH | Erstellt mit <a href="http://www.silverstripe.org" title="Dieses QMS wurde mit SilverStripe realisiert">SilverStripe Open Source CMS</a></p>

		</div> 
	</div>
</body>
</html>

I did originally point the browser to 10.22.140.204:8086 but it seems to work without the port as well (there's other stuff running on the same machine).

Just now tried to do /dev/buildcache without the port number and that might be the problem, I got this at the end of the page:

 * Publishing page 86/86: sitemap.xml
[User Error] Uncaught Exception: Object->__call(): the method 'sitemap' does not exist on 'DevelopmentAdmin'GET /QM/dev/sitemap.xmlLine 724 in C:\inetpub\wwwroot\QM\sapphire\core\Object.phpSource715 				
716 				default :
717 					throw new Exception (
718 						"Object->__call(): extra method $method is invalid on $this->class:" . var_export($config, true)
719 					);
720 			}
721 		} else {
722 			// Please do not change the exception code number below.
723 			
724 			throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175);
725 		}
726 	}
727 	
728 	// -----------------------------------------------------------------------------------------------------------------
729 	
730 	/**
TraceObject->__call(sitemap,Array)

Line 143 of RequestHandler.php
DevelopmentAdmin->sitemap(SS_HTTPRequest)

Line 143 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)

Line 147 of Controller.php
Controller->handleRequest(SS_HTTPRequest)

Line 282 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)

Line 224 of Director.php
Director::test(http://10.22.140.204/QM/dev/sitemap.xml)

Line 186 of FilesystemPublisher.php
FilesystemPublisher->publishPages(Array,,,,,,)

Line 963 of Object.php
Object->extend(publishPages,Array)

Line 108 of RebuildStaticCacheTask.php
RebuildStaticCacheTask->rebuildCache(Array,1)

Line 33 of RebuildStaticCacheTask.php
RebuildStaticCacheTask->index(SS_HTTPRequest)

Line 193 of Controller.php
Controller->handleAction(SS_HTTPRequest)

Line 143 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)

Line 147 of Controller.php
Controller->handleRequest(SS_HTTPRequest)

Line 282 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)

Line 125 of Director.php
Director::direct(dev/buildcache)

Line 127 of main.php

Avatar
ronaan

Community Member, 9 Posts

30 May 2012 at 1:54am

So since I seem to have run against a wall with this....

is there another (easy) way to generate a static copy of the site? PDF export, HTML files, whatever? Something to maybe do once a year. Else I'll just be stuck with sending 80 pages to the pdf printer once a year. Undesirable, but still not so bad...

Avatar
Mateusz U

Community Member, 2 Posts

6 June 2012 at 5:04pm

Hmm, and these pages are fully published, i.e. no difference between live and stage? Otherwise rewrite your pagesAffectedByChanges to only pick up Live items, because that's what static publisher is working against.

So if everything on your site is on draft, or in some other way not accessible, it may be causing this...

m

Avatar
ronaan

Community Member, 9 Posts

6 June 2012 at 6:10pm

Yeah, everything is fully published.