You are here

function uc_fedex_cron in FedEx Shipping 7.2

Same name and namespace in other branches
  1. 6.2 uc_fedex.module \uc_fedex_cron()

Implements hook_cron().

Deletes FedEx shipping labels from the file system automatically on a periodic basis. Cron must be enabled for automatic deletion. Default lifetime is 1 week (604800 seconds).

File

./uc_fedex.module, line 77
FedEx Web Services Rate / Available Services Quote.

Code

function uc_fedex_cron() {
  $cutoff = REQUEST_TIME - variable_get('uc_fedex_label_lifetime', 604800);
  if ($cutoff == REQUEST_TIME) {

    // Label lifetime is set to 0, meaning never delete.
    return;
  }

  // Loop over label files in public://fedex_labels and test
  // creation date against 'uc_fedex_label_lifetime'.
  $files = file_scan_directory('public://fedex_labels', '/^label-/');
  foreach ($files as $file) {
    if ($cutoff > filectime($file->uri)) {
      drupal_unlink($file->uri);
      watchdog('uc_fedex', 'Removed uc_fedex label file @file.', array(
        '@file' => $file->uri,
      ), WATCHDOG_NOTICE);
    }
  }
}