Problem/Motivation

Either this is a bug in the way the maintenance theme is being applied or the documentation needs updating:

/**
 * A custom theme can be set for the offline page. This applies when the site
 * is explicitly set to maintenance mode through the administration page or when
 * the database is inactive due to an error. It can be set through the
 * 'maintenance_theme' key. The template file should also be copied into the
 * theme. It is located inside 'modules/system/maintenance-page.tpl.php'.
 * Note: This setting does not apply to installation and update pages.
 */
$conf['maintenance_theme'] = 'stark';

If you select a different theme for your site it will be used to display the site offline message - this is contrary to the above comments. A theme set here in settings.php only gets used when the database fails.

Steps to reproduce

Proposed resolution

TBD

Remaining tasks

Decide if the documentation is incorrect or a bug in apply the maiuntenance theme when in maintenance mode.

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mattyoung’s picture

.

jhodgdon’s picture

Status: Active » Postponed (maintainer needs more info)

Jeff: When I read the above (which is in default.settings.php), it looks like it's saying that $conf['maintenance_theme'] should be used when:
- Database is off-line
- You have set the site to maintenance mode

Are you saying that this is not working? Your original report seems to b emissing a "not" somewhere, and I'm not sure what behavior you have observed...

AdamGerthel’s picture

I've just stumbled across this as well. It seems as if it simply doesn't work. Nothing happens when you change $conf['maintenance_theme'] in settings.php. The maintenance theme is enabled, but the default theme is still used for maintenance pages.

Like Jeff mentioned, if I make the DB fail, the maintenance theme I've set in settings.php is used.

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Component: documentation » base system
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Active
Issue tags: +Needs backport to D7

Sounds like a code bug then. Thanks for the confirmation and explanation!

olofbokedal’s picture

Subscribing

catch’s picture

Component: base system » theme system
Priority: Major » Normal

Hmm I'm going to downgrade this from major for the following reasons

It's my understanding that this setting is so that you can have your main site theme used for maintenance instead of Seven (or Garland in D6).

It sounds like people on this issue are trying to set a completely different theme for site maintenance from their main site theme, which might be a valid use case, but I don't think the original system was designed for that at all.

Jeff Burnz’s picture

AFAICT the only thing this setting does is set the theme for when the database fails, which is just fine and the actual bug is the documentation which is rather misleading. All it should say is something like:

This sets the theme in the event of a database failure. When the site is in maintenance the sites default theme will be used.

Or something along those lines.

Also reported here: #1109014: Maintenance theme does not apply

AdamGerthel’s picture

So, it's not supposed to be possible to have a maintenance theme that is different from the site theme? It was possible in D6 using that setting in settings.php

Our use case is for a lot of smaller sites that we produce. In order to have one well made maintenance page across all mini-projects rather than having to custom theme it for each project we produced a small low profile maintenance theme that works well no matter which site uses it.

David_Rothstein’s picture

Status: Active » Needs review
FileSize
2.55 KB

Although it was possible to specify a different maintenance theme in D6, it never really worked reliably. Things would break badly if there was any code on the site that caused the theme system to be initialized too early in the page request. (See #219910-14: Calling theme function from hook_init() interferes with administration theme as well as other comments in that thread - there are actually a host of related issues not just involving the maintenance theme.)

In D7/D8, there is code to deliberately initialize the theme system early on in every page request, so I assume that's what causes it to not work all the time there.

Here's a simple patch that seems to fix things. I suspect it might not be quite as simple as this, but testing it out it works fine.

To really solve this properly we might need something like #981654: Use several themes during the same page request, though.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Hmm, do we have test coverage for maintenance mode?

Note that the Drupal 8.x patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades). When the patch has been rerolled, please set the issue back to "Needs Review."

Tagging as novice for the task of rerolling the Drupal 8.x patch.

Haza’s picture

Status: Needs work » Needs review
FileSize
2.6 KB

Just rerolling the patch with the right directory structure.

xjm’s picture

Issue tags: -Novice

Thanks!

JohnAlbin’s picture

I tried testing this by purposefully putting wrong db info into my settings.php file, but I got a "Uncaught exception thrown in shutdown function" error instead of the maintenance theme. That's how I used to test it in D7. Is this a new bug? Or do I just need to change my testing methodology?

plach’s picture

Sorry if I'm just adding noise but the patch above looks a bit convolute to me (maybe I'm just looking it from the wrong perspective), although it fixed the issue.

The attached one also works and looks like the right fix to me.

@JohnAlbin:

I don't get that exception with wrong db info and this patch applied, but I get:

PDOException: SQLSTATE[42000] [1049] Unknown database 'wrong_db' in lock_may_be_available() (line 167 of [...]\webroot\includes\lock.inc).

with the maintenance theme I set (seven). Looks like the correct behavior to me.

AdamGerthel’s picture

@plach:

Setting the maintenance theme for offline databases using $conf['maintenance_theme'] = 'themename'; only seems to work for themes in /themes folder. Using Bartik, Garland etc works as intended.

However, If the theme is in sites/all/themes or in a profile, such as /profiles/profile-name/themes it doesn't work. I did notice however, that If I copy "seven" to sites/all/themes, rename it, and make it into a subtheme of seven, it actually works. It's all very very strange.

plach’s picture

Are you sure this don't work with sites/all/themes? The profile dir will work only if the profile is the actually installed one.

David_Rothstein’s picture

@plach, does your patch work in the case where the database is online but a fatal error occurs for other reasons? (For example, when a page callback throws an exception.) It doesn't look like it would.

It might make sense to go with your approach as an interim fix, though, since it certainly looks like it would deal with the "site deliberately taken offline" situation. On the other hand, the current codebase already has a "halfway" fix in place, and per @catch's comment in #6 the current split actually does make some sense... Drupal always tries to get the theme from the database (corresponding to the one that was chosen in the user interface), and only consults the settings.php variable when the database is unreachable.

AdamGerthel’s picture

@plach According to my test it doesn't work. Regarding the profile: the profile the theme was in was installed and active. However - how is Drupal supposed to know which profile is installed when the database connection is failing? If the settings.php setting should apply to all scenarios where the database is failing then it has to be able to find a theme that is placed in the correct spot (i.e profiles/xxx/themes, themes, sites/xxx/themes) regardless of whether it's enabled or the default theme.

vinmassaro’s picture

Found this thread trying to figure out why $conf['maintenance_theme'] in settings.php was not working. Hoping to revive this since we need it to work in D7 for our university installation where we want to set a maintenance theme page no matter what theme is being used. Would be happy to submit a D7 patch since the menu.inc code looks the same. Thanks.

rootwork’s picture

Title: Maintenance theme conf in settings.php only works when the database is offline » Document that maintenance_theme conf in settings.php only works when the database is offline

Reading the above, this seems like a documentation issue. The comment in settings.php reads:

"This applies when the site is explicitly set to maintenance mode through the administration page or when the database is inactive due to an error."

It sounds like that's not true -- it's only triggered when the database is inactive. If so, at a minimum this description in the 8.x and 7.x default.settings.php file should be updated.

Personally I'd love to be able to set a maintenance-specific theme, but it sounds like there are technical limitations to doing that, at least in core, as the patches above try to. But we should at least have a description of what this setting does accurate for D8.

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, 14: drupal-maintenance_theme-903042-14.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative

Not knowing a thing about themes I took a dive into this and learned the following:

This if block in common.inc that is to set the maintenance theme always fails so drupal_maintenance_theme() never executes. So I changed like so to see what happens.

  if (function_exists('drupal_maintenance_theme')) {
    \Drupal::theme()->resetActiveTheme();
    drupal_maintenance_theme();
  }

then drupal_maintenence_theme executed but after clearing cache and reloading the home page the theme was still not what was set in $settings['maintenance_theme']. I removed my changes to the code.

Then I learned that there is a themeNegotiator and the \Drupal\Core\Theme\DefaultNegotiator::determineActiveTheme was being called and that always retrieved the default system.theme which was not the maintenance theme in setttings.php.

The only way I got this to use theme set in $settings['maintenance_theme'] was:

  public function determineActiveTheme(RouteMatchInterface $route_match) {
    if (\Drupal::state()->get('system.maintenance_mode')) {
      return Settings::get('maintenance_theme');
    }
    return $this->configFactory->get('system.theme')->get('default');

What should be done here? Is this a documentation problem or not?

quietone’s picture

Version: 8.9.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
148 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.