Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » Bug in StaticPublisher?!

Discuss all other Modules here.

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

Page: 1 2 3
Go to End
Author Topic: 2336 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    Bug in StaticPublisher?! Link to this post

    Hi,

    I am nearly certain I have discovered a bug in the Static Publisher which disables you from exporting any site to HTML files which contains one or more instances of a Redirect Page containing an external URL. This appears to occur in \sapphire\filesystem\Filesystem.php where the method MakeFolder() attempts to name the file using the external URL(s) from the Redirect Pages. This can easily be reproduced in any version 2.3 and later by creating a Redirect Page on your site which has an external URL associated with it and then making a request in the browser to http://www.mysite.com/dev/buildcache?flush=1.

    I think everyone will agree that when exporting a site to cache, links that redirect to external URL's need not have pages created for them.

    Can anyone offer some help on how I can fix this locally? Add some code to prevent pages of this ClassName from being exported?

    Any help offered would be greatly appreciated

    Thanks,
    Garrett

  • martimiz
    Avatar
    Forum Moderator
    1078 Posts

    Re: Bug in StaticPublisher?! Link to this post

    I'm using StaticPublisher quite a bit, but never used redirectorpages. So I didn't test this yet, but if it is true, I'd consider it a bug as well

    You should be able to manually exclude the RedirectorPage type in your page's allPagesToCache() and pagesAffectedByChanges() methods. Something like

    if ($this->ClassName != 'RedirectorPage') { ... }

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Bug in StaticPublisher?! Link to this post

    Yeah. I ended up doing exactly that:

    function allPagesToCache() {

    $urls = array();

    $pages = DataObject::get("SiteTree");

    foreach($pages as $page) {
          if($page->ClassName!="RedirectorPage") {
           $urls = array_merge($urls, (array)$page->subPagesToCache());
          }
    }

    }

    And that pretty much takes care of it. Thanks for replying. Hey listen-- since you're familiar with StaticPublisher, and I'm new, let me ask you a question-- how do you DEPLOY this static version? I looked at the documentation but it's a little unclear. It refers to an .htaccess file here, but this file is confusing because I think it's a collection of examples instead of the ACTUAL file I should use. I haven't been able yet to configure it such that when I request the normal URL for the site I get the static version. Could you walk me through that?

    Thanks,
    Garrett

  • martimiz
    Avatar
    Forum Moderator
    1078 Posts

    Re: Bug in StaticPublisher?! Link to this post

    Since you're clear about the allPagesToCache() and pagesAffectedByChanges() methods, I assume you got to the point where static files are written to the cache directory? If not, don't hesitate...

    Now all you need is a working .htaccess file. On my sites I'm using the .htaccess file pretty much as in the example, I just leave out the ## CONFIG FOR DEV ENVIRONMENTS part.

    The '# Cached content - live webserver' part redirects request to the static file with the same name as the URLSegment - if they exist.
    The '# Cached content - homepage' part redirects requests for the home page (www.mydomain.ext) to the cached index.html - if it exists.
    The '# Dynamic content' part handles all other requests that couldn't be mapped to

    On some hosts %{DOCUMENT_ROOT} is not defined. In that case it won't work, you'll have to replace it by a 'hardcoded' path to the doc root. See also http://www.silverstripe.org/customising-the-cms/show/257044#post257044

    I'll paste in the part that works for me (on LAMP):

    ### SILVERSTRIPE START ###
    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}/html-cache/%1.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /html-cache/%1.html [L]

    # Cached content - homepage
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/html-cache/index.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /html-cache/index.html [L]
       
    ## DYNAMIC CONFIG
       
    # Dynamic content
    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]
    ### SILVERSTRIPE END ###

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Bug in StaticPublisher?! Link to this post

    Hi-- thanks again for your continued help. However, I am not noticing ANYTHING different in how the site behaves once I applied these changes. I'm pretty sure it's still running dynamic. My original RewriteBase was /looksmart. Here is my new .htaccess file:

    ### SILVERSTRIPE START ###

    RewriteEngine On
       
    ## CONFIG FOR DEV ENVIRONMENTS

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

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

    ## DYNAMIC CONFIG

    # Dynamic content
    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]

    ### SILVERSTRIPE END ###

    The /looksmart/cache folder exists, and all the *.html files are in there. What am I doing wrong?

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Bug in StaticPublisher?! Link to this post

    You can do a test to make sure that the static HTML pages are being served. Just download one of those HTML pages & make a simple change and see if it renders live.

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Bug in StaticPublisher?! Link to this post

    Hi and thanks for your reply-- I think you may have misunderstood, however. There is nothing wrong with the HTML files themselves, it's just that when I go to the URL I normally would to look at this site, I am still seeing the dynamic version despite my drastic changes to the .htaccess file. I think I followed the StaticPublisher instructions correctly but alas it has had no effect. Ideas?

    //Garrett

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Bug in StaticPublisher?! Link to this post

    It sounded like you were unsure if the Dynamic pages or the HTML pages were actually being served. That's why I suggested you modify an HTML page directly, visit your web browser and check to make sure the Static Publisher was or was not working.

    If this is for your hosted site, not localhost, I think you need to put back your RewriteBase and use this exact code (at least that's what I did and it's working properly). I also left out the Config for Dev Environments (localhost). In martimiz's example, the default folder was changed from "cache" to "html-cache".

    1.

    ### SILVERSTRIPE START ###

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

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /looksmart

    ## CACHE 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 CONFIG ##

    # Dynamic content
    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 ###

    2. Did you add this to your mysite > _config.php ?

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

    3. And it sounds like you have put the needed code into Page.php (//Return a list of all pages to cache... & //Get a list of URLs to cache related to this page)

    4. And obviously you ran mysite.com/dev/buildcache or that cache folder wouldn't exist.

    2336 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.