You are here

function commerce_license_cron in Commerce License 7

Same name and namespace in other branches
  1. 8.2 commerce_license.module \commerce_license_cron()

Implements hook_cron().

Enqueues licenses for expiration. The queue worker will load them one by one, change their status (allowing other modules to respond via Rules and hooks), and if synchronizable, enqueue them for synchronization.

File

./commerce_license.module, line 581
Provides a framework for selling access to local or remote resources.

Code

function commerce_license_cron() {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'commerce_license')
    ->propertyCondition('status', COMMERCE_LICENSE_ACTIVE)
    ->propertyCondition('expires', 0, '<>')
    ->propertyCondition('expires', commerce_license_get_time(), '<=')
    ->propertyCondition('expires_automatically', 1);
  $results = $query
    ->execute();
  if (!empty($results['commerce_license'])) {
    foreach (array_keys($results['commerce_license']) as $license_id) {
      $queue = DrupalQueue::get('commerce_license_expiration');
      $task = array(
        'license_id' => $license_id,
        'title' => t('License #@license_id', array(
          '@license_id' => $license_id,
        )),
      );
      $queue
        ->createItem($task);
    }
  }
}