hosting_web_pack.service.inc 3.46 KB
Newer Older
1 2 3 4
<?php

module_load_include('service.inc', 'hosting_web_server');

anarcat's avatar
anarcat committed
5 6
class hostingService_http_pack extends hostingService_http {
  public $type = 'pack';
7 8

  function view(&$render) {
9
    $render['master_servers'] = array(
10
      '#type' => 'item',
11 12 13 14 15 16 17
      '#title' => t('Master web servers'),
      '#value' => theme('item_list', array_map('_hosting_node_link', array_intersect_key($this->master_servers, hosting_get_servers('http')))),
    );
    $render['slave_servers'] = array(
      '#type' => 'item',
      '#title' => t('Slave web servers'),
      '#value' => theme('item_list', array_map('_hosting_node_link', array_intersect_key($this->slave_servers, hosting_get_servers('http')))),
18 19 20 21 22 23 24 25 26
    );
  }

  function form(&$form) {
    parent::form($form);

    $servers = hosting_get_servers('http');
    unset($servers[$this->server->nid]);

27 28 29 30 31 32 33 34
    $form['master_servers'] = array(
      '#title' => t('Master servers'),
      '#type' => 'checkboxes',
      '#options' => $servers,
      '#default_value' => isset($this->master_servers) ? $this->master_servers : array(),
    );
    $form['slave_servers'] = array(
      '#title' => t('Slave servers'),
35 36
      '#type' => 'checkboxes',
      '#options' => $servers,
37
      '#default_value' => isset($this->slave_servers) ? $this->slave_servers : array(),
38 39 40 41 42 43 44 45
    );
  }

  function load() {
    parent::load();

    $ssl_enabled = TRUE;

46
    $master_servers = array();
anarcat's avatar
anarcat committed
47
    $result = db_query('SELECT web_server_nid, type FROM {hosting_web_pack} WHERE vid = %d', $this->server->vid);
48
    while ($web_server = db_fetch_object($result)) {
49 50 51 52 53 54
      if ($web_server->type == 'master') {
        $master_servers[] = $web_server->web_server_nid;
      }
      else {
        $slave_servers[] = $web_server->web_server_nid;
      }
55 56 57 58 59
      $server = node_load($web_server->web_server_nid);
      $ssl_enabled = $ssl_enabled && $server->services['http']->ssl_enabled;
    }

    $this->ssl_enabled = $ssl_enabled;
60
    $this->setValues(array('master_servers' => drupal_map_assoc($master_servers)));
anarcat's avatar
anarcat committed
61
    $this->setValues(array('slave_servers' => drupal_map_assoc($slave_servers)));
62 63 64 65
  }

  function insert() {
    parent::insert();
66 67 68 69 70 71 72
    foreach (array_filter($this->master_servers) as $web_server) {
      $record = array(
        'nid' => $this->server->nid,
        'vid' => $this->server->vid,
        'web_server_nid' => $web_server,
        'type' => 'master',
      );
anarcat's avatar
anarcat committed
73
      drupal_write_record('hosting_web_pack', $record);
74 75
    }
    foreach (array_filter($this->slave_servers) as $web_server) {
76 77 78 79
      $record = array(
        'nid' => $this->server->nid,
        'vid' => $this->server->vid,
        'web_server_nid' => $web_server,
80
        'type' => 'slave',
81
      );
anarcat's avatar
anarcat committed
82
      drupal_write_record('hosting_web_pack', $record);
83 84 85 86 87
    }
  }

  function delete() {
    parent::delete();
anarcat's avatar
anarcat committed
88
    db_query('DELETE FROM {hosting_web_pack} WHERE nid = %d', $this->server->nid);
89 90 91 92
  }

  function delete_revision() {
    parent::delete_revision();
anarcat's avatar
anarcat committed
93
    db_query('DELETE FROM {hosting_web_pack} WHERE vid = %d', $this->server->vid);
94 95 96 97 98
  }

  function context_options($task_type, $ref_type, &$task) {
    parent::context_options($task_type, $ref_type, $task);

99 100
    $task->context_options['master_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->master_servers, hosting_get_servers('http')))));
    $task->context_options['slave_web_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->slave_servers, hosting_get_servers('http')))));
101 102
  }
}