Skip to content

Commit a8e1af0

Browse files
committed
updated modifydomain to correctly replace namervers, admin and tech contacts
1 parent 1b3ae6a commit a8e1af0

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

Examples/modifydomain.php

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,51 +42,49 @@
4242
* @param null $nameservers string
4343
*/
4444
function modifydomain($conn, $domainname, $registrant = null, $admincontact = null, $techcontact = null, $billingcontact = null, $nameservers = null) {
45+
$response = null;
4546
try {
4647
$domain = new Metaregistrar\EPP\eppDomain($domainname);
4748
// First, retrieve the current domain info. Nameservers can be unset and then set again.
4849
$del = null;
4950
$info = new Metaregistrar\EPP\eppInfoDomainRequest($domain);
5051
if ((($response = $conn->writeandread($info)) instanceof Metaregistrar\EPP\eppInfoDomainResponse) && ($response->Success())) {
51-
/* @var $response Metaregistrar\EPP\eppInfoDomainResponse */
5252
// If new nameservers are given, get the old ones to remove them
5353
if (is_array($nameservers)) {
5454
/* @var Metaregistrar\EPP\eppInfoDomainResponse $response */
55-
// Check if nameservers are not already set for this domain name
5655
$oldns = $response->getDomainNameservers();
5756
if (is_array($oldns)) {
58-
foreach($oldns as $index=>$ns) {
59-
/* @var $ns Metaregistrar\EPP\eppHost */
60-
if (in_array($ns->getHostname(),$nameservers)) {
61-
unset($nameservers[array_search($ns->getHostname(),$nameservers)]);
62-
unset($oldns[$index]);
63-
}
57+
if (!$del) {
58+
$del = new Metaregistrar\EPP\eppDomain($domainname);
6459
}
65-
if (count($oldns)>0) {
66-
if (!$del) {
67-
$del = new Metaregistrar\EPP\eppDomain($domainname);
68-
}
69-
foreach ($oldns as $ns) {
70-
$del->addHost($ns);
71-
}
60+
foreach ($oldns as $ns) {
61+
$del->addHost($ns);
7262
}
7363
}
74-
// Remove DNSSEC keydata that is present on this domain name
75-
$keydata = $response->getKeydata();
76-
if ((is_array($keydata)) && (count($keydata)>0)) {
64+
}
65+
if ($admincontact) {
66+
$oldadmin = $response->getDomainContact(Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_ADMIN);
67+
if ($oldadmin == $admincontact) {
68+
$admincontact = null;
69+
} else {
7770
if (!$del) {
7871
$del = new Metaregistrar\EPP\eppDomain($domainname);
7972
}
80-
$del->addSecdns($keydata[0]);
73+
$admin = new Metaregistrar\EPP\eppContactHandle($oldadmin, Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_ADMIN);
74+
$del->addContact($admin);
8175
}
8276
}
83-
if ($admincontact) {
84-
$oldadmin = $response->getDomainContact(Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_ADMIN);
85-
if (!$del) {
86-
$del = new Metaregistrar\EPP\eppDomain($domainname);
77+
if ($techcontact) {
78+
$oldtech = $response->getDomainContact(Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_TECH);
79+
if ($oldtech == $techcontact) {
80+
$techcontact = null;
81+
} else {
82+
if (!$del) {
83+
$del = new Metaregistrar\EPP\eppDomain($domainname);
84+
}
85+
$tech = new Metaregistrar\EPP\eppContactHandle($oldtech, Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_TECH);
86+
$del->addContact($tech);
8787
}
88-
$admin = new Metaregistrar\EPP\eppContactHandle($oldadmin, Metaregistrar\EPP\eppContactHandle::CONTACT_TYPE_ADMIN);
89-
$del->addContact($admin);
9088
}
9189
}
9290
// In the UpdateDomain command you can set or add parameters
@@ -130,18 +128,15 @@ function modifydomain($conn, $domainname, $registrant = null, $admincontact = nu
130128
$add->addHost($host);
131129
}
132130
}
133-
if ((!$add) && (!$del) && (!$mod)) {
134-
echo "Nothing to update";
135-
return;
136-
}
137-
$update = new Metaregistrar\EPP\eppDnssecUpdateDomainRequest($domain, $add, $del, $mod);
131+
$update = new Metaregistrar\EPP\rrpproxyEppUpdateDomainRequest($domain, $add, $del, $mod);
132+
//echo $update->saveXML();
138133
if ((($response = $conn->writeandread($update)) instanceof Metaregistrar\EPP\eppUpdateResponse) && ($response->Success())) {
139-
/* @var $response Metaregistrar\EPP\eppUpdateResponse */
134+
/* @var Metaregistrar\EPP\eppUpdateResponse $response */
140135
echo $response->getResultMessage() . "\n";
141136
}
142137
} catch (Metaregistrar\EPP\eppException $e) {
143138
echo $e->getMessage() . "\n";
144-
if ((isset($response)) && ($response instanceof Metaregistrar\EPP\eppUpdateResponse)) {
139+
if ($response instanceof Metaregistrar\EPP\eppUpdateResponse) {
145140
echo $response->textContent . "\n";
146141
}
147142
}

0 commit comments

Comments
 (0)