You are here

function demo_drush_snapshots in Demonstration site (Sandbox / Snapshot) 6

Callback for drush command demo-snapshot.

1 string reference to 'demo_drush_snapshots'
demo_drush_command in ./demo.drush.inc
Implementation of hook_drush_command().

File

./demo.drush.inc, line 166

Code

function demo_drush_snapshots($filename = NULL) {
  module_load_include('inc', 'demo', 'demo.admin');
  if (!isset($filename)) {

    // print table of available snapshots.
    $rows = array();
    $fileconfig = demo_get_fileconfig();
    $files = file_scan_directory($fileconfig['dumppath'], '.info$');
    $rows[time()] = array(
      'File name',
      'Date',
      'Size',
      'Description',
    );
    foreach ($files as $filename => $file) {

      // Build basic file info
      $files[$filename] = (array) $file;
      $info = demo_get_info($filename);
      $m_time = filemtime($filename);
      $rows[$m_time] = array(
        'name' => check_plain($info['filename']),
        'date' => format_date($m_time, 'small'),
        'size' => format_size(filesize(substr($filename, 0, -4) . 'sql')),
        'desc' => !empty($info['description']) ? $info['description'] : dt('n/a'),
      );
    }
    krsort($rows);
    drush_print_table($rows, TRUE);
  }
  else {

    // is snapshot with given name exists ?
    if (!_demo_drush_is_file_exists($filename)) {
      drush_set_error('File does not exist. Use "drush demo-snapshots" to get the list of available snapshots.');
      return;
    }
    $file = demo_get_fileconfig($filename);
    $info = demo_get_info($file['infofile']);
    if (!empty($info['description'])) {
      drush_print('Description: ' . $info['description']);
    }
    $modules = array_diff($info['modules'], array(
      'block',
      'filter',
      'node',
      'system',
      'user',
      'demo',
    ));
    sort($info['modules']);
    drush_print('Modules: ' . implode(', ', $info['modules']));
  }
}