'admin/deploy', 'title' => t('Deployment'), 'callback' => 'deploy_overview', 'access' => user_access('administer deployment'), 'description' => t('Deployment'), ); $items[] = array( 'path' => 'admin/deploy/plans', 'title' => t('Plans'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'access' => user_access('administer deployment'), ); $items[] = array( 'path' => 'admin/deploy/servers', 'title' => t('Servers'), 'description' => t('Manage deployment servers'), 'callback' => 'deploy_server_overview', 'access' => user_access('administer deployment'), 'type' => MENU_LOCAL_TASK, 'weight' => 3 ); $items[] = array( 'path' => 'admin/deploy/add', 'title' => t('Add a deployment plan'), 'description' => t('Add a deployment plan.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('deploy_plan_form'), 'access' => user_access('administer deployment'), 'type' => MENU_CALLBACK, 'weight' => 2 ); $items[] = array( 'path' => 'admin/deploy/plan', 'title' => t('Edit plan'), 'callback' => 'drupal_get_form', 'callback arguments' => array('deploy_plan_form'), 'access' => user_access('administer deployment'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/deploy/server/add', 'title' => t('Add server'), 'description' => t('Add a deployment server.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('deploy_server_form'), 'access' => user_access('administer deployment'), 'type' => MENU_CALLBACK, 'weight' => 2 ); $items[] = array( 'path' => 'admin/deploy/server', 'title' => t('Edit server'), 'description' => t('Edit a deployment server.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('deploy_server_form'), 'access' => user_access('administer deployment'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/deploy/push', 'title' => t('Push a plan live'), 'callback' => 'deploy_push', 'type' => MENU_CALLBACK, 'access' => user_access('deploy items'), 'weight' => 1, ); $items[] = array( 'path' => 'admin/deploy/list', 'title' => t('View deployment plan items'), 'callback' => 'deploy_list', 'type' => MENU_CALLBACK, 'access' => user_access('administer deployment'), 'weight' => 1, ); $items[] = array( 'path' => 'admin/deploy/delete/item', 'title' => t('Delete a deployment plan item'), 'callback' => 'deploy_delete_item', 'type' => MENU_CALLBACK, 'access' => user_access('administer deployment'), 'weight' => 1, ); $items[] = array( 'path' => 'admin/deploy/delete/plan', 'title' => t('Delete a deployment plan'), 'callback' => 'deploy_delete_plan', 'type' => MENU_CALLBACK, 'access' => user_access('administer deployment'), 'weight' => 1, ); $items[] = array( 'path' => 'admin/deploy/delete/server', 'title' => t('Delete a server'), 'callback' => 'deploy_delete_server', 'type' => MENU_CALLBACK, 'access' => user_access('administer deployment'), 'weight' => 1, ); return $items; } /** * deployment overview page menu callback */ function deploy_overview() { $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 2)); $result = db_query("select * from {deploy_plan}"); while ($row = db_fetch_array($result)) { $row = array(l($row['name'], 'admin/deploy/list/'. $row['pid']), l('edit', 'admin/deploy/plan/'. $row['pid']), l('delete', 'admin/deploy/delete/plan/'. $row['pid'])); $rows[] = $row; } if (empty($rows)) { $rows[] = array(array('data' => t('No deployment plans available.'), 'colspan' => '4', 'class' => 'message')); } $output = theme('table', $header, $rows); $output .= l("Add a New Deployment Plan", "/admin/deploy/add", array()); return $output; } /** * add/edit deployment plan form */ function deploy_plan_form($pid = NULL) { $plan = NULL; if (!is_null($pid)) { $plan = deploy_get_plan($pid); $form['pid'] = array( '#type' => 'hidden', '#default_value' => $pid, ); } $form['plan_name'] = array( '#title' => t('Name'), '#type' => 'textfield', '#size' => 30, '#maxlength' => 50, '#default_value' => $plan['name'], '#description' => t('A unique name for this deployment plan.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; } /** * deployment plan form validator */ function deploy_plan_form_validate($form_id, $form_values) { if ($form_values['plan_name'] == '') { form_set_error('plan_name', t('Plan name is required')); } } /** * add deployment plan form submit function */ function deploy_plan_form_submit($form_id, $form_values) { $name = $form_values['plan_name']; // if form_values has 'pid', then this is an update. Otherwise it is an // insert if (array_key_exists('pid', $form_values)) { $pid = $form_values['pid']; db_query("update {deploy_plan} set name = '%s' where pid = %d", $name, $pid); drupal_set_message(t('Plan updated')); } else { $pid = db_next_id('{deploy_plan}_pid'); db_query("insert into {deploy_plan} (pid, name) values (%d, '%s')", $pid, $name); drupal_set_message(t('Plan added')); } return 'admin/deploy'; } /** * deployment servers overview page menu callback */ function deploy_server_overview() { $header = array(t('Name'), t('URL'), array('data' => t('Operations'), 'colspan' => 2)); $result = db_query("select * from {deploy_servers}"); while ($row = db_fetch_array($result)) { $row = array($row['description'], $row['url'], l('edit', 'admin/deploy/server/'. $row['sid']), l('delete', 'admin/deploy/delete/server/'. $row['sid'])); $rows[] = $row; } if (empty($rows)) { $rows[] = array(array('data' => t('No deployment servers available.'), 'colspan' => '4', 'class' => 'message')); } $output = theme('table', $header, $rows); $output .= l("Add a New Server", "/admin/deploy/server/add", array()); return $output; } /** * add deployment server form */ function deploy_server_form($sid = NULL) { $server = NULL; if (!is_null($sid)) { $server = deploy_get_server($sid); $form['sid'] = array( '#type' => 'hidden', '#default_value' => $sid, ); } $form['description'] = array( '#title' => t('Name'), '#type' => 'textfield', '#size' => 50, '#maxlength' => 100, '#default_value' => $server['description'], '#description' => t('Description of this server.'), ); $form['url'] = array( '#title' => t('URL'), '#type' => 'textfield', '#size' => 50, '#maxlength' => 100, '#default_value' => $server['url'], '#description' => t('Domain name and path to xmlrpc service.'), ); $form['api_key'] = array( '#title' => t('API key'), '#type' => 'textfield', '#size' => 32, '#maxlength' => 32, '#default_value' => $server['api_key'], '#description' => t('API key (if needed)'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; } /** * add deployment server form validator */ function deploy_server_form_validate($form_id, $form_values) { if ($form_values['description'] == '') { form_set_error('description', t('Server description is required')); } if ($form_values['url'] == '') { form_set_error('url', t('URL is required')); } } /** * add deployment server form submit function */ function deploy_server_form_submit($form_id, $form_values) { $url = $form_values['url']; $description = $form_values['description']; $api_key = $form_values['api_key']; if (array_key_exists('sid', $form_values)) { $sid = $form_values['sid']; db_query("update {deploy_servers} set description = '%s', url = '%s', api_key = '%s' where sid = %d", $description, $url, $api_key, $sid); drupal_set_message(t('Deployment server updated')); } else { $sid = db_next_id('{deploy_servers}_sid'); db_query("insert into {deploy_servers} (sid, description, url, api_key) values (%d, '%s', '%s', '%s')", $sid, $description, $url, $api_key); drupal_set_message(t('Deployment server added')); } return 'admin/deploy/servers'; } /** * list deployment plan items menu callback */ function deploy_list($pid = NULL) { if (is_null($pid)) { drupal_goto('/admin/deploy'); } $output = "We will want to add item weighting here as well, since order of execution can matter"; $header = array(t('Module'), t('Description'), t('Operations')); $result = db_query("select module, description, iid from {deploy_plan_items} where pid = %d", $pid); while ($row = db_fetch_array($result)) { $row = array($row['module'], $row['description'], l(t('Delete From Plan'), "/admin/deploy/delete/item/$pid/" . $row['iid'] )); $rows[] = $row; } if (empty($rows)) { $rows[] = array(array('data' => t('No items have been added to this deployment.'), 'colspan' => '3', 'class' => 'message')); } $output .= theme('table', $header, $rows); $output .= l('Push this plan live', 'admin/deploy/push/'. $pid); return $output; } /** * return an assoc array of deployment plans of format pid => name */ function deploy_get_plans() { $result = db_query("select * from {deploy_plan} order by name"); $plans = array(); while ($plan = db_fetch_array($result)) { $plans[$plan['pid']] = $plan['name']; } return $plans; } /** * delete a deployment plan. * should probably add a confirmation here */ function deploy_delete_plan($pid = NULL) { if (is_null($pid)) { drupal_goto('/admin/deploy'); } db_query("delete from {deploy_plan_items} where pid = %d", $pid); db_query("delete from {deploy_plan} where pid = %d", $pid); drupal_set_message('Plan Deleted'); drupal_goto("/admin/deploy/"); } /** * delete a deployment plan. * should probably add a confirmation here */ function deploy_delete_server($sid = NULL) { if (is_null($sid)) { drupal_goto('/admin/deploy/servers'); } db_query("delete from {deploy_servers} where sid = %d", $sid); drupal_set_message('Server Deleted'); drupal_goto("/admin/deploy/servers"); } /** * delete an item from a deployment plan. * should probably add a confirmation here */ function deploy_delete_item($pid = NULL, $iid = NULL) { if (is_null($iid) || is_null($pid)) { drupal_goto('/admin/deploy'); } db_query("delete from {deploy_plan_items} where iid = %d", $iid); drupal_set_message('Item Deleted'); drupal_goto("/admin/deploy/list/$pid"); } /** * hook_xmlrpc deploy.install callback */ function deploy_install_items($module, $form_id, $data) { watchdog('install', $module); if (module_exists($module)) { $data = unserialize($data); drupal_execute($form_id, $data); } else { return "Module not enabled: $module"; } } /** * add data to a deployment plan */ function deploy_add_to_plan($pid, $module, $description, $data) { $iid = db_next_id('{deploy_plan_items}_iid'); $result = db_query("insert into deploy_plan_items (iid, pid, module, description, data) values (%d, %d, '%s', '%s', '%s')", $iid, $pid, $module, $description, $data); if (!$result) { drupal_set_message("an error occured"); } else { drupal_set_message("$description successfully added to plan"); } } /** * push a deployment plan live */ function deploy_push($pid) { if (is_null($pid)) { drupal_goto('/admin/deploy'); } $output = 'Choose a deployment server'; $output .= drupal_get_form('deploy_pushform', $pid); return $output; } function deploy_pushform($pid) { $servers = _deploy_get_servers(); $form['pid'] = array( '#type' => 'hidden', '#value' => $pid, ); $form['sid'] = array( '#title' => t('Server'), '#type' => 'select', '#options' => $servers, '#description' => t('The server you want to deploy to'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; } /** * submit handler for deployment push form */ function deploy_pushform_submit($form_id, $form_values) { $sid = $form_values['sid']; $pid = $form_values['pid']; $result = db_query("select * from deploy_servers where sid = %d", $sid); $row = db_fetch_array($result); $url = $row['url']; $api_key = $row['api_key']; $result = db_query("select * from deploy_plan_items where pid = %d", $pid); while ($row = db_fetch_array($result)) { call_user_func($row['module'] .'_deploy', $url, $api_key, $row['data']); } return "/admin/deploy/list/$pid"; } /** * return an assoc array of servers of format sid => description */ function _deploy_get_servers() { $result = db_query("select * from {deploy_servers} order by description"); $servers = array(); while ($server = db_fetch_array($result)) { $servers[$server['sid']] = $server['description']; } return $servers; } /** * update a single item in a deployment plan with new data */ function deploy_update_item($iid, $data) { db_query("update {deploy_plan_items} set data = '%s' where iid = %d", $data, $iid); } /** * retrieve an array of a deployment plan */ function deploy_get_plan($pid) { $result = db_query("select * from {deploy_plan} where pid = %d", $pid); return db_fetch_array($result); } /** * retrieve an array of a deployment plan server */ function deploy_get_server($sid) { $result = db_query("select * from {deploy_servers} where sid = %d", $sid); return db_fetch_array($result); }