Skip to content

Commit d0ce81d

Browse files
committed
added DNS "clone" function
1 parent fec2740 commit d0ce81d

File tree

3 files changed

+73
-32
lines changed

3 files changed

+73
-32
lines changed

lib/OpenCloud/DNS/AsyncResponse.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
* The AsyncResponse class encapsulates the data returned by a Cloud DNS
2020
* asynchronous response.
2121
*/
22-
class AsyncResponse extends PersistentObject
22+
class AsyncResponse extends PersistentObject
2323
{
2424

2525
public $jobId;
26-
public $callbackUrl;
26+
public $callbackUrl;
2727
public $status;
2828
public $requestUrl;
2929
public $verb;
3030
public $request;
3131
public $response;
3232
public $error;
33+
public $domains;
3334

3435
protected static $json_name = false;
3536

@@ -40,7 +41,7 @@ class AsyncResponse extends PersistentObject
4041
* @param \OpenCloud\Service $service the calling service
4142
* @param string $json the json response from the initial request
4243
*/
43-
public function __construct(AbstractService $service, $json = null)
44+
public function __construct(AbstractService $service, $json = null)
4445
{
4546
if (!$json) {
4647
return;
@@ -61,7 +62,7 @@ public function __construct(AbstractService $service, $json = null)
6162
*
6263
* @return string
6364
*/
64-
public function Url($subresource = null, $qstr = array())
65+
public function Url($subresource = null, $qstr = array())
6566
{
6667
return $this->callbackUrl . '?showDetails=True';
6768
}
@@ -71,32 +72,32 @@ public function Url($subresource = null, $qstr = array())
7172
*
7273
* @return string
7374
*/
74-
public function Name()
75+
public function Name()
7576
{
7677
return $this->jobId;
7778
}
7879

7980
/**
8081
* overrides for methods
8182
*/
82-
public function Create($parm = array())
83-
{
84-
return $this->NoCreate();
83+
public function Create($parm = array())
84+
{
85+
return $this->NoCreate();
8586
}
8687

87-
public function Update($parm = array())
88-
{
89-
return $this->NoUpdate();
88+
public function Update($parm = array())
89+
{
90+
return $this->NoUpdate();
9091
}
9192

92-
public function Delete()
93-
{
94-
return $this->NoDelete();
93+
public function Delete()
94+
{
95+
return $this->NoDelete();
9596
}
9697

97-
public function PrimaryKeyField()
98-
{
99-
return 'jobId';
98+
public function PrimaryKeyField()
99+
{
100+
return 'jobId';
100101
}
101102

102-
}
103+
}

lib/OpenCloud/DNS/Domain.php

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @api
2222
* @author Glen Campbell <[email protected]>
2323
*/
24-
class Domain extends Object
24+
class Domain extends Object
2525
{
2626

2727
public $id;
@@ -38,9 +38,9 @@ class Domain extends Object
3838
protected static $url_resource = 'domains';
3939

4040
protected $_create_keys = array(
41-
'name',
42-
'emailAddress',
43-
'ttl',
41+
'name',
42+
'emailAddress',
43+
'ttl',
4444
'comment'
4545
);
4646

@@ -61,7 +61,7 @@ class Domain extends Object
6161
*
6262
* @return Record
6363
*/
64-
public function Record($info = null)
64+
public function Record($info = null)
6565
{
6666
return new Record($this, $info);
6767
}
@@ -72,7 +72,7 @@ public function Record($info = null)
7272
* @param array $filter query-string parameters
7373
* @return \OpenCloud\Collection
7474
*/
75-
public function RecordList($filter = array())
75+
public function RecordList($filter = array())
7676
{
7777
return $this->Parent()->Collection('\OpenCloud\DNS\Record', null, $this, $filter);
7878
}
@@ -81,7 +81,7 @@ public function RecordList($filter = array())
8181
* returns a Subdomain object (child of current domain)
8282
*
8383
*/
84-
public function Subdomain($info = array())
84+
public function Subdomain($info = array())
8585
{
8686
return new Subdomain($this, $info);
8787
}
@@ -95,7 +95,7 @@ public function Subdomain($info = array())
9595
* @param array $filter key/value pairs for query string parameters
9696
* return \OpenCloud\Collection
9797
*/
98-
public function SubdomainList($filter = array())
98+
public function SubdomainList($filter = array())
9999
{
100100
return $this->Parent()->Collection('\OpenCloud\DNS\Subdomain', null, $this);
101101
}
@@ -107,7 +107,7 @@ public function SubdomainList($filter = array())
107107
* @param Record $rec the record to add
108108
* @return integer the number of records
109109
*/
110-
public function AddRecord(Record $record)
110+
public function AddRecord(Record $record)
111111
{
112112
$this->records[] = $record;
113113
return count($this->records);
@@ -120,7 +120,7 @@ public function AddRecord(Record $record)
120120
* @param Subdomain $subd the subdomain to add
121121
* @return integer the number of subdomains
122122
*/
123-
public function AddSubdomain(Subdomain $subdomain)
123+
public function AddSubdomain(Subdomain $subdomain)
124124
{
125125
$this->subdomains[] = $subdomain;
126126
return count($this->subdomains);
@@ -132,7 +132,7 @@ public function AddSubdomain(Subdomain $subdomain)
132132
* @param string $since the date or time
133133
* @return DNS\Changes
134134
*/
135-
public function Changes($since = null)
135+
public function Changes($since = null)
136136
{
137137
if (isset($since)) {
138138
$url = $this->Url('changes', array('since' => $since));
@@ -149,19 +149,52 @@ public function Changes($since = null)
149149
*
150150
* @return AsyncResponse
151151
*/
152-
public function Export()
152+
public function Export()
153153
{
154154
$url = $this->Url('export');
155155
return $this->Service()->AsyncRequest($url);
156156
}
157157

158+
/**
159+
* clones the domain to the specified target domain
160+
*
161+
* @param string $newdomain the new domain to create from this domain
162+
* @param boolean $sub to clone subdomains as well
163+
* @param boolean $comments Replace occurrences of the reference domain
164+
* name with the new domain name in comments
165+
* @param boolean $email Replace occurrences of the reference domain
166+
* name with the new domain name in email addresses on the cloned
167+
* (new) domain.
168+
* @param boolean $records Replace occurrences of the reference domain
169+
* name with the new domain name in data fields (of records) on the
170+
* cloned (new) domain. Does not affect NS records.
171+
* @return AsyncResponse
172+
*/
173+
public function CloneDomain(
174+
$newdomain,
175+
$sub=TRUE,
176+
$comments=TRUE,
177+
$email=TRUE,
178+
$records=TRUE)
179+
{
180+
$param = array(
181+
'cloneName' => $newdomain,
182+
'cloneSubdomains' => $sub,
183+
'modifyComment' => $comments,
184+
'modifyEmailAddress' => $email,
185+
'modifyRecordData' => $records
186+
);
187+
$url = $this->Url('clone', $param);
188+
return $this->Service()->AsyncRequest($url);
189+
}
190+
158191
/**
159192
* handles creation of multiple records at Create()
160193
*
161194
* @api
162195
* @return \stdClass
163196
*/
164-
protected function CreateJson()
197+
protected function CreateJson()
165198
{
166199
$object = parent::CreateJson();
167200

@@ -200,4 +233,4 @@ protected function CreateJson()
200233
return $object;
201234
}
202235

203-
}
236+
}

tests/OpenCloud/Tests/DomainTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,11 @@ public function testExport() {
110110
'OpenCloud\DNS\AsyncResponse',
111111
get_class($this->domain->Export()));
112112
}
113+
public function testCloneDomain() {
114+
$asr = $this->domain->CloneDomain('newdomain.io');
115+
//print_r($asr);
116+
$this->assertEquals(
117+
'OpenCloud\DNS\AsyncResponse',
118+
get_class($asr));
119+
}
113120
}

0 commit comments

Comments
 (0)