Jump to content


Photo

Module: Maintenance Mode


  • Please log in to reply
49 replies to this topic

#1 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 25 August 2011 - 02:11 PM

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.proce...intenance-mode/
 

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



#2 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,156 posts
  • 1707

  • LocationVihti, Finland

Posted 25 August 2011 - 02:26 PM

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 :)

#3 ryan

ryan

    Reiska

  • Administrators
  • 7,797 posts
  • 6573

  • LocationAtlanta, GA

Posted 26 August 2011 - 08:05 AM

Thanks Pete, it seems to work great! Nice job.

#4 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 26 August 2011 - 01:19 PM

Cheers guys!

Congrats on your release too apeisa - you'rs is a bit bigger, but who's measuring! :D

#5 Soma

Soma

    Hero Member

  • Moderators
  • 5,057 posts
  • 3823

  • LocationSH, Switzerland

Posted 26 August 2011 - 02:34 PM

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.

@somartist | modules created | support me, flattr my work flattr.com


#6 SiNNuT

SiNNuT

    Hero Member

  • Members
  • PipPipPipPipPip
  • 548 posts
  • 431

  • LocationThe Netherlands

Posted 27 August 2011 - 08:22 AM

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.

#7 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 27 August 2011 - 02:22 PM

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.

#8 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 27 August 2011 - 03:31 PM

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.

#9 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,156 posts
  • 1707

  • LocationVihti, Finland

Posted 27 August 2011 - 03:49 PM

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.

#10 diogo

diogo

    Hero Member

  • Moderators
  • 2,897 posts
  • 2303

  • LocationPorto, Portugal

Posted 02 November 2011 - 07:50 AM

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?

#11 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 02 November 2011 - 08:29 AM

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.

#12 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 02 November 2011 - 10:30 AM

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 :)

#13 diogo

diogo

    Hero Member

  • Moderators
  • 2,897 posts
  • 2303

  • LocationPorto, Portugal

Posted 02 November 2011 - 10:41 AM

That was quick :)

This solution solves the problem well, thanks!

#14 Jeroen

Jeroen

    Distinguished Member

  • Members
  • PipPip
  • 19 posts
  • 4

Posted 04 November 2011 - 07:42 AM

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?



#15 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 04 November 2011 - 07:59 AM

I'll have a look in a bit and get back to you.

#16 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 04 November 2011 - 08:11 AM

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?

#17 Jeroen

Jeroen

    Distinguished Member

  • Members
  • PipPip
  • 19 posts
  • 4

Posted 04 November 2011 - 08:33 AM

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?

#18 Pete

Pete

    Forum Admin

  • Administrators
  • 2,422 posts
  • 1455

  • LocationChester, England

Posted 04 November 2011 - 09:22 AM

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.

#19 Jeroen

Jeroen

    Distinguished Member

  • Members
  • PipPip
  • 19 posts
  • 4

Posted 04 November 2011 - 09:34 AM

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.

#20 Jeroen

Jeroen

    Distinguished Member

  • Members
  • PipPip
  • 19 posts
  • 4

Posted 04 November 2011 - 10:22 AM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users