Hi there, thanks for this great module.

While debugging a performance problem for a client, I've come across this bit of code that looked strange to me:

  if ($phase == 'runtime') {
    $correct_key = variable_set('smart_ip_correct_ipinfodb_key', FALSE);
    if (!$correct_key) {
      $smart_ip_source = variable_get('smart_ip_source', 'ipinfodb_service');
      if ($smart_ip_source == 'ipinfodb_service') {
        // Generate an appropriate error message:
        // Missing API keys.
.......
.......

The logic within the whole block seems correct, but the problem is that variable_set() is incorrectly called at the beginning of it. It should be variable_get() instead:

$correct_key = variable_get('smart_ip_correct_ipinfodb_key', FALSE);

Otherwise, 2 things happen:

1.- a cache_clear_all is triggered for the variables in cache_bootstrap (as part of the variable_set() call).
2.- The logic of the conditional is always triggered because $correct_key evaluates always to FALSE (), since variable_set() returns nothing.

I'm attaching a patch for the Drupal 7 version of this. I'm not sure, but I think the problem exists for Drupal 8 too.

CommentFileSizeAuthor
#2 2890397-incorrect_variable_set-2.patch2.09 KBslv_
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slv_ created an issue. See original summary.

slv_’s picture

Patch attached. It fixes a couple of spacing issues too.

slv_’s picture

Status: Active » Needs review

  • arpeggio committed 4cb4134 on 7.x-2.x authored by slv_
    Issue #2890397 by slv_: Fixed hook_requirements in 'runtime' phase...

  • arpeggio committed d7f4f1c on 6.x-2.x
    Issue #2890397 by slv_: Fixed hook_requirements in 'runtime' phase...
arpeggio’s picture

Status: Needs review » Fixed

Hi, I have already pushed your patch. Thank you for sharing it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.