From 1666084675ef6fc42977dba37e3a36360f7f7621 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 24 Oct 2016 17:30:52 +0200 Subject: [PATCH 01/22] Add delete DNS records --- src/pmill/Plesk/DeleteDNSRecords.php | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/pmill/Plesk/DeleteDNSRecords.php diff --git a/src/pmill/Plesk/DeleteDNSRecords.php b/src/pmill/Plesk/DeleteDNSRecords.php new file mode 100644 index 0000000..ab89102 --- /dev/null +++ b/src/pmill/Plesk/DeleteDNSRecords.php @@ -0,0 +1,44 @@ + + + + + + {ID} + + + + +EOT; + + /** + * @var array + */ + protected $default_params = [ + 'id' => null, + ]; + + /** + * @param $xml + * @return bool + * @throws ApiRequestException + */ + protected function processResponse($xml) + { + $result = $xml->dns->{'del-rec'}->result; + + if ($result->status == 'error') { + throw new ApiRequestException($result); + } + + return true; + } +} From c16a54476d893793e2c44c1bc2012f65018a9c85 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 24 Oct 2016 17:35:05 +0200 Subject: [PATCH 02/22] Add example to delete DNS records --- examples/DNS/delete_dns_records.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 examples/DNS/delete_dns_records.php diff --git a/examples/DNS/delete_dns_records.php b/examples/DNS/delete_dns_records.php new file mode 100644 index 0000000..2986ea1 --- /dev/null +++ b/examples/DNS/delete_dns_records.php @@ -0,0 +1,12 @@ +'', +); + +$request = new \pmill\Plesk\DeleteDNSRecords($config, $params); +$info = $request->process(); + +var_dump($info); From 7a2ce5f4441a3e3797fe5ce0bd7fefad2b83cac6 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 24 Oct 2016 18:04:44 +0200 Subject: [PATCH 03/22] Change get site xml --- src/pmill/Plesk/GetSite.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pmill/Plesk/GetSite.php b/src/pmill/Plesk/GetSite.php index a36ca23..99503b1 100644 --- a/src/pmill/Plesk/GetSite.php +++ b/src/pmill/Plesk/GetSite.php @@ -8,17 +8,17 @@ class GetSite extends BaseRequest */ public $xml_packet = << - - + + - {DOMAIN} + {DOMAIN} - + EOT; From c04f49f54306b6b9fdcfc2411d42f832c35aa7b6 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Wed, 26 Oct 2016 12:15:23 +0200 Subject: [PATCH 04/22] Fixed the name class --- src/pmill/Plesk/DeleteDNSRecords.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pmill/Plesk/DeleteDNSRecords.php b/src/pmill/Plesk/DeleteDNSRecords.php index ab89102..984d5ce 100644 --- a/src/pmill/Plesk/DeleteDNSRecords.php +++ b/src/pmill/Plesk/DeleteDNSRecords.php @@ -1,7 +1,7 @@ Date: Fri, 28 Oct 2016 12:32:13 +0200 Subject: [PATCH 05/22] add the site-id with a domain param --- examples/DNS/delete_dns_records.php | 3 ++- src/pmill/Plesk/DeleteDNSRecords.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/DNS/delete_dns_records.php b/examples/DNS/delete_dns_records.php index 2986ea1..f6f3911 100644 --- a/examples/DNS/delete_dns_records.php +++ b/examples/DNS/delete_dns_records.php @@ -3,7 +3,8 @@ require_once("../config.php"); $params = array( - 'id'=>'', + 'id'=>1, + //'domain'=>'example.com' ); $request = new \pmill\Plesk\DeleteDNSRecords($config, $params); diff --git a/src/pmill/Plesk/DeleteDNSRecords.php b/src/pmill/Plesk/DeleteDNSRecords.php index 984d5ce..bab331d 100644 --- a/src/pmill/Plesk/DeleteDNSRecords.php +++ b/src/pmill/Plesk/DeleteDNSRecords.php @@ -13,6 +13,7 @@ class DeleteDNSRecords extends BaseRequest {ID} + {ID} @@ -24,8 +25,26 @@ class DeleteDNSRecords extends BaseRequest */ protected $default_params = [ 'id' => null, + 'site_id' => null, ]; + /** + * @param array $config + * @param array $params + * @throws ApiRequestException + */ + public function __construct($config, $params) + { + if (isset($params['domain'])) { + $request = new GetSite($config, ['domain' => $params['domain']]); + $info = $request->process(); + + $params['site_id'] = $info['id']; + } + + parent::__construct($config, $params); + } + /** * @param $xml * @return bool From 903145290947c56acb63d9d78d12ac75e7b83513 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Fri, 28 Oct 2016 12:32:44 +0200 Subject: [PATCH 06/22] add list auxiliary user --- examples/Users/list_users.php | 8 ++++ src/pmill/Plesk/ListUsers.php | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 examples/Users/list_users.php create mode 100644 src/pmill/Plesk/ListUsers.php diff --git a/examples/Users/list_users.php b/examples/Users/list_users.php new file mode 100644 index 0000000..4add519 --- /dev/null +++ b/examples/Users/list_users.php @@ -0,0 +1,8 @@ +process(); + +var_dump($info); diff --git a/src/pmill/Plesk/ListUsers.php b/src/pmill/Plesk/ListUsers.php new file mode 100644 index 0000000..058e85c --- /dev/null +++ b/src/pmill/Plesk/ListUsers.php @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + +EOT; + + /** + * @param $xml + * @return array + */ + protected function processResponse($xml) + { + $result = []; + + for ($i = 0; $i < count($xml->user->get->result); $i++) { + $user = $xml->user->get->result[$i]; + + $result[] = [ + 'id' => (int)$user->id, + 'filter-id' => (int)$user->filter_id, + 'status' => (string)$user->status, + 'login' => (string)$user->data->gen_info->login, + 'name' => (string)$user->data->gen_info->name, + 'owner-guid' => (string)$user->data->gen_info->owner_guid, + 'status' => (string)$user->data->gen_info->status, + 'guid' => (string)$user->data->gen_info->guid, + 'is-built-in' => (int)$user->data->gen_info->is_built_in, + 'subcription-domain-id' => (int)$user->data->gen_info->subcription_domain_id, + 'email' => (string)$user->data->gen_info->email, + 'contact-info' => [ + 'company' => (string)$user->data->gen_info->contact_info->company, + 'phone' => (string)$user->data->gen_info->contact_info->phone, + 'fax' => (string)$user->data->gen_info->contact_info->fax, + 'address' => (string)$user->data->gen_info->contact_info->address, + 'city' => (string)$user->data->gen_info->contact_info->city, + 'state' => (string)$user->data->gen_info->contact_info->state, + 'zip' => (string)$user->data->gen_info->contact_info->zip, + 'country' => (string)$user->data->gen_info->contact_info->country, + 'im' => (string)$user->data->gen_info->contact_info->im, + 'imtype' => (string)$user->data->gen_info->contact_info->imtype, + 'comment' => (string)$user->data->gen_info->contact_info->comment, + 'locale' => (string)$user->data->gen_info->contact_info->locale, + ], + 'role' => (string)$user->data->roles->name, + ]; + } + + return $result; + } +} From 4bc7ddd594561cb1455cec2fbf13b0b6c35f61f9 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Fri, 28 Oct 2016 13:39:54 +0200 Subject: [PATCH 07/22] add get user --- examples/Users/get_user.php | 13 +++++ src/pmill/Plesk/GetUser.php | 96 +++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 examples/Users/get_user.php create mode 100644 src/pmill/Plesk/GetUser.php diff --git a/examples/Users/get_user.php b/examples/Users/get_user.php new file mode 100644 index 0000000..ae4d628 --- /dev/null +++ b/examples/Users/get_user.php @@ -0,0 +1,13 @@ +'', + //'username'=>'', +); + +$request = new \pmill\Plesk\GetUser($config, $params); +$info = $request->process(); + +var_dump($info); diff --git a/src/pmill/Plesk/GetUser.php b/src/pmill/Plesk/GetUser.php new file mode 100644 index 0000000..df49ce1 --- /dev/null +++ b/src/pmill/Plesk/GetUser.php @@ -0,0 +1,96 @@ + + + + + + {GUID} + + + + + + + + +EOT; + + /** + * @var array + */ + protected $default_params = [ + 'guid' => null, + ]; + + /** + * GetClient constructor. + * @param array $config + * @param array $params + */ + public function __construct(array $config, $params = []) + { + if (isset($params['username'])) { + $request = new ListUsers($config); + $info = $request->process(); + foreach($info as $user){ + if ($user['login'] == $username) + $params['guid'] = $user['guid']; + } + } + + parent::__construct($config, $params); + } + + /** + * @param $xml + * @return array + */ + protected function processResponse($xml) + { + $user = $xml->user->get->result; + + if ((string)$user->status == 'error') { + throw new ApiRequestException($user); + } + + if ((string)$user->result->status == 'error') { + throw new ApiRequestException($user->result); + } + return [ + 'id' => (int)$user->id, + 'filter-id' => (int)$user->filter_id, + 'status' => (string)$user->status, + 'login' => (string)$user->data->gen_info->login, + 'name' => (string)$user->data->gen_info->name, + 'owner-guid' => (string)$user->data->gen_info->owner_guid, + 'status' => (string)$user->data->gen_info->status, + 'guid' => (string)$user->data->gen_info->guid, + 'is-built-in' => (int)$user->data->gen_info->is_built_in, + 'subcription-domain-id' => (int)$user->data->gen_info->subcription_domain_id, + 'email' => (string)$user->data->gen_info->email, + 'contact-info' => [ + 'company' => (string)$user->data->gen_info->contact_info->company, + 'phone' => (string)$user->data->gen_info->contact_info->phone, + 'fax' => (string)$user->data->gen_info->contact_info->fax, + 'address' => (string)$user->data->gen_info->contact_info->address, + 'city' => (string)$user->data->gen_info->contact_info->city, + 'state' => (string)$user->data->gen_info->contact_info->state, + 'zip' => (string)$user->data->gen_info->contact_info->zip, + 'country' => (string)$user->data->gen_info->contact_info->country, + 'im' => (string)$user->data->gen_info->contact_info->im, + 'imtype' => (string)$user->data->gen_info->contact_info->imtype, + 'comment' => (string)$user->data->gen_info->contact_info->comment, + 'locale' => (string)$user->data->gen_info->contact_info->locale, + ], + 'role' => (string)$user->data->roles->name, + ]; + } +} From 39d26ebb7fa7529034cd1a6ff1808ce46c8e57d0 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 31 Oct 2016 18:24:19 +0100 Subject: [PATCH 08/22] fixed hotfix problem change xml tag (gen_info to gen-info) --- src/pmill/Plesk/GetUser.php | 2 +- src/pmill/Plesk/ListUsers.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pmill/Plesk/GetUser.php b/src/pmill/Plesk/GetUser.php index df49ce1..68845a7 100644 --- a/src/pmill/Plesk/GetUser.php +++ b/src/pmill/Plesk/GetUser.php @@ -15,7 +15,7 @@ class GetUser extends BaseRequest {GUID} - + diff --git a/src/pmill/Plesk/ListUsers.php b/src/pmill/Plesk/ListUsers.php index 058e85c..3e9ee79 100644 --- a/src/pmill/Plesk/ListUsers.php +++ b/src/pmill/Plesk/ListUsers.php @@ -15,7 +15,7 @@ class ListUsers extends BaseRequest - + From 8e8047d92682793ad9a940c6fb02e664e7f4341e Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 31 Oct 2016 18:24:53 +0100 Subject: [PATCH 09/22] get subcription add filter owner-login --- src/pmill/Plesk/GetSubscription.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pmill/Plesk/GetSubscription.php b/src/pmill/Plesk/GetSubscription.php index 23f3009..a0b6ffe 100644 --- a/src/pmill/Plesk/GetSubscription.php +++ b/src/pmill/Plesk/GetSubscription.php @@ -40,9 +40,13 @@ public function __construct($config, $params = []) $this->default_params['filter'] = new Node('filter'); if (isset($params['subscription_id'])) { - $ownerIdNode = new Node('id', $params['subscription_id']); - $params['filter'] = new Node('filter', $ownerIdNode); - } + $idNode = new Node('id', $params['subscription_id']); + $params['filter'] = new Node('filter', $idNode); + } + if (isset($params['username'])) { + $ownerLoginNode = new Node('owner-login', $params['username']); + $params['filter'] = new Node('filter', $ownerLoginNode); + } parent::__construct($config, $params); } From 2fd9bcd452132df9f8e6109bebce592382d47af1 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 7 Nov 2016 12:03:49 +0100 Subject: [PATCH 10/22] add name to get subscriptions --- examples/Subscriptions/get_subscription.php | 2 ++ src/pmill/Plesk/GetSubscription.php | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/examples/Subscriptions/get_subscription.php b/examples/Subscriptions/get_subscription.php index ef6d53e..1d6eb94 100644 --- a/examples/Subscriptions/get_subscription.php +++ b/examples/Subscriptions/get_subscription.php @@ -7,6 +7,8 @@ */ $params = array( 'subscription_id'=>'1', + //'name'=>'example.com', + //'username'=>'', ); $request = new \pmill\Plesk\GetSubscription($config, $params); diff --git a/src/pmill/Plesk/GetSubscription.php b/src/pmill/Plesk/GetSubscription.php index a0b6ffe..9bdfb93 100644 --- a/src/pmill/Plesk/GetSubscription.php +++ b/src/pmill/Plesk/GetSubscription.php @@ -47,6 +47,10 @@ public function __construct($config, $params = []) $ownerLoginNode = new Node('owner-login', $params['username']); $params['filter'] = new Node('filter', $ownerLoginNode); } + if (isset($params['name'])) { + $nameNode = new Node('name', $params['name']); + $params['filter'] = new Node('filter', $nameNode); + } parent::__construct($config, $params); } From 541dfbe5e617f4ca4966e3e0586898f27588735c Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 7 Nov 2016 18:16:20 +0100 Subject: [PATCH 11/22] Add throw the Api Execption --- src/pmill/Plesk/BaseRequest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pmill/Plesk/BaseRequest.php b/src/pmill/Plesk/BaseRequest.php index 0aa049a..40d684f 100644 --- a/src/pmill/Plesk/BaseRequest.php +++ b/src/pmill/Plesk/BaseRequest.php @@ -172,11 +172,13 @@ public function process() return $this->processResponse($responseXml); } + return false; + } catch (ApiRequestException $e) { $this->error = $e; + throw new ApiRequestException($e->getMessage(), $e->getCode()); } - return false; } /** From b0d2cb8131901addaa60f5f205fcf28fce621cba Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 7 Nov 2016 18:19:43 +0100 Subject: [PATCH 12/22] Change get subscription and list subscription, the first method get subscriptions (owner_id, owner_login, subscription_id, name) and if not exists have an Exception, the second method list all subscriptions --- src/pmill/Plesk/GetSubscription.php | 14 +++++++++++--- src/pmill/Plesk/ListSubscriptions.php | 26 +------------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/pmill/Plesk/GetSubscription.php b/src/pmill/Plesk/GetSubscription.php index 9bdfb93..7f3d2de 100644 --- a/src/pmill/Plesk/GetSubscription.php +++ b/src/pmill/Plesk/GetSubscription.php @@ -39,9 +39,9 @@ public function __construct($config, $params = []) { $this->default_params['filter'] = new Node('filter'); - if (isset($params['subscription_id'])) { - $idNode = new Node('id', $params['subscription_id']); - $params['filter'] = new Node('filter', $idNode); + if (isset($params['client_id'])) { + $ownerIdNode = new Node('owner-id', $params['client_id']); + $params['filter'] = new Node('filter', $ownerIdNode); } if (isset($params['username'])) { $ownerLoginNode = new Node('owner-login', $params['username']); @@ -51,6 +51,10 @@ public function __construct($config, $params = []) $nameNode = new Node('name', $params['name']); $params['filter'] = new Node('filter', $nameNode); } + if (isset($params['subscription_id'])) { + $idNode = new Node('id', $params['subscription_id']); + $params['filter'] = new Node('filter', $idNode); + } parent::__construct($config, $params); } @@ -65,6 +69,10 @@ protected function processResponse($xml) for ($i = 0; $i < count($xml->webspace->get->result); $i++) { $webspace = $xml->webspace->get->result[$i]; + if ($webspace->status == 'error') { + throw new ApiRequestException($webspace); + } + $hosting = []; foreach ($webspace->data->hosting->children() as $host) { $hosting[$host->getName()] = Xml::getProperties($host); diff --git a/src/pmill/Plesk/ListSubscriptions.php b/src/pmill/Plesk/ListSubscriptions.php index a64e67e..6090b49 100644 --- a/src/pmill/Plesk/ListSubscriptions.php +++ b/src/pmill/Plesk/ListSubscriptions.php @@ -13,7 +13,7 @@ class ListSubscriptions extends BaseRequest - {FILTER} + @@ -23,30 +23,6 @@ class ListSubscriptions extends BaseRequest EOT; - /** - * @var array - */ - protected $default_params = [ - 'filter' => null, - ]; - - /** - * @param array $config - * @param array $params - * @throws ApiRequestException - */ - public function __construct($config, $params = []) - { - $this->default_params['filter'] = new Node('filter'); - - if (isset($params['client_id'])) { - $ownerIdNode = new Node('owner-id', $params['client_id']); - $params['filter'] = new Node('filter', $ownerIdNode); - } - - parent::__construct($config, $params); - } - /** * @param $xml * @return array From 7599189b01eead6a9257567fa25b3cf5f914ad6d Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 14 Nov 2016 12:27:27 +0100 Subject: [PATCH 13/22] Add list empty --- src/pmill/Plesk/ListSubdomains.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pmill/Plesk/ListSubdomains.php b/src/pmill/Plesk/ListSubdomains.php index 51faef4..7619e27 100644 --- a/src/pmill/Plesk/ListSubdomains.php +++ b/src/pmill/Plesk/ListSubdomains.php @@ -57,15 +57,17 @@ protected function processResponse($xml) $result = []; foreach ($xml->subdomain->get->result as $node) { - $result[] = [ - 'id' => (int)$node->id, - 'status' => (string)$node->status, - 'parent' => (string)$node->data->parent, - 'name' => (string)$node->data->name, - 'php' => (string)Xml::findProperty($node->data, 'php'), - 'php_handler_type' => (string)Xml::findProperty($node->data, 'php_handler_type'), - 'www_root' => (string)Xml::findProperty($node->data, 'www_root'), - ]; + if (isset($node->id)){ + $result[] = [ + 'id' => (int)$node->id, + 'status' => (string)$node->status, + 'parent' => (string)$node->data->parent, + 'name' => (string)$node->data->name, + 'php' => (string)Xml::findProperty($node->data, 'php'), + 'php_handler_type' => (string)Xml::findProperty($node->data, 'php_handler_type'), + 'www_root' => (string)Xml::findProperty($node->data, 'www_root'), + ]; + } } return $result; From 83ed32ee9775cf181c3c98a712877d65ac0e31b8 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 14 Nov 2016 13:12:24 +0100 Subject: [PATCH 14/22] Add list empty subscription and sites --- src/pmill/Plesk/ListSites.php | 28 ++++++++------- src/pmill/Plesk/ListSubscriptions.php | 50 ++++++++++++++------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/pmill/Plesk/ListSites.php b/src/pmill/Plesk/ListSites.php index 551beab..d12266f 100644 --- a/src/pmill/Plesk/ListSites.php +++ b/src/pmill/Plesk/ListSites.php @@ -56,20 +56,22 @@ protected function processResponse($xml) for ($i = 0; $i < $itemCount; $i++) { $site = $xml->site->get->result[$i]; - $hosting_type = (string)$site->data->gen_info->htype; + if (isset($site->id)){ + $hosting_type = (string)$site->data->gen_info->htype; - $result[] = [ - 'id' => (string)$site->id, - 'status' => (string)$site->status, - 'created' => (string)$site->data->gen_info->cr_date, - 'name' => (string)$site->data->gen_info->name, - 'ip' => (string)$site->data->gen_info->dns_ip_address, - 'hosting_type' => $hosting_type, - 'ip_address' => (string)$site->data->hosting->{$hosting_type}->ip_address, - 'www_root' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'www_root'), - 'ftp_username' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_login'), - 'ftp_password' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_password'), - ]; + $result[] = [ + 'id' => (string)$site->id, + 'status' => (string)$site->status, + 'created' => (string)$site->data->gen_info->cr_date, + 'name' => (string)$site->data->gen_info->name, + 'ip' => (string)$site->data->gen_info->dns_ip_address, + 'hosting_type' => $hosting_type, + 'ip_address' => (string)$site->data->hosting->{$hosting_type}->ip_address, + 'www_root' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'www_root'), + 'ftp_username' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_login'), + 'ftp_password' => $this->findHostingProperty($site->data->hosting->{$hosting_type}, 'ftp_password'), + ]; + } } return $result; diff --git a/src/pmill/Plesk/ListSubscriptions.php b/src/pmill/Plesk/ListSubscriptions.php index 6090b49..fcf020d 100644 --- a/src/pmill/Plesk/ListSubscriptions.php +++ b/src/pmill/Plesk/ListSubscriptions.php @@ -33,34 +33,36 @@ protected function processResponse($xml) for ($i = 0; $i < count($xml->webspace->get->result); $i++) { $webspace = $xml->webspace->get->result[$i]; + if (isset($webspace->id)){ - $hosting = []; - foreach ($webspace->data->hosting->children() as $host) { - $hosting[$host->getName()] = Xml::getProperties($host); - } + $hosting = []; + foreach ($webspace->data->hosting->children() as $host) { + $hosting[$host->getName()] = Xml::getProperties($host); + } + + $subscriptions = []; + foreach ($webspace->data->subscriptions->children() as $subscription) { + $subscriptions[] = [ + 'locked' => (bool)$subscription->locked, + 'synchronized' => (bool)$subscription->synchronized, + 'plan-guid' => (string)$subscription->plan->{"plan-guid"}, + ]; + } - $subscriptions = []; - foreach ($webspace->data->subscriptions->children() as $subscription) { - $subscriptions[] = [ - 'locked' => (bool)$subscription->locked, - 'synchronized' => (bool)$subscription->synchronized, - 'plan-guid' => (string)$subscription->plan->{"plan-guid"}, + $result[] = [ + 'id' => (string)$webspace->id, + 'status' => (string)$webspace->status, + 'subscription_status' => (int)$webspace->data->gen_info->status, + 'created' => (string)$webspace->data->gen_info->cr_date, + 'name' => (string)$webspace->data->gen_info->name, + 'owner_id' => (string)$webspace->data->gen_info->{"owner-id"}, + 'hosting' => $hosting, + 'real_size' => (int)$webspace->data->gen_info->real_size, + 'dns_ip_address' => (string)$webspace->data->gen_info->dns_ip_address, + 'htype' => (string)$webspace->data->gen_info->htype, + 'subscriptions' => $subscriptions, ]; } - - $result[] = [ - 'id' => (string)$webspace->id, - 'status' => (string)$webspace->status, - 'subscription_status' => (int)$webspace->data->gen_info->status, - 'created' => (string)$webspace->data->gen_info->cr_date, - 'name' => (string)$webspace->data->gen_info->name, - 'owner_id' => (string)$webspace->data->gen_info->{"owner-id"}, - 'hosting' => $hosting, - 'real_size' => (int)$webspace->data->gen_info->real_size, - 'dns_ip_address' => (string)$webspace->data->gen_info->dns_ip_address, - 'htype' => (string)$webspace->data->gen_info->htype, - 'subscriptions' => $subscriptions, - ]; } return $result; From dd63591253126a0cf0834f4a29b4c186b71755c8 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 14 Nov 2016 13:57:02 +0100 Subject: [PATCH 15/22] Add a class GetDatabaseServer --- src/pmill/Plesk/GetDatabaseServer.php | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/pmill/Plesk/GetDatabaseServer.php diff --git a/src/pmill/Plesk/GetDatabaseServer.php b/src/pmill/Plesk/GetDatabaseServer.php new file mode 100644 index 0000000..70b0d37 --- /dev/null +++ b/src/pmill/Plesk/GetDatabaseServer.php @@ -0,0 +1,60 @@ + + + + + + {FILTER} + + + +EOT; + + /** + * @var array + */ + protected $default_params = [ + 'filter' => null, + ]; + + /** + * GetDatabaseServer constructor. + * @param array $config + * @param array $params + */ + public function __construct(array $config, $params = []) + { + if (isset($params['type'])) { + $params['filter'] = new Node('type', $params['type']); + } + if (isset($params['id'])) { + $params['filter'] = new Node('id', $params['id']); + } + parent::__construct($config, $params); + } + + /** + * @param $xml + * @return bool + * @throws ApiRequestException + */ + protected function processResponse($xml) + { + if ($xml->db_server->{'get-local'}->result->status == 'error') { + throw new ApiRequestException($xml->db_server->{'get-local'}->result); + } + + $this->id = (int)$xml->db_server->{'get-local'}->result->id; + return true; + } + +} From fed12002de1f476a61089f6d6b24ef59158cab67 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Mon, 14 Nov 2016 14:07:26 +0100 Subject: [PATCH 16/22] fix error in xml format --- src/pmill/Plesk/GetDatabaseServer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pmill/Plesk/GetDatabaseServer.php b/src/pmill/Plesk/GetDatabaseServer.php index 70b0d37..9ef208f 100644 --- a/src/pmill/Plesk/GetDatabaseServer.php +++ b/src/pmill/Plesk/GetDatabaseServer.php @@ -14,8 +14,8 @@ class GetDatabaseServer extends BaseRequest {FILTER} - + + EOT; From 33b41dc7bc566eea719bdf5e123c1b346d546714 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Fri, 18 Nov 2016 14:18:44 +0100 Subject: [PATCH 17/22] add new functions GetDefaultDatabaseUser SetDefaultDatabaseUser ListDatabaseUsers DeleteDatabaseUser GetDatabase --- src/pmill/Plesk/DeleteDatabaseUser.php | 46 +++++++++++++++ src/pmill/Plesk/GetDatabase.php | 51 +++++++++++++++++ src/pmill/Plesk/GetDefaultDatabaseUser.php | 49 ++++++++++++++++ src/pmill/Plesk/ListDatabaseUsers.php | 65 ++++++++++++++++++++++ src/pmill/Plesk/SetDefaultDatabaseUser.php | 44 +++++++++++++++ 5 files changed, 255 insertions(+) create mode 100644 src/pmill/Plesk/DeleteDatabaseUser.php create mode 100644 src/pmill/Plesk/GetDatabase.php create mode 100644 src/pmill/Plesk/GetDefaultDatabaseUser.php create mode 100644 src/pmill/Plesk/ListDatabaseUsers.php create mode 100644 src/pmill/Plesk/SetDefaultDatabaseUser.php diff --git a/src/pmill/Plesk/DeleteDatabaseUser.php b/src/pmill/Plesk/DeleteDatabaseUser.php new file mode 100644 index 0000000..3758725 --- /dev/null +++ b/src/pmill/Plesk/DeleteDatabaseUser.php @@ -0,0 +1,46 @@ + + + + + + {ID} + {DATABASE_ID} + + + + +EOT; + + /** + * @var array + */ + protected $default_params = [ + 'id' => null, + 'database_id' => null, + ]; + + /** + * @param $xml + * @return bool + * @throws ApiRequestException + */ + protected function processResponse($xml) + { + $result = $xml->database->{'del-db-user'}->result; + + if ($result->status == 'error') { + throw new ApiRequestException($result); + } + + return true; + } +} diff --git a/src/pmill/Plesk/GetDatabase.php b/src/pmill/Plesk/GetDatabase.php new file mode 100644 index 0000000..5504d31 --- /dev/null +++ b/src/pmill/Plesk/GetDatabase.php @@ -0,0 +1,51 @@ + + + + + + {ID} + + + + +EOT; + + /** + * @var array + */ + protected $default_params = [ + 'id' => null, + ]; + + /** + * @param $xml + * @return array + */ + protected function processResponse($xml) + { + $db = $xml->db->{'get-db'}->result; + if ((string)$db->status == 'error') { + throw new ApiRequestException($db); + } + if ((string)$db->result->status == 'error') { + throw new ApiRequestException($db->result); + } + return [ + 'status' => (string)$node->status, + 'id' => (int)$node->id, + 'name' => (string)$node->name, + 'subscription_id' => (int)$node->{'webspace-id'}, + 'db_server_id' => (int)$node->{'db-server-id'}, + 'default_user_id' => (int)$node->{'default-user-id'}, + ]; + } +} diff --git a/src/pmill/Plesk/GetDefaultDatabaseUser.php b/src/pmill/Plesk/GetDefaultDatabaseUser.php new file mode 100644 index 0000000..94c65a8 --- /dev/null +++ b/src/pmill/Plesk/GetDefaultDatabaseUser.php @@ -0,0 +1,49 @@ + + + + + + {DATABASE_ID} + + + + +EOT; + + /** + * @var int + */ + public $id; + + /** + * @var array + */ + protected $default_params = [ + 'database_id' => null, + ]; + + /** + * @param $xml + * @return bool + * @throws ApiRequestException + */ + protected function processResponse($xml) + { + if ($xml->database->{'get-default-user'}->result->status == 'error') { + throw new ApiRequestException($xml->database->{'get-default-user'}->result); + } + + $this->id = (int)$xml->database->{'get-default-user'}->result->id; + return true; + } + +} diff --git a/src/pmill/Plesk/ListDatabaseUsers.php b/src/pmill/Plesk/ListDatabaseUsers.php new file mode 100644 index 0000000..bc315cd --- /dev/null +++ b/src/pmill/Plesk/ListDatabaseUsers.php @@ -0,0 +1,65 @@ + + + + + + {DATABASE_ID} + + + + +EOT; + + /** + * @var int + */ + public $id; + + /** + * @var array + */ + protected $default_params = [ + 'database_id' => null, + ]; + + /** + * @param $xml + * @return bool + * @throws ApiRequestException + */ + protected function processResponse($xml) + { + $result = []; + + if ($xml->database->{'get-db-users'}->result->status == 'error') { + throw new ApiRequestException($xml->database->{'get-default-user'}->result); + } + + $users = $xml->database->{'get-db-users'}->result; + foreach ($users as $user){ + if (isset($user->id)){ + $result[] = [ + 'status'=> (string)$user->status, + 'filter-id'=> (int)$user->{'filter-id'}, + 'id'=> (int)$user->id, + 'db-id'=> (int)$user->{'db-id'}, + 'login'=> (string)$user->login, + 'acl-host'=> (string)$user->acl->host, + 'allow-access-from-ip'=> (string)$user->{'allow-access-from'}->{'ip-address'}, + ]; + } + } + + return $result; + } + +} diff --git a/src/pmill/Plesk/SetDefaultDatabaseUser.php b/src/pmill/Plesk/SetDefaultDatabaseUser.php new file mode 100644 index 0000000..bf92b5a --- /dev/null +++ b/src/pmill/Plesk/SetDefaultDatabaseUser.php @@ -0,0 +1,44 @@ + + + + + {DATABASE_ID} + {ID} + + + +EOT; + + /** + * @var array + */ + protected $default_params = [ + 'database_id' => null, + 'id' => null, + ]; + + /** + * @param $xml + * @return bool + * @throws ApiRequestException + */ + protected function processResponse($xml) + { + if ($xml->database->{'set-default-user'}->result->status == 'error') { + throw new ApiRequestException($xml->database->{'set-default-user'}->result); + } + + return true; + + } + +} From 824874aa916a12e0f2b291e9919b420486526b34 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Fri, 18 Nov 2016 14:20:19 +0100 Subject: [PATCH 18/22] get dbserver info and dbuser info --- src/pmill/Plesk/GetDatabaseServer.php | 8 ++++++-- src/pmill/Plesk/GetDatabaseUser.php | 24 ++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/pmill/Plesk/GetDatabaseServer.php b/src/pmill/Plesk/GetDatabaseServer.php index 9ef208f..dbe3a9a 100644 --- a/src/pmill/Plesk/GetDatabaseServer.php +++ b/src/pmill/Plesk/GetDatabaseServer.php @@ -53,8 +53,12 @@ protected function processResponse($xml) throw new ApiRequestException($xml->db_server->{'get-local'}->result); } - $this->id = (int)$xml->db_server->{'get-local'}->result->id; - return true; + $db_server = $xml->db_server->{'get-local'}->result; + return [ + 'id' => (int)$db_sever->id, + 'status' => (string)$db_sever->status, + 'type' => (string)$db_server->type, + ]; } } diff --git a/src/pmill/Plesk/GetDatabaseUser.php b/src/pmill/Plesk/GetDatabaseUser.php index 920ddd7..0dc5e4a 100644 --- a/src/pmill/Plesk/GetDatabaseUser.php +++ b/src/pmill/Plesk/GetDatabaseUser.php @@ -10,11 +10,11 @@ class GetDatabaseUser extends BaseRequest - + - {DATABASE_ID} + {ID} - + EOT; @@ -28,7 +28,7 @@ class GetDatabaseUser extends BaseRequest * @var array */ protected $default_params = [ - 'database_id' => null, + 'id' => null, ]; /** @@ -38,12 +38,20 @@ class GetDatabaseUser extends BaseRequest */ protected function processResponse($xml) { - if ($xml->database->{'get-default-user'}->result->status == 'error') { + if ($xml->database->{'get-db-users'}->result->status == 'error') { throw new ApiRequestException($xml->database->{'get-default-user'}->result); } - $this->id = (int)$xml->database->{'get-default-user'}->result->id; - return true; + $user = $xml->database->{'get-db-users'}->result; + return [ + 'status' => (string)$user->status, + 'filter-id' => (int)$user->{'filter-id'}, + 'id' => (int)$user->id, + 'db-id' => (int)$user->{'db-id'}, + 'login' => (string)$user->login, + 'acl-host' => (string)$user->acl->host, + 'allow-access-from-ip' => (string)$user->{'allow-access-from'}->{'ip-address'}, + ]; } -} \ No newline at end of file +} From 9045bd1a965256e8e7549f2accf4273624c9708e Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Fri, 18 Nov 2016 14:20:57 +0100 Subject: [PATCH 19/22] fix and error when get username param --- src/pmill/Plesk/GetUser.php | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/pmill/Plesk/GetUser.php b/src/pmill/Plesk/GetUser.php index 68845a7..ddd00ed 100644 --- a/src/pmill/Plesk/GetUser.php +++ b/src/pmill/Plesk/GetUser.php @@ -39,9 +39,9 @@ public function __construct(array $config, $params = []) { if (isset($params['username'])) { $request = new ListUsers($config); - $info = $request->process(); - foreach($info as $user){ - if ($user['login'] == $username) + $users = $request->process(); + foreach($users as $user){ + if ($user['login'] == $params['username']) $params['guid'] = $user['guid']; } } @@ -66,29 +66,29 @@ protected function processResponse($xml) } return [ 'id' => (int)$user->id, - 'filter-id' => (int)$user->filter_id, + 'filter-id' => (int)$user->{'filter-id'}, 'status' => (string)$user->status, - 'login' => (string)$user->data->gen_info->login, - 'name' => (string)$user->data->gen_info->name, - 'owner-guid' => (string)$user->data->gen_info->owner_guid, - 'status' => (string)$user->data->gen_info->status, - 'guid' => (string)$user->data->gen_info->guid, - 'is-built-in' => (int)$user->data->gen_info->is_built_in, - 'subcription-domain-id' => (int)$user->data->gen_info->subcription_domain_id, - 'email' => (string)$user->data->gen_info->email, + 'login' => (string)$user->data->{'gen-info'}->login, + 'name' => (string)$user->data->{'gen-info'}->name, + 'owner-guid' => (string)$user->data->{'gen-info'}->{'owner-guid'}, + 'status' => (string)$user->data->{'gen-info'}->status, + 'guid' => (string)$user->data->{'gen-info'}->guid, + 'is-built-in' => (int)$user->data->{'gen-info'}->{'is-built-in'}, + 'subcription-domain-id' => (int)$user->data->{'gen-info'}->{'subcription-domain-id'}, + 'email' => (string)$user->data->{'gen-info'}->email, 'contact-info' => [ - 'company' => (string)$user->data->gen_info->contact_info->company, - 'phone' => (string)$user->data->gen_info->contact_info->phone, - 'fax' => (string)$user->data->gen_info->contact_info->fax, - 'address' => (string)$user->data->gen_info->contact_info->address, - 'city' => (string)$user->data->gen_info->contact_info->city, - 'state' => (string)$user->data->gen_info->contact_info->state, - 'zip' => (string)$user->data->gen_info->contact_info->zip, - 'country' => (string)$user->data->gen_info->contact_info->country, - 'im' => (string)$user->data->gen_info->contact_info->im, - 'imtype' => (string)$user->data->gen_info->contact_info->imtype, - 'comment' => (string)$user->data->gen_info->contact_info->comment, - 'locale' => (string)$user->data->gen_info->contact_info->locale, + 'company' => (string)$user->data->{'gen-info'}->{'contact-info'}->company, + 'phone' => (string)$user->data->{'gen-info'}->{'contact-info'}->phone, + 'fax' => (string)$user->data->{'gen-info'}->{'contact-info'}->fax, + 'address' => (string)$user->data->{'gen-info'}->{'contact-info'}->address, + 'city' => (string)$user->data->{'gen-info'}->{'contact-info'}->city, + 'state' => (string)$user->data->{'gen-info'}->{'contact-info'}->state, + 'zip' => (string)$user->data->{'gen-info'}->{'contact-info'}->zip, + 'country' => (string)$user->data->{'gen-info'}->{'contact-info'}->country, + 'im' => (string)$user->data->{'gen-info'}->{'contact-info'}->im, + 'imtype' => (string)$user->data->{'gen-info'}->{'contact-info'}->imtype, + 'comment' => (string)$user->data->{'gen-info'}->{'contact-info'}->comment, + 'locale' => (string)$user->data->{'gen-info'}->{'contact-info'}->locale, ], 'role' => (string)$user->data->roles->name, ]; From dde7b288781ba1904a7e1b304f3fcdd5a2e76317 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Fri, 18 Nov 2016 14:22:53 +0100 Subject: [PATCH 20/22] fix problem with _ and - --- src/pmill/Plesk/ListUsers.php | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/pmill/Plesk/ListUsers.php b/src/pmill/Plesk/ListUsers.php index 3e9ee79..40eecdd 100644 --- a/src/pmill/Plesk/ListUsers.php +++ b/src/pmill/Plesk/ListUsers.php @@ -36,29 +36,29 @@ protected function processResponse($xml) $result[] = [ 'id' => (int)$user->id, - 'filter-id' => (int)$user->filter_id, + 'filter-id' => (int)$user->{'filter-id'}, 'status' => (string)$user->status, - 'login' => (string)$user->data->gen_info->login, - 'name' => (string)$user->data->gen_info->name, - 'owner-guid' => (string)$user->data->gen_info->owner_guid, - 'status' => (string)$user->data->gen_info->status, - 'guid' => (string)$user->data->gen_info->guid, - 'is-built-in' => (int)$user->data->gen_info->is_built_in, - 'subcription-domain-id' => (int)$user->data->gen_info->subcription_domain_id, - 'email' => (string)$user->data->gen_info->email, + 'login' => (string)$user->data->{'gen-info'}->login, + 'name' => (string)$user->data->{'gen-info'}->name, + 'owner-guid' => (string)$user->data->{'gen-info'}->{'owner-guid'}, + 'status' => (string)$user->data->{'gen-info'}->status, + 'guid' => (string)$user->data->{'gen-info'}->guid, + 'is-built-in' => (int)$user->data->{'gen-info'}->{'is-built-in'}, + 'subcription-domain-id' => (int)$user->data->{'gen-info'}->{'subcription-domain-id'}, + 'email' => (string)$user->data->{'gen-info'}->email, 'contact-info' => [ - 'company' => (string)$user->data->gen_info->contact_info->company, - 'phone' => (string)$user->data->gen_info->contact_info->phone, - 'fax' => (string)$user->data->gen_info->contact_info->fax, - 'address' => (string)$user->data->gen_info->contact_info->address, - 'city' => (string)$user->data->gen_info->contact_info->city, - 'state' => (string)$user->data->gen_info->contact_info->state, - 'zip' => (string)$user->data->gen_info->contact_info->zip, - 'country' => (string)$user->data->gen_info->contact_info->country, - 'im' => (string)$user->data->gen_info->contact_info->im, - 'imtype' => (string)$user->data->gen_info->contact_info->imtype, - 'comment' => (string)$user->data->gen_info->contact_info->comment, - 'locale' => (string)$user->data->gen_info->contact_info->locale, + 'company' => (string)$user->data->{'gen-info'}->{'contact-info'}->company, + 'phone' => (string)$user->data->{'gen-info'}->{'contact-info'}->phone, + 'fax' => (string)$user->data->{'gen-info'}->{'contact-info'}->fax, + 'address' => (string)$user->data->{'gen-info'}->{'contact-info'}->address, + 'city' => (string)$user->data->{'gen-info'}->{'contact-info'}->city, + 'state' => (string)$user->data->{'gen-info'}->{'contact-info'}->state, + 'zip' => (string)$user->data->{'gen-info'}->{'contact-info'}->zip, + 'country' => (string)$user->data->{'gen-info'}->{'contact-info'}->country, + 'im' => (string)$user->data->{'gen-info'}->{'contact-info'}->im, + 'imtype' => (string)$user->data->{'gen-info'}->{'contact-info'}->imtype, + 'comment' => (string)$user->data->{'gen-info'}->{'contact-info'}->comment, + 'locale' => (string)$user->data->{'gen-info'}->{'contact-info'}->locale, ], 'role' => (string)$user->data->roles->name, ]; From 2a7f859fb8171e5d4bcf6374b54bdc4cdb735e59 Mon Sep 17 00:00:00 2001 From: mUniKeS Date: Fri, 18 Nov 2016 14:23:25 +0100 Subject: [PATCH 21/22] create new filters --- src/pmill/Plesk/ListDatabases.php | 43 ++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/pmill/Plesk/ListDatabases.php b/src/pmill/Plesk/ListDatabases.php index 0ada2c6..bb08d60 100644 --- a/src/pmill/Plesk/ListDatabases.php +++ b/src/pmill/Plesk/ListDatabases.php @@ -11,9 +11,7 @@ class ListDatabases extends BaseRequest - - {SUBSCRIPTION_ID} - + {FILTER} @@ -23,9 +21,28 @@ class ListDatabases extends BaseRequest * @var array */ protected $default_params = [ - 'subscription_id' => null, + 'filter' => '', ]; + /** + * @param array $config + * @param array $params + * @throws ApiRequestException + * */ + public function __construct(array $config, $params = []) + { + $this->default_params['filter'] = new Node('filter'); + if (isset($params['subscription_id'])) { + $webspaceIdNode = new Node('webspace-id', $params['subscription_id']); + $params['filter'] = new Node('filter', $webspaceIdNode); + } + if (isset($params['subscription_id'])) { + $webspaceNameNode = new Node('webspace-name', $params['subscription_name']); + $params['filter'] = new Node('filter', $webspaceNameNode); + } + parent::__construct($config, $params); + } + /** * @param $xml * @return array @@ -35,14 +52,16 @@ protected function processResponse($xml) $result = []; foreach ($xml->database->{'get-db'}->children() as $node) { - $result[] = [ - 'status' => (string)$node->status, - 'id' => (int)$node->id, - 'name' => (string)$node->name, - 'subscription_id' => (int)$node->{'webspace-id'}, - 'db_server_id' => (int)$node->{'db-server-id'}, - 'default_user_id' => (int)$node->{'default-user-id'}, - ]; + if (isset($node->id)){ + $result[] = [ + 'status' => (string)$node->status, + 'id' => (int)$node->id, + 'name' => (string)$node->name, + 'subscription_id' => (int)$node->{'webspace-id'}, + 'db_server_id' => (int)$node->{'db-server-id'}, + 'default_user_id' => (int)$node->{'default-user-id'}, + ]; + } } return $result; From 115965d468f8c1d4e0442dc397a7fe01598a7a18 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 21 Nov 2016 13:23:49 +0100 Subject: [PATCH 22/22] Some fixes --- examples/Subscriptions/get_subscription.php | 2 -- src/pmill/Plesk/ApiRequestException.php | 1 - src/pmill/Plesk/BaseRequest.php | 1 - src/pmill/Plesk/CreateDatabase.php | 2 +- src/pmill/Plesk/DeleteDatabaseUser.php | 22 +++++++++++++--- src/pmill/Plesk/GetDatabase.php | 21 ++++++++------- src/pmill/Plesk/GetDatabaseServer.php | 6 ++--- src/pmill/Plesk/GetDatabaseUser.php | 7 +---- src/pmill/Plesk/GetDefaultDatabaseUser.php | 5 ---- src/pmill/Plesk/GetSubscription.php | 2 +- src/pmill/Plesk/GetUser.php | 22 ++++++++-------- src/pmill/Plesk/ListDatabases.php | 29 ++++++++++----------- src/pmill/Plesk/ListSubdomains.php | 22 ++++++++-------- 13 files changed, 72 insertions(+), 70 deletions(-) diff --git a/examples/Subscriptions/get_subscription.php b/examples/Subscriptions/get_subscription.php index 1d6eb94..ef6d53e 100644 --- a/examples/Subscriptions/get_subscription.php +++ b/examples/Subscriptions/get_subscription.php @@ -7,8 +7,6 @@ */ $params = array( 'subscription_id'=>'1', - //'name'=>'example.com', - //'username'=>'', ); $request = new \pmill\Plesk\GetSubscription($config, $params); diff --git a/src/pmill/Plesk/ApiRequestException.php b/src/pmill/Plesk/ApiRequestException.php index 9c870e8..e12037a 100644 --- a/src/pmill/Plesk/ApiRequestException.php +++ b/src/pmill/Plesk/ApiRequestException.php @@ -16,7 +16,6 @@ public function __construct($errorNode, $code = 0) $message = isset($errorNode->errtext) ? (string)$errorNode->errtext : ''; $code = isset($errorNode->errcode) ? (int)$errorNode->errcode : ''; } - parent::__construct($message, $code); } } diff --git a/src/pmill/Plesk/BaseRequest.php b/src/pmill/Plesk/BaseRequest.php index 40d684f..8781523 100644 --- a/src/pmill/Plesk/BaseRequest.php +++ b/src/pmill/Plesk/BaseRequest.php @@ -178,7 +178,6 @@ public function process() $this->error = $e; throw new ApiRequestException($e->getMessage(), $e->getCode()); } - } /** diff --git a/src/pmill/Plesk/CreateDatabase.php b/src/pmill/Plesk/CreateDatabase.php index 6b6678c..05320d8 100644 --- a/src/pmill/Plesk/CreateDatabase.php +++ b/src/pmill/Plesk/CreateDatabase.php @@ -49,4 +49,4 @@ protected function processResponse($xml) $this->id = (int)$xml->database->{'add-db'}->result->id; return true; } -} \ No newline at end of file +} diff --git a/src/pmill/Plesk/DeleteDatabaseUser.php b/src/pmill/Plesk/DeleteDatabaseUser.php index 3758725..1c49e7e 100644 --- a/src/pmill/Plesk/DeleteDatabaseUser.php +++ b/src/pmill/Plesk/DeleteDatabaseUser.php @@ -12,8 +12,7 @@ class DeleteDatabaseUser extends BaseRequest - {ID} - {DATABASE_ID} + {FILTER} @@ -24,10 +23,25 @@ class DeleteDatabaseUser extends BaseRequest * @var array */ protected $default_params = [ - 'id' => null, - 'database_id' => null, + 'filter' => null, ]; + /** + * @param array $config + * @param array $params + * @throws ApiRequestException + */ + public function __construct($config, $params = []) + { + if (isset($params['id'])) { + $params['filter'] = new Node('id', $params['id']); + } + else if (isset($params['database_id'])) { + $params['filter'] = new Node('db-id', $params['database_id']); + } + parent::__construct($config, $params); + } + /** * @param $xml * @return bool diff --git a/src/pmill/Plesk/GetDatabase.php b/src/pmill/Plesk/GetDatabase.php index 5504d31..8a59536 100644 --- a/src/pmill/Plesk/GetDatabase.php +++ b/src/pmill/Plesk/GetDatabase.php @@ -12,7 +12,7 @@ class GetDatabase extends BaseRequest - {ID} + {SUBSCRIPTION_ID} @@ -32,14 +32,16 @@ class GetDatabase extends BaseRequest */ protected function processResponse($xml) { - $db = $xml->db->{'get-db'}->result; - if ((string)$db->status == 'error') { - throw new ApiRequestException($db); - } - if ((string)$db->result->status == 'error') { - throw new ApiRequestException($db->result); - } - return [ + + $db = $xml->database->{'get-db'}->result; + if ((string)$db->status == 'error') { + throw new ApiRequestException($db); + } + if ((string)$db->result->status == 'error') { + throw new ApiRequestException($db->result); + } + + return [ 'status' => (string)$node->status, 'id' => (int)$node->id, 'name' => (string)$node->name, @@ -47,5 +49,6 @@ protected function processResponse($xml) 'db_server_id' => (int)$node->{'db-server-id'}, 'default_user_id' => (int)$node->{'default-user-id'}, ]; + } } diff --git a/src/pmill/Plesk/GetDatabaseServer.php b/src/pmill/Plesk/GetDatabaseServer.php index dbe3a9a..054bf45 100644 --- a/src/pmill/Plesk/GetDatabaseServer.php +++ b/src/pmill/Plesk/GetDatabaseServer.php @@ -55,9 +55,9 @@ protected function processResponse($xml) $db_server = $xml->db_server->{'get-local'}->result; return [ - 'id' => (int)$db_sever->id, - 'status' => (string)$db_sever->status, - 'type' => (string)$db_server->type, + 'id' => (int)$db_server->id, + 'status' => (string)$db_server->status, + 'type' => (string)$db_server->type, ]; } diff --git a/src/pmill/Plesk/GetDatabaseUser.php b/src/pmill/Plesk/GetDatabaseUser.php index 0dc5e4a..8dbb43d 100644 --- a/src/pmill/Plesk/GetDatabaseUser.php +++ b/src/pmill/Plesk/GetDatabaseUser.php @@ -8,7 +8,7 @@ class GetDatabaseUser extends BaseRequest */ public $xml_packet = << - + @@ -19,11 +19,6 @@ class GetDatabaseUser extends BaseRequest EOT; - /** - * @var int - */ - public $id; - /** * @var array */ diff --git a/src/pmill/Plesk/GetDefaultDatabaseUser.php b/src/pmill/Plesk/GetDefaultDatabaseUser.php index 94c65a8..4ee7727 100644 --- a/src/pmill/Plesk/GetDefaultDatabaseUser.php +++ b/src/pmill/Plesk/GetDefaultDatabaseUser.php @@ -19,11 +19,6 @@ class GetDefaultDatabaseUser extends BaseRequest EOT; - /** - * @var int - */ - public $id; - /** * @var array */ diff --git a/src/pmill/Plesk/GetSubscription.php b/src/pmill/Plesk/GetSubscription.php index 7f3d2de..c8ff627 100644 --- a/src/pmill/Plesk/GetSubscription.php +++ b/src/pmill/Plesk/GetSubscription.php @@ -70,7 +70,7 @@ protected function processResponse($xml) $webspace = $xml->webspace->get->result[$i]; if ($webspace->status == 'error') { - throw new ApiRequestException($webspace); + throw new ApiRequestException($webspace); } $hosting = []; diff --git a/src/pmill/Plesk/GetUser.php b/src/pmill/Plesk/GetUser.php index ddd00ed..b94cce0 100644 --- a/src/pmill/Plesk/GetUser.php +++ b/src/pmill/Plesk/GetUser.php @@ -10,16 +10,16 @@ class GetUser extends BaseRequest - - - {GUID} - - - - - - - + + + {GUID} + + + + + + + EOT; @@ -35,7 +35,7 @@ class GetUser extends BaseRequest * @param array $config * @param array $params */ - public function __construct(array $config, $params = []) + public function __construct(array $config, $params) { if (isset($params['username'])) { $request = new ListUsers($config); diff --git a/src/pmill/Plesk/ListDatabases.php b/src/pmill/Plesk/ListDatabases.php index bb08d60..310096c 100644 --- a/src/pmill/Plesk/ListDatabases.php +++ b/src/pmill/Plesk/ListDatabases.php @@ -28,20 +28,20 @@ class ListDatabases extends BaseRequest * @param array $config * @param array $params * @throws ApiRequestException - * */ - public function __construct(array $config, $params = []) - { - $this->default_params['filter'] = new Node('filter'); - if (isset($params['subscription_id'])) { - $webspaceIdNode = new Node('webspace-id', $params['subscription_id']); - $params['filter'] = new Node('filter', $webspaceIdNode); - } - if (isset($params['subscription_id'])) { - $webspaceNameNode = new Node('webspace-name', $params['subscription_name']); - $params['filter'] = new Node('filter', $webspaceNameNode); - } - parent::__construct($config, $params); - } + */ + public function __construct(array $config, $params = []) + { + $this->default_params['filter'] = new Node('filter'); + if (isset($params['subscription_id'])) { + $webspaceIdNode = new Node('webspace-id', $params['subscription_id']); + $params['filter'] = new Node('filter', $webspaceIdNode); + } + if (isset($params['subscription_id'])) { + $webspaceNameNode = new Node('webspace-name', $params['subscription_name']); + $params['filter'] = new Node('filter', $webspaceNameNode); + } + parent::__construct($config, $params); + } /** * @param $xml @@ -50,7 +50,6 @@ public function __construct(array $config, $params = []) protected function processResponse($xml) { $result = []; - foreach ($xml->database->{'get-db'}->children() as $node) { if (isset($node->id)){ $result[] = [ diff --git a/src/pmill/Plesk/ListSubdomains.php b/src/pmill/Plesk/ListSubdomains.php index 7619e27..263a3eb 100644 --- a/src/pmill/Plesk/ListSubdomains.php +++ b/src/pmill/Plesk/ListSubdomains.php @@ -57,17 +57,17 @@ protected function processResponse($xml) $result = []; foreach ($xml->subdomain->get->result as $node) { - if (isset($node->id)){ - $result[] = [ - 'id' => (int)$node->id, - 'status' => (string)$node->status, - 'parent' => (string)$node->data->parent, - 'name' => (string)$node->data->name, - 'php' => (string)Xml::findProperty($node->data, 'php'), - 'php_handler_type' => (string)Xml::findProperty($node->data, 'php_handler_type'), - 'www_root' => (string)Xml::findProperty($node->data, 'www_root'), - ]; - } + if (isset($node->id)){ + $result[] = [ + 'id' => (int)$node->id, + 'status' => (string)$node->status, + 'parent' => (string)$node->data->parent, + 'name' => (string)$node->data->name, + 'php' => (string)Xml::findProperty($node->data, 'php'), + 'php_handler_type' => (string)Xml::findProperty($node->data, 'php_handler_type'), + 'www_root' => (string)Xml::findProperty($node->data, 'www_root'), + ]; + } } return $result;