class hostingService_dns_master

Helper class to factor together master functionality

This mostly consists of master->slave mapping

Hierarchy

Expanded class hierarchy of hostingService_dns_master

Members

File

dns/hosting_dns.service.inc, line 19
Provide the hosting serivce classes for DNS integration.

View source
class hostingService_dns_master extends hostingService_dns {
  function view(&$render) {
    parent::view($render);

    if (sizeof($this->slave_servers)) {
      $render['slave_servers'] = array(
        '#type' => 'item',
        '#title' => t('Slave servers'),
        '#value' => theme('item_list', array('items' => array_map('_hosting_node_link', array_intersect_key($this->slave_servers, hosting_get_servers('dns'))))),
      );
    }
  }

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

    $servers = hosting_get_servers('dns');

    // Exclude the current server from the list of possible slaves.
    if (isset($this->server->nid)) {
      unset($servers[$this->server->nid]);
    }

    if (sizeof($servers)) {
      $form['slave_servers'] = array(
        '#title' => t('Slave DNS servers'),
        '#type' => 'checkboxes',
        '#options' => $servers,
        '#default_value' => isset($this->slave_servers) ? $this->slave_servers : array(),
      );
    }
    else {
      $form['slave_server'] = array(
        '#type' => 'value',
        '#value' => array(),
      );
    }
  }

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

    $slave_servers = array();
    $result = db_query('SELECT slave_nid FROM {hosting_dns_slaves} WHERE master_vid = :master_vid', array(':master_vid' => $this->server->vid));
    while ($slave_server = $result->fetch()) {
      $slave_servers[] = $slave_server->slave_nid;
    }

    $this->setValues(array('slave_servers' => drupal_map_assoc($slave_servers)));
  }

  function insert() {
    parent::insert();
    if (is_array($this->slave_servers)) {
      foreach (array_filter($this->slave_servers) as $slave_server) {
        $record = array(
          'master_nid' => $this->server->nid,
          'master_vid' => $this->server->vid,
          'slave_nid' => $slave_server,
        );
        drupal_write_record('hosting_dns_slaves', $record);
      }
    }
  }

  function delete() {
    parent::delete();
    db_delete('hosting_dns_slaves')->condition('master_nid', $this->server->nid)->execute();
  }

  function delete_revision() {
    parent::delete_revision();
    db_delete('hosting_dns_slaves')->condition('master_vid', $this->server->vid)->execute();
  }

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

    if (is_array($this->slave_servers) && sizeof($this->slave_servers)) {
      $task->context_options['slave_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->slave_servers, hosting_get_servers('dns')))));
    }
  }

}