You are here

function drush_hook_update_deploy_tools_site_deploy_export in Hook Update Deploy Tools 7

Same name and namespace in other branches
  1. 8 hook_update_deploy_tools.drush.inc \drush_hook_update_deploy_tools_site_deploy_export()

Drush command to export anything that implements the ExportInterface.

Parameters

string $type: The type of thing to export Rules, Menus... must match HUDT class name.

string $machine_name: The machine name or unique identifier of the item to export.

File

./hook_update_deploy_tools.drush.inc, line 212
Drush commands for Hook Deploy Update Tools.

Code

function drush_hook_update_deploy_tools_site_deploy_export($type, $machine_name) {
  try {
    $msg = array();
    $alter_plurals = array(
      'Rule' => 'Rules',
      'Node' => 'Nodes',
    );
    $type = !empty($alter_plurals[$type]) ? $alter_plurals[$type] : $type;

    // Check to see if the class exists.
    $class = '\\HookUpdateDeployTools\\' . $type;
    \HookUpdateDeployTools\Check::classExists($class);

    // Check that we are dealing with an exportable type (an ExportInterface).
    $implements = class_implements($class);
    if (is_array($implements) && in_array('HookUpdateDeployTools\\ExportInterface', $implements)) {

      // Check that we have what it needs to export.
      $class::canExport();

      // It can export so can safely proceed.
      $msg = dt('Exported') . " {$type}: [{$machine_name}] => " . $class::export($machine_name);
    }
    else {

      // It does not implement ExportInterface.  Throw an exception.
      $msg = '\\HookUpdateDeployTools\\@type does not implement ExportInterface so this command can not be called.';
      $vars = array(
        '@type' => $type,
      );
      throw new \HookUpdateDeployTools\HudtException($msg, $vars, WATCHDOG_ERROR, FALSE);
    }
  } catch (\Exception $e) {

    // Any errors from this drush command do not need to be watchdog logged.
    $e->logIt = FALSE;
    $vars = array(
      '@error' => method_exists($e, 'logMessage') ? $e
        ->logMessage() : $e
        ->getMessage(),
    );
    $msg = dt("site-deploy-export Caught exception:  @error", $vars);
    drush_log($msg, 'error');

    // Clear out the $msg so it is not duplicated in the return.
    $msg = '';
  }
  return $msg;
}