Jump to content

Module: Maintenance Mode


Pete

Recommended Posts

This is a little module that allows you to put your site into maintenance mode should you ever wish to.

It basically checks to see if you're a superuser and if you're not then every page on the site which you try and load will send you to the login page with an appropriate maintenance message.

The styles are hardcoded into the module at present, so changing the default style of the front-end EDIT button could well have a knock-on effect.

Ideas for the future:

I was also thinking about expanding this in future to allow chooseable roles in the configuration that can access the site whilst it's in maintenance mode, as well as adding the messages to the config so they can be translated.

It might also be nice to specify another page to send the user to so that if you want to keep your admin login page hidden you can do.

Thanks to adamkiss whose ListAfterSave module this was written over the top of ;)
Thanks to ryan for solving the last piece of the puzzle and helping me display the message in the top-left of every page.

EDIT: And my particular usage scenario is that I'm building a site on a live server. It's a brand new site so nobody would really know the URL so I thought I'd build it in the root of the site rather than a subfolder and this module lets me do that without letting folks see it until it's finished.

Other usage scenarios could include major template file updates or... whatever else you think it might be good for :)

You can fined the module in the directory here: http://modules.processwire.com/modules/maintenance-mode/
 

v1.0.6 adds ability to bypass maintenance mode for certain user roles.

  • Like 2
Link to comment
Share on other sites

Nice job Pete and congratulations! Will test this right away. Great to see two new community modules released at the same day!

EDIT: Tested and works just like expected! Nice work.

EDIT2: Don't know what I meant with "third party" in this context, community modules is what I meant :)

Link to comment
Share on other sites

Just installed, nice idea! Thanks for sharing.

But, wouldn't it be an bit of a issue to redirect visitors to the PW login page? It's not what I would expect, the /processwire/ path that's usually something you want to hide.

Nice would be to just not render the page and put the put a message instead (that can be customized), or maybe even define a custom page/path to redirect to. And let the /processwire/ still accessible for those who know.

Link to comment
Share on other sites

Nice job Pete.

The module does what you want it to do but in i agree with Soma. When a site is in maintenance mode (or more general "unavailable") i don't want to forward all the site visitors to a login page.

Maybe it can be a nice addition to have some of these kinds of settings and functionality in (a) PW core (module):

site status => live, unavailable

site unavailable message => "The site is currently unavailable" (this would only render the message)

site unavailable page => choose a specific page from the tree (if defined this will render the set page, just like we have a 404 page)

Personally i would welcome this, it is something you see in a lot of other webcms.

Link to comment
Share on other sites

I've nearly finished a version with the last suggestion you listed - a choosable page. Will upload it soon!

Other options will probably follow, however this is probably the more useful setting for now.

Link to comment
Share on other sites

Okay, I've updated the module in the first post to v1.0.1 - it now allows you to choose a page to redirect to. If you don't choose a page to redirect to, it defaults back to the login page.

I'll likely make more changes over time however this makes it much more useful for now :)

EDIT: Just a quick note - you can unselect a page to make it fall back to the login page, however you have to navigate to the page in the tree and click the "unselect" option - this seems to be the default way PageListSelect operates. ryan - is there any quick way for me to add an "unselect" link next to the "select" link at the top of the page tree?

I'll also probably be trying to open the tree automatically to the right page if one is selected, but for now it's fine.

Link to comment
Share on other sites

I'll also probably be trying to open the tree automatically to the right page if one is selected, but for now it's fine.

That is something that Ryan showed me and is used in ProcessRedirects:

<?php
$field = $this->modules->get("InputfieldPageListSelect");
$field->label = 'Select Page to Redirect to';
$field->attr('id+name', 'select_page');
$field->startLabel = "Select Page";
$field->parent_id = 0; // tell it to start from homepage

if(strpos($to, '/') === 0) {
// if a value is already set, determine if it's a page
// if it's a page, then populate the input with the page_id
$page = $this->pages->get($to);
if($page->id) $field->value = $page->id;
} else $page = new NullPage();
$form->add($field);

So $field->parent_id tells where to start (root of it) and $field->value holds the selected page id.

Link to comment
Share on other sites

  • 2 months later...

Pete, thanks for this module. I'm using it in two under construction webpages.

However i have one concern. Because it redirects to one page, the URL changes, and i'm worried that visitors might bookmark it instead of the real page. If so, when they come back, they might think the website is still under maintenance.

Is thee any possibility that the change wouldn't reflect on the URL?

Link to comment
Share on other sites

Glad to hear you're finding it useful :)

I think the simplest solution there would be to get the maintenance page to simply redirect them to the homepage once the site is live - a simple php header in the maintenance page's template file should do the trick.

I'll look at adding a line or two of code so that it maintenance mode is switched off then it redirects silently to the homepage if the maintenance page is requested when I get some free time.

Link to comment
Share on other sites

Okay, updated the file in the original post to version 1.0.2 :)

If the module is installed and you view the maintenance page when you're not logged in as an admin, it takes you straight to the homepage, so that should solve your scenario Diogo. I figured admins might want it to actually render the maintenance page rather than redirect in case they're actually tweaking the look and feel of the maintenance template file and want to see the output ;)

I also switched the hook to run before Page::render instead of before Page::loaded - difference being that if you do before Page::loaded it runs the hook whilst iterating through all the parent pages in the tree to get to the current page, whereas adding the hook before Page::render seems to just run it for the final page in the tree, which is what we want. I just thought I'd mention that in case anyone needs to know for future module-writing :)

This last part also means that the module now works for a maintenance page that's not in the site root - prior to this if your maintenance page's parent wasn't the homepage then it would just fail to work, which I only noticed today. Not that I imagine you'd put it under another page in the tree, but you never know.

@diogo - Going back to your original question, I think you might be asking if it's possible to render the maintenance page without actually changing the URL. That should definitely be possible and might look into it, but the above should work in the meantime. My only worry would be that if your site was in maintenance mode after it was launched and indexed by Google etc, and then Google re-crawled then it would see every page as having the same content. I'm not sure if there is a similar issue either way though as I suppose it would see all pages redirecting to one maintenance page as well the way it currently works. I guess if you turn this on after the site is launched and indexed then I would suggest doing maintenance fairly quickly :)

Link to comment
Share on other sites

Bug?

I changed the loginurl to admin. Everything works like a charm (clean install btw), but..

when I install the maintenance-module and turn it on, it's buggin'

eg. when I try to add a new template (in maintenancemode) and hit 'save',

it adds the template, but my screen remains white..

turn off maintenancemode doesn't help. Uninstalling it, makes it back to normal again.

Probably something simple, but anyone an idea?

Link to comment
Share on other sites

Hmm... can't reproduce your error on my install - I just updated to make sure I had the latest PW download from GitHub as well just to make sure.

What do you mean when you say "I changed the loginurl to admin"? Do you mean you installed the module but didn't specify a maintenance page? Or did you actually specify the maintenance page as the admin page?

Also, do you have any other modules installed that aren't part of the base installation?

Hopefully one of these things will be able to help me track down any issues and we can get this sorted out for you.

Can someone else double-check and see if they get a blank screen in the same way Jeroen describes please?

Link to comment
Share on other sites

In the admin I went to the page 'admin', 'settings' and changed the defaulturl ('processwire') into 'admin'

So from now on I can login into the website by going to the /admin (instead of /processwire). I think that's causing the issues..

I'm sorry if I wasn't clear. I hope I'm now :)

I didn't redirect it to another page (just using the defaultpage). And I don't have any other modules installed

Does this module refer to a pageid, title or.. by default?

Link to comment
Share on other sites

No problem - I understand what you mean now.

I just tried that, and apart from it redirecting to a "404 page not found" page when you save the admin page with the new URL, I was still able to create a new template okay when I went in via the new admin URL.

The module redirects to the value of config->urls->admin by default, so it actually won't matter that the page name has changed (internally PW knows the ID of the admin page so it gets the correct admin URL that way - pretty sure that's how it works).

What browser and and browser version are you using? It's a long shot, but that might help me to reproduce the issue.

Link to comment
Share on other sites

I'm using Google Chrome (16.0.912.21), but Firefox (3.6.17) is showing me exactly the same.

This behaviour is shown to me, while being logged in (administrator) as well as being a visitor (without being logged in).

In the meantime I changed the 'loginurl' back to 'processwire' and it's still showing this blank page.

I will startoff with a fresh install again and will post my findings.

Link to comment
Share on other sites

To my surprise the module seems to be working after a fresh install, using defaultsettings, but..

as I redirect it to the 'About' page it returns 'maintenance status = 1' to visitors (not being logged in).

Feature request:

Is it possible to have the website return a "503 - Service unavailable" status to visitors (and spiders) in maintenance mode?

Link to comment
Share on other sites

Oops - that message you got about the maintenance status was a debug message I left in and might have been the cause of some of your earlier problems, although if it works on a clean install I'd guess the module wasn't causing the issue.

I've removed the offending line and updated the original post with the new file which should be version 1.0.3 now.

It should be possible to add the option for it to return a 503 - I could into that early next week if I don't get around to it today. My only thought on that would be that most folks who don't know what error codes mean might just think the site is broken.

Link to comment
Share on other sites

I don't know.. the issue popped up again. I just reinstalled everything for the 2nd time..

I will check out the new file.

A 503-status might prevent showing up in the SERPs like '404-page not found' in some cases.

I would love the feature to be added  :)

Link to comment
Share on other sites

No problem.

The default header code for redirects in PW is a 302 redirect (page has temporarily moved) which is actually the default code for a redirect in PHP itself.

The 302 (the way it currently works) might actually the best header anyway as it tells search engines to always check the original URL for a page next time it visits despite the redirect and that the redirect is only temporary. I don't think it affects SEO in any way looking at it - as long as maintenance more isn't left switched on for months of course ;)

A 503 suggests the actual server is down for maintenance if I'm reading the description right on Wikipedia, although I see it says it's only temporary: http://en.m.wikipedia.org/wiki/List_of_HTTP_status_codes

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...