diff --git a/mollom.module b/mollom.module index 05eb729..1ff9f8f 100644 --- a/mollom.module +++ b/mollom.module @@ -1405,52 +1405,68 @@ function _mollom_status($reset = FALSE) { $private_key = $mollom->loadConfiguration('privateKey'); $status['keys'] = (!empty($public_key) && !empty($private_key)); - // If we have keys and are asked to reset, check whether keys are valid. - if ($status['keys'] && $reset) { - $status['keys valid'] = $mollom->verifyKeys(); - if ($status['keys valid'] === TRUE) { - mollom_log(array( - 'message' => 'API keys are valid.', - ), WATCHDOG_INFO); - } - elseif ($status['keys valid'] === Mollom::REQUEST_ERROR) { - mollom_log(array( - 'message' => 'Invalid client configuration.', - ), WATCHDOG_ERROR); - } - elseif ($status['keys valid'] === Mollom::AUTH_ERROR) { - mollom_log(array( - 'message' => 'Invalid API keys.', - ), WATCHDOG_ERROR); - } - // If the response is neither positive nor a known negative error, and - // the previous status was positive, then the Mollom service might be - // temporarily down. In this case, return an enforced RESPONSE_ERROR to - // indicate a server-side service failure, but do not update the stored - // status. - // @todo Test this. - elseif ($current_status['keys valid'] === TRUE) { - $status['keys valid'] = Mollom::RESPONSE_ERROR; - // Do not update the stored configuration status with the bogus result - // caused by the server-side failure. - $reset = FALSE; - mollom_log(array( - 'message' => 'API keys could not be verified.', - ), WATCHDOG_WARNING); - } - } - // Otherwise, if there are no keys, they cannot be valid. - elseif (!$status['keys']) { + // If there are no keys, then they cannot be valid. + if (!$status['keys']) { $status['keys valid'] = FALSE; } - // Update stored status upon reset, but only if the status changed, as a - // variable_set() invalidates the variable cache. - // Requires array_diff_assoc() instead of ($current_status != $status), since - // 'keys valid' may be an error code integer, which is equal to TRUE, so a - // type-agnostic strict comparison is required. - if ($reset && array_diff_assoc($current_status, $status)) { - variable_set('mollom_status', $status); + // If we have keys and are asked to reset, check whether keys are valid. + if ($status['keys'] && $reset) { + if (!lock_acquire('mollom_status', 5)) { + lock_wait('mollom_status'); + // variable_initialize() cannot be safely called again, so retrieve the + // value directly from the database. + $db_status = db_query('SELECT value FROM {variable} WHERE name = :name', array( + ':name' => 'mollom_status', + ))->fetchField(); + if ($db_status) { + $status = unserialize($db_status); + } + } + else { + $status['keys valid'] = $mollom->verifyKeys(); + if ($status['keys valid'] === TRUE) { + mollom_log(array( + 'message' => 'API keys are valid.', + ), WATCHDOG_INFO); + } + elseif ($status['keys valid'] === Mollom::REQUEST_ERROR) { + mollom_log(array( + 'message' => 'Invalid client configuration.', + ), WATCHDOG_ERROR); + } + elseif ($status['keys valid'] === Mollom::AUTH_ERROR) { + mollom_log(array( + 'message' => 'Invalid API keys.', + ), WATCHDOG_ERROR); + } + // If the response is neither positive nor a known negative error, and + // the previous status was positive, then the Mollom service might be + // temporarily down. In this case, return an enforced RESPONSE_ERROR to + // indicate a server-side service failure, but do not update the stored + // status. + // @todo Test this. + elseif ($current_status['keys valid'] === TRUE) { + $status['keys valid'] = Mollom::RESPONSE_ERROR; + // Do not update the stored configuration status with the bogus result + // caused by the server-side failure. + $reset = FALSE; + mollom_log(array( + 'message' => 'API keys could not be verified.', + ), WATCHDOG_WARNING); + } + + // Update stored status upon reset, but only if the status changed, as a + // variable_set() invalidates the variable cache. + // Requires array_diff_assoc() instead of ($current_status != $status), + // since 'keys valid' may be an error code integer (equaling TRUE), so a + // strict comparison is required. + if (array_diff_assoc($current_status, $status)) { + variable_set('mollom_status', $status); + } + + lock_release('mollom_status'); + } } return ($status['keys valid'] === TRUE ? TRUE : $status);