'admin/build/deploy/ahah/auth-form',
'wrapper' => 'deploy-auth-wrapper',
'method' => 'replace',
);
$form['auth_wrapper'] = array(
'#prefix' => '
',
'#suffix' => '
',
);
$sid = $form['sid']['#default_value'];
if (!empty($sid)) {
$server = deploy_get_server($sid);
$form['auth_wrapper']['settings'] = deploy_auth_invoke($server['auth_type'], 'form callback', $server);
}
else {
// This form element will be replaced with the response from
// an AHAH request.
$form['auth_wrapper']['settings'] = array(
'#type' => 'hidden',
);
}
$form['submit']['#weight'] = 10;
}
elseif (isset($form['#node']) && $form_id == $form['#node']->type . '_node_form') {
$form['options']['autodeploy_sid'] = autodeploy_settings_form($form['#node']->type);
}
elseif ($form_id == 'node_type_form') {
$form['#submit'][] = 'autodeploy_node_type_form_submit';
$form['workflow']['autodeploy_sid'] = autodeploy_settings_form($form['#node_type']->type);
}
}
/**
* Implementation of hook_deploy_auth_type_alter().
*/
function autodeploy_deploy_auth_type_alter(&$types) {
$types['deploy_key']['form callback'] = 'autodeploy_auth_key_form';
$types['deploy_sessid']['form callback'] = 'autodeploy_auth_sessid_form';
}
/**
* Form callback for the deploy_key authentication type.
*/
function autodeploy_auth_key_form($server) {
// We are reusing the original form definition.
$form = deploy_auth_key_form();
autodeploy_server_settings_populate($form, $server['sid']);
return $form;
}
/**
* Form callback for the deploy_key authentication type.
*/
function autodeploy_auth_sessid_form($server) {
// We are reusing the original form definition.
$form = deploy_auth_sessid_form();
autodeploy_server_settings_populate($form, $server['sid']);
return $form;
}
/**
* Do the deployment.
*/
function autodeploy_do($node) {
// If we are updating a node and if we wan't to auto deploy it and if
// this operation isn't called during a deployment.
if ($node->autodeploy_sid && !$node->deploy) {
// Include functions from node_deploy.
module_load_include('inc', 'node_deploy', 'node_deploy.pages');
// Ignore all destination redirects.
unset($_REQUEST['destination']);
// Create the deployment plan.
$pid = node_deploy_operations_create_plan($node->nid);
$settings = autodeploy_variable_get('autodeploy_server_settings', $node->autodeploy_sid);
if (deploy_plan_init($pid, $node->autodeploy_sid, $settings)) {
// Redirect to the log overview page for this push.
drupal_goto('admin/build/deploy/deploy_check_batch');
}
// If the initiation of the plan failed we need to clean up after us.
deploy_plan_cleanup();
}
return FALSE;
}
/**
* Helper function for the node and node type form.
*/
function autodeploy_settings_form($type) {
$servers = deploy_get_servers();
// Rebuild the server list so we also have an empty option.
$options = array('' => t('-- Select a server'));
foreach ($servers as $sid => $server) {
$options[$sid] = $server;
}
return array(
'#title' => t('Deploy to server'),
'#type' => 'select',
'#options' => $options,
'#description' => t('Select the default server for auto deployments.'),
'#default_value' => autodeploy_variable_get('autodeploy_settings', $type),
);
}
/**
* Submission callback for the deploy server form.
*/
function autodeploy_deploy_server_form_submit($form, &$form_state) {
$settings = autodeploy_server_settings_extract($form, $form_state);
autodeploy_variable_set('autodeploy_server_settings', $form_state['values']['sid'], $settings);
}
/**
* Submission callback for the node type form.
*/
function autodeploy_node_type_form_submit($form, &$form_state) {
autodeploy_variable_set('autodeploy_settings', $form_state['values']['type'], $form_state['values']['autodeploy_sid']);
}
/**
* Helper function that extracts server settings from a form submission.
*/
function autodeploy_server_settings_extract($form, $form_state) {
$settings = array();
foreach ($form['auth_wrapper']['settings'] as $key => $value) {
if (substr($key, 0, 1) != '#' && !empty($form_state['values'][$key])) {
$settings[$key] = $form_state['values'][$key];
}
}
return $settings;
}
/**
* Helper function that populates server settings in a form.
*/
function autodeploy_server_settings_populate(&$auth_form, $sid) {
$settings = autodeploy_variable_get('autodeploy_server_settings', $sid);
foreach ($auth_form as $component => $definition) {
$auth_form[$component]['#default_value'] = $settings[$component];
}
}
/**
* Helper function for retrieving server settings.
*/
function autodeploy_variable_get($variable_name, $key, $default_value = array()) {
$values = variable_get($variable_name, $default_value);
if (!isset($values[$key])) {
return $default_value;
}
return $values[$key];
}
/**
* Helper function for saving server settings.
*/
function autodeploy_variable_set($variable_name, $key, $value) {
$values = variable_get($variable_name, array());
$values[$key] = $value;
variable_set($variable_name, $values);
}