Skip to content

Commit 65d4793

Browse files
committed
Adding functionality to delete site aliases by site id, fixing logic bugs caused from not allowing more than one delete at one time (discovered friday)
1 parent 0bc44f4 commit 65d4793

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/PleskX/Api/Operator/SiteAlias.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,17 @@ public function get($site_id)
5151
return $response;
5252
}
5353

54+
public function delete($site_id)
55+
{
56+
$packet = $this->_client->getPacket();
57+
58+
$delete = $packet->addChild($this->_wrapperTag)->addChild('delete');
59+
60+
$filter = $delete->addChild('filter');
61+
$filter->addChild('site-id',$site_id);
62+
$response = $this->_client->request($packet);
63+
64+
return new Struct\Info($response);
65+
}
66+
5467
}

src/PleskX/Api/Struct/SiteAlias/Info.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
class Info extends \PleskX\Api\Struct implements \Iterator
77
{
88

9+
public $id;
10+
public $status;
11+
912
public $site_id;
1013

1114
private $array = array();
@@ -17,13 +20,21 @@ public function __construct($apiResponse)
1720
$json = json_encode($apiResponse);
1821
$responses = json_decode($json);
1922

20-
$this->site_id = $responses[0]->id;
21-
22-
foreach($responses as $response) {
23-
$this->array[] = array(
24-
'site-name' => $response->info->name,
25-
'ascii-name' => $response->info->{'ascii-name'}
26-
);
23+
if(array_key_exists(0,$responses)) {
24+
foreach ($responses as $response) {
25+
if(isset($response->info)) {
26+
$this->array[] = array(
27+
'site-name' => $response->info->name,
28+
'ascii-name' => $response->info->{'ascii-name'}
29+
);
30+
}
31+
}
32+
}
33+
else {
34+
$this->_initScalarProperties($apiResponse, [
35+
'id',
36+
'status'
37+
]);
2738
}
2839
}
2940

@@ -39,11 +50,18 @@ public function key() {
3950
return $this->position;
4051
}
4152

42-
public function next() {
53+
public function next()
54+
{
4355
++$this->position;
4456
}
4557

46-
public function valid() {
58+
public function valid()
59+
{
4760
return isset($this->array[$this->position]);
4861
}
62+
63+
public function name()
64+
{
65+
return $this->array[$this->position]['site-name'];
66+
}
4967
}

0 commit comments

Comments
 (0)