You are here

function backup_migrate_ui_destination_display_files in Backup and Migrate 8.2

Same name and namespace in other branches
  1. 8.3 includes/destinations.inc \backup_migrate_ui_destination_display_files()
  2. 5.2 includes/destinations.inc \backup_migrate_ui_destination_display_files()
  3. 6.3 includes/destinations.inc \backup_migrate_ui_destination_display_files()
  4. 6.2 includes/destinations.inc \backup_migrate_ui_destination_display_files()
  5. 7.3 includes/destinations.inc \backup_migrate_ui_destination_display_files()
  6. 7.2 includes/destinations.inc \backup_migrate_ui_destination_display_files()

List the backup files in the given destination.

1 string reference to 'backup_migrate_ui_destination_display_files'
backup_migrate_destination::get_menu_items in includes/destinations.inc
Add the menu items specific to the destination type.

File

includes/destinations.inc, line 260

Code

function backup_migrate_ui_destination_display_files($destination_id = NULL) {
  drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
  $rows = $sort = array();
  if ($destination = backup_migrate_get_destination($destination_id)) {

    // Refresh the file listing cache if requested.
    if (isset($_GET['refresh'])) {
      $destination
        ->file_cache_clear();
      drupal_goto($_GET['q']);
    }
    drupal_set_title(t('@title Files', array(
      '@title' => $destination
        ->get_name(),
    )));
    $headers = array(
      array(
        'data' => t('Filename'),
        'field' => 'filename',
      ),
      array(
        'data' => t('Date'),
        'field' => 'filetime',
      ),
      array(
        'data' => t('Age'),
        'field' => 'filetime',
        'sort' => 'desc',
      ),
      array(
        'data' => t('Size'),
        'field' => 'filesize',
      ),
    );
    $sort_order = tablesort_get_order($headers);
    $sort_key = $sort_order['sql'] ? $sort_order['sql'] : 'filetime';
    $sort_dir = tablesort_get_sort($headers) == 'desc' ? SORT_DESC : SORT_ASC;
    $files = $destination
      ->list_files();
    $i = 0;
    $ops = 0;
    foreach ((array) $files as $file) {
      $info = $file
        ->info();
      $operations = $destination
        ->get_file_links($file
        ->file_id());
      $description = '';

      // Add the description as a new row.
      if (!empty($info['description'])) {
        $description = ' <div title="' . check_plain($info['description']) . '" class="backup-migrate-description">' . $info['description'] . '</div>';
      }

      // Show only files that can be restored from.
      if ($file
        ->is_recognized_type()) {
        $sort[] = $info[$sort_key];
        $rows[] = array_merge(array(
          check_plain($info['filename']) . $description,
          format_date($info['filetime'], 'small'),
          format_interval(time() - $info['filetime'], 1),
          format_size($info['filesize']),
        ), $operations);
      }
      $ops = max($ops, count($operations));
    }

    // Add the operations if any
    if ($ops) {
      $headers[] = array(
        'data' => t('Operations'),
        'colspan' => $ops,
      );
    }
    array_multisort($sort, $sort_dir, $rows);
    if ($rows) {
      $out = theme('table', array(
        'header' => $headers,
        'rows' => $rows,
      ));
    }
    else {
      $out = t('There are no backup files to display.');
    }
    if ($destination->cache_files && $destination->fetch_time) {
      drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
      $out .= '<div class="backup-migrate-cache-time">' . t('This listing was fetched !time ago. !refresh', array(
        '!time' => format_interval(time() - $destination->fetch_time, 1),
        '!refresh' => l(t('fetch now'), $_GET['q'], array(
          'query' => array(
            'refresh' => 'true',
          ),
        )),
      )) . '</div>';
    }
    return $out;
  }
  drupal_goto(BACKUP_MIGRATE_MENU_PATH . "/destination");
}