hosting_web_pack.service.inc

Hosting service class for the Hosting web pack module.

Classes

File

web_pack/hosting_web_pack.service.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hosting service class for the Hosting web pack module.
  5. */
  6. module_load_include('service.inc', 'hosting_web_server');
  7. class hostingService_http_pack extends hostingService_http {
  8. public $type = 'pack';
  9. function view(&$render) {
  10. $render['master_servers'] = array(
  11. '#type' => 'item',
  12. '#title' => t('Master web servers'),
  13. '#markup' => theme('item_list', array('items' => array_map('_hosting_node_link', array_intersect_key($this->master_servers, hosting_get_servers('http'))))),
  14. );
  15. $render['slave_servers'] = array(
  16. '#type' => 'item',
  17. '#title' => t('Slave web servers'),
  18. '#markup' => theme('item_list', array('items' => array_map('_hosting_node_link', array_intersect_key($this->slave_servers, hosting_get_servers('http'))))),
  19. );
  20. }
  21. function form(&$form) {
  22. parent::form($form);
  23. $servers = hosting_get_servers('http');
  24. if (isset($this->server->nid)) {
  25. unset($servers[$this->server->nid]);
  26. }
  27. $form['master_servers'] = array(
  28. '#title' => t('Master servers'),
  29. '#type' => 'checkboxes',
  30. '#options' => $servers,
  31. '#default_value' => isset($this->master_servers) ? $this->master_servers : array(),
  32. );
  33. $form['slave_servers'] = array(
  34. '#title' => t('Slave servers'),
  35. '#type' => 'checkboxes',
  36. '#options' => $servers,
  37. '#default_value' => isset($this->slave_servers) ? $this->slave_servers : array(),
  38. );
  39. }
  40. function load() {
  41. parent::load();
  42. $ssl_enabled = TRUE;
  43. $master_servers = array();
  44. $slave_servers = array();
  45. $result = db_query('SELECT web_server_nid, type FROM {hosting_web_pack} WHERE vid = :vid', array(':vid' => $this->server->vid));
  46. while ($web_server = $result->fetch()) {
  47. if ($web_server->type == 'master') {
  48. $master_servers[] = $web_server->web_server_nid;
  49. }
  50. else {
  51. $slave_servers[] = $web_server->web_server_nid;
  52. }
  53. $server = node_load($web_server->web_server_nid);
  54. $ssl_enabled = $ssl_enabled && $server->services['http']->ssl_enabled;
  55. }
  56. $this->ssl_enabled = $ssl_enabled;
  57. $this->setValues(array('master_servers' => drupal_map_assoc($master_servers)));
  58. $this->setValues(array('slave_servers' => drupal_map_assoc($slave_servers)));
  59. }
  60. function insert() {
  61. parent::insert();
  62. foreach (array_filter($this->master_servers) as $web_server) {
  63. $record = array(
  64. 'nid' => $this->server->nid,
  65. 'vid' => $this->server->vid,
  66. 'web_server_nid' => $web_server,
  67. 'type' => 'master',
  68. );
  69. drupal_write_record('hosting_web_pack', $record);
  70. }
  71. foreach (array_filter($this->slave_servers) as $web_server) {
  72. $record = array(
  73. 'nid' => $this->server->nid,
  74. 'vid' => $this->server->vid,
  75. 'web_server_nid' => $web_server,
  76. 'type' => 'slave',
  77. );
  78. drupal_write_record('hosting_web_pack', $record);
  79. }
  80. }
  81. function delete() {
  82. parent::delete();
  83. db_delete('hosting_web_pack')
  84. ->condition('nid', $this->server->nid)
  85. ->execute();
  86. }
  87. function delete_revision() {
  88. parent::delete_revision();
  89. db_delete('hosting_web_pack')
  90. ->condition('vid', $this->server->vid)
  91. ->execute();
  92. }
  93. function context_options($task_type, $ref_type, &$task) {
  94. parent::context_options($task_type, $ref_type, $task);
  95. $task->context_options['master_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->master_servers, hosting_get_servers('http')))));
  96. $task->context_options['slave_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->slave_servers, hosting_get_servers('http')))));
  97. }
  98. }