From 789125dcb5fc9dc43c063bb79379f2c32094a1e5 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Thu, 1 Oct 2015 20:54:27 -0300 Subject: [PATCH 01/35] inserting arrayToXml in Client and site tests --- .gitignore | 4 ++ src/PleskX/Api/Client.php | 45 ++++++++++++++++ src/PleskX/Api/Operator/Site.php | 43 +++++++++++++++ src/PleskX/Api/Operator/Webspace.php | 9 +--- tests/SiteTest.php | 33 ++++++++++++ tests/WebspaceTest.php | 80 ++++++++++++++++++++++++++-- 6 files changed, 204 insertions(+), 10 deletions(-) create mode 100644 tests/SiteTest.php diff --git a/.gitignore b/.gitignore index 17c52938..190889d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ /php/tests/node_modules /vendor /phpunit.xml +composer.lock +composer.phar +node_modules + diff --git a/src/PleskX/Api/Client.php b/src/PleskX/Api/Client.php index 1b069a65..1187dabc 100644 --- a/src/PleskX/Api/Client.php +++ b/src/PleskX/Api/Client.php @@ -85,6 +85,51 @@ public function getPacket($version = null) return new SimpleXMLElement($content); } + + /** + * Recursive function that transforms array in XML + * + * @param array $attributes + * @param SimpleXMLElement $xmlData + * @return SimpleXMLElement + */ + protected function _createXml( $data, &$xmlData ) { + foreach ($data as $key => $value) { + if (is_array($value)) { + if (is_numeric($key)) { + $key = array_keys($data[$key])[0]; + $subnode = $xmlData->addChild($key); + foreach ($value[$key] as $k => $v) { + if (is_array($v)) { + $this->_createXml($v, $subnode); + } else { + $subnode->addChild("$k",htmlspecialchars("$v")); + } + } + } else { + $subnode = $xmlData->addChild($key); + $this->_createXml($value, $subnode); + } + } else { + $xmlData->addChild("$key",htmlspecialchars("$value")); + } + } + } + + /** + * Gen XML Request by Array + * + * @param array $attributes + * @param string|null $version + * @return SimpleXMLElement + */ + public function genRequestXml($attributes, $version = null) + { + $res = $this->getPacket($version); + $this->_createXml($attributes,$res); + return $res; + } + /** * Perform API request * diff --git a/src/PleskX/Api/Operator/Site.php b/src/PleskX/Api/Operator/Site.php index 4b2a1bc6..bb778e11 100644 --- a/src/PleskX/Api/Operator/Site.php +++ b/src/PleskX/Api/Operator/Site.php @@ -3,7 +3,50 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\Webspace as Struct; + class Site extends \PleskX\Api\Operator { + /** + * @param string $field + * @param integer|string $value + * @return Struct\GeneralInfo + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('site')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $getTag->addChild('dataset')->addChild('gen_info'); + $response = $this->_client->request($packet); + return new Struct\GeneralInfo($response->data->gen_info); + } + + + /** + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['site' => ['add' => $properties]]; + $packet = $this->_client->genRequestXml( $properties ); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('site')->addChild('del')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + } diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index 2f8fe107..23d4213d 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -31,13 +31,8 @@ public function getPhysicalHostingDescriptor() */ public function create($properties) { - $packet = $this->_client->getPacket(); - $info = $packet->addChild('webspace')->addChild('add')->addChild('gen_setup'); - - foreach ($properties as $name => $value) { - $info->addChild($name, $value); - } - + $properties = ['webspace' => ['add' => $properties]]; + $packet = $this->_client->genRequestXml($properties); $response = $this->_client->request($packet); return new Struct\Info($response); } diff --git a/tests/SiteTest.php b/tests/SiteTest.php new file mode 100644 index 00000000..3f27fe33 --- /dev/null +++ b/tests/SiteTest.php @@ -0,0 +1,33 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + return $this->_client->webspace()->create([ + 'name' => $this->n, + 'ip_address' => $ipInfo->ipAddress, + ]); + } + + public function testGet() + { + $ws = $this->_createWebspace(); + + $siteInfo = $this->_client->site()->get('id', $ws->id); + $this->assertEquals($this->n, $siteInfo->name); + + $this->_client->webspace()->delete('id', $ws->id); + + } + +} diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index f3f55a03..b811a1c1 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -4,16 +4,54 @@ class WebspaceTest extends TestCase { + private $webspaceSiteName = 'example-test-parent.dom'; + private $siteName = 'example-test-child.dom'; + /** + * + * * @return \PleskX\Api\Struct\Webspace\Info */ private function _createWebspace() { + $ips = $this->_client->ip()->get(); $ipInfo = reset($ips); + return $this->_client->webspace()->create([ - 'name' => 'example-test.dom', - 'ip_address' => $ipInfo->ipAddress, + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + /** + * @return \PleskX\Api\Struct\Webspace\Info + */ + private function _createSite($webspace) + { + return $this->_client->site()->create([ + 'gen_setup' => [ + 'name' => $this->siteName, + 'webspace-id' => $webspace->id + ], ]); } @@ -62,9 +100,45 @@ public function testGet() { $webspace = $this->_createWebspace(); $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - $this->assertEquals('example-test.dom', $webspaceInfo->name); + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); + + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testCreateSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + + $this->assertInternalType('integer', $site->id); + $this->assertGreaterThan(0, $site->id); + + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDeleteSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + + $result = $this->_client->site()->delete('id', $site->id); + $this->assertTrue($result); $this->_client->webspace()->delete('id', $webspace->id); } + public function testGetSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + + $siteInfo = $this->_client->site()->get('id', $site->id); + $this->assertEquals($this->siteName, $siteInfo->name); + + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + } From 0078adae084b55e2d08956128b23c25dacc6bef2 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Thu, 1 Oct 2015 21:20:19 -0300 Subject: [PATCH 02/35] changing composer.json --- composer.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index bfe3ee03..66f8f005 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,17 @@ { - "name": "plesk/api-php-lib", - "description": "PHP object-oriented library for Plesk API-RPC", + "name": "lucasmarin/api-php-lib", + "description": "PHP object-oriented library for Plesk API-RPC. forked >> plesk/api-php-lib", "license": "Apache-2.0", "authors": [ { "name": "Alexei Yuzhakov", "email": "sibprogrammer@gmail.com" + }, + { + "name": "Lucas Stevanelli Marin", + "email": "lucasmarin@gmail.com" } + ], "minimum-stability": "dev", "require": { From 7b0c65f2f1d619d0650086e58b7acb2367831747 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Mon, 5 Oct 2015 20:14:18 -0300 Subject: [PATCH 03/35] Create getAllData call Webspace --- README.md | 8 +- src/PleskX/Api/Client.php | 2 +- src/PleskX/Api/Operator/Webspace.php | 29 ++++ src/PleskX/Api/Struct.php | 13 +- src/PleskX/Api/Struct/Webspace/Data.php | 41 +++++ src/PleskX/Api/Struct/Webspace/DiskUsage.php | 66 ++++++++ .../Api/Struct/Webspace/GeneralInfo.php | 52 +++++- src/PleskX/Api/Struct/Webspace/Hosting.php | 35 ++++ src/PleskX/Api/Struct/Webspace/Limits.php | 31 ++++ src/PleskX/Api/Struct/Webspace/Perfomance.php | 21 +++ src/PleskX/Api/Struct/Webspace/Preference.php | 21 +++ src/PleskX/Api/Struct/Webspace/Stat.php | 69 ++++++++ src/PleskX/Api/StructData.php | 49 ++++++ tests/WebspaceTest.php | 149 ++++++++++-------- 14 files changed, 503 insertions(+), 83 deletions(-) create mode 100644 src/PleskX/Api/Struct/Webspace/Data.php create mode 100644 src/PleskX/Api/Struct/Webspace/DiskUsage.php create mode 100644 src/PleskX/Api/Struct/Webspace/Hosting.php create mode 100644 src/PleskX/Api/Struct/Webspace/Limits.php create mode 100644 src/PleskX/Api/Struct/Webspace/Perfomance.php create mode 100644 src/PleskX/Api/Struct/Webspace/Preference.php create mode 100644 src/PleskX/Api/Struct/Webspace/Stat.php create mode 100644 src/PleskX/Api/StructData.php diff --git a/README.md b/README.md index 8a927d0c..d2d86645 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ ## PHP library for Plesk API-RPC -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/plesk/api-php-lib/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/plesk/api-php-lib/?branch=master) - PHP object-oriented library for Plesk API-RPC. ## Install Via Composer [Composer](https://getcomposer.org/) is a preferable way to install the library: -`composer require plesk/api-php-lib:@dev` +`composer require lucasmarin/api-php-lib:@dev-master` ## How to Run Unit Tests @@ -16,11 +14,11 @@ One the possible ways to become familiar with the library is to check the unit t To run the unit tests use the following command: -`REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password phpunit` +`REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password REMOTE_LOGIN=login phpunit` ## Using Grunt for Continuous Testing * Install Node.js * Install dependencies via `npm install` command -* Run `REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password grunt watch:test` +* Run `REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password REMOTE_LOGIN=user grunt watch:test` diff --git a/src/PleskX/Api/Client.php b/src/PleskX/Api/Client.php index 1187dabc..126352f6 100644 --- a/src/PleskX/Api/Client.php +++ b/src/PleskX/Api/Client.php @@ -87,7 +87,7 @@ public function getPacket($version = null) /** - * Recursive function that transforms array in XML + * Recursive function that transforms array to XML * * @param array $attributes * @param SimpleXMLElement $xmlData diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index 23d4213d..4ea01f80 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -50,7 +50,10 @@ public function delete($field, $value) return 'ok' === (string)$response->status; } + /** + * Get gen_info of webspace [name,guid] + * * @param string $field * @param integer|string $value * @return Struct\GeneralInfo @@ -65,4 +68,30 @@ public function get($field, $value) return new Struct\GeneralInfo($response->data->gen_info); } + + /** + * Get Data of webspace + * + * @param string $field + * @param integer|string $value + * @return Struct\Data + */ + public function getData($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('webspace')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $dataset = $getTag->addChild('dataset'); + $dataset->addChild('gen_info'); + $dataset->addChild('hosting'); + $dataset->addChild('limits'); + $dataset->addChild('stat'); + $dataset->addChild('prefs'); + $dataset->addChild('disk_usage'); + $dataset->addChild('performance'); + $response = $this->_client->request($packet); + return new Struct\Data($response->data); + } + + } diff --git a/src/PleskX/Api/Struct.php b/src/PleskX/Api/Struct.php index 928d8fba..6d5c5978 100644 --- a/src/PleskX/Api/Struct.php +++ b/src/PleskX/Api/Struct.php @@ -21,7 +21,7 @@ public function __set($property, $value) protected function _initScalarProperties($apiResponse, array $properties) { foreach ($properties as $property) { - if (is_array($property)) { + if (is_array($property) || is_object($property)) { $classPropertyName = current($property); $value = $apiResponse->{key($property)}; } else { @@ -31,7 +31,7 @@ protected function _initScalarProperties($apiResponse, array $properties) $reflectionProperty = new \ReflectionProperty($this, $classPropertyName); $docBlock = $reflectionProperty->getDocComment(); - $propertyType = preg_replace('/^.+ @var ([a-z]+) .+$/', '\1', $docBlock); + $propertyType = trim(preg_replace('/^.+ @var ([^\*]+) .+$/', '\1', $docBlock)); if ('string' == $propertyType) { $value = (string)$value; @@ -40,7 +40,10 @@ protected function _initScalarProperties($apiResponse, array $properties) } else if ('boolean' == $propertyType) { $value = in_array((string)$value, ['true', 'on', 'enabled']); } else { - throw new \Exception("Unknown property type '$propertyType'."); + if ( class_exists($propertyType) ) { + $value = new $propertyType($value); + } else + throw new \Exception("Unknown property type '$propertyType'."); } $this->$classPropertyName = $value; @@ -53,9 +56,9 @@ protected function _initScalarProperties($apiResponse, array $properties) * @param string $under * @return string */ - private function _underToCamel($under) + protected function _underToCamel($under) { - $under = '_' . str_replace('_', ' ', strtolower($under)); + $under = '_' . str_replace(['_','-'], ' ', strtolower($under)); return ltrim(str_replace(' ', '', ucwords($under)), '_'); } diff --git a/src/PleskX/Api/Struct/Webspace/Data.php b/src/PleskX/Api/Struct/Webspace/Data.php new file mode 100644 index 00000000..184f50bc --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Data.php @@ -0,0 +1,41 @@ +_initScalarProperties($apiResponse, [ + 'gen_info', + 'hosting', + 'limits', + 'stat', + 'prefs', + 'disk-usage', + 'performance' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/DiskUsage.php b/src/PleskX/Api/Struct/Webspace/DiskUsage.php new file mode 100644 index 00000000..82f7a80d --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/DiskUsage.php @@ -0,0 +1,66 @@ +_initScalarProperties($apiResponse, [ + 'httpdocs', + 'httpsdocs', + 'subdomains', + 'web_users', + 'anonftp', + 'logs', + 'dbases', + 'mailboxes', + 'webapps', + 'maillists', + 'domaindumps', + 'configs', + 'chroot' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/GeneralInfo.php b/src/PleskX/Api/Struct/Webspace/GeneralInfo.php index 40e0a466..34bc3bbf 100644 --- a/src/PleskX/Api/Struct/Webspace/GeneralInfo.php +++ b/src/PleskX/Api/Struct/Webspace/GeneralInfo.php @@ -5,17 +5,65 @@ class GeneralInfo extends \PleskX\Api\Struct { - /** @var string */ + /** @var string */ + public $crDate; + + /** @var string */ public $name; - /** @var string */ + /** @var string */ + public $asciiName; + + /** @var string */ + public $status; + + /** @var integer */ + public $realSize; + + /** @var string */ + public $ownerLogin; + + /** @var string */ + public $dnsIpAddress; + + /** @var string */ + public $htype; + + /** @var string */ public $guid; + /** @var string */ + public $vendorGuid; + + /** @var string */ + public $externalId; + + /** @var string */ + public $sbSiteUuid; + + /** @var string */ + public $description; + + /** @var string */ + public $adminDescription; + public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ + 'cr_date', 'name', + 'ascii-name', + 'status', + 'real_size', + 'owner-login', + 'dns_ip_address', + 'htype', 'guid', + 'vendor-guid', + 'external-id', + 'sb-site-uuid', + 'description', + 'admin-description' ]); } } \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Hosting.php b/src/PleskX/Api/Struct/Webspace/Hosting.php new file mode 100644 index 00000000..5b72ba9b --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Hosting.php @@ -0,0 +1,35 @@ +_hostingScalarProperties($apiResponse, ['property']); + } + + private function _hostingScalarProperties($apiResponse,$arrayElement) + { + $sxe = new \SimpleXmlIterator($apiResponse->asXML()); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + $this->types[$k] = new \stdClass(); + if ( $sxe->hasChildren() ) { + foreach ($sxe->getChildren() as $element => $value) { + if ( in_array($element, $arrayElement) ) { + $this->types[$k]->{parent::_underToCamel($value->name)} = $value->value; + } else { + $this->types[$k]->{parent::_underToCamel($element)} = $value; + } + } + } + } + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Limits.php b/src/PleskX/Api/Struct/Webspace/Limits.php new file mode 100644 index 00000000..c0c0a707 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Limits.php @@ -0,0 +1,31 @@ +_limitScalarProperties($apiResponse); + } + + private function _limitScalarProperties( $apiResponse ) + { + foreach ($apiResponse as $attr => $obj) { + if (is_array($obj)) { + foreach ($obj as $key => $v) { + $this->{$attr}->{parent::_underToCamel($v->name)} = $v->value; + } + } else $this->{$this->_underToCamel($attr)} = $obj; + } + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Perfomance.php b/src/PleskX/Api/Struct/Webspace/Perfomance.php new file mode 100644 index 00000000..f4ffb3b9 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Perfomance.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'bandwidth', + 'max_connections', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Preference.php b/src/PleskX/Api/Struct/Webspace/Preference.php new file mode 100644 index 00000000..7619b49f --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Preference.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'www', + 'stat_ttl', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Stat.php b/src/PleskX/Api/Struct/Webspace/Stat.php new file mode 100644 index 00000000..6dda0386 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Stat.php @@ -0,0 +1,69 @@ +_initScalarProperties($apiResponse, [ + 'traffic', + 'subdom', + 'wu', + 'box', + 'redir', + 'mg', + 'resp', + 'maillists', + 'db', + 'mssql_db', + 'webapps', + 'traffic_prevday', + 'domains', + 'sites' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/StructData.php b/src/PleskX/Api/StructData.php new file mode 100644 index 00000000..1a6a83e9 --- /dev/null +++ b/src/PleskX/Api/StructData.php @@ -0,0 +1,49 @@ +{key($property)}; + } else { + $classPropertyName = $this->_underToCamel(str_replace('-', '_', $property)); + $value = $apiResponse->$property; + } + + $reflectionProperty = new \ReflectionProperty($this, $classPropertyName); + $docBlock = $reflectionProperty->getDocComment(); + $propertyType = trim(preg_replace('/^.+ @var ([^\*]+) .+$/', '\1', $docBlock)); + + if ('string' == $propertyType) { + $value = (string)$value; + } else if ('integer' == $propertyType) { + $value = (int)$value; + } else if ('boolean' == $propertyType) { + $value = in_array((string)$value, ['true', 'on', 'enabled']); + } else { + if ( class_exists($propertyType) ) { + $value = new $property($value); + } + throw new \Exception("Unknown property type '$propertyType'."); + } + + $this->$classPropertyName = $value; + } + } + + +} \ No newline at end of file diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index b811a1c1..43c68b6f 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -55,90 +55,99 @@ private function _createSite($webspace) ]); } - public function testGetPermissionDescriptor() - { - $descriptor = $this->_client->webspace()->getPermissionDescriptor(); - $this->assertInternalType('array', $descriptor->permissions); - $this->assertGreaterThan(0, count($descriptor->permissions)); - } - - public function testGetLimitDescriptor() - { - $descriptor = $this->_client->webspace()->getLimitDescriptor(); - $this->assertInternalType('array', $descriptor->limits); - $this->assertGreaterThan(0, count($descriptor->limits)); - } - - public function testGetPhysicalHostingDescriptor() - { - $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); - $this->assertInternalType('array', $descriptor->properties); - $this->assertGreaterThan(0, count($descriptor->properties)); - - $ftpLoginProperty = $descriptor->properties['ftp_login']; - $this->assertEquals('ftp_login', $ftpLoginProperty->name); - $this->assertEquals('string', $ftpLoginProperty->type); - } - - public function testCreate() + // public function testGetPermissionDescriptor() + // { + // $descriptor = $this->_client->webspace()->getPermissionDescriptor(); + // $this->assertInternalType('array', $descriptor->permissions); + // $this->assertGreaterThan(0, count($descriptor->permissions)); + // } + + // public function testGetLimitDescriptor() + // { + // $descriptor = $this->_client->webspace()->getLimitDescriptor(); + // $this->assertInternalType('array', $descriptor->limits); + // $this->assertGreaterThan(0, count($descriptor->limits)); + // } + + // public function testGetPhysicalHostingDescriptor() + // { + // $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); + // $this->assertInternalType('array', $descriptor->properties); + // $this->assertGreaterThan(0, count($descriptor->properties)); + + // $ftpLoginProperty = $descriptor->properties['ftp_login']; + // $this->assertEquals('ftp_login', $ftpLoginProperty->name); + // $this->assertEquals('string', $ftpLoginProperty->type); + // } + + // public function testCreate() + // { + // $webspace = $this->_createWebspace(); + // $this->assertInternalType('integer', $webspace->id); + // $this->assertGreaterThan(0, $webspace->id); + + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testDelete() + // { + // $webspace = $this->_createWebspace(); + // $result = $this->_client->webspace()->delete('id', $webspace->id); + // $this->assertTrue($result); + // } + + // public function testGet() + // { + // $webspace = $this->_createWebspace(); + // $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); + // $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); + + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + public function testData() { $webspace = $this->_createWebspace(); - $this->assertInternalType('integer', $webspace->id); - $this->assertGreaterThan(0, $webspace->id); - + $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->genInfo->name); $this->_client->webspace()->delete('id', $webspace->id); } - public function testDelete() - { - $webspace = $this->_createWebspace(); - $result = $this->_client->webspace()->delete('id', $webspace->id); - $this->assertTrue($result); - } - - public function testGet() - { - $webspace = $this->_createWebspace(); - $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); - - $this->_client->webspace()->delete('id', $webspace->id); - } - public function testCreateSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); + // public function testCreateSite() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); - $this->assertInternalType('integer', $site->id); - $this->assertGreaterThan(0, $site->id); + // $this->assertInternalType('integer', $site->id); + // $this->assertGreaterThan(0, $site->id); - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } - public function testDeleteSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); + // public function testDeleteSite() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); - $result = $this->_client->site()->delete('id', $site->id); - $this->assertTrue($result); + // $result = $this->_client->site()->delete('id', $site->id); + // $this->assertTrue($result); - $this->_client->webspace()->delete('id', $webspace->id); - } + // $this->_client->webspace()->delete('id', $webspace->id); + // } - public function testGetSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); + // public function testGetSite() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); - $siteInfo = $this->_client->site()->get('id', $site->id); - $this->assertEquals($this->siteName, $siteInfo->name); + // $siteInfo = $this->_client->site()->get('id', $site->id); + // $this->assertEquals($this->siteName, $siteInfo->name); - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } } From 46cbbb17390e4ee34e07b872c4d0fa60f8ac652d Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 6 Oct 2015 10:45:50 -0300 Subject: [PATCH 04/35] Limit structure on Webspace::getData return --- src/PleskX/Api/Struct/Webspace/Hosting.php | 4 +- src/PleskX/Api/Struct/Webspace/Limits.php | 23 ++-- tests/WebspaceTest.php | 150 ++++++++++----------- 3 files changed, 90 insertions(+), 87 deletions(-) diff --git a/src/PleskX/Api/Struct/Webspace/Hosting.php b/src/PleskX/Api/Struct/Webspace/Hosting.php index 5b72ba9b..fe4fc64b 100644 --- a/src/PleskX/Api/Struct/Webspace/Hosting.php +++ b/src/PleskX/Api/Struct/Webspace/Hosting.php @@ -14,7 +14,7 @@ public function __construct($apiResponse) $this->_hostingScalarProperties($apiResponse, ['property']); } - private function _hostingScalarProperties($apiResponse,$arrayElement) + private function _hostingScalarProperties($apiResponse, array $arrayElement) { $sxe = new \SimpleXmlIterator($apiResponse->asXML()); for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { @@ -22,7 +22,7 @@ private function _hostingScalarProperties($apiResponse,$arrayElement) $this->types[$k] = new \stdClass(); if ( $sxe->hasChildren() ) { foreach ($sxe->getChildren() as $element => $value) { - if ( in_array($element, $arrayElement) ) { + if ( FALSE !== in_array($element, $arrayElement) ) { $this->types[$k]->{parent::_underToCamel($value->name)} = $value->value; } else { $this->types[$k]->{parent::_underToCamel($element)} = $value; diff --git a/src/PleskX/Api/Struct/Webspace/Limits.php b/src/PleskX/Api/Struct/Webspace/Limits.php index c0c0a707..da7ed927 100644 --- a/src/PleskX/Api/Struct/Webspace/Limits.php +++ b/src/PleskX/Api/Struct/Webspace/Limits.php @@ -6,25 +6,28 @@ class Limits extends \PleskX\Api\Struct { - /** @var stdObject **/ - public $limits; + /** @var stdClass **/ + public $limit; /** @var string **/ public $overuse; public function __construct($apiResponse) { - $this->_limitScalarProperties($apiResponse); + $this->_limitScalarProperties($apiResponse,['limit']); } - private function _limitScalarProperties( $apiResponse ) + private function _limitScalarProperties($apiResponse, array $arrayElement) { - foreach ($apiResponse as $attr => $obj) { - if (is_array($obj)) { - foreach ($obj as $key => $v) { - $this->{$attr}->{parent::_underToCamel($v->name)} = $v->value; - } - } else $this->{$this->_underToCamel($attr)} = $obj; + foreach( $arrayElement as $el ) { + $this->{$el} = new \stdClass(); + } + $sxe = new \SimpleXmlIterator($apiResponse->asXML()); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + if ( FALSE !== in_array($k, $arrayElement) ) { + $this->{$k}->{parent::_underToCamel($sxe->current()->name)} = $sxe->current()->value; + } else $this->{parent::_underToCamel($k)} = $sxe->current(); } } diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index 43c68b6f..1cd4ded8 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -55,55 +55,55 @@ private function _createSite($webspace) ]); } - // public function testGetPermissionDescriptor() - // { - // $descriptor = $this->_client->webspace()->getPermissionDescriptor(); - // $this->assertInternalType('array', $descriptor->permissions); - // $this->assertGreaterThan(0, count($descriptor->permissions)); - // } - - // public function testGetLimitDescriptor() - // { - // $descriptor = $this->_client->webspace()->getLimitDescriptor(); - // $this->assertInternalType('array', $descriptor->limits); - // $this->assertGreaterThan(0, count($descriptor->limits)); - // } - - // public function testGetPhysicalHostingDescriptor() - // { - // $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); - // $this->assertInternalType('array', $descriptor->properties); - // $this->assertGreaterThan(0, count($descriptor->properties)); - - // $ftpLoginProperty = $descriptor->properties['ftp_login']; - // $this->assertEquals('ftp_login', $ftpLoginProperty->name); - // $this->assertEquals('string', $ftpLoginProperty->type); - // } - - // public function testCreate() - // { - // $webspace = $this->_createWebspace(); - // $this->assertInternalType('integer', $webspace->id); - // $this->assertGreaterThan(0, $webspace->id); - - // $this->_client->webspace()->delete('id', $webspace->id); - // } - - // public function testDelete() - // { - // $webspace = $this->_createWebspace(); - // $result = $this->_client->webspace()->delete('id', $webspace->id); - // $this->assertTrue($result); - // } - - // public function testGet() - // { - // $webspace = $this->_createWebspace(); - // $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - // $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); - - // $this->_client->webspace()->delete('id', $webspace->id); - // } + public function testGetPermissionDescriptor() + { + $descriptor = $this->_client->webspace()->getPermissionDescriptor(); + $this->assertInternalType('array', $descriptor->permissions); + $this->assertGreaterThan(0, count($descriptor->permissions)); + } + + public function testGetLimitDescriptor() + { + $descriptor = $this->_client->webspace()->getLimitDescriptor(); + $this->assertInternalType('array', $descriptor->limits); + $this->assertGreaterThan(0, count($descriptor->limits)); + } + + public function testGetPhysicalHostingDescriptor() + { + $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); + $this->assertInternalType('array', $descriptor->properties); + $this->assertGreaterThan(0, count($descriptor->properties)); + + $ftpLoginProperty = $descriptor->properties['ftp_login']; + $this->assertEquals('ftp_login', $ftpLoginProperty->name); + $this->assertEquals('string', $ftpLoginProperty->type); + } + + public function testCreate() + { + $webspace = $this->_createWebspace(); + $this->assertInternalType('integer', $webspace->id); + $this->assertGreaterThan(0, $webspace->id); + + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() + { + $webspace = $this->_createWebspace(); + $result = $this->_client->webspace()->delete('id', $webspace->id); + $this->assertTrue($result); + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); + + $this->_client->webspace()->delete('id', $webspace->id); + } public function testData() { @@ -114,40 +114,40 @@ public function testData() } - // public function testCreateSite() - // { - // $webspace = $this->_createWebspace(); - // $site = $this->_createSite($webspace); + public function testCreateSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); - // $this->assertInternalType('integer', $site->id); - // $this->assertGreaterThan(0, $site->id); + $this->assertInternalType('integer', $site->id); + $this->assertGreaterThan(0, $site->id); - // $this->_client->site()->delete('id', $site->id); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } - // public function testDeleteSite() - // { - // $webspace = $this->_createWebspace(); - // $site = $this->_createSite($webspace); + public function testDeleteSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); - // $result = $this->_client->site()->delete('id', $site->id); - // $this->assertTrue($result); + $result = $this->_client->site()->delete('id', $site->id); + $this->assertTrue($result); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + $this->_client->webspace()->delete('id', $webspace->id); + } - // public function testGetSite() - // { - // $webspace = $this->_createWebspace(); - // $site = $this->_createSite($webspace); + public function testGetSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); - // $siteInfo = $this->_client->site()->get('id', $site->id); - // $this->assertEquals($this->siteName, $siteInfo->name); + $siteInfo = $this->_client->site()->get('id', $site->id); + $this->assertEquals($this->siteName, $siteInfo->name); - // $this->_client->site()->delete('id', $site->id); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } } From 694924b012b4378bd65f73f02c05e581ddac9213 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 6 Oct 2015 11:40:36 -0300 Subject: [PATCH 05/35] mapping fix --- src/PleskX/Api/Struct.php | 10 +++++----- src/PleskX/Api/Struct/Webspace/Data.php | 2 +- src/PleskX/Api/Struct/Webspace/GeneralInfo.php | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/PleskX/Api/Struct.php b/src/PleskX/Api/Struct.php index 6d5c5978..7a996302 100644 --- a/src/PleskX/Api/Struct.php +++ b/src/PleskX/Api/Struct.php @@ -20,12 +20,13 @@ public function __set($property, $value) */ protected function _initScalarProperties($apiResponse, array $properties) { + foreach ($properties as $property) { - if (is_array($property) || is_object($property)) { + if (is_array($property)) { $classPropertyName = current($property); $value = $apiResponse->{key($property)}; } else { - $classPropertyName = $this->_underToCamel(str_replace('-', '_', $property)); + $classPropertyName = $this->_underToCamel($property); $value = $apiResponse->$property; } @@ -40,9 +41,8 @@ protected function _initScalarProperties($apiResponse, array $properties) } else if ('boolean' == $propertyType) { $value = in_array((string)$value, ['true', 'on', 'enabled']); } else { - if ( class_exists($propertyType) ) { - $value = new $propertyType($value); - } else + if ( class_exists($propertyType) ) $value = new $propertyType($value); + else throw new \Exception("Unknown property type '$propertyType'."); } diff --git a/src/PleskX/Api/Struct/Webspace/Data.php b/src/PleskX/Api/Struct/Webspace/Data.php index 184f50bc..b4d74ea2 100644 --- a/src/PleskX/Api/Struct/Webspace/Data.php +++ b/src/PleskX/Api/Struct/Webspace/Data.php @@ -34,7 +34,7 @@ public function __construct($apiResponse) 'limits', 'stat', 'prefs', - 'disk-usage', + 'disk_usage', 'performance' ]); } diff --git a/src/PleskX/Api/Struct/Webspace/GeneralInfo.php b/src/PleskX/Api/Struct/Webspace/GeneralInfo.php index 34bc3bbf..ce8fe00e 100644 --- a/src/PleskX/Api/Struct/Webspace/GeneralInfo.php +++ b/src/PleskX/Api/Struct/Webspace/GeneralInfo.php @@ -52,18 +52,18 @@ public function __construct($apiResponse) $this->_initScalarProperties($apiResponse, [ 'cr_date', 'name', - 'ascii-name', + ['ascii-name' => 'asciiName'], 'status', 'real_size', - 'owner-login', + ['owner-login' => 'ownerLogin'], 'dns_ip_address', 'htype', 'guid', - 'vendor-guid', - 'external-id', - 'sb-site-uuid', + ['vendor-guid' => 'vendorGuid'], + ['external-id' => 'externalId'], + ['sb-site-uuid' => 'sbSiteUuid'], 'description', - 'admin-description' + ['admin-description' => 'adminDescription'] ]); } } \ No newline at end of file From 5b76100935098c496b44a8db985bc952b8acff08 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 6 Oct 2015 16:42:26 -0300 Subject: [PATCH 06/35] adding traffic information --- src/PleskX/Api/Operator/Webspace.php | 20 +++ src/PleskX/Api/Struct/Webspace/Traffic.php | 48 ++++++ tests/WebspaceTest.php | 176 ++++++++++++--------- 3 files changed, 168 insertions(+), 76 deletions(-) create mode 100644 src/PleskX/Api/Struct/Webspace/Traffic.php diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index 4ea01f80..ede599db 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -93,5 +93,25 @@ public function getData($field, $value) return new Struct\Data($response->data); } + /** + * Get Traffic of webspace + * + * @param string $field + * @param integer|string $value + * @param DateTime $sinceDate optional + * @param DateTime $toDate optional + * @return Struct\Data + */ + public function getTraffic($field, $value, $sinceDate = NULL, $toDate = NULL ) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('webspace')->addChild('get_traffic'); + $getTag->addChild('filter')->addChild($field, $value); + if ( $sinceDate ) $getTag->addChild('since_date', $sinceDate->format('Y-m-d')); + if ( $toDate ) $getTag->addChild('to_date', $toDate->format('Y-m-d')); + $response = $this->_client->request($packet); + return new Struct\Traffic($response->traffic); + } + } diff --git a/src/PleskX/Api/Struct/Webspace/Traffic.php b/src/PleskX/Api/Struct/Webspace/Traffic.php new file mode 100644 index 00000000..91b9d96d --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Traffic.php @@ -0,0 +1,48 @@ +_trafficScalarProperties($apiResponse); + } + + /** + * Initialize list of scalar properties of traffic response + * + * @param \SimpleXMLElement $apiResponse + * @throws \Exception + */ + protected function _trafficScalarProperties( $apiResponse ) { + $this->sinceDate = $apiResponse->xpath('//traffic')[0]->date; + $this->toDate = $apiResponse->xpath('//traffic[last()]')[0]->date; + foreach( $apiResponse as $i => $traffic ) { + $this->httpIn += $traffic->http_in; + $this->httpOut += $traffic->http_out; + $this->ftpIn += $traffic->ftp_in; + $this->ftpOUt += $traffic->ftp_out; + } + } + +} \ No newline at end of file diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index 1cd4ded8..80880935 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -6,6 +6,7 @@ class WebspaceTest extends TestCase private $webspaceSiteName = 'example-test-parent.dom'; private $siteName = 'example-test-child.dom'; + private $trafficTestSite = 'exal.com.br'; //SITE HOSTED BY MY PLESK /** * @@ -55,99 +56,122 @@ private function _createSite($webspace) ]); } - public function testGetPermissionDescriptor() + // public function testGetPermissionDescriptor() + // { + // $descriptor = $this->_client->webspace()->getPermissionDescriptor(); + // $this->assertInternalType('array', $descriptor->permissions); + // $this->assertGreaterThan(0, count($descriptor->permissions)); + // } + + // public function testGetLimitDescriptor() + // { + // $descriptor = $this->_client->webspace()->getLimitDescriptor(); + // $this->assertInternalType('array', $descriptor->limits); + // $this->assertGreaterThan(0, count($descriptor->limits)); + // } + + // public function testGetPhysicalHostingDescriptor() + // { + // $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); + // $this->assertInternalType('array', $descriptor->properties); + // $this->assertGreaterThan(0, count($descriptor->properties)); + + // $ftpLoginProperty = $descriptor->properties['ftp_login']; + // $this->assertEquals('ftp_login', $ftpLoginProperty->name); + // $this->assertEquals('string', $ftpLoginProperty->type); + // } + + // public function testCreate() + // { + // $webspace = $this->_createWebspace(); + // $this->assertInternalType('integer', $webspace->id); + // $this->assertGreaterThan(0, $webspace->id); + + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testDelete() + // { + // $webspace = $this->_createWebspace(); + // $result = $this->_client->webspace()->delete('id', $webspace->id); + // $this->assertTrue($result); + // } + + // public function testGet() + // { + // $webspace = $this->_createWebspace(); + // $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); + // $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); + + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testData() + // { + // $webspace = $this->_createWebspace(); + // $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); + // $this->assertEquals($this->webspaceSiteName, $webspaceInfo->genInfo->name); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + + public function testGetTrafficThisMonth() { - $descriptor = $this->_client->webspace()->getPermissionDescriptor(); - $this->assertInternalType('array', $descriptor->permissions); - $this->assertGreaterThan(0, count($descriptor->permissions)); + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + new DateTime('@'.strtotime('first day of this month')) + ); + $this->assertInternalType('integer', $webspaceTraffic->httpIn); } - public function testGetLimitDescriptor() + public function testGetTrafficLastMonth() { - $descriptor = $this->_client->webspace()->getLimitDescriptor(); - $this->assertInternalType('array', $descriptor->limits); - $this->assertGreaterThan(0, count($descriptor->limits)); + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + new DateTime('@'.strtotime('first day of previous month')), + new DateTime('@'.strtotime('last day of previous month'))) + ; + $this->assertInternalType('integer', $webspaceTraffic->httpIn); } - public function testGetPhysicalHostingDescriptor() + public function testGetTraffic() { - $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); - $this->assertInternalType('array', $descriptor->properties); - $this->assertGreaterThan(0, count($descriptor->properties)); - - $ftpLoginProperty = $descriptor->properties['ftp_login']; - $this->assertEquals('ftp_login', $ftpLoginProperty->name); - $this->assertEquals('string', $ftpLoginProperty->type); - } - - public function testCreate() - { - $webspace = $this->_createWebspace(); - $this->assertInternalType('integer', $webspace->id); - $this->assertGreaterThan(0, $webspace->id); - - $this->_client->webspace()->delete('id', $webspace->id); - } - - public function testDelete() - { - $webspace = $this->_createWebspace(); - $result = $this->_client->webspace()->delete('id', $webspace->id); - $this->assertTrue($result); - } - - public function testGet() - { - $webspace = $this->_createWebspace(); - $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); - - $this->_client->webspace()->delete('id', $webspace->id); + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite ); + $this->assertInternalType('integer', $webspaceTraffic->httpIn); } - public function testData() - { - $webspace = $this->_createWebspace(); - $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); - $this->assertEquals($this->webspaceSiteName, $webspaceInfo->genInfo->name); - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testCreateSite() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $this->assertInternalType('integer', $site->id); + // $this->assertGreaterThan(0, $site->id); - public function testCreateSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } - $this->assertInternalType('integer', $site->id); - $this->assertGreaterThan(0, $site->id); + // public function testDeleteSite() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // $result = $this->_client->site()->delete('id', $site->id); + // $this->assertTrue($result); - public function testDeleteSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); + // $this->_client->webspace()->delete('id', $webspace->id); + // } - $result = $this->_client->site()->delete('id', $site->id); - $this->assertTrue($result); + // public function testGetSite() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); - $this->_client->webspace()->delete('id', $webspace->id); - } - - public function testGetSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); + // $siteInfo = $this->_client->site()->get('id', $site->id); + // $this->assertEquals($this->siteName, $siteInfo->name); - $siteInfo = $this->_client->site()->get('id', $site->id); - $this->assertEquals($this->siteName, $siteInfo->name); - - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } } From 876b2d27ce7fb7f06c90fa7d2305a5db45fdf65f Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 6 Oct 2015 18:20:01 -0300 Subject: [PATCH 07/35] bugfix: check traffic return --- src/PleskX/Api/Struct/Webspace/Traffic.php | 6 +++++- tests/WebspaceTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PleskX/Api/Struct/Webspace/Traffic.php b/src/PleskX/Api/Struct/Webspace/Traffic.php index 91b9d96d..e02e79b2 100644 --- a/src/PleskX/Api/Struct/Webspace/Traffic.php +++ b/src/PleskX/Api/Struct/Webspace/Traffic.php @@ -35,7 +35,11 @@ public function __construct($apiResponse) * @throws \Exception */ protected function _trafficScalarProperties( $apiResponse ) { - $this->sinceDate = $apiResponse->xpath('//traffic')[0]->date; + + $first = $apiResponse->xpath('//traffic'); + if ( ! $first ) return; + + $this->sinceDate = $first[0]->date; $this->toDate = $apiResponse->xpath('//traffic[last()]')[0]->date; foreach( $apiResponse as $i => $traffic ) { $this->httpIn += $traffic->http_in; diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index 80880935..630ac033 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -6,7 +6,7 @@ class WebspaceTest extends TestCase private $webspaceSiteName = 'example-test-parent.dom'; private $siteName = 'example-test-child.dom'; - private $trafficTestSite = 'exal.com.br'; //SITE HOSTED BY MY PLESK + private $trafficTestSite = 'worksecurity.net'; //SITE HOSTED BY MY PLESK /** * From d79e07ac00983a71123432d98d7526970667f555 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 6 Oct 2015 20:04:53 -0300 Subject: [PATCH 08/35] manage ftp users --- src/PleskX/Api/Operator/FtpUser.php | 46 ++++++++++++++++++++++++++++ src/PleskX/Api/Operator/Webspace.php | 1 - 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/PleskX/Api/Operator/FtpUser.php b/src/PleskX/Api/Operator/FtpUser.php index 76f113c7..ef19599f 100644 --- a/src/PleskX/Api/Operator/FtpUser.php +++ b/src/PleskX/Api/Operator/FtpUser.php @@ -3,7 +3,53 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\FtpUser as Struct; + class FtpUser extends \PleskX\Api\Operator { + + /** + * Create FTP account + * + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['ftp-user' => ['add' => $properties]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('ftp-user')->addChild('del')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + /** + * Get FTP accounts + * + * @param string $field + * @param integer|string $value + * @return Struct\GeneralInfo + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('ftp-user')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return new Struct\GeneralInfo($response); + } + } diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index ede599db..0b9a13bc 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -67,7 +67,6 @@ public function get($field, $value) $response = $this->_client->request($packet); return new Struct\GeneralInfo($response->data->gen_info); } - /** * Get Data of webspace From 0e52a589a0a390ef3629141c31cadd9c7ddc669d Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 6 Oct 2015 20:08:46 -0300 Subject: [PATCH 09/35] manage ftp users --- src/PleskX/Api/Struct/FtpUser/GeneralInfo.php | 34 ++++++++ src/PleskX/Api/Struct/FtpUser/Info.php | 18 +++++ tests/FtpUserTest.php | 78 +++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 src/PleskX/Api/Struct/FtpUser/GeneralInfo.php create mode 100644 src/PleskX/Api/Struct/FtpUser/Info.php create mode 100644 tests/FtpUserTest.php diff --git a/src/PleskX/Api/Struct/FtpUser/GeneralInfo.php b/src/PleskX/Api/Struct/FtpUser/GeneralInfo.php new file mode 100644 index 00000000..7c7626c9 --- /dev/null +++ b/src/PleskX/Api/Struct/FtpUser/GeneralInfo.php @@ -0,0 +1,34 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + 'home', + 'quota', + ['webspace-id' => 'webspaceId'], + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/FtpUser/Info.php b/src/PleskX/Api/Struct/FtpUser/Info.php new file mode 100644 index 00000000..639b2e97 --- /dev/null +++ b/src/PleskX/Api/Struct/FtpUser/Info.php @@ -0,0 +1,18 @@ +_initScalarProperties($apiResponse, [ + 'id' + ]); + } +} \ No newline at end of file diff --git a/tests/FtpUserTest.php b/tests/FtpUserTest.php new file mode 100644 index 00000000..67db3a04 --- /dev/null +++ b/tests/FtpUserTest.php @@ -0,0 +1,78 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'passwordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + + private function _createFtpUser( $webspace ) + { + return $this->_client->ftpUser()->create([ + 'name' => 'newftpuser', + 'password' => 'userpassword', + 'home' => '', + 'webspace-id' => $webspace->id + ]); + } + + public function testCreate() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $this->assertGreaterThan(0, $ftpuser->id); + $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $result = $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->assertTrue($result); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $ftpUserInfo = $this->_client->ftpUser()->get('id', $ftpuser->id); + $this->assertGreaterThan(0, $ftpUserInfo->id); + $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + +} From e086ba788dc13bc14a925ba4c8bac48bd7ec890d Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Wed, 7 Oct 2015 16:34:23 -0300 Subject: [PATCH 10/35] Returning more then ftpuser --- src/PleskX/Api/Operator/FtpUser.php | 14 +++++++++++--- tests/FtpUserTest.php | 21 ++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/PleskX/Api/Operator/FtpUser.php b/src/PleskX/Api/Operator/FtpUser.php index ef19599f..01fa8635 100644 --- a/src/PleskX/Api/Operator/FtpUser.php +++ b/src/PleskX/Api/Operator/FtpUser.php @@ -41,15 +41,23 @@ public function delete($field, $value) * * @param string $field * @param integer|string $value - * @return Struct\GeneralInfo + * @return mixed Struct\GeneralInfo|Array */ public function get($field, $value) { $packet = $this->_client->getPacket(); $getTag = $packet->addChild('ftp-user')->addChild('get'); $getTag->addChild('filter')->addChild($field, $value); - $response = $this->_client->request($packet); - return new Struct\GeneralInfo($response); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'ftp-user'}->get->result; + if ( $field == 'id' ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; } } diff --git a/tests/FtpUserTest.php b/tests/FtpUserTest.php index 67db3a04..158dffa6 100644 --- a/tests/FtpUserTest.php +++ b/tests/FtpUserTest.php @@ -37,10 +37,10 @@ private function _createWebspace() } - private function _createFtpUser( $webspace ) + private function _createFtpUser( $webspace, $name = 'newftpuser' ) { return $this->_client->ftpUser()->create([ - 'name' => 'newftpuser', + 'name' => $name, 'password' => 'userpassword', 'home' => '', 'webspace-id' => $webspace->id @@ -75,4 +75,19 @@ public function testGet() $this->_client->webspace()->delete('id', $webspace->id); } -} + public function testGetAllWebspace() + { + $webspace = $this->_createWebspace(); + $ftpuser1 = $this->_createFtpUser( $webspace ); + $ftpuser2 = $this->_createFtpUser( $webspace, 'ftpuser22' ); + + $ftpUserInfo = $this->_client->ftpUser()->get('webspace-id', $webspace->id); + $this->assertGreaterThan(0, $ftpuser2->id); + + $this->_client->ftpuser()->delete('id', $ftpuser1->id); + $this->_client->ftpuser()->delete('id', $ftpuser2->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + +} \ No newline at end of file From b5eacc47cd67a43228c8ec22735a97873c30ab67 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Wed, 7 Oct 2015 17:03:04 -0300 Subject: [PATCH 11/35] Improving return of ftpuser get --- src/PleskX/Api/Operator/FtpUser.php | 6 ++++-- tests/FtpUserTest.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/PleskX/Api/Operator/FtpUser.php b/src/PleskX/Api/Operator/FtpUser.php index 01fa8635..53b55769 100644 --- a/src/PleskX/Api/Operator/FtpUser.php +++ b/src/PleskX/Api/Operator/FtpUser.php @@ -49,12 +49,14 @@ public function get($field, $value) $getTag = $packet->addChild('ftp-user')->addChild('get'); $getTag->addChild('filter')->addChild($field, $value); $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'ftp-user'}->get->result; - if ( $field == 'id' ) { + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { $ret = new Struct\GeneralInfo($response); } else { $ret = []; foreach ($response as $f) { - $ret[] = new Struct\GeneralInfo($f); + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); } } return $ret; diff --git a/tests/FtpUserTest.php b/tests/FtpUserTest.php index 158dffa6..6a5e0c60 100644 --- a/tests/FtpUserTest.php +++ b/tests/FtpUserTest.php @@ -82,7 +82,8 @@ public function testGetAllWebspace() $ftpuser2 = $this->_createFtpUser( $webspace, 'ftpuser22' ); $ftpUserInfo = $this->_client->ftpUser()->get('webspace-id', $webspace->id); - $this->assertGreaterThan(0, $ftpuser2->id); + $this->assertGreaterThan(0, $ftpUserInfo[0]->id); + $this->assertGreaterThan(0, $ftpUserInfo[1]->id); $this->_client->ftpuser()->delete('id', $ftpuser1->id); $this->_client->ftpuser()->delete('id', $ftpuser2->id); From d16ebd12e1d1778dd3924778756673ddf8b01263 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Wed, 7 Oct 2015 18:59:17 -0300 Subject: [PATCH 12/35] Adding database manage --- src/PleskX/Api/Operator/Database.php | 55 +++++++++++ .../Api/Struct/Database/GeneralInfo.php | 38 ++++++++ src/PleskX/Api/Struct/Database/Info.php | 18 ++++ tests/DatabaseTest.php | 93 +++++++++++++++++++ 4 files changed, 204 insertions(+) create mode 100644 src/PleskX/Api/Struct/Database/GeneralInfo.php create mode 100644 src/PleskX/Api/Struct/Database/Info.php create mode 100644 tests/DatabaseTest.php diff --git a/src/PleskX/Api/Operator/Database.php b/src/PleskX/Api/Operator/Database.php index 98c00472..5b6b56e0 100644 --- a/src/PleskX/Api/Operator/Database.php +++ b/src/PleskX/Api/Operator/Database.php @@ -3,7 +3,62 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\Database as Struct; + class Database extends \PleskX\Api\Operator { + /** + * Create database + * + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['database' => ['add-db' => $properties]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * Delete Database + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('database')->addChild('del-db')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + /** + * Get database + * + * @param string $field + * @param integer|string $value + * @return mixed Struct\GeneralInfo|Array + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('database')->addChild('get-db'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'database'}->{'get-db'}->result; + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; + } } diff --git a/src/PleskX/Api/Struct/Database/GeneralInfo.php b/src/PleskX/Api/Struct/Database/GeneralInfo.php new file mode 100644 index 00000000..43b1f61f --- /dev/null +++ b/src/PleskX/Api/Struct/Database/GeneralInfo.php @@ -0,0 +1,38 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + 'type', + ['webspace-id' => 'webspaceId'], + ['default-user-id' => 'defaultUserId'], + ['db-server-id' => 'dbServerId'], + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Database/Info.php b/src/PleskX/Api/Struct/Database/Info.php new file mode 100644 index 00000000..3b77f55d --- /dev/null +++ b/src/PleskX/Api/Struct/Database/Info.php @@ -0,0 +1,18 @@ +_initScalarProperties($apiResponse, [ + 'id' + ]); + } +} \ No newline at end of file diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php new file mode 100644 index 00000000..45427a63 --- /dev/null +++ b/tests/DatabaseTest.php @@ -0,0 +1,93 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'passwordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + + private function _createDatabase( $webspace, $name = 'newdatabase' ) + { + return $this->_client->database()->create([ + 'webspace-id' => $webspace->id, + 'name' => $name, + 'type' => 'mysql' + ]); + } + + // public function testCreate() + // { + // $webspace = $this->_createWebspace(); + // $database = $this->_createDatabase( $webspace ); + // $this->assertGreaterThan(0, $database->id); + // $this->_client->database()->delete('id', $database->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testDelete() + // { + // $webspace = $this->_createWebspace(); + // $database = $this->_createDatabase( $webspace ); + // $result = $this->_client->database()->delete('id', $database->id); + // $this->assertTrue($result); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testGet() + // { + // $webspace = $this->_createWebspace(); + // $database = $this->_createDatabase( $webspace ); + // $databaseInfo = $this->_client->database()->get('id', $database->id); + // $this->assertGreaterThan(0, $databaseInfo->id); + // $this->_client->database()->delete('id', $database->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + public function testGetAllWebspace() + { + $webspace = $this->_createWebspace(); + $database1 = $this->_createDatabase( $webspace ); + $database2 = $this->_createDatabase( $webspace, 'database2' ); + + $databaseInfo = $this->_client->database()->get('webspace-id', $webspace->id); + $this->assertGreaterThan(0, $databaseInfo[0]->id); + $this->assertGreaterThan(0, $databaseInfo[1]->id); + + $this->_client->database()->delete('id', $database1->id); + $this->_client->database()->delete('id', $database2->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + +} \ No newline at end of file From 6d32bacdb8135a016b1773bcf239f16b48f957e1 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Wed, 7 Oct 2015 19:53:56 -0300 Subject: [PATCH 13/35] adding database user management --- src/PleskX/Api/Operator/Database.php | 56 +++++++++++ .../Api/Struct/Database/GeneralInfoUser.php | 26 ++++++ src/PleskX/Api/Struct/Database/InfoUser.php | 8 ++ tests/DatabaseTest.php | 93 +++++++++++++------ 4 files changed, 156 insertions(+), 27 deletions(-) create mode 100644 src/PleskX/Api/Struct/Database/GeneralInfoUser.php create mode 100644 src/PleskX/Api/Struct/Database/InfoUser.php diff --git a/src/PleskX/Api/Operator/Database.php b/src/PleskX/Api/Operator/Database.php index 5b6b56e0..c96cb434 100644 --- a/src/PleskX/Api/Operator/Database.php +++ b/src/PleskX/Api/Operator/Database.php @@ -61,4 +61,60 @@ public function get($field, $value) } return $ret; } + + + /** + * Create database user + * + * @param array $properties + * @return Struct\InfoUser + */ + public function createUser($properties) + { + $properties = ['database' => ['add-db-user' => $properties]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\InfoUser($response); + } + + /** + * Delete Database user + * @param string $field + * @param integer|string $value + * @return bool + */ + public function deleteUser($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('database')->addChild('del-db-user')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + /** + * Get database user + * + * @param string $field + * @param integer|string $value + * @return mixed Struct\GeneralInfoUser|Array + */ + public function getUser($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('database')->addChild('get-db-users'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'database'}->{'get-db-users'}->result; + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { + $ret = new Struct\GeneralInfoUser($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfoUser($f); + } + } + return $ret; + } + } diff --git a/src/PleskX/Api/Struct/Database/GeneralInfoUser.php b/src/PleskX/Api/Struct/Database/GeneralInfoUser.php new file mode 100644 index 00000000..eb13d0b8 --- /dev/null +++ b/src/PleskX/Api/Struct/Database/GeneralInfoUser.php @@ -0,0 +1,26 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'login', + ['db-id' => 'dbId'], + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Database/InfoUser.php b/src/PleskX/Api/Struct/Database/InfoUser.php new file mode 100644 index 00000000..c4640bab --- /dev/null +++ b/src/PleskX/Api/Struct/Database/InfoUser.php @@ -0,0 +1,8 @@ +_createWebspace(); - // $database = $this->_createDatabase( $webspace ); - // $this->assertGreaterThan(0, $database->id); - // $this->_client->database()->delete('id', $database->id); - // $this->_client->webspace()->delete('id', $webspace->id); - // } - - // public function testDelete() - // { - // $webspace = $this->_createWebspace(); - // $database = $this->_createDatabase( $webspace ); - // $result = $this->_client->database()->delete('id', $database->id); - // $this->assertTrue($result); - // $this->_client->webspace()->delete('id', $webspace->id); - // } - - // public function testGet() - // { - // $webspace = $this->_createWebspace(); - // $database = $this->_createDatabase( $webspace ); - // $databaseInfo = $this->_client->database()->get('id', $database->id); - // $this->assertGreaterThan(0, $databaseInfo->id); - // $this->_client->database()->delete('id', $database->id); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + private function _createUser( $database, $login = 'newuserdatabase' ) + { + return $this->_client->database()->createUser([ + 'db-id' => $database->id, + 'login' => $login, + 'password' => 'dbpassword' + ]); + } + + public function testCreate() + { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $this->assertGreaterThan(0, $database->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() + { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $result = $this->_client->database()->delete('id', $database->id); + $this->assertTrue($result); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $databaseInfo = $this->_client->database()->get('id', $database->id); + $this->assertGreaterThan(0, $databaseInfo->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } public function testGetAllWebspace() { @@ -89,5 +98,35 @@ public function testGetAllWebspace() $this->_client->webspace()->delete('id', $webspace->id); } + public function testCreateUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $this->assertGreaterThan(0, $user->id); + $this->_client->database()->deleteUser('id', $user->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDeleteUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $result = $this->_client->database()->deleteUser('id', $user->id); + $this->assertTrue($result); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testGetUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $userInfo = $this->_client->database()->getUser('id', $user->id); + $this->assertGreaterThan(0, $userInfo->id); + $this->_client->database()->deleteUser('id', $user->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } } \ No newline at end of file From b3785530c2fb1e8e4e68088b8b88baa623848f71 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Wed, 7 Oct 2015 20:22:54 -0300 Subject: [PATCH 14/35] adding os version in stat call on server --- src/PleskX/Api/Struct/Server/Statistics/Version.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/PleskX/Api/Struct/Server/Statistics/Version.php b/src/PleskX/Api/Struct/Server/Statistics/Version.php index d01e6b77..a446ddc9 100644 --- a/src/PleskX/Api/Struct/Server/Statistics/Version.php +++ b/src/PleskX/Api/Struct/Server/Statistics/Version.php @@ -12,11 +12,19 @@ class Version extends \PleskX\Api\Struct /** @var string */ public $version; + /** @var string */ + public $pleskOs; + + /** @var string */ + public $pleskOsVersion; + public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ ['plesk_name' => 'internalName'], ['plesk_version' => 'version'], + ['plesk_os' => 'pleskOs'], + ['plesk_os_version' => 'pleskOsVersion'], ]); } } \ No newline at end of file From ff8f5e9462e6a8db7f02820a60a10b5d994a061e Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Wed, 7 Oct 2015 21:23:33 -0300 Subject: [PATCH 15/35] Adding ServicePlan and subscriptions return on WebSpace --- src/PleskX/Api/Operator/ServicePlan.php | 16 ++ src/PleskX/Api/Operator/Webspace.php | 1 + src/PleskX/Api/Struct/ServicePlan/Info.php | 21 +++ src/PleskX/Api/Struct/Webspace/Data.php | 6 +- src/PleskX/Api/Struct/Webspace/Plan.php | 14 ++ .../Api/Struct/Webspace/Subscription.php | 24 +++ .../Api/Struct/Webspace/Subscriptions.php | 18 ++ tests/ServicePlanTest.php | 53 ++++++ tests/WebspaceTest.php | 166 +++++++++--------- 9 files changed, 235 insertions(+), 84 deletions(-) create mode 100644 src/PleskX/Api/Struct/ServicePlan/Info.php create mode 100644 src/PleskX/Api/Struct/Webspace/Plan.php create mode 100644 src/PleskX/Api/Struct/Webspace/Subscription.php create mode 100644 src/PleskX/Api/Struct/Webspace/Subscriptions.php create mode 100644 tests/ServicePlanTest.php diff --git a/src/PleskX/Api/Operator/ServicePlan.php b/src/PleskX/Api/Operator/ServicePlan.php index 37644cf1..586e25ae 100644 --- a/src/PleskX/Api/Operator/ServicePlan.php +++ b/src/PleskX/Api/Operator/ServicePlan.php @@ -3,7 +3,23 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\ServicePlan as Struct; + class ServicePlan extends \PleskX\Api\Operator { + /** + * @param string $field + * @param integer|string $value + * @return Struct\GeneralInfo + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('service-plan')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'service-plan'}->get->result; + return new Struct\Info($response); + } + } diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index 0b9a13bc..b1a7e620 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -88,6 +88,7 @@ public function getData($field, $value) $dataset->addChild('prefs'); $dataset->addChild('disk_usage'); $dataset->addChild('performance'); + $dataset->addChild('subscriptions'); $response = $this->_client->request($packet); return new Struct\Data($response->data); } diff --git a/src/PleskX/Api/Struct/ServicePlan/Info.php b/src/PleskX/Api/Struct/ServicePlan/Info.php new file mode 100644 index 00000000..e58e43cb --- /dev/null +++ b/src/PleskX/Api/Struct/ServicePlan/Info.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Data.php b/src/PleskX/Api/Struct/Webspace/Data.php index b4d74ea2..a8b8fb59 100644 --- a/src/PleskX/Api/Struct/Webspace/Data.php +++ b/src/PleskX/Api/Struct/Webspace/Data.php @@ -26,6 +26,9 @@ class Data extends \PleskX\Api\Struct /** @var PleskX\Api\Struct\Webspace\Perfomance **/ public $performance; + /** @var PleskX\Api\Struct\Webspace\Subscriptions **/ + public $subscriptions; + public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ @@ -35,7 +38,8 @@ public function __construct($apiResponse) 'stat', 'prefs', 'disk_usage', - 'performance' + 'performance', + 'subscriptions' ]); } } \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Plan.php b/src/PleskX/Api/Struct/Webspace/Plan.php new file mode 100644 index 00000000..bff313ed --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Plan.php @@ -0,0 +1,14 @@ +locked = $apiResponse->locked; + $this->synchronized = $apiResponse->synchronized; + $this->plan = new Plan(); + $this->plan->planGuid = $apiResponse->plan->{'plan-guid'}; + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Webspace/Subscriptions.php b/src/PleskX/Api/Struct/Webspace/Subscriptions.php new file mode 100644 index 00000000..dd5e9b38 --- /dev/null +++ b/src/PleskX/Api/Struct/Webspace/Subscriptions.php @@ -0,0 +1,18 @@ +data = []; + foreach ($apiResponse->subscription as $sb) { + $this->data[] = new Subscription($sb); + } + } +} \ No newline at end of file diff --git a/tests/ServicePlanTest.php b/tests/ServicePlanTest.php new file mode 100644 index 00000000..5925529f --- /dev/null +++ b/tests/ServicePlanTest.php @@ -0,0 +1,53 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + public function testGet() + { + $webspace = $this->_createWebspace(); + $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); + $servicePlan = $this->_client->servicePlan()->get('guid', $webspaceInfo->subscriptions->data[0]->plan->planGuid); + $this->assertGreaterThan(0, $servicePlan->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + +} \ No newline at end of file diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index 630ac033..6cd604bd 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -56,63 +56,63 @@ private function _createSite($webspace) ]); } - // public function testGetPermissionDescriptor() - // { - // $descriptor = $this->_client->webspace()->getPermissionDescriptor(); - // $this->assertInternalType('array', $descriptor->permissions); - // $this->assertGreaterThan(0, count($descriptor->permissions)); - // } - - // public function testGetLimitDescriptor() - // { - // $descriptor = $this->_client->webspace()->getLimitDescriptor(); - // $this->assertInternalType('array', $descriptor->limits); - // $this->assertGreaterThan(0, count($descriptor->limits)); - // } - - // public function testGetPhysicalHostingDescriptor() - // { - // $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); - // $this->assertInternalType('array', $descriptor->properties); - // $this->assertGreaterThan(0, count($descriptor->properties)); - - // $ftpLoginProperty = $descriptor->properties['ftp_login']; - // $this->assertEquals('ftp_login', $ftpLoginProperty->name); - // $this->assertEquals('string', $ftpLoginProperty->type); - // } - - // public function testCreate() - // { - // $webspace = $this->_createWebspace(); - // $this->assertInternalType('integer', $webspace->id); - // $this->assertGreaterThan(0, $webspace->id); - - // $this->_client->webspace()->delete('id', $webspace->id); - // } - - // public function testDelete() - // { - // $webspace = $this->_createWebspace(); - // $result = $this->_client->webspace()->delete('id', $webspace->id); - // $this->assertTrue($result); - // } - - // public function testGet() - // { - // $webspace = $this->_createWebspace(); - // $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - // $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); - - // $this->_client->webspace()->delete('id', $webspace->id); - // } - - // public function testData() - // { - // $webspace = $this->_createWebspace(); - // $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); - // $this->assertEquals($this->webspaceSiteName, $webspaceInfo->genInfo->name); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + public function testGetPermissionDescriptor() + { + $descriptor = $this->_client->webspace()->getPermissionDescriptor(); + $this->assertInternalType('array', $descriptor->permissions); + $this->assertGreaterThan(0, count($descriptor->permissions)); + } + + public function testGetLimitDescriptor() + { + $descriptor = $this->_client->webspace()->getLimitDescriptor(); + $this->assertInternalType('array', $descriptor->limits); + $this->assertGreaterThan(0, count($descriptor->limits)); + } + + public function testGetPhysicalHostingDescriptor() + { + $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); + $this->assertInternalType('array', $descriptor->properties); + $this->assertGreaterThan(0, count($descriptor->properties)); + + $ftpLoginProperty = $descriptor->properties['ftp_login']; + $this->assertEquals('ftp_login', $ftpLoginProperty->name); + $this->assertEquals('string', $ftpLoginProperty->type); + } + + public function testCreate() + { + $webspace = $this->_createWebspace(); + $this->assertInternalType('integer', $webspace->id); + $this->assertGreaterThan(0, $webspace->id); + + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() + { + $webspace = $this->_createWebspace(); + $result = $this->_client->webspace()->delete('id', $webspace->id); + $this->assertTrue($result); + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); + + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testData() + { + $webspace = $this->_createWebspace(); + $webspaceInfo = $this->_client->webspace()->getData('id', $webspace->id); + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->genInfo->name); + $this->_client->webspace()->delete('id', $webspace->id); + } public function testGetTrafficThisMonth() @@ -138,40 +138,40 @@ public function testGetTraffic() $this->assertInternalType('integer', $webspaceTraffic->httpIn); } - // public function testCreateSite() - // { - // $webspace = $this->_createWebspace(); - // $site = $this->_createSite($webspace); + public function testCreateSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); - // $this->assertInternalType('integer', $site->id); - // $this->assertGreaterThan(0, $site->id); + $this->assertInternalType('integer', $site->id); + $this->assertGreaterThan(0, $site->id); - // $this->_client->site()->delete('id', $site->id); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } - // public function testDeleteSite() - // { - // $webspace = $this->_createWebspace(); - // $site = $this->_createSite($webspace); + public function testDeleteSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); - // $result = $this->_client->site()->delete('id', $site->id); - // $this->assertTrue($result); + $result = $this->_client->site()->delete('id', $site->id); + $this->assertTrue($result); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + $this->_client->webspace()->delete('id', $webspace->id); + } - // public function testGetSite() - // { - // $webspace = $this->_createWebspace(); - // $site = $this->_createSite($webspace); + public function testGetSite() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); - // $siteInfo = $this->_client->site()->get('id', $site->id); - // $this->assertEquals($this->siteName, $siteInfo->name); + $siteInfo = $this->_client->site()->get('id', $site->id); + $this->assertEquals($this->siteName, $siteInfo->name); - // $this->_client->site()->delete('id', $site->id); - // $this->_client->webspace()->delete('id', $webspace->id); - // } + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } } From 960e7496a073fa58c9f47db987fa7554ecd08aaa Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Thu, 8 Oct 2015 19:22:40 -0300 Subject: [PATCH 16/35] Managing Sites --- src/PleskX/Api/Operator/Site.php | 23 ++++++- src/PleskX/Api/Struct/Site/Data.php | 33 +++++++++ src/PleskX/Api/Struct/Site/DiskUsage.php | 66 ++++++++++++++++++ src/PleskX/Api/Struct/Site/GeneralInfo.php | 69 +++++++++++++++++++ src/PleskX/Api/Struct/Site/Hosting.php | 36 ++++++++++ src/PleskX/Api/Struct/Site/Info.php | 21 ++++++ src/PleskX/Api/Struct/Site/Preference.php | 21 ++++++ src/PleskX/Api/Struct/Site/Stat.php | 69 +++++++++++++++++++ tests/SiteTest.php | 80 +++++++++++++++++++--- tests/WebspaceTest.php | 49 ------------- 10 files changed, 409 insertions(+), 58 deletions(-) create mode 100644 src/PleskX/Api/Struct/Site/Data.php create mode 100644 src/PleskX/Api/Struct/Site/DiskUsage.php create mode 100644 src/PleskX/Api/Struct/Site/GeneralInfo.php create mode 100644 src/PleskX/Api/Struct/Site/Hosting.php create mode 100644 src/PleskX/Api/Struct/Site/Info.php create mode 100644 src/PleskX/Api/Struct/Site/Preference.php create mode 100644 src/PleskX/Api/Struct/Site/Stat.php diff --git a/src/PleskX/Api/Operator/Site.php b/src/PleskX/Api/Operator/Site.php index bb778e11..71d202ee 100644 --- a/src/PleskX/Api/Operator/Site.php +++ b/src/PleskX/Api/Operator/Site.php @@ -3,7 +3,7 @@ namespace PleskX\Api\Operator; -use PleskX\Api\Struct\Webspace as Struct; +use PleskX\Api\Struct\Site as Struct; class Site extends \PleskX\Api\Operator { @@ -23,6 +23,27 @@ public function get($field, $value) return new Struct\GeneralInfo($response->data->gen_info); } + /** + * Get Data of site + * + * @param string $field + * @param integer|string $value + * @return Struct\Data + */ + public function getData($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('site')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $dataset = $getTag->addChild('dataset'); + $dataset->addChild('gen_info'); + $dataset->addChild('hosting'); + $dataset->addChild('stat'); + $dataset->addChild('prefs'); + $dataset->addChild('disk_usage'); + $response = $this->_client->request($packet); + return new Struct\Data($response->data); + } /** * @param array $properties diff --git a/src/PleskX/Api/Struct/Site/Data.php b/src/PleskX/Api/Struct/Site/Data.php new file mode 100644 index 00000000..06e2af03 --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Data.php @@ -0,0 +1,33 @@ +_initScalarProperties($apiResponse, [ + 'gen_info', + 'hosting', + 'stat', + 'prefs', + 'disk_usage', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/DiskUsage.php b/src/PleskX/Api/Struct/Site/DiskUsage.php new file mode 100644 index 00000000..88d6286d --- /dev/null +++ b/src/PleskX/Api/Struct/Site/DiskUsage.php @@ -0,0 +1,66 @@ +_initScalarProperties($apiResponse, [ + 'httpdocs', + 'httpsdocs', + 'subdomains', + 'web_users', + 'anonftp', + 'logs', + 'dbases', + 'mailboxes', + 'webapps', + 'maillists', + 'domaindumps', + 'configs', + 'chroot' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/GeneralInfo.php b/src/PleskX/Api/Struct/Site/GeneralInfo.php new file mode 100644 index 00000000..b0f3e62e --- /dev/null +++ b/src/PleskX/Api/Struct/Site/GeneralInfo.php @@ -0,0 +1,69 @@ +_initScalarProperties($apiResponse, [ + 'cr_date', + 'name', + ['ascii-name' => 'asciiName'], + 'status', + 'real_size', + ['owner-login' => 'ownerLogin'], + 'dns_ip_address', + 'htype', + 'guid', + ['vendor-guid' => 'vendorGuid'], + ['external-id' => 'externalId'], + ['sb-site-uuid' => 'sbSiteUuid'], + 'description', + ['admin-description' => 'adminDescription'] + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Hosting.php b/src/PleskX/Api/Struct/Site/Hosting.php new file mode 100644 index 00000000..5a5cc44e --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Hosting.php @@ -0,0 +1,36 @@ +_hostingScalarProperties($apiResponse, ['property']); + } + + private function _hostingScalarProperties($apiResponse, array $arrayElement) + { + $xml = $apiResponse->asXML(); + $sxe = new \SimpleXmlIterator($xml); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + $this->types[$k] = new \stdClass(); + if ( $sxe->hasChildren() ) { + foreach ($sxe->getChildren() as $element => $value) { + if ( FALSE !== in_array($element, $arrayElement) ) { + $this->types[$k]->{parent::_underToCamel($value->name)} = $value->value; + } else { + $this->types[$k]->{parent::_underToCamel($element)} = $value; + } + } + } + } + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Info.php b/src/PleskX/Api/Struct/Site/Info.php new file mode 100644 index 00000000..626eeb43 --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Info.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'guid', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Preference.php b/src/PleskX/Api/Struct/Site/Preference.php new file mode 100644 index 00000000..0b3c5c27 --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Preference.php @@ -0,0 +1,21 @@ +_initScalarProperties($apiResponse, [ + 'www', + 'stat_ttl', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/Site/Stat.php b/src/PleskX/Api/Struct/Site/Stat.php new file mode 100644 index 00000000..b2810038 --- /dev/null +++ b/src/PleskX/Api/Struct/Site/Stat.php @@ -0,0 +1,69 @@ +_initScalarProperties($apiResponse, [ + 'traffic', + 'subdom', + 'wu', + 'box', + 'redir', + 'mg', + 'resp', + 'maillists', + 'db', + 'mssql_db', + 'webapps', + 'traffic_prevday', + 'domains', + 'sites' + ]); + } +} \ No newline at end of file diff --git a/tests/SiteTest.php b/tests/SiteTest.php index 3f27fe33..7cb2494c 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -4,30 +4,94 @@ class SiteTest extends TestCase { - private $n = 'example-test-other.dom'; + private $webspaceSiteName = 'example-test-parent.dom'; + private $siteName = 'example-test-child.dom'; /** + * + * * @return \PleskX\Api\Struct\Webspace\Info */ private function _createWebspace() { + $ips = $this->_client->ip()->get(); $ipInfo = reset($ips); + return $this->_client->webspace()->create([ - 'name' => $this->n, - 'ip_address' => $ipInfo->ipAddress, + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' ]); + } - public function testGet() + /** + * @return \PleskX\Api\Struct\Webspace\Info + */ + private function _createSite($webspace) + { + return $this->_client->site()->create([ + 'gen_setup' => [ + 'name' => $this->siteName, + 'webspace-id' => $webspace->id + ], + ]); + } + + public function testCreate() { - $ws = $this->_createWebspace(); + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + $this->assertInternalType('integer', $site->id); + $this->assertGreaterThan(0, $site->id); + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } - $siteInfo = $this->_client->site()->get('id', $ws->id); - $this->assertEquals($this->n, $siteInfo->name); + public function testDelete() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + $result = $this->_client->site()->delete('id', $site->id); + $this->assertTrue($result); + $this->_client->webspace()->delete('id', $webspace->id); + } - $this->_client->webspace()->delete('id', $ws->id); + public function testGet() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + $siteInfo = $this->_client->site()->get('id', $site->id); + $this->assertEquals($this->siteName, $siteInfo->name); + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + public function testData() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + $siteInfo = $this->_client->site()->get('id', $site->id); + $this->assertEquals($this->siteName, $siteInfo->name); + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); } } diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index 6cd604bd..5d91bf13 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -43,18 +43,6 @@ private function _createWebspace() } - /** - * @return \PleskX\Api\Struct\Webspace\Info - */ - private function _createSite($webspace) - { - return $this->_client->site()->create([ - 'gen_setup' => [ - 'name' => $this->siteName, - 'webspace-id' => $webspace->id - ], - ]); - } public function testGetPermissionDescriptor() { @@ -114,7 +102,6 @@ public function testData() $this->_client->webspace()->delete('id', $webspace->id); } - public function testGetTrafficThisMonth() { $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, @@ -138,40 +125,4 @@ public function testGetTraffic() $this->assertInternalType('integer', $webspaceTraffic->httpIn); } - public function testCreateSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); - - $this->assertInternalType('integer', $site->id); - $this->assertGreaterThan(0, $site->id); - - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } - - public function testDeleteSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); - - $result = $this->_client->site()->delete('id', $site->id); - $this->assertTrue($result); - - $this->_client->webspace()->delete('id', $webspace->id); - } - - public function testGetSite() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); - - $siteInfo = $this->_client->site()->get('id', $site->id); - $this->assertEquals($this->siteName, $siteInfo->name); - - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } - - } From 69c0848d57d525a2fd0b15d621cc4a5f55ca6b12 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Thu, 8 Oct 2015 19:57:33 -0300 Subject: [PATCH 17/35] Site getData returning array when search are not attributes id,name --- src/PleskX/Api/Operator/Site.php | 15 ++++++++++++--- tests/SiteTest.php | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/PleskX/Api/Operator/Site.php b/src/PleskX/Api/Operator/Site.php index 71d202ee..f21e3ef1 100644 --- a/src/PleskX/Api/Operator/Site.php +++ b/src/PleskX/Api/Operator/Site.php @@ -28,7 +28,7 @@ public function get($field, $value) * * @param string $field * @param integer|string $value - * @return Struct\Data + * @return mixed Array|Struct\Data */ public function getData($field, $value) { @@ -41,8 +41,17 @@ public function getData($field, $value) $dataset->addChild('stat'); $dataset->addChild('prefs'); $dataset->addChild('disk_usage'); - $response = $this->_client->request($packet); - return new Struct\Data($response->data); + $ret = NULL; + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'site'}->{'get'}->result; + if ( in_array($field,['id','name','guid']) && isset( $response->id ) ) { + $ret = new Struct\Data($response->data); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) $ret[] = new Struct\Data($f->data); + } + } + return $ret; } /** diff --git a/tests/SiteTest.php b/tests/SiteTest.php index 7cb2494c..9503a96c 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -88,8 +88,18 @@ public function testData() { $webspace = $this->_createWebspace(); $site = $this->_createSite($webspace); - $siteInfo = $this->_client->site()->get('id', $site->id); - $this->assertEquals($this->siteName, $siteInfo->name); + $siteInfo = $this->_client->site()->getData('id', $site->id); + $this->assertEquals($this->siteName, $siteInfo->genInfo->name); + $this->_client->site()->delete('id', $site->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDataSearchBySpace() + { + $webspace = $this->_createWebspace(); + $site = $this->_createSite($webspace); + $siteInfo = $this->_client->site()->getData('parent-id', $webspace->id); + $this->assertEquals($this->siteName, $siteInfo[0]->genInfo->name); $this->_client->site()->delete('id', $site->id); $this->_client->webspace()->delete('id', $webspace->id); } From 37e3fa79b2ad379a384fac106fc3c5748d8193c1 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Fri, 9 Oct 2015 12:18:01 -0300 Subject: [PATCH 18/35] add SiteAlias management --- src/PleskX/Api/Operator/SiteAlias.php | 76 ++++++++++++++- .../Api/Struct/SiteAlias/GeneralInfo.php | 33 +++++++ src/PleskX/Api/Struct/SiteAlias/Info.php | 17 ++++ .../Api/Struct/SiteAlias/Preferences.php | 25 +++++ tests/SiteAliasTest.php | 96 +++++++++++++++++++ 5 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php create mode 100644 src/PleskX/Api/Struct/SiteAlias/Info.php create mode 100644 src/PleskX/Api/Struct/SiteAlias/Preferences.php create mode 100644 tests/SiteAliasTest.php diff --git a/src/PleskX/Api/Operator/SiteAlias.php b/src/PleskX/Api/Operator/SiteAlias.php index cb0ca391..6d086301 100644 --- a/src/PleskX/Api/Operator/SiteAlias.php +++ b/src/PleskX/Api/Operator/SiteAlias.php @@ -3,7 +3,81 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\SiteAlias as Struct; + class SiteAlias extends \PleskX\Api\Operator { -} + /** + * @param string $field + * @param integer|string $value + * @return Struct\GeneralInfo + */ + public function get($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('site-alias')->addChild('get'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return new Struct\GeneralInfo($response); + } + + + /** + * @param array $properties + * @return Struct\Info + */ + public function create($properties) + { + $properties = ['site-alias' => ['create' => $properties]]; + $packet = $this->_client->genRequestXml( $properties ); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + + /** + * @param array $filter + * @param array $properties + * @return Struct\Info + */ + public function update($filter, $settings) + { + $properties = ['site-alias'=>['set'=>['filter'=>$filter,'settings'=>$settings]]]; + $packet = $this->_client->genRequestXml( $properties ); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + + /** + * @param string $field + * @param integer|string $value + * @return bool + */ + public function delete($field, $value) + { + $packet = $this->_client->getPacket(); + $packet->addChild('site-alias')->addChild('delete')->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + + /** + * @param string $filter + * @param string|integer $valueFilter + * @param string $newName + * @param integer|string $value + * @return bool + */ + public function rename($filter, $valueFilter, $newName) + { + $packet = $this->_client->getPacket(); + $operator = $packet->addChild('site-alias')->addChild('rename'); + $operator->addChild( $filter, $valueFilter ); + $operator->addChild( 'new_name', $newName ); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php b/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php new file mode 100644 index 00000000..a6d924ee --- /dev/null +++ b/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php @@ -0,0 +1,33 @@ +id = $apiResponse->id; + $this->_initScalarProperties($apiResponse->info, [ + ['prefs' => 'preferences'], + ['site-id' => 'siteId'], + 'name', + ['ascii-name' => 'asciiName'] + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/SiteAlias/Info.php b/src/PleskX/Api/Struct/SiteAlias/Info.php new file mode 100644 index 00000000..b64836c5 --- /dev/null +++ b/src/PleskX/Api/Struct/SiteAlias/Info.php @@ -0,0 +1,17 @@ +_initScalarProperties($apiResponse, [ + 'id' + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/SiteAlias/Preferences.php b/src/PleskX/Api/Struct/SiteAlias/Preferences.php new file mode 100644 index 00000000..ec9247c3 --- /dev/null +++ b/src/PleskX/Api/Struct/SiteAlias/Preferences.php @@ -0,0 +1,25 @@ +_initScalarProperties($apiResponse, [ + 'web', + 'tomcat', + 'seo-redirect', + ]); + } +} \ No newline at end of file diff --git a/tests/SiteAliasTest.php b/tests/SiteAliasTest.php new file mode 100644 index 00000000..e351c8c2 --- /dev/null +++ b/tests/SiteAliasTest.php @@ -0,0 +1,96 @@ +_client->ip()->get(); + $ipInfo = reset($ips); + + return $this->_client->webspace()->create([ + 'gen_setup' => [ + 'name' => $this->webspaceSiteName, + 'ip_address' => $ipInfo->ipAddress, + 'htype' => 'vrt_hst' + ], + 'hosting' => [ + 'vrt_hst' => [ + ['property' => [ + 'name' => 'ftp_login', + 'value' => 'ftpusertest', + ]], + ['property' => [ + 'name' => 'ftp_password', + 'value' => 'ftpuserpasswordtest', + ]], + 'ip_address' => $ipInfo->ipAddress + ], + ], + 'plan-name' => 'basic' + ]); + + } + + /** + * @return \PleskX\Api\Struct\SiteAlias\Info + */ + private function _createSiteAlias($webspace) + { + return $this->_client->siteAlias()->create([ + 'site-id' => $webspace->id, + 'name' => $this->aliasName + ]); + } + + public function testGet() { + $webspace = $this->_createWebspace(); + $siteAlias = $this->_createSiteAlias($webspace); + $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); + $this->assertEquals($this->aliasName, $siteAlias->name); + $this->_client->siteAlias()->delete('id', $siteAlias->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testCreate() { + $webspace = $this->_createWebspace(); + $siteAlias = $this->_createSiteAlias($webspace); + $this->assertInternalType('integer', $siteAlias->id); + $this->assertGreaterThan(0, $siteAlias->id); + $this->_client->siteAlias()->delete('id', $siteAlias->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() { + $webspace = $this->_createWebspace(); + $siteAlias = $this->_createSiteAlias($webspace); + $result = $this->_client->siteAlias()->delete('id', $siteAlias->id); + $this->assertTrue($result); + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testRename() { + + $webspace = $this->_createWebspace(); + $siteAlias = $this->_createSiteAlias($webspace); + $result = $this->_client->siteAlias()->rename('id', $siteAlias->id, $this->aliasNewName); + $this->assertTrue($result); + $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); + $this->assertEquals($this->aliasNewName, $siteAlias->name); + $this->_client->siteAlias()->delete('id', $siteAlias->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + +} From 8c4b599743c14efd560a5355f7049282c94a54c5 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Fri, 9 Oct 2015 13:58:46 -0300 Subject: [PATCH 19/35] returning one or more results on get SiteAlias --- src/PleskX/Api/Operator/SiteAlias.php | 13 ++++- tests/SiteAliasTest.php | 69 ++++++++++++++++----------- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/PleskX/Api/Operator/SiteAlias.php b/src/PleskX/Api/Operator/SiteAlias.php index 6d086301..4c05c179 100644 --- a/src/PleskX/Api/Operator/SiteAlias.php +++ b/src/PleskX/Api/Operator/SiteAlias.php @@ -18,8 +18,17 @@ public function get($field, $value) $packet = $this->_client->getPacket(); $getTag = $packet->addChild('site-alias')->addChild('get'); $getTag->addChild('filter')->addChild($field, $value); - $response = $this->_client->request($packet); - return new Struct\GeneralInfo($response); + $ret = NULL; + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'site-alias'}->{'get'}->result; + if ( in_array($field,['id','name']) && isset( $response->id ) ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; } diff --git a/tests/SiteAliasTest.php b/tests/SiteAliasTest.php index e351c8c2..ae1ad44c 100644 --- a/tests/SiteAliasTest.php +++ b/tests/SiteAliasTest.php @@ -55,42 +55,53 @@ private function _createSiteAlias($webspace) ]); } - public function testGet() { - $webspace = $this->_createWebspace(); - $siteAlias = $this->_createSiteAlias($webspace); - $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); - $this->assertEquals($this->aliasName, $siteAlias->name); - $this->_client->siteAlias()->delete('id', $siteAlias->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testGet() { + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); + // $this->assertEquals($this->aliasName, $siteAlias->name); + // $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } - public function testCreate() { + public function testGetSearchBySiteName() + { $webspace = $this->_createWebspace(); $siteAlias = $this->_createSiteAlias($webspace); - $this->assertInternalType('integer', $siteAlias->id); - $this->assertGreaterThan(0, $siteAlias->id); - $this->_client->siteAlias()->delete('id', $siteAlias->id); + $siteAlias = $this->_client->siteAlias()->get('site-id', $webspace->id); + $this->assertEquals($this->aliasName, $siteAlias[0]->name); + $this->_client->siteAlias()->delete('id', $siteAlias[0]->id); $this->_client->webspace()->delete('id', $webspace->id); } - public function testDelete() { - $webspace = $this->_createWebspace(); - $siteAlias = $this->_createSiteAlias($webspace); - $result = $this->_client->siteAlias()->delete('id', $siteAlias->id); - $this->assertTrue($result); - $this->_client->webspace()->delete('id', $webspace->id); - } - public function testRename() { + // public function testCreate() { + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $this->assertInternalType('integer', $siteAlias->id); + // $this->assertGreaterThan(0, $siteAlias->id); + // $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } - $webspace = $this->_createWebspace(); - $siteAlias = $this->_createSiteAlias($webspace); - $result = $this->_client->siteAlias()->rename('id', $siteAlias->id, $this->aliasNewName); - $this->assertTrue($result); - $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); - $this->assertEquals($this->aliasNewName, $siteAlias->name); - $this->_client->siteAlias()->delete('id', $siteAlias->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testDelete() { + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $result = $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->assertTrue($result); + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testRename() { + + // $webspace = $this->_createWebspace(); + // $siteAlias = $this->_createSiteAlias($webspace); + // $result = $this->_client->siteAlias()->rename('id', $siteAlias->id, $this->aliasNewName); + // $this->assertTrue($result); + // $siteAlias = $this->_client->siteAlias()->get('id', $siteAlias->id); + // $this->assertEquals($this->aliasNewName, $siteAlias->name); + // $this->_client->siteAlias()->delete('id', $siteAlias->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } } From ca91dae4a2a156cacdfbe7c5a0b08957ab0d6e8f Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Mon, 19 Oct 2015 14:30:28 -0200 Subject: [PATCH 20/35] Adding PHPHandler call --- src/PleskX/Api/Client.php | 8 ++++++ src/PleskX/Api/Operator/PHPHandler.php | 25 +++++++++++++++++ src/PleskX/Api/Struct/PHPHandler/Info.php | 33 +++++++++++++++++++++++ tests/PHPHandlerTest.php | 13 +++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/PleskX/Api/Operator/PHPHandler.php create mode 100644 src/PleskX/Api/Struct/PHPHandler/Info.php create mode 100644 tests/PHPHandlerTest.php diff --git a/src/PleskX/Api/Client.php b/src/PleskX/Api/Client.php index 126352f6..f0e91652 100644 --- a/src/PleskX/Api/Client.php +++ b/src/PleskX/Api/Client.php @@ -691,4 +691,12 @@ public function wpInstance() return $this->_getOperator('WpInstance'); } + /** + * @return Operator\PHPHandler + */ + public function phpHandler() + { + return $this->_getOperator('PHPHandler'); + } + } diff --git a/src/PleskX/Api/Operator/PHPHandler.php b/src/PleskX/Api/Operator/PHPHandler.php new file mode 100644 index 00000000..423d5e11 --- /dev/null +++ b/src/PleskX/Api/Operator/PHPHandler.php @@ -0,0 +1,25 @@ +_client->getPacket(); + $filter = $packet->addChild('php-handler')->addChild('get')->addChild('filter'); + if ($field) $filter->addChild($field, $value); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + +} diff --git a/src/PleskX/Api/Struct/PHPHandler/Info.php b/src/PleskX/Api/Struct/PHPHandler/Info.php new file mode 100644 index 00000000..4ddb6bf6 --- /dev/null +++ b/src/PleskX/Api/Struct/PHPHandler/Info.php @@ -0,0 +1,33 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'display-name', + 'full-version', + 'version', + 'type', + ]); + } +} \ No newline at end of file diff --git a/tests/PHPHandlerTest.php b/tests/PHPHandlerTest.php new file mode 100644 index 00000000..a56003a0 --- /dev/null +++ b/tests/PHPHandlerTest.php @@ -0,0 +1,13 @@ +_client->phpHandler()->get('id', 'cgi'); + $this->assertEquals('cgi', $get->id); + } + +} \ No newline at end of file From 1a1c94457fe2f1647a2f76570130bf56574e41d0 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Thu, 22 Oct 2015 15:32:10 -0200 Subject: [PATCH 21/35] inserting id info on return root of getData site/webSpace --- src/PleskX/Api/Struct/Site/Data.php | 5 + src/PleskX/Api/Struct/Webspace/Data.php | 5 + tests/SiteTest.php | 71 ++++++------ tests/WebspaceTest.php | 142 ++++++++++++------------ 4 files changed, 117 insertions(+), 106 deletions(-) diff --git a/src/PleskX/Api/Struct/Site/Data.php b/src/PleskX/Api/Struct/Site/Data.php index 06e2af03..6302656d 100644 --- a/src/PleskX/Api/Struct/Site/Data.php +++ b/src/PleskX/Api/Struct/Site/Data.php @@ -5,6 +5,10 @@ class Data extends \PleskX\Api\Struct { + + /** @var integer **/ + public $integer; + /** @var PleskX\Api\Struct\Site\GeneralInfo **/ public $genInfo; @@ -23,6 +27,7 @@ class Data extends \PleskX\Api\Struct public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ + 'integer', 'gen_info', 'hosting', 'stat', diff --git a/src/PleskX/Api/Struct/Webspace/Data.php b/src/PleskX/Api/Struct/Webspace/Data.php index a8b8fb59..79b98e61 100644 --- a/src/PleskX/Api/Struct/Webspace/Data.php +++ b/src/PleskX/Api/Struct/Webspace/Data.php @@ -5,6 +5,10 @@ class Data extends \PleskX\Api\Struct { + + /** @var integer **/ + public $id; + /** @var PleskX\Api\Struct\Webspace\GeneralInfo **/ public $genInfo; @@ -32,6 +36,7 @@ class Data extends \PleskX\Api\Struct public function __construct($apiResponse) { $this->_initScalarProperties($apiResponse, [ + 'id', 'gen_info', 'hosting', 'limits', diff --git a/tests/SiteTest.php b/tests/SiteTest.php index 9503a96c..e5392beb 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -55,34 +55,34 @@ private function _createSite($webspace) ]); } - public function testCreate() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); - $this->assertInternalType('integer', $site->id); - $this->assertGreaterThan(0, $site->id); - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testCreate() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $this->assertInternalType('integer', $site->id); + // $this->assertGreaterThan(0, $site->id); + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } - public function testDelete() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); - $result = $this->_client->site()->delete('id', $site->id); - $this->assertTrue($result); - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testDelete() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $result = $this->_client->site()->delete('id', $site->id); + // $this->assertTrue($result); + // $this->_client->webspace()->delete('id', $webspace->id); + // } - public function testGet() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); - $siteInfo = $this->_client->site()->get('id', $site->id); - $this->assertEquals($this->siteName, $siteInfo->name); - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testGet() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $siteInfo = $this->_client->site()->get('id', $site->id); + // $this->assertEquals($this->siteName, $siteInfo->name); + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } public function testData() { @@ -90,18 +90,19 @@ public function testData() $site = $this->_createSite($webspace); $siteInfo = $this->_client->site()->getData('id', $site->id); $this->assertEquals($this->siteName, $siteInfo->genInfo->name); + $this->assertEquals($site->id, $siteInfo->id); $this->_client->site()->delete('id', $site->id); $this->_client->webspace()->delete('id', $webspace->id); } - public function testDataSearchBySpace() - { - $webspace = $this->_createWebspace(); - $site = $this->_createSite($webspace); - $siteInfo = $this->_client->site()->getData('parent-id', $webspace->id); - $this->assertEquals($this->siteName, $siteInfo[0]->genInfo->name); - $this->_client->site()->delete('id', $site->id); - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testDataSearchBySpace() + // { + // $webspace = $this->_createWebspace(); + // $site = $this->_createSite($webspace); + // $siteInfo = $this->_client->site()->getData('parent-id', $webspace->id); + // $this->assertEquals($this->siteName, $siteInfo[0]->genInfo->name); + // $this->_client->site()->delete('id', $site->id); + // $this->_client->webspace()->delete('id', $webspace->id); + // } } diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index 5d91bf13..f5ed6fdb 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -44,55 +44,55 @@ private function _createWebspace() } - public function testGetPermissionDescriptor() - { - $descriptor = $this->_client->webspace()->getPermissionDescriptor(); - $this->assertInternalType('array', $descriptor->permissions); - $this->assertGreaterThan(0, count($descriptor->permissions)); - } - - public function testGetLimitDescriptor() - { - $descriptor = $this->_client->webspace()->getLimitDescriptor(); - $this->assertInternalType('array', $descriptor->limits); - $this->assertGreaterThan(0, count($descriptor->limits)); - } - - public function testGetPhysicalHostingDescriptor() - { - $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); - $this->assertInternalType('array', $descriptor->properties); - $this->assertGreaterThan(0, count($descriptor->properties)); - - $ftpLoginProperty = $descriptor->properties['ftp_login']; - $this->assertEquals('ftp_login', $ftpLoginProperty->name); - $this->assertEquals('string', $ftpLoginProperty->type); - } - - public function testCreate() - { - $webspace = $this->_createWebspace(); - $this->assertInternalType('integer', $webspace->id); - $this->assertGreaterThan(0, $webspace->id); - - $this->_client->webspace()->delete('id', $webspace->id); - } - - public function testDelete() - { - $webspace = $this->_createWebspace(); - $result = $this->_client->webspace()->delete('id', $webspace->id); - $this->assertTrue($result); - } - - public function testGet() - { - $webspace = $this->_createWebspace(); - $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); - - $this->_client->webspace()->delete('id', $webspace->id); - } + // public function testGetPermissionDescriptor() + // { + // $descriptor = $this->_client->webspace()->getPermissionDescriptor(); + // $this->assertInternalType('array', $descriptor->permissions); + // $this->assertGreaterThan(0, count($descriptor->permissions)); + // } + + // public function testGetLimitDescriptor() + // { + // $descriptor = $this->_client->webspace()->getLimitDescriptor(); + // $this->assertInternalType('array', $descriptor->limits); + // $this->assertGreaterThan(0, count($descriptor->limits)); + // } + + // public function testGetPhysicalHostingDescriptor() + // { + // $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); + // $this->assertInternalType('array', $descriptor->properties); + // $this->assertGreaterThan(0, count($descriptor->properties)); + + // $ftpLoginProperty = $descriptor->properties['ftp_login']; + // $this->assertEquals('ftp_login', $ftpLoginProperty->name); + // $this->assertEquals('string', $ftpLoginProperty->type); + // } + + // public function testCreate() + // { + // $webspace = $this->_createWebspace(); + // $this->assertInternalType('integer', $webspace->id); + // $this->assertGreaterThan(0, $webspace->id); + + // $this->_client->webspace()->delete('id', $webspace->id); + // } + + // public function testDelete() + // { + // $webspace = $this->_createWebspace(); + // $result = $this->_client->webspace()->delete('id', $webspace->id); + // $this->assertTrue($result); + // } + + // public function testGet() + // { + // $webspace = $this->_createWebspace(); + // $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); + // $this->assertEquals($webspace->id, $webspaceInfo->id); + + // $this->_client->webspace()->delete('id', $webspace->id); + // } public function testData() { @@ -102,27 +102,27 @@ public function testData() $this->_client->webspace()->delete('id', $webspace->id); } - public function testGetTrafficThisMonth() - { - $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, - new DateTime('@'.strtotime('first day of this month')) - ); - $this->assertInternalType('integer', $webspaceTraffic->httpIn); - } - - public function testGetTrafficLastMonth() - { - $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, - new DateTime('@'.strtotime('first day of previous month')), - new DateTime('@'.strtotime('last day of previous month'))) - ; - $this->assertInternalType('integer', $webspaceTraffic->httpIn); - } - - public function testGetTraffic() - { - $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite ); - $this->assertInternalType('integer', $webspaceTraffic->httpIn); - } + // public function testGetTrafficThisMonth() + // { + // $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + // new DateTime('@'.strtotime('first day of this month')) + // ); + // $this->assertInternalType('integer', $webspaceTraffic->httpIn); + // } + + // public function testGetTrafficLastMonth() + // { + // $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + // new DateTime('@'.strtotime('first day of previous month')), + // new DateTime('@'.strtotime('last day of previous month'))) + // ; + // $this->assertInternalType('integer', $webspaceTraffic->httpIn); + // } + + // public function testGetTraffic() + // { + // $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite ); + // $this->assertInternalType('integer', $webspaceTraffic->httpIn); + // } } From 92865c698aa9f328b856372fde57e5af28f3020c Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Thu, 22 Oct 2015 16:15:47 -0200 Subject: [PATCH 22/35] inserting id info on return root of getData site/webSpace --- src/PleskX/Api/Operator/Site.php | 4 ++-- src/PleskX/Api/Operator/Webspace.php | 2 +- src/PleskX/Api/Struct/Site/Data.php | 8 +++++--- src/PleskX/Api/Struct/Webspace/Data.php | 4 +++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/PleskX/Api/Operator/Site.php b/src/PleskX/Api/Operator/Site.php index f21e3ef1..e18c20a2 100644 --- a/src/PleskX/Api/Operator/Site.php +++ b/src/PleskX/Api/Operator/Site.php @@ -44,11 +44,11 @@ public function getData($field, $value) $ret = NULL; $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'site'}->{'get'}->result; if ( in_array($field,['id','name','guid']) && isset( $response->id ) ) { - $ret = new Struct\Data($response->data); + $ret = new Struct\Data($response); } else { $ret = []; foreach ($response as $f) { - if ( isset( $f->id ) ) $ret[] = new Struct\Data($f->data); + if ( isset( $f->id ) ) $ret[] = new Struct\Data($f); } } return $ret; diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index b1a7e620..0679e087 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -90,7 +90,7 @@ public function getData($field, $value) $dataset->addChild('performance'); $dataset->addChild('subscriptions'); $response = $this->_client->request($packet); - return new Struct\Data($response->data); + return new Struct\Data($response); } /** diff --git a/src/PleskX/Api/Struct/Site/Data.php b/src/PleskX/Api/Struct/Site/Data.php index 6302656d..b8bf08af 100644 --- a/src/PleskX/Api/Struct/Site/Data.php +++ b/src/PleskX/Api/Struct/Site/Data.php @@ -7,7 +7,7 @@ class Data extends \PleskX\Api\Struct { /** @var integer **/ - public $integer; + public $id; /** @var PleskX\Api\Struct\Site\GeneralInfo **/ public $genInfo; @@ -26,8 +26,10 @@ class Data extends \PleskX\Api\Struct public function __construct($apiResponse) { - $this->_initScalarProperties($apiResponse, [ - 'integer', + $data = $apiResponse->data; + $data->addChild('id',$apiResponse->id); + $this->_initScalarProperties($data, [ + 'id', 'gen_info', 'hosting', 'stat', diff --git a/src/PleskX/Api/Struct/Webspace/Data.php b/src/PleskX/Api/Struct/Webspace/Data.php index 79b98e61..ceefdc7b 100644 --- a/src/PleskX/Api/Struct/Webspace/Data.php +++ b/src/PleskX/Api/Struct/Webspace/Data.php @@ -35,7 +35,9 @@ class Data extends \PleskX\Api\Struct public function __construct($apiResponse) { - $this->_initScalarProperties($apiResponse, [ + $data = $apiResponse->data; + $data->addChild('id',$apiResponse->id); + $this->_initScalarProperties($data, [ 'id', 'gen_info', 'hosting', From 368996d334ebcb573672529dffe1fe20c42912d6 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 27 Oct 2015 12:56:38 -0200 Subject: [PATCH 23/35] getting all serviceplans --- src/PleskX/Api/Operator/ServicePlan.php | 14 ++++++++++++++ tests/ServicePlanTest.php | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/PleskX/Api/Operator/ServicePlan.php b/src/PleskX/Api/Operator/ServicePlan.php index 586e25ae..a71c633c 100644 --- a/src/PleskX/Api/Operator/ServicePlan.php +++ b/src/PleskX/Api/Operator/ServicePlan.php @@ -22,4 +22,18 @@ public function get($field, $value) return new Struct\Info($response); } + public function getAll() + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('service-plan')->addChild('get'); + $getTag->addChild('filter'); + $getTag->addChild('owner-all'); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'service-plan'}->get->result; + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) $ret[] = new Struct\Info($f); + } + return $ret; + } + } diff --git a/tests/ServicePlanTest.php b/tests/ServicePlanTest.php index 5925529f..79c68f60 100644 --- a/tests/ServicePlanTest.php +++ b/tests/ServicePlanTest.php @@ -50,4 +50,10 @@ public function testGet() $this->_client->webspace()->delete('id', $webspace->id); } + public function testGetAll() + { + $servicePlan = $this->_client->servicePlan()->getAll(); + $this->assertGreaterThan(0, $servicePlan[0]->id); + } + } \ No newline at end of file From cda61b96289ba46f21273b06174308a49cc9134e Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 27 Oct 2015 13:46:57 -0200 Subject: [PATCH 24/35] ServicePlan returning limits --- src/PleskX/Api/Operator/ServicePlan.php | 9 ++++-- src/PleskX/Api/Struct/ServicePlan/Data.php | 26 +++++++++++++++ src/PleskX/Api/Struct/ServicePlan/Limits.php | 34 ++++++++++++++++++++ tests/ServicePlanTest.php | 1 + 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/PleskX/Api/Struct/ServicePlan/Data.php create mode 100644 src/PleskX/Api/Struct/ServicePlan/Limits.php diff --git a/src/PleskX/Api/Operator/ServicePlan.php b/src/PleskX/Api/Operator/ServicePlan.php index a71c633c..2ebdbe97 100644 --- a/src/PleskX/Api/Operator/ServicePlan.php +++ b/src/PleskX/Api/Operator/ServicePlan.php @@ -11,7 +11,7 @@ class ServicePlan extends \PleskX\Api\Operator /** * @param string $field * @param integer|string $value - * @return Struct\GeneralInfo + * @return Struct\Data */ public function get($field, $value) { @@ -19,9 +19,12 @@ public function get($field, $value) $getTag = $packet->addChild('service-plan')->addChild('get'); $getTag->addChild('filter')->addChild($field, $value); $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'service-plan'}->get->result; - return new Struct\Info($response); + return new Struct\Data($response); } + /** + * @return array [Struct\Data] + */ public function getAll() { $packet = $this->_client->getPacket(); @@ -31,7 +34,7 @@ public function getAll() $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'service-plan'}->get->result; $ret = []; foreach ($response as $f) { - if ( isset( $f->id ) ) $ret[] = new Struct\Info($f); + if ( isset( $f->id ) ) $ret[] = new Struct\Data($f); } return $ret; } diff --git a/src/PleskX/Api/Struct/ServicePlan/Data.php b/src/PleskX/Api/Struct/ServicePlan/Data.php new file mode 100644 index 00000000..a0cfdf7a --- /dev/null +++ b/src/PleskX/Api/Struct/ServicePlan/Data.php @@ -0,0 +1,26 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + 'limits', + ]); + } +} \ No newline at end of file diff --git a/src/PleskX/Api/Struct/ServicePlan/Limits.php b/src/PleskX/Api/Struct/ServicePlan/Limits.php new file mode 100644 index 00000000..2a5b9748 --- /dev/null +++ b/src/PleskX/Api/Struct/ServicePlan/Limits.php @@ -0,0 +1,34 @@ +_limitScalarProperties($apiResponse,['limit']); + } + + private function _limitScalarProperties($apiResponse, array $arrayElement) + { + foreach( $arrayElement as $el ) { + $this->{$el} = new \stdClass(); + } + $sxe = new \SimpleXmlIterator($apiResponse->asXML()); + for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + $k = $sxe->key(); + if ( FALSE !== in_array($k, $arrayElement) ) { + $this->{$k}->{parent::_underToCamel($sxe->current()->name)} = $sxe->current()->value; + } else $this->{parent::_underToCamel($k)} = $sxe->current(); + } + } + +} \ No newline at end of file diff --git a/tests/ServicePlanTest.php b/tests/ServicePlanTest.php index 79c68f60..4afd3230 100644 --- a/tests/ServicePlanTest.php +++ b/tests/ServicePlanTest.php @@ -41,6 +41,7 @@ private function _createWebspace() ]); } + public function testGet() { $webspace = $this->_createWebspace(); From 7ee03769b66d8446f12e24fed89988b9339b7922 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 27 Oct 2015 19:19:22 -0200 Subject: [PATCH 25/35] inserting id return on Customer.Get --- src/PleskX/Api/Operator/Customer.php | 4 +-- .../Api/Struct/Customer/GeneralInfo.php | 8 +++-- tests/CustomerTest.php | 31 ++++++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/PleskX/Api/Operator/Customer.php b/src/PleskX/Api/Operator/Customer.php index 1ee0b229..f0112120 100644 --- a/src/PleskX/Api/Operator/Customer.php +++ b/src/PleskX/Api/Operator/Customer.php @@ -48,8 +48,8 @@ public function get($field, $value) $getTag = $packet->addChild('customer')->addChild('get'); $getTag->addChild('filter')->addChild($field, $value); $getTag->addChild('dataset')->addChild('gen_info'); - $response = $this->_client->request($packet); - return new Struct\GeneralInfo($response->data->gen_info); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'customer'}->get->result; + return new Struct\GeneralInfo($response); } } diff --git a/src/PleskX/Api/Struct/Customer/GeneralInfo.php b/src/PleskX/Api/Struct/Customer/GeneralInfo.php index 74a50b9d..cc1e553a 100644 --- a/src/PleskX/Api/Struct/Customer/GeneralInfo.php +++ b/src/PleskX/Api/Struct/Customer/GeneralInfo.php @@ -11,11 +11,15 @@ class GeneralInfo extends \PleskX\Api\Struct /** @var string */ public $login; + /** @var integer */ + public $id; + public function __construct($apiResponse) { - $this->_initScalarProperties($apiResponse, [ + $this->id = (integer) $apiResponse->id; + $this->_initScalarProperties($apiResponse->data->gen_info, [ ['pname' => 'personalName'], - 'login', + 'login' ]); } } \ No newline at end of file diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index 8d4a3bc2..6ee83005 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -10,21 +10,21 @@ class CustomerTest extends TestCase 'passwd' => 'simple-password', ]; - public function testCreate() - { - $customer = $this->_client->customer()->create($this->_customerProperties); - $this->assertInternalType('integer', $customer->id); - $this->assertGreaterThan(0, $customer->id); - - $this->_client->customer()->delete('id', $customer->id); - } - - public function testDelete() - { - $customer = $this->_client->customer()->create($this->_customerProperties); - $result = $this->_client->customer()->delete('id', $customer->id); - $this->assertTrue($result); - } + // public function testCreate() + // { + // $customer = $this->_client->customer()->create($this->_customerProperties); + // $this->assertInternalType('integer', $customer->id); + // $this->assertGreaterThan(0, $customer->id); + + // $this->_client->customer()->delete('id', $customer->id); + // } + + // public function testDelete() + // { + // $customer = $this->_client->customer()->create($this->_customerProperties); + // $result = $this->_client->customer()->delete('id', $customer->id); + // $this->assertTrue($result); + // } public function testGet() { @@ -32,6 +32,7 @@ public function testGet() $customerInfo = $this->_client->customer()->get('id', $customer->id); $this->assertEquals('John Smith', $customerInfo->personalName); $this->assertEquals('john-unit-test', $customerInfo->login); + $this->assertEquals($customer->id, $customerInfo->id); $this->_client->customer()->delete('id', $customer->id); } From 0c9a8a19cb0a235451c6c7c0bf8122889d370060 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Thu, 29 Oct 2015 16:09:56 -0200 Subject: [PATCH 26/35] changing ftp user and webspace --- src/PleskX/Api/Operator/FtpUser.php | 16 +++ src/PleskX/Api/Operator/Webspace.php | 16 +++ tests/FtpUserTest.php | 10 ++ tests/WebspaceTest.php | 150 ++++++++++++++------------- 4 files changed, 121 insertions(+), 71 deletions(-) diff --git a/src/PleskX/Api/Operator/FtpUser.php b/src/PleskX/Api/Operator/FtpUser.php index 53b55769..3307197d 100644 --- a/src/PleskX/Api/Operator/FtpUser.php +++ b/src/PleskX/Api/Operator/FtpUser.php @@ -23,6 +23,22 @@ public function create($properties) return new Struct\Info($response); } + /** + * Change FTP account + * + * @param string $field + * @param integer|string $value + * @param array $properties + * @return Struct\Info + */ + public function set($field, $value, $properties) + { + $properties = ['ftp-user' => ['set' => ['filter' => [ $field => $value ], 'values' => $properties ]]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + /** * @param string $field * @param integer|string $value diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index 0679e087..62eb6aea 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -51,6 +51,22 @@ public function delete($field, $value) } + /** + * Change Webspace + * + * @param string $field + * @param integer|string $value + * @param array $properties + * @return Struct\Info + */ + public function set($field, $value, $properties) + { + $properties = ['webspace' => ['set' => ['filter' => [ $field => $value ], 'values' => $properties ]]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return new Struct\Info($response); + } + /** * Get gen_info of webspace [name,guid] * diff --git a/tests/FtpUserTest.php b/tests/FtpUserTest.php index 6a5e0c60..112acfec 100644 --- a/tests/FtpUserTest.php +++ b/tests/FtpUserTest.php @@ -56,6 +56,16 @@ public function testCreate() $this->_client->webspace()->delete('id', $webspace->id); } + public function testSet() + { + $webspace = $this->_createWebspace(); + $ftpuser = $this->_createFtpUser( $webspace ); + $result = $this->_client->ftpuser()->set('id', $ftpuser->id, ['password' => 'kjklasdjlkaj']); + $this->assertGreaterThan(0, $result->id); + $this->_client->ftpuser()->delete('id', $ftpuser->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + public function testDelete() { $webspace = $this->_createWebspace(); diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index f5ed6fdb..a1605454 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -44,55 +44,63 @@ private function _createWebspace() } - // public function testGetPermissionDescriptor() - // { - // $descriptor = $this->_client->webspace()->getPermissionDescriptor(); - // $this->assertInternalType('array', $descriptor->permissions); - // $this->assertGreaterThan(0, count($descriptor->permissions)); - // } - - // public function testGetLimitDescriptor() - // { - // $descriptor = $this->_client->webspace()->getLimitDescriptor(); - // $this->assertInternalType('array', $descriptor->limits); - // $this->assertGreaterThan(0, count($descriptor->limits)); - // } - - // public function testGetPhysicalHostingDescriptor() - // { - // $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); - // $this->assertInternalType('array', $descriptor->properties); - // $this->assertGreaterThan(0, count($descriptor->properties)); - - // $ftpLoginProperty = $descriptor->properties['ftp_login']; - // $this->assertEquals('ftp_login', $ftpLoginProperty->name); - // $this->assertEquals('string', $ftpLoginProperty->type); - // } - - // public function testCreate() - // { - // $webspace = $this->_createWebspace(); - // $this->assertInternalType('integer', $webspace->id); - // $this->assertGreaterThan(0, $webspace->id); - - // $this->_client->webspace()->delete('id', $webspace->id); - // } - - // public function testDelete() - // { - // $webspace = $this->_createWebspace(); - // $result = $this->_client->webspace()->delete('id', $webspace->id); - // $this->assertTrue($result); - // } - - // public function testGet() - // { - // $webspace = $this->_createWebspace(); - // $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - // $this->assertEquals($webspace->id, $webspaceInfo->id); - - // $this->_client->webspace()->delete('id', $webspace->id); - // } + public function testGetPermissionDescriptor() + { + $descriptor = $this->_client->webspace()->getPermissionDescriptor(); + $this->assertInternalType('array', $descriptor->permissions); + $this->assertGreaterThan(0, count($descriptor->permissions)); + } + + public function testGetLimitDescriptor() + { + $descriptor = $this->_client->webspace()->getLimitDescriptor(); + $this->assertInternalType('array', $descriptor->limits); + $this->assertGreaterThan(0, count($descriptor->limits)); + } + + public function testGetPhysicalHostingDescriptor() + { + $descriptor = $this->_client->webspace()->getPhysicalHostingDescriptor(); + $this->assertInternalType('array', $descriptor->properties); + $this->assertGreaterThan(0, count($descriptor->properties)); + + $ftpLoginProperty = $descriptor->properties['ftp_login']; + $this->assertEquals('ftp_login', $ftpLoginProperty->name); + $this->assertEquals('string', $ftpLoginProperty->type); + } + + public function testCreate() + { + $webspace = $this->_createWebspace(); + $this->assertInternalType('integer', $webspace->id); + $this->assertGreaterThan(0, $webspace->id); + + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testDelete() + { + $webspace = $this->_createWebspace(); + $result = $this->_client->webspace()->delete('id', $webspace->id); + $this->assertTrue($result); + } + + public function testGet() + { + $webspace = $this->_createWebspace(); + $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); + $this->assertEquals($webspace->id, $webspaceInfo->id); + + $this->_client->webspace()->delete('id', $webspace->id); + } + + public function testSet() + { + $webspace = $this->_createWebspace(); + $result = $this->_client->webspace()->set('id', $webspace->id, [ 'hosting' => ['vrt_hst' => [ 'property' => [ 'name' => 'ftp_password', 'value' => 'kjklasdjlkaj']]]]); + $this->assertGreaterThan(0, $result->id); + $this->_client->webspace()->delete('id', $webspace->id); + } public function testData() { @@ -102,27 +110,27 @@ public function testData() $this->_client->webspace()->delete('id', $webspace->id); } - // public function testGetTrafficThisMonth() - // { - // $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, - // new DateTime('@'.strtotime('first day of this month')) - // ); - // $this->assertInternalType('integer', $webspaceTraffic->httpIn); - // } - - // public function testGetTrafficLastMonth() - // { - // $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, - // new DateTime('@'.strtotime('first day of previous month')), - // new DateTime('@'.strtotime('last day of previous month'))) - // ; - // $this->assertInternalType('integer', $webspaceTraffic->httpIn); - // } - - // public function testGetTraffic() - // { - // $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite ); - // $this->assertInternalType('integer', $webspaceTraffic->httpIn); - // } + public function testGetTrafficThisMonth() + { + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + new DateTime('@'.strtotime('first day of this month')) + ); + $this->assertInternalType('integer', $webspaceTraffic->httpIn); + } + + public function testGetTrafficLastMonth() + { + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, + new DateTime('@'.strtotime('first day of previous month')), + new DateTime('@'.strtotime('last day of previous month'))) + ; + $this->assertInternalType('integer', $webspaceTraffic->httpIn); + } + + public function testGetTraffic() + { + $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite ); + $this->assertInternalType('integer', $webspaceTraffic->httpIn); + } } From 577aeb0738f702722cf984ec7bbc1fe9f672f6bc Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Fri, 30 Oct 2015 12:55:31 -0200 Subject: [PATCH 27/35] SetDbUser --- src/PleskX/Api/Operator/Database.php | 16 ++++++++++++++++ src/PleskX/Api/Struct/Database/InfoUser.php | 4 +--- tests/DatabaseTest.php | 11 +++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/PleskX/Api/Operator/Database.php b/src/PleskX/Api/Operator/Database.php index c96cb434..a7877d0b 100644 --- a/src/PleskX/Api/Operator/Database.php +++ b/src/PleskX/Api/Operator/Database.php @@ -77,6 +77,22 @@ public function createUser($properties) return new Struct\InfoUser($response); } + /** + * Change database user + * + * @param integer $id The database user id + * @param array $properties + * @return Struct\InfoUser + */ + public function setUser($id, $properties) + { + $properties = ['database' => ['set-db-user' => array_merge(['id' => $id], $properties)]]; + $packet = $this->_client->genRequestXml($properties); + $response = $this->_client->request($packet); + return 'ok' === (string)$response->status; + } + + /** * Delete Database user * @param string $field diff --git a/src/PleskX/Api/Struct/Database/InfoUser.php b/src/PleskX/Api/Struct/Database/InfoUser.php index c4640bab..c647718f 100644 --- a/src/PleskX/Api/Struct/Database/InfoUser.php +++ b/src/PleskX/Api/Struct/Database/InfoUser.php @@ -3,6 +3,4 @@ namespace PleskX\Api\Struct\Database; -class InfoUser extends Info { - -} \ No newline at end of file +class InfoUser extends Info {} \ No newline at end of file diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 041c30df..6682e21c 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -108,6 +108,17 @@ public function testCreateUser() { $this->_client->webspace()->delete('id', $webspace->id); } + public function testSetUser() { + $webspace = $this->_createWebspace(); + $database = $this->_createDatabase( $webspace ); + $user = $this->_createUser( $database ); + $result = $this->_client->database()->setUser($user->id,['password'=>'daskljaskljdaskladj']); + $this->assertTrue($result); + $this->_client->database()->deleteUser('id', $user->id); + $this->_client->database()->delete('id', $database->id); + $this->_client->webspace()->delete('id', $webspace->id); + } + public function testDeleteUser() { $webspace = $this->_createWebspace(); $database = $this->_createDatabase( $webspace ); From 864770992f5618248e76b885f8291249a2b51ec7 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Sat, 31 Oct 2015 10:35:09 -0200 Subject: [PATCH 28/35] Webspace call getData with option that returns more than one result --- src/PleskX/Api/Operator/Webspace.php | 25 ++++++++++++++++++------- tests/WebspaceTest.php | 9 +++++++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/PleskX/Api/Operator/Webspace.php b/src/PleskX/Api/Operator/Webspace.php index 62eb6aea..10307489 100644 --- a/src/PleskX/Api/Operator/Webspace.php +++ b/src/PleskX/Api/Operator/Webspace.php @@ -87,15 +87,16 @@ public function get($field, $value) /** * Get Data of webspace * - * @param string $field - * @param integer|string $value - * @return Struct\Data + * @param string $field optional + * @param integer|string $value optional + * @return mixed Struct\Data|Array */ - public function getData($field, $value) + public function getData($field=null,$value=null) { $packet = $this->_client->getPacket(); $getTag = $packet->addChild('webspace')->addChild('get'); - $getTag->addChild('filter')->addChild($field, $value); + $g = $getTag->addChild('filter'); + if ($field) $g->addChild($field, $value); $dataset = $getTag->addChild('dataset'); $dataset->addChild('gen_info'); $dataset->addChild('hosting'); @@ -105,8 +106,18 @@ public function getData($field, $value) $dataset->addChild('disk_usage'); $dataset->addChild('performance'); $dataset->addChild('subscriptions'); - $response = $this->_client->request($packet); - return new Struct\Data($response); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'webspace'}->{'get'}->result; + $ret = NULL; + if ( in_array($field,['id','name']) && isset( $response->id ) ) { + $ret = new Struct\Data($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\Data($f); + } + } + return $ret; } /** diff --git a/tests/WebspaceTest.php b/tests/WebspaceTest.php index a1605454..ceec7785 100644 --- a/tests/WebspaceTest.php +++ b/tests/WebspaceTest.php @@ -89,8 +89,7 @@ public function testGet() { $webspace = $this->_createWebspace(); $webspaceInfo = $this->_client->webspace()->get('id', $webspace->id); - $this->assertEquals($webspace->id, $webspaceInfo->id); - + $this->assertEquals($this->webspaceSiteName, $webspaceInfo->name); $this->_client->webspace()->delete('id', $webspace->id); } @@ -110,6 +109,12 @@ public function testData() $this->_client->webspace()->delete('id', $webspace->id); } + public function testDataAll() + { + $webspaceInfo = $this->_client->webspace()->getData(); + $this->assertGreaterThan(0, $webspaceInfo[0]->id); + } + public function testGetTrafficThisMonth() { $webspaceTraffic = $this->_client->webspace()->getTraffic('name', $this->trafficTestSite, From 04ac96946e6f02a02ad09ae38a422e9a57a7077f Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Sat, 31 Oct 2015 11:08:46 -0200 Subject: [PATCH 29/35] GetCustomerDomainList --- src/PleskX/Api/Operator/Customer.php | 19 +++++++++ src/PleskX/Api/Struct/Customer/Domain.php | 50 +++++++++++++++++++++++ tests/CustomerTest.php | 36 +++++++++------- 3 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 src/PleskX/Api/Struct/Customer/Domain.php diff --git a/src/PleskX/Api/Operator/Customer.php b/src/PleskX/Api/Operator/Customer.php index f0112120..b1f96eac 100644 --- a/src/PleskX/Api/Operator/Customer.php +++ b/src/PleskX/Api/Operator/Customer.php @@ -52,4 +52,23 @@ public function get($field, $value) return new Struct\GeneralInfo($response); } + /** + * @param string $field + * @param integer|string $value + * @return array[Struct\Domain] + */ + public function getDomainList($field, $value) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild('customer')->addChild('get-domain-list'); + $getTag->addChild('filter')->addChild($field, $value); + $response = $this->_client->request($packet)->domains->domain; + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\Domain($f); + } + return $ret; + } + } diff --git a/src/PleskX/Api/Struct/Customer/Domain.php b/src/PleskX/Api/Struct/Customer/Domain.php new file mode 100644 index 00000000..41d9a53b --- /dev/null +++ b/src/PleskX/Api/Struct/Customer/Domain.php @@ -0,0 +1,50 @@ +_initScalarProperties($apiResponse, [ + 'id', + 'name', + ['ascii-name' => 'asciiName'], + 'type', + 'main', + 'guid', + ['external-id' => 'externalId'], + ['parent-id' => 'parentId'], + ['domain-id' => 'domainId'], + ]); + } +} \ No newline at end of file diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index 6ee83005..34b833af 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -10,21 +10,21 @@ class CustomerTest extends TestCase 'passwd' => 'simple-password', ]; - // public function testCreate() - // { - // $customer = $this->_client->customer()->create($this->_customerProperties); - // $this->assertInternalType('integer', $customer->id); - // $this->assertGreaterThan(0, $customer->id); - - // $this->_client->customer()->delete('id', $customer->id); - // } - - // public function testDelete() - // { - // $customer = $this->_client->customer()->create($this->_customerProperties); - // $result = $this->_client->customer()->delete('id', $customer->id); - // $this->assertTrue($result); - // } + public function testCreate() + { + $customer = $this->_client->customer()->create($this->_customerProperties); + $this->assertInternalType('integer', $customer->id); + $this->assertGreaterThan(0, $customer->id); + + $this->_client->customer()->delete('id', $customer->id); + } + + public function testDelete() + { + $customer = $this->_client->customer()->create($this->_customerProperties); + $result = $this->_client->customer()->delete('id', $customer->id); + $this->assertTrue($result); + } public function testGet() { @@ -37,4 +37,10 @@ public function testGet() $this->_client->customer()->delete('id', $customer->id); } + public function testGetDomainList() + { + $domainList = $this->_client->customer()->getDomainList('login', 1); + $this->assertGreaterThan(0, $domainList[0]->id); + } + } From 170b7980c15c34765bc3e9cf91c9e237291abdac Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Sat, 31 Oct 2015 11:24:31 -0200 Subject: [PATCH 30/35] Customer Get filter params optional --- src/PleskX/Api/Operator/Customer.php | 16 +++++++++++++--- tests/CustomerTest.php | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/PleskX/Api/Operator/Customer.php b/src/PleskX/Api/Operator/Customer.php index b1f96eac..0924435b 100644 --- a/src/PleskX/Api/Operator/Customer.php +++ b/src/PleskX/Api/Operator/Customer.php @@ -42,14 +42,24 @@ public function delete($field, $value) * @param integer|string $value * @return Struct\GeneralInfo */ - public function get($field, $value) + public function get($field=null, $value=null) { $packet = $this->_client->getPacket(); $getTag = $packet->addChild('customer')->addChild('get'); - $getTag->addChild('filter')->addChild($field, $value); + $f = $getTag->addChild('filter'); + if ($field) $f->addChild($field, $value); $getTag->addChild('dataset')->addChild('gen_info'); $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'customer'}->get->result; - return new Struct\GeneralInfo($response); + if ($field) + return new Struct\GeneralInfo($response); + else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); + } + return $ret; + } } /** diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index 34b833af..4c04d07f 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -43,4 +43,10 @@ public function testGetDomainList() $this->assertGreaterThan(0, $domainList[0]->id); } + public function testGetAll() + { + $customerList = $this->_client->customer()->get(); + $this->assertGreaterThan(0, $customerList[0]->id); + } + } From 80b98f62ebc54a4af7c355dfe8006ce5f361865b Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Mon, 9 Nov 2015 19:00:05 -0200 Subject: [PATCH 31/35] Adding a call to given DBServers info --- src/PleskX/Api/Operator/DatabaseServer.php | 30 +++++++++++++++++++ .../Api/Struct/DatabaseServer/GeneralInfo.php | 30 +++++++++++++++++++ tests/DatabaseServerTest.php | 7 +++++ 3 files changed, 67 insertions(+) create mode 100644 src/PleskX/Api/Struct/DatabaseServer/GeneralInfo.php diff --git a/src/PleskX/Api/Operator/DatabaseServer.php b/src/PleskX/Api/Operator/DatabaseServer.php index 70924b7a..32f5f689 100644 --- a/src/PleskX/Api/Operator/DatabaseServer.php +++ b/src/PleskX/Api/Operator/DatabaseServer.php @@ -3,6 +3,8 @@ namespace PleskX\Api\Operator; +use PleskX\Api\Struct\DatabaseServer as Struct; + class DatabaseServer extends \PleskX\Api\Operator { @@ -17,4 +19,32 @@ public function getSupportedTypes() return (array)$response->type; } + + /** + * Get database + * + * @param string $field + * @param integer|string $value + * @return mixed Struct\GeneralInfo|Array + */ + public function get($field = null, $value = null) + { + $packet = $this->_client->getPacket(); + $getTag = $packet->addChild($this->_wrapperTag)->addChild('get'); + $filter = $getTag->addChild('filter'); + if ($field && $value) $filteri->addChild($field, $value); + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{$this->_wrapperTag}->{'get'}->result; + $ret = NULL; + if ( $field == 'id' && isset( $response->id ) ) { + $ret = new Struct\GeneralInfo($response); + } else { + $ret = []; + foreach ($response as $f) { + if ( isset( $f->id ) ) + $ret[] = new Struct\GeneralInfo($f); + } + } + return $ret; + } + } diff --git a/src/PleskX/Api/Struct/DatabaseServer/GeneralInfo.php b/src/PleskX/Api/Struct/DatabaseServer/GeneralInfo.php new file mode 100644 index 00000000..8aab55fe --- /dev/null +++ b/src/PleskX/Api/Struct/DatabaseServer/GeneralInfo.php @@ -0,0 +1,30 @@ +id = (integer) $apiResponse->id; + $this->_initScalarProperties($apiResponse->data, [ + 'host', + 'port', + 'type' + ]); + } +} \ No newline at end of file diff --git a/tests/DatabaseServerTest.php b/tests/DatabaseServerTest.php index 855f6102..c0dfaf3e 100644 --- a/tests/DatabaseServerTest.php +++ b/tests/DatabaseServerTest.php @@ -11,4 +11,11 @@ public function testGetSupportedTypes() $this->assertContains('mysql', $types); } + + public function testGet() + { + $servers = $this->_client->databaseServer()->get(); + $this->assertGreaterThan(0, $servers[0]->id); + } + } From 342e57ad227e8c2362508e59424ddf374cf41c17 Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Mon, 9 Nov 2015 19:11:25 -0200 Subject: [PATCH 32/35] bugfix --- src/PleskX/Api/Operator/DatabaseServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PleskX/Api/Operator/DatabaseServer.php b/src/PleskX/Api/Operator/DatabaseServer.php index 32f5f689..a430ab2e 100644 --- a/src/PleskX/Api/Operator/DatabaseServer.php +++ b/src/PleskX/Api/Operator/DatabaseServer.php @@ -32,7 +32,7 @@ public function get($field = null, $value = null) $packet = $this->_client->getPacket(); $getTag = $packet->addChild($this->_wrapperTag)->addChild('get'); $filter = $getTag->addChild('filter'); - if ($field && $value) $filteri->addChild($field, $value); + if ($field && $value) $filter->addChild($field, $value); $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{$this->_wrapperTag}->{'get'}->result; $ret = NULL; if ( $field == 'id' && isset( $response->id ) ) { From 754237471f82426fd93a061b9e8a090fc5fec89c Mon Sep 17 00:00:00 2001 From: Lucas Marin Date: Tue, 10 Nov 2015 00:05:41 -0200 Subject: [PATCH 33/35] bugfix: set alias preferences on get --- src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php b/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php index a6d924ee..ac8532b3 100644 --- a/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php +++ b/src/PleskX/Api/Struct/SiteAlias/GeneralInfo.php @@ -24,7 +24,7 @@ public function __construct($apiResponse) { $this->id = $apiResponse->id; $this->_initScalarProperties($apiResponse->info, [ - ['prefs' => 'preferences'], + ['pref' => 'preferences'], ['site-id' => 'siteId'], 'name', ['ascii-name' => 'asciiName'] From 264afc988b12b436de754c8012e32f4d2c37612c Mon Sep 17 00:00:00 2001 From: Lucas Stevanelli Marin Date: Tue, 3 Jan 2017 13:02:23 -0200 Subject: [PATCH 34/35] Bugfix: Wrong name of property ftpOUt is different of ftpOut --- src/PleskX/Api/Struct/Webspace/Traffic.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PleskX/Api/Struct/Webspace/Traffic.php b/src/PleskX/Api/Struct/Webspace/Traffic.php index e02e79b2..3018e5ec 100644 --- a/src/PleskX/Api/Struct/Webspace/Traffic.php +++ b/src/PleskX/Api/Struct/Webspace/Traffic.php @@ -45,8 +45,8 @@ protected function _trafficScalarProperties( $apiResponse ) { $this->httpIn += $traffic->http_in; $this->httpOut += $traffic->http_out; $this->ftpIn += $traffic->ftp_in; - $this->ftpOUt += $traffic->ftp_out; + $this->ftpOut += $traffic->ftp_out; } } -} \ No newline at end of file +} From e1b5db7bb3ef98abbe9bb38b960ecf1c7886815b Mon Sep 17 00:00:00 2001 From: Lucas Stevanelli Marin Date: Mon, 4 Mar 2019 00:35:45 -0300 Subject: [PATCH 35/35] Bugfix: Always returning one result on get Changing logic of get method on PHPHanlder Operator to get all PHPHandler available on plesk --- src/PleskX/Api/Operator/PHPHandler.php | 29 +++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/PleskX/Api/Operator/PHPHandler.php b/src/PleskX/Api/Operator/PHPHandler.php index 423d5e11..bf402c63 100644 --- a/src/PleskX/Api/Operator/PHPHandler.php +++ b/src/PleskX/Api/Operator/PHPHandler.php @@ -2,6 +2,8 @@ // Copyright 1999-2015. Parallels IP Holdings GmbH. namespace PleskX\Api\Operator; + +use PleskX\Api\Client; use PleskX\Api\Struct\PHPHandler as Struct; class PHPHandler extends \PleskX\Api\Operator @@ -10,16 +12,33 @@ class PHPHandler extends \PleskX\Api\Operator /** * @param string $field * @param integer|string $value - * @return Struct\Info + * + * @return array|Struct\Info */ public function get($field = null, $value = null) { - $ips = []; $packet = $this->_client->getPacket(); + $filter = $packet->addChild('php-handler')->addChild('get')->addChild('filter'); - if ($field) $filter->addChild($field, $value); - $response = $this->_client->request($packet); - return new Struct\Info($response); + if ($field) { + $filter->addChild($field, $value); + } + + $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL)->{'php-handler'}->get->result; + + $ret = null; + if ($field == 'id' && isset($response->id)) { + $ret = new Struct\Info($response); + } else { + $ret = []; + foreach ($response as $f) { + if (isset($f->id)) { + $ret[] = new Struct\Info($f); + } + } + } + + return $ret; } }