From fdba6930bf7ff360a7974865f2919bea5804bb95 Mon Sep 17 00:00:00 2001 From: Stefan Warnat Date: Fri, 20 Sep 2019 16:35:48 +0200 Subject: [PATCH 1/3] Add all available data to GeneralInfo --- src/Api/Struct/Site/GeneralInfo.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Api/Struct/Site/GeneralInfo.php b/src/Api/Struct/Site/GeneralInfo.php index 11e22aba..1a692635 100644 --- a/src/Api/Struct/Site/GeneralInfo.php +++ b/src/Api/Struct/Site/GeneralInfo.php @@ -20,6 +20,22 @@ class GeneralInfo extends \PleskX\Api\Struct /** @var string */ public $description; + /** @var integer */ + public $webspaceId ; + + /** @var string */ + public $webspaceGuid; + + /** @var string */ + public $dnsIpAddress; + + /** @var string */ + public $crDate; + + /** @var integer */ + public $realSize; + + public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ @@ -28,6 +44,11 @@ public function __construct($apiResponse) 'status', 'guid', 'description', + 'webspace-id', + 'dns_ip_address', + 'cr_date', + 'real_size', + 'webspace-guid', ]); } } From edcd2bc9bc8c8c5a6782be8975bffe1132a20416 Mon Sep 17 00:00:00 2001 From: Stefan Warnat Date: Tue, 22 Dec 2020 13:00:03 +0100 Subject: [PATCH 2/3] Implement getTraffic Adjust composer.json --- composer.json | 2 +- src/Api/Operator/Site.php | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 9ca7bacc..030fb8bb 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "plesk/api-php-lib", + "name": "redoo-networks/plesk-api-php-lib", "type": "library", "description": "PHP object-oriented library for Plesk XML-RPC API", "license": "Apache-2.0", diff --git a/src/Api/Operator/Site.php b/src/Api/Operator/Site.php index e1b45dbd..2def8b04 100644 --- a/src/Api/Operator/Site.php +++ b/src/Api/Operator/Site.php @@ -2,7 +2,7 @@ // Copyright 1999-2020. Plesk International GmbH. namespace PleskX\Api\Operator; - +use PleskX\Api\Client; use PleskX\Api\Struct\Site as Struct; class Site extends \PleskX\Api\Operator @@ -11,7 +11,6 @@ class Site extends \PleskX\Api\Operator /** * @param array $properties - * * @return Struct\Info */ public function create(array $properties) @@ -38,14 +37,12 @@ public function create(array $properties) } $response = $this->_client->request($packet); - return new Struct\Info($response); } /** * @param string $field * @param int|string $value - * * @return bool */ public function delete($field, $value) @@ -56,20 +53,17 @@ public function delete($field, $value) /** * @param string $field * @param int|string $value - * * @return Struct\GeneralInfo */ public function get($field, $value) { $items = $this->_getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value); - return reset($items); } /** * @param string $field * @param int|string $value - * * @return Struct\HostingInfo|null */ public function getHosting($field, $value) @@ -77,10 +71,32 @@ public function getHosting($field, $value) $items = $this->_getItems(Struct\HostingInfo::class, 'hosting', $field, $value, function ($node) { return isset($node->vrt_hst); }); - return empty($items) ? null : reset($items); } + /** + * @param string $field + * @param int|string $value + * @return Struct\TrafficInfo|null + */ + public function getTraffic($field, $value, $fromDate, $toDate) + { + $items = $this->request(' +<'.$field.'>'.$value.' +'.date('Y-m-d', strtotime($fromDate)).' +'.date('Y-m-d', strtotime($toDate)).' +', Client::RESPONSE_SHORT); + + $result = array(); + foreach($items->traffic as $traffic) { + $date = (string)$traffic->date; + unset($traffic->date); + $result[$date] = json_decode(json_encode($traffic)); + } + + return $result; + } + /** * @return Struct\GeneralInfo[] */ @@ -88,4 +104,5 @@ public function getAll() { return $this->_getItems(Struct\GeneralInfo::class, 'gen_info'); } + } From 5ac5dc21d86ce53a77d496772a46f212ef34c561 Mon Sep 17 00:00:00 2001 From: Stefan Warnat Date: Sun, 3 Jan 2021 13:07:18 +0100 Subject: [PATCH 3/3] Update to support Hosting array return value --- src/Api/Operator/Site.php | 1 + src/Api/Struct.php | 2 ++ src/Api/Struct/Site/GeneralInfo.php | 4 ++-- src/Api/Struct/Webspace/GeneralInfo.php | 2 +- wait-for-plesk.sh | 0 5 files changed, 6 insertions(+), 3 deletions(-) mode change 100755 => 100644 wait-for-plesk.sh diff --git a/src/Api/Operator/Site.php b/src/Api/Operator/Site.php index 2def8b04..077ed586 100644 --- a/src/Api/Operator/Site.php +++ b/src/Api/Operator/Site.php @@ -71,6 +71,7 @@ public function getHosting($field, $value) $items = $this->_getItems(Struct\HostingInfo::class, 'hosting', $field, $value, function ($node) { return isset($node->vrt_hst); }); + return empty($items) ? null : reset($items); } diff --git a/src/Api/Struct.php b/src/Api/Struct.php index aa5a1377..346ac842 100644 --- a/src/Api/Struct.php +++ b/src/Api/Struct.php @@ -37,6 +37,8 @@ protected function _initScalarProperties($apiResponse, array $properties) $value = (string) $value; } elseif ('int' == $propertyType) { $value = (int) $value; + } elseif ('array' == $propertyType) { + } elseif ('bool' == $propertyType) { $value = in_array((string) $value, ['true', 'on', 'enabled']); } else { diff --git a/src/Api/Struct/Site/GeneralInfo.php b/src/Api/Struct/Site/GeneralInfo.php index bc604ab7..606c8a36 100644 --- a/src/Api/Struct/Site/GeneralInfo.php +++ b/src/Api/Struct/Site/GeneralInfo.php @@ -20,7 +20,7 @@ class GeneralInfo extends \PleskX\Api\Struct /** @var string */ public $description; - /** @var integer */ + /** @var int */ public $webspaceId ; /** @var string */ @@ -32,7 +32,7 @@ class GeneralInfo extends \PleskX\Api\Struct /** @var string */ public $crDate; - /** @var integer */ + /** @var int */ public $realSize; diff --git a/src/Api/Struct/Webspace/GeneralInfo.php b/src/Api/Struct/Webspace/GeneralInfo.php index d9be8f1a..ef866433 100644 --- a/src/Api/Struct/Webspace/GeneralInfo.php +++ b/src/Api/Struct/Webspace/GeneralInfo.php @@ -19,7 +19,7 @@ public function __construct($apiResponse) $this->_initScalarProperties($apiResponse, [ 'name', 'guid', - 'real_size', + 'real_size' ]); } } diff --git a/wait-for-plesk.sh b/wait-for-plesk.sh old mode 100755 new mode 100644