civicrm / org.civicrm.shoreditch

Other
44 stars 59 forks source link

MAE-633: Regenerate CiviCRM menu if it is empty #535

Closed lisandro-compucorp closed 2 years ago

lisandro-compucorp commented 2 years ago

Overview

This PR solves the theme problem that appears after clearing the DB Cache

Before

The problem observed consists of the Shoreditch theme not loading correctly at some intervals, but that situation gets solved after refreshing the page. This is an example of how the interface looks: Screenshot 2021-12-08 at 13 21 14 The error can be reproduced by executing the Job that clears the DB Cache: capture_broken Note The job usually runs by a console, not using the "Execute now" in the UI as I did on the demo, then the page refresh that we are seeing is not performed. This causes that the next user to access the site after the cron runs in the background sees the error on the theme.

After

The error after clearing DB Cache does not appear anymore: capture_fixed

Technical Details

The function _shoreditch_isActive depends on Civi::service('themes')->getActiveThemeKey() to determine if it is active. This is, in turn, depending on DrupalBase method for detecting if the path corresponds to a frontend or backend theme:

      $config = \CRM_Core_Config::singleton();
      $settingKey = $config->userSystem->isFrontEndPage() ? 'theme_frontend' : 'theme_backend';

Since the first moment after the Db Cache clears the menu is empty, the condition of the mentioned method:

    $path = CRM_Utils_System::currentPath();

    // Get the menu for above URL.
    $item = CRM_Core_Menu::get($path);
    // In case the URL is not a civicrm page (a drupal page) we set the FE theme to TRUE - covering the corner case
    return (empty($item) || !empty($item['is_public']));

Returns true (since empty($item) === TRUE).

For solving this we have two options:

In this PR I go for the second option, which is easier and acceptable in performance terms.

Backstop JS Report

jamienovick commented 2 years ago

@lisandro-compucorp this issue appears to be happening at other times then just when you clear DB cache. Can you confirm this PR fixes it in other situations also?

lisandro-compucorp commented 2 years ago

@lisandro-compucorp this issue appears to be happening at other times then just when you clear DB cache. Can you confirm this PR fixes it in other situations also?

Yes @jamienovick this solves those problems also. I added an extra Note on the PR description, on "Before" section, explaining why.