You are here

function backup_migrate_drush_destination_files in Backup and Migrate 6.3

Same name and namespace in other branches
  1. 8.2 includes/backup_migrate.drush.inc \backup_migrate_drush_destination_files()
  2. 8.3 includes/backup_migrate.drush.inc \backup_migrate_drush_destination_files()
  3. 6.2 includes/backup_migrate.drush.inc \backup_migrate_drush_destination_files()
  4. 7.3 includes/backup_migrate.drush.inc \backup_migrate_drush_destination_files()
  5. 7.2 includes/backup_migrate.drush.inc \backup_migrate_drush_destination_files()

Get a list of files in a given destination

1 string reference to 'backup_migrate_drush_destination_files'
backup_migrate_drush_command in includes/backup_migrate.drush.inc
Implementation of hook_drush_command().

File

includes/backup_migrate.drush.inc, line 191
Drush commands for backup and migrate.

Code

function backup_migrate_drush_destination_files($destination_id = NULL) {
  backup_migrate_include('destinations');
  $destinations = array();

  // Set the message mode to drush output.
  _backup_migrate_message_callback('_backup_migrate_message_drush');
  if ($destination_id && !($destination = backup_migrate_get_destination($destination_id))) {
    _backup_migrate_message("Could not find the destination '@destination'. Try using 'drush bam-destinations' to get a list of available destinations.", array(
      '@destination' => $destination_id,
    ), 'error');
    return;
  }

  // Single destination required.
  if ($destination) {
    $destinations = array(
      $destination,
    );
  }
  else {
    $destinations = backup_migrate_get_destinations('list files');
  }

  // Load all the files.
  $rows = $sort = array();
  foreach ($destinations as $destination) {
    $destination
      ->file_cache_clear();
    $dest_files = $destination
      ->list_files();
    foreach ($dest_files as $id => $file) {
      $info = $file
        ->info();
      $rows[] = array(
        check_plain($info['filename']),
        $destination
          ->get_id(),
        format_date($info['filetime'], 'small'),
        format_interval(time() - $info['filetime'], 1),
        format_size($info['filesize']),
      );
      $sort[] = $info['filetime'];
    }
  }
  $headers = array(
    array(
      dt('Filename'),
      dt('Destination'),
      dt('Date'),
      dt('Age'),
      dt('Size'),
    ),
  );
  if (count($rows)) {
    array_multisort($sort, SORT_DESC, $rows);
    drush_print_table(array_merge($headers, $rows), TRUE);
  }
  else {
    drush_print(dt('There are no backup files to display.'));
  }
}