You are here

function acquia_connector_cron in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 acquia_connector.module \acquia_connector_cron()
  2. 3.x acquia_connector.module \acquia_connector_cron()

Implements hook_cron().

File

./acquia_connector.module, line 84
Acquia Connector module.

Code

function acquia_connector_cron() {
  $config = \Drupal::config('acquia_connector.settings');
  $state_site_name = \Drupal::state()
    ->get('spi.site_name');
  $state_site_machine_name = \Drupal::state()
    ->get('spi.site_machine_name');

  // Don't send data if site is blocked or missing components.
  if ($config
    ->get('spi.blocked') || is_null($state_site_name) && is_null($state_site_machine_name)) {
    return;
  }

  // Check subscription and send a heartbeat to Acquia.
  $subscription = new Subscription();
  $subscription
    ->update();

  // Get the last time we processed data.
  $last = \Drupal::state()
    ->get('acquia_connector.cron_last', 0);

  // 30 minute interval for sending site profile.
  $interval = $config
    ->get('cron_interval');
  if ($config
    ->get('cron_interval_override')) {
    $interval = $config
      ->get('cron_interval_override');
  }

  // Determine if the required interval has passed.
  if ($config
    ->get('spi.use_cron') && \Drupal::time()
    ->getRequestTime() - $last > $interval * 60) {
    \Drupal::service('acquia_connector.spi')
      ->sendFullSpi(ACQUIA_CONNECTOR_ACQUIA_SPI_METHOD_CRON);
  }
}