You are here

function drush_deploy_create_plan in Deploy - Content Staging 7.2

Same name and namespace in other branches
  1. 7.3 deploy.drush.inc \drush_deploy_create_plan()

Command callback for creating plans.

File

./deploy.drush.inc, line 110
Provides Drush integration for Deploy.

Code

function drush_deploy_create_plan($name) {
  $endpoints = deploy_endpoint_load_all();
  if (!count($endpoints)) {
    return drush_set_error(dt("No endpoints configured"));
  }
  $endpoint = drush_get_option('endpoint');
  if (!$endpoint || !isset($endpoints[$endpoint])) {
    return drush_set_error(dt('Invalid endpoint: @endpoint.', array(
      '@endpoint' => $endpoint,
    )));
  }
  unset($endpoints);
  $aggregator = drush_get_option('aggregator', 'DeployAggregatorManaged');
  $aggregators = deploy_get_aggregator_plugins();
  if (!isset($aggregators[$aggregator])) {
    return drush_set_error(dt('Invalid aggregator: @aggregator.', array(
      '@aggregator' => $aggregator,
    )));
  }
  unset($aggregators);
  $delete = (bool) drush_get_option('delete', 0);
  $debug = (bool) drush_get_option('debug-plan', 1);
  $plan = deploy_plan_load($name);
  if (FALSE !== $plan) {
    if (!(bool) drush_get_option('overwrite', 0)) {
      return drush_set_error(dt('Plan @name already exists. Use --overwrite=1 to overwite the configuration for the plan.', array(
        '@name' => $name,
      )));
    }
    $plan->debug = $debug;
    $plan->endpoints = array(
      $endpoint => $endpoint,
    );
    if ('DeployAggregatorManaged' == $aggregator) {
      $plan->aggregator_config = array(
        'delete_post_deploy' => $delete,
      );
    }
    $plan = deploy_plan_save($plan);
    drush_print(dt('Updated plan @name(@pid).', array(
      '@name' => $name,
      '@pid' => $plan->pid,
    )));
    drush_print_pipe($plan->pid);
    return TRUE;
  }
  $plan = (object) array(
    'pid' => NULL,
    'name' => $name,
    'title' => dt('@name plan', array(
      '@name' => $name,
    )),
    'description' => dt('@name plan', array(
      '@name' => $name,
    )),
    'debug' => $debug,
    'aggregator_plugin' => $aggregator,
    'aggregator_config' => array(
      'delete_post_deploy' => $delete,
    ),
    'processor_plugin' => 'DeployProcessorMemory',
    'endpoints' => array(
      $endpoint => $endpoint,
    ),
    'fetch_only' => 0,
    'table' => 'deploy_plans',
    'type' => 'Normal',
  );
  $plan = deploy_plan_save($plan);
  drush_print(dt('Created new plan @pid.', array(
    '@pid' => $plan->pid,
  )));
  drush_print_pipe($plan->pid);
}