You are here

function uc_fedex_cron in FedEx Shipping 6.2

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

Implements hook_cron().

Deletes FedEx shipping labels from the file system automatically on a periodic basis. Default period is 1 week.

File

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

Code

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

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

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