From 486c04a4b8b6571a8b218dc6fdd239247dc3651e Mon Sep 17 00:00:00 2001
From: Thomas Bosviel <thomas@bosviel.org>
Date: Sat, 5 Mar 2011 19:46:09 +0100
Subject: [PATCH] Issue #1083710 by tbosviel: Clean hosting_dns module of 'Undefined Index' notices.

---
 dns/bind_slave/bind_slave_service.inc |   25 ++++++++++++-------------
 dns/dns.drush.inc                     |    1 -
 dns/dnsmasq/dnsmasq_service.inc       |    5 +++++
 provision.service.inc                 |   11 ++++++++---
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/dns/bind_slave/bind_slave_service.inc b/dns/bind_slave/bind_slave_service.inc
index 55c7618..d6bb4d3 100644
--- a/dns/bind_slave/bind_slave_service.inc
+++ b/dns/bind_slave/bind_slave_service.inc
@@ -27,10 +27,6 @@ class provisionService_dns_bind_slave extends provisionService_dns {
   /**
    * Create the zonefile record on the slave server
    *
-   * This differs from the parent implementation because it *requires* you to
-   * pass the master server, as it is necessary for the slave to know what its
-   * slave is (and it can vary according to the zone).
-   *
    * Contrarily to the parent class implementation, this *only* creates the
    * bind config (managed through the provisionConfig_bind_slave class), and no
    * zonefile, because the zonefile should be managed by bind itself through
@@ -39,16 +35,11 @@ class provisionService_dns_bind_slave extends provisionService_dns {
    * Note that this function shouldn't be called directly through the API, but
    * only from the master server's create_zone() function.
    *
-   * @todo this needs to be pushed up in a provisionService_dns_slave common
-   * class
-   * 
-   * @arg $master mixed a string or array of strings of IPs pointing to the
-   * master server for this zone
-   *
    * @arg $zone string the zonefile name to create
    *
    * @see provisionService_dns::create_zone()
-  function create_zone($master, $zone = null) {
+   */
+  function create_zone($zone = null) {
     if (is_null($zone) && ($this->context->type == 'site')) {
       $host = $this->context->uri;
       $zone = $this->context->dns_zone;
@@ -57,11 +48,19 @@ class provisionService_dns_bind_slave extends provisionService_dns {
     if (empty($zone)) {
       return drush_set_error('DRUSH_DNS_NO_ZONE', "Could not determine the zone to create");
     }
-
+    
     drush_log(dt("recording zone in slave configuration"));
-    $this->config('server')->record_set($zone, $master)->write();
+    $status = $this->config('server')->record_set($zone, $zone)->write();
+    
+    return $status;
   }
+  
+  /**
+   * This completely drops a zone, without any checks.
    */
+  function delete_zone($zone) {
+    return $this->config('server')->record_del($zone, $zone)->write();
+  }
 }
 
 class provisionConfig_bind_slave extends provisionConfig_dns_server {
diff --git a/dns/dns.drush.inc b/dns/dns.drush.inc
index 6b60034..9d3da2d 100644
--- a/dns/dns.drush.inc
+++ b/dns/dns.drush.inc
@@ -342,7 +342,6 @@ class provisionService_dns extends provisionService {
     $this->config('zone', $zone)->record_set($sub, array('A' => $ips));
     
     $this->create_zone($zone);
-    $this->create_config('host');
   }
 
 
diff --git a/dns/dnsmasq/dnsmasq_service.inc b/dns/dnsmasq/dnsmasq_service.inc
index bb4b8ef..cdfe5f9 100644
--- a/dns/dnsmasq/dnsmasq_service.inc
+++ b/dns/dnsmasq/dnsmasq_service.inc
@@ -18,6 +18,11 @@ class provisionService_dns_dnsmasq extends provisionService_dns {
   function parse_configs() {
     $this->restart();
   }
+  
+  function create_host($host = NULL) {
+    parent::create_host($host);
+    $this->create_config('host');
+  }
 }
 
 class provisionConfig_dnsmasq_server extends provisionConfig_dns_server {
diff --git a/provision.service.inc b/provision.service.inc
index 92ecd72..7b9b802 100644
--- a/provision.service.inc
+++ b/provision.service.inc
@@ -132,13 +132,18 @@ class provisionService extends provisionChainedState {
         }
         elseif (!is_numeric($arg1)) {
           if (is_array($arg2)) {
-            if (!is_array($this->_config->store->loaded_records[$arg1])) {
+            if (!isset($this->_config->store->loaded_records[$arg1])
+                || !is_array($this->_config->store->loaded_records[$arg1]))
+            {
               $this->_config->store->loaded_records[$arg1] = array();
             }
-            if (!is_array($this->_config->store->records[$arg1])) {
+            if (!isset($this->_config->store->records[$arg1])
+                || !is_array($this->_config->store->records[$arg1]))
+            {
               $this->_config->store->records[$arg1] = array();
             }
-            $this->_config->store->records[$arg1] = array_merge($this->_config->store->loaded_records[$arg1], $this->_config->store->records[$arg1], $arg2);
+            $this->_config->store->records[$arg1] = array_merge($this->_config->store->loaded_records[$arg1],
+                                                                $this->_config->store->records[$arg1], $arg2);
           } else {
             $this->_config->store->records[$arg1] = $arg2;
           }
-- 
1.7.0.4

