You are here

fastly.install in Fastly 8.3

Same filename and directory in other branches
  1. 7.2 fastly.install
  2. 7 fastly.install

Install, update, and uninstall functions for the Fastly module.

File

fastly.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Fastly module.
 */
use Drupal\Core\Link;
use Drupal\Core\Url;

/**
 * Implements hook_requirements().
 */
function fastly_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {

    // Check API token to be sure it has not been removed from
    // Fastly or expired.
    $api = \Drupal::service('fastly.api');
    $state = \Drupal::service('fastly.state');
    $purge_credentials_are_valid = $api
      ->validatePurgeCredentials();
    $state
      ->setPurgeCredentialsState($purge_credentials_are_valid);
    if (!$purge_credentials_are_valid) {
      $link_to_settings = Url::fromRoute('fastly.settings')
        ->toString();
      $message = t('Missing valid purge credentials for Fastly. Please go <a href=":link_to_settings">here</a> to set.', [
        ':link_to_settings' => $link_to_settings,
      ]);
      $requirements['fastly'] = [
        'title' => t('Fastly - Credentials'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $message,
      ];
    }
  }
  return $requirements;
}

/**
 * Purge cache after module update.
 */
function fastly_update_8001(&$sandbox) {
  $link = Link::createFromRoute('/admin/config/services/fastly', 'fastly.settings');
  return t("Cache tag hashing algorithm has changed with the latest module version so you'll need to purge your entire service cache manually if you currently use cache tags. You can do that by either visiting fastly settings form (@link) and clicking on 'Purge whole service' action or going directly to your fastly dashboard and do it from there.", [
    '@link' => $link
      ->toString(),
  ]);
}

Functions

Namesort descending Description
fastly_requirements Implements hook_requirements().
fastly_update_8001 Purge cache after module update.