You are here

function uc_ups_cron in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 shipping/uc_ups/uc_ups.module \uc_ups_cron()
  2. 6.2 shipping/uc_ups/uc_ups.module \uc_ups_cron()

Implements hook_cron().

Deletes UPS shipping labels from the file system automatically on a periodic basis. Cron must be enabled for automatic deletion. Default is never delete the labels, keep them forever.

File

shipping/uc_ups/uc_ups.module, line 50
UPS shipping quote module.

Code

function uc_ups_cron() {
  $cutoff = REQUEST_TIME - variable_get('uc_ups_label_lifetime', 0);
  if ($cutoff == REQUEST_TIME) {

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

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