Skip to content

Commit

Permalink
Drupal8::isMaintenceMode() - Don't crash on new/clean sites
Browse files Browse the repository at this point in the history
In E2E\AfformMock\MockPublicFormTest, it attempts to submit form as an
anonymous user. On a new/clean instance of D9/D10 with php83, the test fails
consistently.

BEFORE:

The submission is rejected. In the Drupal log, we see a corresponding error:

TypeError: CRM_Utils_System_Drupal8::isMaintenanceMode(): Return value must be of type bool, null returned in CRM_Utils_System_Drupal8->isMaintenanceMode() (line 1023 of /home/totten/bknix/build/build-0/src/civicrm-core/CRM/Utils/System/Drupal8.php).

- #0 /home/totten/bknix/build/build-0/src/civicrm-core/CRM/Utils/System.php(1952): CRM_Utils_System_Drupal8->isMaintenanceMode()
- #1 /home/totten/bknix/build/build-0/src/civicrm-core/CRM/Api4/Page/AJAX.php(28): CRM_Utils_System::isMaintenanceMode()
- #2 /home/totten/bknix/build/build-0/src/civicrm-core/CRM/Core/Invoke.php(278): CRM_Api4_Page_AJAX->run(Array, NULL)
- #3 /home/totten/bknix/build/build-0/src/civicrm-core/CRM/Core/Invoke.php(73): CRM_Core_Invoke::runItem(Array)

AFTER: It's ok.

TECHNICAL DETAILS:

On a new/clean system, the content of `system.maintenance_mode` appears to be `NULL`.

The bug is likely hard to see in manual testing because:

1. A lot of manual testing is done as admin user (who can bypass maintence-mode checks).
2. After you've toggled maintenance-mode for the first, the value becomes `0` or `1`.
  • Loading branch information
totten committed Mar 7, 2025
1 parent b162dcf commit 4214ac7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion CRM/Utils/System/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ public function clearResourceCache() {
*/
public function isMaintenanceMode(): bool {
try {
return \Drupal::state()->get('system.maintenance_mode');
return \Drupal::state()->get('system.maintenance_mode') ?: FALSE;
}
catch (\Exception $e) {
// catch in case Drupal isn't fully booted and can't answer
Expand Down

0 comments on commit 4214ac7

Please sign in to comment.