'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_auth_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_auth_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_auth_settings_get($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_type_settings_get($type), ); } /** * Submission callback for the deploy server form. */ function autodeploy_deploy_server_form_submit($form, &$form_state) { $settings = autodeploy_auth_settings_extract($form, $form_state); autodeploy_auth_settings_set($form_state['values']['sid'], $settings); } /** * Submission callback for the node type form. */ function autodeploy_node_type_form_submit($form, &$form_state) { autodeploy_type_settings_set($form_state['values']['type'], $form_state['values']['autodeploy_sid']); } /** * Helper function that extracts authentication settings from a form submission. */ function autodeploy_auth_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 the authentication form. */ function autodeploy_auth_settings_populate(&$auth_form, $sid) { $settings = autodeploy_auth_settings_get($sid); foreach ($auth_form as $component => $definition) { $auth_form[$component]['#default_value'] = $settings[$component]; } } /** * Helper function for retrieving authentication settings for a server. */ function autodeploy_auth_settings_get($sid, $default_value = array()) { $values = variable_get('autodeploy_auth_settings', $default_value); if (!isset($values[$sid])) { return $default_value; } $decrypted = decrypt($values[$sid]); return unserialize($decrypted); } /** * Helper function for saving authentication settings for a server. */ function autodeploy_auth_settings_set($sid, $value) { $encrypted = encrypt(serialize($value)); $values = variable_get('autodeploy_auth_settings', array()); $values[$sid] = $encrypted; variable_set('autodeploy_auth_settings', $values); } /** * Helper function for retrieving content type specific settings. */ function autodeploy_type_settings_get($type, $default_value = array()) { $values = variable_get('autodeploy_type_settings', $default_value); if (!isset($values[$type])) { return $default_value; } return $values[$type]; } /** * Helper function for saving content type specific settings. */ function autodeploy_type_settings_set($type, $value) { $values = variable_get('autodeploy_type_settings', array()); $values[$type] = $value; variable_set('autodeploy_type_settings', $values); }