Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
pmill/php-plesk contributors
============================

* **[Glenn Hermans](https://github.com/ghermans)**
* **[ghermans](https://github.com/ghermans)**

* GetSubscription

* **[texh](https://github.com/texh)**

* GetTraffic

* **[carlswart](https://github.com/carlswart)**

* ListDNS
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@ Unversioned (13 Apr 2013)

0.5.4 (13/06/2016)

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

0.5.5 (15/08/2016)

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

0.5.6 (01/09/2016)

* Error handling bug fix
* Exposed service plan guid property (thanks [ghermans](https://github.com/ghermans))


Copyright and License
---------------------
Expand Down
23 changes: 23 additions & 0 deletions examples/Subscriptions/get_traffic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once("../config.php");

/*
* Get subscription details
*/
$params = array(
'id'=>'1',
// 'name' => 'demo.parallels.com',
// 'owner-login' => 'customer',
// 'since_date' => '2016-06-01',
// 'to_date' => '2016-06-10'
);

$request = new \pmill\Plesk\GetTraffic($config, $params);
$info = $request->process();

var_dump($info);

if ($info === false) {
var_dump($request->error);
}
2 changes: 1 addition & 1 deletion examples/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$classLoader->register();

$config = array(
'host'=>'plesk12-webhost.demo.parallels.com',
'host'=>'plesk12-webadmin.demo.parallels.com',
'username'=>'admin',
'password'=>'panel',
);
2 changes: 1 addition & 1 deletion src/pmill/Plesk/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function sendRequest($packet)
*/
private function checkResponse(SimpleXMLElement $response)
{
if ($response->system->status === 'error') {
if ((string)$response->system->status === 'error') {
throw new ApiRequestException($response->system);
}
}
Expand Down
104 changes: 104 additions & 0 deletions src/pmill/Plesk/GetTraffic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
namespace pmill\Plesk;

use pmill\Plesk\Helper\Xml;

class GetTraffic extends BaseRequest
{
/**
* @var string
*/
public $xml_packet = <<<EOT
<?xml version="1.0"?>
<packet version="1.6.3.0">
<webspace>
<get_traffic>
{FILTER}
</get_traffic>
</webspace>
</packet>
EOT;

/**
* @var array
*/
protected $default_params = [
'filter' => null,
];

/**
* @param array $config
* @param array $params
* @throws ApiRequestException
*/
public function __construct($config, $params = [])
{
$filterChildNodes = [];

foreach (['name', 'owner-id', 'owner-login', 'guid', 'id'] as $nodeName) {
if (isset($params[$nodeName])) {
if (!is_array($params[$nodeName])) {
$params[$nodeName] = [$params[$nodeName]];
}

foreach ($params[$nodeName] as $value) {
$filterChildNodes[] = new Node($nodeName, $value);
}
}
}

$filter = [ new Node('filter', new NodeList($filterChildNodes)) ];

if (isset($params['since_date'])) {
$filter[] = new Node('since_date', $params['since_date']);
}

if (isset($params['to_date'])) {
$filter[] = new Node('to_date', $params['to_date']);
}

$params = [
'filter' => new NodeList($filter)
];

parent::__construct($config, $params);
}

/**
* @param $xml
* @return array
*/
protected function processResponse($xml)
{
$result = [];

for ($i = 0; $i < count($xml->webspace->get_traffic->result); $i++) {
$webspace = $xml->webspace->get_traffic->result[$i];

$traffic = [];
foreach ($webspace->traffic as $day) {
$traffic[] = [
'date' => (string)$day->date,
'http_in' => (int)$day->http_in,
'http_out' => (int)$day->http_out,
'ftp_in' => (int)$day->ftp_in,
'ftp_out' => (int)$day->ftp_out,
'smtp_in' => (int)$day->smtp_in,
'smtp_out' => (int)$day->smtp_out,
'pop3_imap_in' => (int)$day->pop3_imap_in,
'pop3_imap_out' => (int)$day->pop3_imap_out
];
}

$result[] = [
'id' => (string)$webspace->id,
'status' => (string)$webspace->status,
'error_code' => (int)$webspace->errcode,
'error_text' => (string)$webspace->errtext,
'traffic' => $traffic,
];
}

return $result;
}
}
2 changes: 1 addition & 1 deletion src/pmill/Plesk/UpdateSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(array $config, $params = [])
{
$properties = [];

foreach (['php', 'php_handler_type', 'webstat', 'www_root'] as $key) {
foreach (['php', 'php_handler_type', 'webstat', 'www_root', 'php', 'php_handler_id', 'php_version'] as $key) {
if (isset($params[$key])) {
$properties[$key] = $params[$key];
}
Expand Down