You are here

function uc_ups_cron in Ubercart 6.2

Same name and namespace in other branches
  1. 8.4 shipping/uc_ups/uc_ups.module \uc_ups_cron()
  2. 7.3 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 60
Shipping quote module that interfaces with www.ups.com to get rates for small package shipments.

Code

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

    // Label lifetime is set to 0, meaning never delete
    return;
  }
  $path = file_create_path('ups_labels');
  if (is_dir($path)) {
    $files = array_diff(scandir($path), array(
      '.',
      '..',
    ));
    if ($files) {

      // Loop over label files in sites/default/files/ups_labels
      // and test creation date against 'uc_ups_label_lifetime'
      foreach ($files as $file) {
        if ($cutoff > filectime($path . '/' . $file)) {
          unlink($path . '/' . $file);
        }
      }
    }
  }
}