You are here

function ctools_drush_export_op_command in Chaos Tool Suite (ctools) 7

Drush callback: Acts as the hub for all op commands to keep all arg handling etc in one place.

1 string reference to 'ctools_drush_export_op_command'
ctools_drush_command in drush/ctools.drush.inc
Implements hook_drush_command().

File

drush/ctools.drush.inc, line 454
CTools Drush commands.

Code

function ctools_drush_export_op_command() {
  $args = func_get_args();

  // Get all info for the current drush command.
  $command = drush_get_command();
  $op = '';
  switch ($command['command']) {
    case 'ctools-export-view':
      $op = 'view';
      break;
    case 'ctools-export-revert':

      // Revert is same as deleting. As any objects in the db are deleted.
      $op = 'delete';
      break;
    case 'ctools-export-enable':
      $op = 'enable';
      break;
    case 'ctools-export-disable':
      $op = 'disable';
      break;
  }
  if (!$op) {
    return;
  }
  if (drush_get_option('all', FALSE)) {
    $info = _ctools_drush_export_info(array(), TRUE);
    $exportable_info = $info['exportables'];
    $all = drush_confirm(dt('Are you sure you would like to !op all exportables on the system?', array(
      '!op' => _ctools_drush_export_op_alias($op),
    )));
    if ($all && $exportable_info) {
      foreach ($exportable_info as $table => $exportables) {
        if (!empty($exportables)) {
          ctools_drush_export_op($op, $table, $exportables);
        }
      }
    }
  }
  else {

    // Table name should always be first arg...
    $table_name = array_shift($args);

    // Any additional args are assumed to be exportable names.
    $object_names = $args;

    // Return any exportables based on table name, object names, options.
    $exportables = _ctools_drush_export_op_command_logic($op, $table_name, $object_names);
    if ($exportables) {
      ctools_drush_export_op($op, $table_name, $exportables);
    }
  }
}