Skip to content
Snippets Groups Projects

Added new update hook to make sure js_cookie is enabled

1 unresolved thread

Closes #3449275

Merge request reports

Members who can merge are allowed to add commits.
Code Quality is loading
Test summary results are being parsed
Ready to merge by members who can write to the target branch.
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
56 56 $config->save(TRUE);
57 57 }
58
59 /**
60 * Make sure the js_cookie dependency is enabled.
61 */
62 function autologout_update_9201(&$sandbox): void {
63 // Issue #3449275: Multiple warnings after upgrading to 8.x-1.5 & 2.x with js_cookie.
64 // The module to check.
65 $module = 'js_cookie';
66 /** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
67 $moduleHandler = \Drupal::service('module_handler');
68 /** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
69 $moduleInstaller = \Drupal::service('module_installer');
70
71 if (!$moduleHandler->moduleExists($module)) {
  • This should throw an UpdateException if it doesn't exist, since it is required and then the update will remain pending.

  • IMO, that sounds like a good thing since it will cause the update to fail, alerting the user. But looking at the code, there is no error thrown. It returns just a true or false. It's simply an isset check.

    https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/Extension/ModuleHandler.php?ref_type=heads#L248

    Edited by Mike Decker
  • Yes - I read that as why the if condition should be removed, so that an exception is thrown if the module is missing.

    E.g. can we just do

    Suggested change
    63 // Issue #3449275: Multiple warnings after upgrading to 8.x-1.5 & 2.x with js_cookie.
    64 // The module to check.
    65 $module = 'js_cookie';
    66 /** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
    67 $moduleHandler = \Drupal::service('module_handler');
    68 /** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
    69 $moduleInstaller = \Drupal::service('module_installer');
    70
    71 if (!$moduleHandler->moduleExists($module)) {
    72 $moduleInstaller->install([$module]);
    73 }
    63 \Drupal::service('module_installer')->install(['js_cookie']);
    Edited by Eric Smith
  • Just hit this issue with upgrading. Just running an install with no conditionals seems to be what most contrib modules do. It fails relatively gracefully when the module code doesn't exist, allowing the update to be re-ran - so I'd +1 the suggested change by @ericgsmith

    Screenshot_2024-06-06_at_16.31.41

    Screenshot_2024-06-06_at_16.32.08

    Edited by Tawny Bartlett
  • Please register or sign in to reply
Please register or sign in to reply
Loading