public static function AutomaticUpdatesPsa::getPublicServiceMessages in Automatic Updates 7
3 calls to AutomaticUpdatesPsa::getPublicServiceMessages()
- automatic_updates_init in ./
automatic_updates.module - Implements hook_init().
- Notify::send in ./
Notify.php - Send notification for PSAs.
- _automatic_updates_psa_requirements in ./
automatic_updates.install - Display requirements from Public service announcements.
File
- ./
AutomaticUpdatesPsa.php, line 20 - Contains AutomaticUpdatesPsa class.
Class
- AutomaticUpdatesPsa
- Class AutomaticUpdatesPsa.
Code
public static function getPublicServiceMessages() {
$messages = array();
if (!variable_get('automatic_updates_enable_psa', TRUE)) {
return $messages;
}
if ($cache = cache_get('automatic_updates_psa')) {
$response = $cache->data;
}
else {
$psa_endpoint = variable_get('automatic_updates_psa_endpoint', self::PSA_ENDPOINT);
$response = drupal_http_request($psa_endpoint);
if (isset($response->code) && $response->code == 200) {
// Set response in cache for 12 hours.
cache_set('automatic_updates_psa', $response, 'cache', variable_get('automatic_updates_check_frequency', REQUEST_TIME + 3600 * 12));
}
else {
watchdog('automatic_updates', 'Drupal PSA endpoint %url is unreachable.', array(
'%url' => $psa_endpoint,
), WATCHDOG_ERROR);
return array(
t('Drupal PSA endpoint %url is unreachable.', array(
'%url' => $psa_endpoint,
)),
);
}
}
$json_payload = json_decode($response->data, FALSE);
if ($json_payload !== NULL) {
foreach ($json_payload as $json) {
try {
if ($json->is_psa && ($json->type === 'core' || static::isValidExtension($json->type, $json->project))) {
$messages[] = static::message($json->title, $json->link);
}
elseif ($json->type === 'core') {
static::parseConstraints($messages, $json, VERSION);
}
elseif (static::isValidExtension($json->type, $json->project)) {
static::contribParser($messages, $json);
}
} catch (\UnexpectedValueException $exception) {
watchdog_exception('automatic_updates', $exception);
$messages[] = t('Drupal PSA endpoint service is malformed.');
}
}
}
return $messages;
}