hosting_web_cluster.service.inc

Extensions to the Hosting service class for the web cluster module.

Classes

File

web_cluster/hosting_web_cluster.service.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Extensions to the Hosting service class for the web cluster module.
  5. */
  6. module_load_include('service.inc', 'hosting_web_server');
  7. class hostingService_http_cluster extends hostingService_http {
  8. public $type = 'cluster';
  9. function view(&$render) {
  10. $render['web_servers'] = array(
  11. '#type' => 'item',
  12. '#title' => t('Web servers'),
  13. '#markup' => theme('item_list', array('items' => array_map('_hosting_node_link', array_intersect_key($this->web_servers, hosting_get_servers('http'))))),
  14. );
  15. }
  16. function form(&$form) {
  17. parent::form($form);
  18. $servers = hosting_get_servers('http');
  19. if (isset($this->server->nid)) {
  20. unset($servers[$this->server->nid]);
  21. }
  22. $form['web_servers'] = array(
  23. '#title' => t('Servers'),
  24. '#type' => 'checkboxes',
  25. '#options' => $servers,
  26. '#default_value' => isset($this->web_servers) ? $this->web_servers : array(),
  27. );
  28. }
  29. function load() {
  30. parent::load();
  31. $ssl_enabled = TRUE;
  32. $web_servers = array();
  33. $result = db_query('SELECT web_server_nid FROM {hosting_web_cluster} WHERE vid = :vid', array(':vid' => $this->server->vid));
  34. while ($web_server = $result->fetch()) {
  35. $web_servers[] = $web_server->web_server_nid;
  36. $server = node_load($web_server->web_server_nid);
  37. $ssl_enabled = $ssl_enabled && $server->services['http']->ssl_enabled;
  38. }
  39. $this->ssl_enabled = $ssl_enabled;
  40. $this->setValues(array('web_servers' => drupal_map_assoc($web_servers)));
  41. }
  42. function insert() {
  43. parent::insert();
  44. foreach (array_filter($this->web_servers) as $web_server) {
  45. $record = array(
  46. 'nid' => $this->server->nid,
  47. 'vid' => $this->server->vid,
  48. 'web_server_nid' => $web_server,
  49. );
  50. drupal_write_record('hosting_web_cluster', $record);
  51. }
  52. }
  53. function delete() {
  54. parent::delete();
  55. db_delete('hosting_web_cluster')
  56. ->condition('nid', $this->server->nid)
  57. ->execute();
  58. }
  59. function delete_revision() {
  60. parent::delete_revision();
  61. db_delete('hosting_web_cluster')
  62. ->condition('vid', $this->server->vid)
  63. ->execute();
  64. }
  65. function context_options($task_type, $ref_type, &$task) {
  66. parent::context_options($task_type, $ref_type, $task);
  67. $task->context_options['cluster_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->web_servers, hosting_get_servers('http')))));
  68. }
  69. }