You are here

public function Subscription::isActive in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Subscription.php \Drupal\acquia_connector\Subscription::isActive()
  2. 3.x src/Subscription.php \Drupal\acquia_connector\Subscription::isActive()

Helper function to check if the site has an active subscription.

File

src/Subscription.php, line 101

Class

Subscription
Storage class for Acquia Subscriptions.

Namespace

Drupal\acquia_connector

Code

public function isActive() {
  $active = FALSE;

  // Subscription cannot be active if we have no credentials.
  if (self::hasCredentials()) {
    $config = \Drupal::config('acquia_connector.settings');
    $subscription = \Drupal::state()
      ->get('acquia_subscription_data');
    $subscription_timestamp = \Drupal::state()
      ->get('acquia_subscription_data.timestamp');

    // Make sure we have data at least once per day.
    if (isset($subscription_timestamp) && time() - $subscription_timestamp > 60 * 60 * 24) {
      try {
        $storage = new Storage();
        $key = $storage
          ->getKey();
        $identifier = $storage
          ->getIdentifier();
        $subscription = \Drupal::service('acquia_connector.client')
          ->getSubscription($identifier, $key, [
          'no_heartbeat' => 1,
        ]);
      } catch (ConnectorException $e) {
      }
    }
    $active = !empty($subscription['active']);
  }
  return $active;
}