Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#5387 add CiviCRM Maintenance Mode #31893

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ufundo
Copy link
Contributor

@ufundo ufundo commented Jan 27, 2025

Overview

This adds a Maintenance Mode concept to CiviCRM.

It can be explicitly controlled by a CiviCRM setting, or if unset will fallback to checking if CMS maintenance mode is set (though CMS check only implemented for Drupal8 so far).

When Maintenance Mode is activated:

  • Job.execute will be skipped (unless you explicitly specify run_in_maintenance_mode)
  • REST api calls will respond with 503 (unless user has bypass maintenance mode permission)

Technical Details

The setting core_maintenance_mode can have 3 values:

  • TRUE = Maintenance Mode is explicitly activated
  • FALSE = Maintenance Mode is explicitly deactivated
  • NULL = refer to CMS (this is the default, only supports Drupal8 so far)

It has an env var CIVICRM_MAINTENANCE_MODE.

Comments

I haven't exposed the setting in the UI. Given this is very much sysadmin functionality, I guess most would be happy to access with env var / cv / $civicrm_setting.

I think it could be good follow up to add to UI specifically for Standalone (for most CMS users, the CMS toggle makes more sense, so shouldn't really need this).

Copy link

civibot bot commented Jan 27, 2025

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the master label Jan 27, 2025
@ufundo ufundo changed the title add CiviCRM Maintenance Mode dev/core#5387 add CiviCRM Maintenance Mode Jan 27, 2025
@ufundo ufundo marked this pull request as ready for review January 27, 2025 21:52
@totten
Copy link
Member

totten commented Jan 31, 2025

The ternary choice looks like a good balance for dealing with CMS maintenance-mode. 👍

From a type-system POV, using NULL may be a little tricky.

  • In the past, there has been some... eh... systemic warfare waged against nullable booleans (eg with an opening salvo in 22430, followed by notable campaigns like 22925, 22954, 23134 -- and ending in FiveFortyNine).
  • FWIW, I went looking for settings that have default=>NULL. They do exist, but they all seem to be Strings. I couldn't find any boolean-settings.
  • If you think about how env-vars are managed, there are many tools (bash, zsh, dotenv, php, docker-compose, phpstorm, ad nauseum) and skill-levels. It is often possible to distinguish forms of emptiness (eg FOO=0 vs FOO= vs unset FOO), but I'd wager the practice is not reliable across users+tools.

The ternary choice should have an explicit symbol for all its options (eg 0/1/auto, like in assetCache).

(I'm still doing more testing -- just wanted to get that thought out.)

@ufundo
Copy link
Contributor Author

ufundo commented Feb 5, 2025

I was working on the basis that there would be no need to set explicit NULL, ie if you had an env var then anything falsey would be off, and anything else would be on.

But given setting values are often strings at some level then I see how a special string like cms or inherit makes more sense than NULL. That also unblocks exposing in the default UI pages, which def didnt like nullable bool.

Will have a go correcting now.

@ufundo
Copy link
Contributor Author

ufundo commented Feb 5, 2025

@totten did you have any further thoughts?

@ufundo
Copy link
Contributor Author

ufundo commented Feb 5, 2025

The ternary choice should have an explicit symbol for all its options (eg 0/1/auto, like in assetCache).

Change made (with inherit as the third option).

I think its better though in a way it's kinda just flipped the type-oddness to the PHP side.

This was you go Civi::settings()->set('core_maintenance_mode', FALSE) and it does what you want, but not as tightly as a strongly typed advocate might like... (Somewhere you're relying on FALSE ending up equivalent to '0' and well, it's not totally clear where?)

But I guess we're PHP developers and Civi setting values are just generally quite softly typed, so maybe good enough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants