It's useful to know when a site went into and came back out of maintenance mode, so it would be nice if this information was added to the admin log when it happened.
Comment | File | Size | Author |
---|---|---|---|
#50 | drupal-n229778-50.patch | 4.22 KB | DamienMcKenna |
#48 | 229778-47.patch | 4.26 KB | Aditi Saraf |
#45 | system-log_maintenance_mode_changes-229778-45.patch | 679 bytes | sumit_saini |
#25 | Maintenance_mode.png | 11.44 KB | Dinesh18 |
#21 | system-log_maintenance_mode_changes-229778-21.patch | 661 bytes | John Cook |
Issue fork drupal-229778
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
Race.it CreditAttribution: Race.it commentedThis would require a override of the submit hook for the form, I think that is the safest way of handling this request.
Comment #2
Race.it CreditAttribution: Race.it commentedCreated a patch to address this request, please review.
Comment #3
Race.it CreditAttribution: Race.it commentedComment #4
cburschkaAdd a period there.
site_maintenance_... is an unnecessary name quirk. This function should start with system_ to reflect the module it is in.
Also, if you use
system_site_maintenance_mode_submit
(mode rather than admin_settings) you get consistency with the form's name as well as shortening the monster a bit.---
I need to read how submit handlers and auto-discovery are handled on system settings forms. There are several possibilities here, including a) that you need to add the submit handler after calling system_settings_form() or b) that if you pick the standard FORM_submit() name (in this case the one I suggested) the submit handler will be automatically discovered without having to be registered. I'm just speculating though.
Comment #5
cburschkaAddendum:
There's a space inside the left parenthesis on the first line, which should go.
Also, if you compare a variable that can only be 1 or 0, it is usually more readable to check it as a boolean - and also to put the truth (1) branch before the falsehood (0). In this case, the condition determines the state of a single variable and therefore should probably be a trinary.
Finally, splitting translateable strings when it's not necessary costs an extra string lookup and makes life difficult for the translators. It may look as though the strings are more "normalized", but be aware that by hard-coding this split, the separating colon and the strings' order, linguistic flexibility is lost. A language with more inflections than English can translate "offline" differently whether its stand-alone or part of a sentence.
In summary, a good choice here might be
Although I would favor a clearer sentence personally, such as "Site was taken offline" or "Site was put online".
(Naturally, all of this also applies to the "reset to defaults" string).
---
Also, it seems I was wrong on both of my earlier speculations:
a) system_settings_form() adds a #submit handler, but doesn't strip the ones that are there (good, because that'd be pretty silly)
b) drupal_prepare_form() adds FORM_ID_submit() only if no #submit handler has been explicitly defined, which system_settings_form() has done by then. So regardless of the name, it has to be explicitly added. It still makes sense to use that name though.
Comment #6
pfahlr CreditAttribution: pfahlr commentedhttp://drupal.org/sandbox/pfahlr/1425554
Comment #7
mmedrano CreditAttribution: mmedrano at Mirum Agency commentedSubmitting a new patch for feature request.
Comment #8
mmedrano CreditAttribution: mmedrano at Mirum Agency commentedComment #9
panshulk CreditAttribution: panshulk at Srijan | A Material+ Company commentedHi @mmedrano
Thanks for working on this.
I tested the latest 229778-log-changes-to-offline-mode.patch, the patch works as expected.
Following is the screenshot of the result in "Recent log messages" :
Hence Moving this to RTBC
Thanks :)
Comment #10
panshulk CreditAttribution: panshulk at Srijan | A Material+ Company commentedComment #11
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThis seems like a good idea but needs to go in Drupal 8 first.
Also a few issues:
Why not check $form_state['values']['maintenance_mode'] instead? That is usually the standard way to look at submitted form values.
It should not be necessary to include the username here - as the above screenshot shows, watchdog already records it automatically. So I think just something like "Site was put in maintenance mode." would be fine here.
Comment #12
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedEh, especially because that's what the issue title says this issue is about :) (And what the earlier patch in this issue did...)
Comment #13
cburschkaNote that in D8, maintenance mode can be triggered non-interactively, such as with drupal-console. Right now, these all simply use \Drupal::service('state')->set('system.maintenance_mode', true) just like the form submit function. That's okay as long as the submit function doesn't do anything special.
If we want to do more, the whole code needs to be moved into a separate function (perhaps in the system.manager service) to allow it to be called from modules.
(Unfortunately, as maintenance mode is now a state variable and not a configuration variable, this message cannot be added by listening to a config change event.)
Comment #14
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThis is true in Drupal 7 also - you can do
drush vset maintenance_mode 1
. However, I think it's not that big of a deal to only log it when maintenance mode is turned on via the admin UI. (Unless we're setting an expectation for people that it will always be logged unconditionally or something?)Comment #15
xjmComment #17
diamondseaAttached is a D8 implementation and screenshot.
Note: This will only log changes made through the UI, not through Drupal Console / Drush.
Comment #18
diamondseaComment #20
mmcintosh CreditAttribution: mmcintosh commentedReviewing patch now
Comment #21
John Cook CreditAttribution: John Cook at Creode commentedI've used the message from the patch in #17 and moved it into the
CacheCollector:set()
method.This allows the message to be logged when being set using Drush, although it is logged as being changed by 'Anonymous'.
Example log entries:
I won't create an interdiff as it's essentially a new patch.
Comment #22
dawehnerMaybe an alternative approach: we could add a method to
\Drupal\Core\Site\MaintenanceMode
and let this logging happen there?Comment #23
joachim CreditAttribution: joachim as a volunteer commented> Maybe an alternative approach: we could add a method to \Drupal\Core\Site\MaintenanceMode and let this logging happen there?
+1 to this. The cache collector seems an odd place to put logging.
Nitpick:
Comment is wrong - it logs when entering and leaving maintenance mode.
Comment #24
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commentedI tried putting logger inside this function with if..else condition but it runs multiple times and print multiple log message for the same event.
Comment #25
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commentedHere is the attached screenshot .
In -- > Maintenance Mode Enabled
Out --> Maintenance Mode Disabled
Comment #26
joachim CreditAttribution: joachim as a volunteer commented> \Drupal\Core\Site\MaintenanceMode and let this logging happen there?
Ah. That service is about *reporting* whether the site is in maintenance mode. It doesn't allow you to change the status. So that's not the right place to put it.
Comment #27
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commentedI am new to D8. So I should declare my own method in MaintenanceModeInterface.php.
I should create the method in MaintenanceMode.php.
How should I access the Enabled /disabled boolean in my new method ?
Comment #28
joachim CreditAttribution: joachim as a volunteer commentedI don't think it's that simple.
Adding a method to set the status in MaintenanceModeInterface is an API change. I think this one should wait for the maintainer to look at.
Comment #38
O'Briat CreditAttribution: O'Briat for E.voyageurs Technologies commentedHi
I just crossed the perfect example on why this issue should be taken much seriously: a admin user saw the "outdated message", so thinking doing the right thing he follows the link and follow the update process putting the site in maintenance mode... The update failed but he didn't notice was still in maintenance mode because he was already logged in.
He do it twice over several months...
It take a while to debug it since there is no drupal log, and webserver log didn't show any visit to maintenance page.
Ok, the fault is mainly on the dev team side (update module enable on production site and bad permissions) but still I think this issue shoul get a higher priority (or the first patch should be accepted)
See also: https://github.com/drush-ops/drush/issues/5365
Comment #39
DamienMcKennaFWIW the last patch still applies cleanly against 9.5.x.
Comment #40
O'Briat CreditAttribution: O'Briat at Klee Interactive (Klee Group) commentedThanks, I just add it to my `composer.json`.
So the patch number 17 could be marked as RTBTC
Comment #41
markdorisonThe patch still applies cleanly. I don't see any outstanding requests for changes. Switching this to 'needs review.'
Comment #42
smustgrave CreditAttribution: smustgrave at Mobomo commentedThe issue summary is pretty bare.
Also could use some kind of test coverage. Even simply coverage.
Comment #44
HeikkiY CreditAttribution: HeikkiY commentedI am running core version 9.5.11 I tested the patch from #21. I was not able to get anything in logs when setting the maintenance mode through the UI. I tried clearing caches with Drush a few times but it didn't have any effect.
Patch from #17 also applies cleanly and now I got log messages when it was set. But I think the solution in #21 would be better if it worked because we also set maintenance mode with Drush and would be good to catch those also.
Comment #45
sumit_saini CreditAttribution: sumit_saini commentedAs maintenance mode is stored in state, it is good to log message in Drupal\Core\State::set() method. So, moving the fix given in #21 to State.php. This way, there will be a log for both cases - drush and form save. Verified the attached patch with Drupal 10.1.4
Comment #46
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commented@sumit_saini Thanks for the patch - tests are still needed, so moving back to Needs Work.
Comment #48
Aditi Saraf CreditAttribution: Aditi Saraf at Valuebound for Valuebound commentedComment #49
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedThe last patch is still missing the test(s).
And it would be great to update to update the issue summary (see #42). We should also include the summary of possible solutions (
State::set()
vsCacheCollector:set()
vsSiteMaintenanceModeForm
..), as there are multiple patches with different approaches, so better to have this summarized. Thanks!Comment #50
DamienMcKennaRerolled.
Comment #51
smustgrave CreditAttribution: smustgrave at Mobomo commentedFor the issue summary update and tests.
Comment #52
HeikkiY CreditAttribution: HeikkiY commentedWe encountered an error when using this patch in core with Redirect 404 submodule of Redirect.
After upgrading to Drupal 10.2, I get the following error when trying to disable the maintenance mode in en/admin/config/development/maintenance: