Skip to content

Commit 3ff2998

Browse files
authored
Merge pull request #44 from pmill/dev
Improvements
2 parents 6e3f66b + d047cae commit 3ff2998

File tree

7 files changed

+145
-5
lines changed

7 files changed

+145
-5
lines changed

CONTRIBUTORS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
pmill/php-plesk contributors
22
============================
33

4-
* **[Glenn Hermans](https://github.com/ghermans)**
4+
* **[ghermans](https://github.com/ghermans)**
55

66
* GetSubscription
7+
8+
* **[texh](https://github.com/texh)**
9+
10+
* GetTraffic
11+
12+
* **[carlswart](https://github.com/carlswart)**
13+
14+
* ListDNS

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,18 @@ Unversioned (13 Apr 2013)
103103

104104
0.5.4 (13/06/2016)
105105

106-
* Added GetSubscription functionality (thanks [Glenn Hermans](https://github.com/ghermans))
106+
* Added GetSubscription functionality (thanks [ghermans](https://github.com/ghermans))
107107

108108
0.5.5 (15/08/2016)
109109

110110
* Added GetTraffic functionality (thanks [texh](https://github.com/texh))
111111
* Added ListDNS functionality (thanks [carlswart](https://github.com/carlswart))
112112

113+
0.5.6 (01/09/2016)
114+
115+
* Error handling bug fix
116+
* Exposed service plan guid property (thanks [ghermans](https://github.com/ghermans))
117+
113118

114119
Copyright and License
115120
---------------------
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
require_once("../config.php");
4+
5+
/*
6+
* Get subscription details
7+
*/
8+
$params = array(
9+
'id'=>'1',
10+
// 'name' => 'demo.parallels.com',
11+
// 'owner-login' => 'customer',
12+
// 'since_date' => '2016-06-01',
13+
// 'to_date' => '2016-06-10'
14+
);
15+
16+
$request = new \pmill\Plesk\GetTraffic($config, $params);
17+
$info = $request->process();
18+
19+
var_dump($info);
20+
21+
if ($info === false) {
22+
var_dump($request->error);
23+
}

examples/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$classLoader->register();
66

77
$config = array(
8-
'host'=>'plesk12-webhost.demo.parallels.com',
8+
'host'=>'plesk12-webadmin.demo.parallels.com',
99
'username'=>'admin',
1010
'password'=>'panel',
1111
);

src/pmill/Plesk/BaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private function sendRequest($packet)
229229
*/
230230
private function checkResponse(SimpleXMLElement $response)
231231
{
232-
if ($response->system->status === 'error') {
232+
if ((string)$response->system->status === 'error') {
233233
throw new ApiRequestException($response->system);
234234
}
235235
}

src/pmill/Plesk/GetTraffic.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
namespace pmill\Plesk;
3+
4+
use pmill\Plesk\Helper\Xml;
5+
6+
class GetTraffic extends BaseRequest
7+
{
8+
/**
9+
* @var string
10+
*/
11+
public $xml_packet = <<<EOT
12+
<?xml version="1.0"?>
13+
<packet version="1.6.3.0">
14+
<webspace>
15+
<get_traffic>
16+
{FILTER}
17+
</get_traffic>
18+
</webspace>
19+
</packet>
20+
EOT;
21+
22+
/**
23+
* @var array
24+
*/
25+
protected $default_params = [
26+
'filter' => null,
27+
];
28+
29+
/**
30+
* @param array $config
31+
* @param array $params
32+
* @throws ApiRequestException
33+
*/
34+
public function __construct($config, $params = [])
35+
{
36+
$filterChildNodes = [];
37+
38+
foreach (['name', 'owner-id', 'owner-login', 'guid', 'id'] as $nodeName) {
39+
if (isset($params[$nodeName])) {
40+
if (!is_array($params[$nodeName])) {
41+
$params[$nodeName] = [$params[$nodeName]];
42+
}
43+
44+
foreach ($params[$nodeName] as $value) {
45+
$filterChildNodes[] = new Node($nodeName, $value);
46+
}
47+
}
48+
}
49+
50+
$filter = [ new Node('filter', new NodeList($filterChildNodes)) ];
51+
52+
if (isset($params['since_date'])) {
53+
$filter[] = new Node('since_date', $params['since_date']);
54+
}
55+
56+
if (isset($params['to_date'])) {
57+
$filter[] = new Node('to_date', $params['to_date']);
58+
}
59+
60+
$params = [
61+
'filter' => new NodeList($filter)
62+
];
63+
64+
parent::__construct($config, $params);
65+
}
66+
67+
/**
68+
* @param $xml
69+
* @return array
70+
*/
71+
protected function processResponse($xml)
72+
{
73+
$result = [];
74+
75+
for ($i = 0; $i < count($xml->webspace->get_traffic->result); $i++) {
76+
$webspace = $xml->webspace->get_traffic->result[$i];
77+
78+
$traffic = [];
79+
foreach ($webspace->traffic as $day) {
80+
$traffic[] = [
81+
'date' => (string)$day->date,
82+
'http_in' => (int)$day->http_in,
83+
'http_out' => (int)$day->http_out,
84+
'ftp_in' => (int)$day->ftp_in,
85+
'ftp_out' => (int)$day->ftp_out,
86+
'smtp_in' => (int)$day->smtp_in,
87+
'smtp_out' => (int)$day->smtp_out,
88+
'pop3_imap_in' => (int)$day->pop3_imap_in,
89+
'pop3_imap_out' => (int)$day->pop3_imap_out
90+
];
91+
}
92+
93+
$result[] = [
94+
'id' => (string)$webspace->id,
95+
'status' => (string)$webspace->status,
96+
'error_code' => (int)$webspace->errcode,
97+
'error_text' => (string)$webspace->errtext,
98+
'traffic' => $traffic,
99+
];
100+
}
101+
102+
return $result;
103+
}
104+
}

src/pmill/Plesk/UpdateSite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(array $config, $params = [])
5454
{
5555
$properties = [];
5656

57-
foreach (['php', 'php_handler_type', 'webstat', 'www_root'] as $key) {
57+
foreach (['php', 'php_handler_type', 'webstat', 'www_root', 'php', 'php_handler_id', 'php_version'] as $key) {
5858
if (isset($params[$key])) {
5959
$properties[$key] = $params[$key];
6060
}

0 commit comments

Comments
 (0)