Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install license #2

Merged
merged 2 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/PleskX/Api/Operator/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// Copyright 1999-2016. Parallels IP Holdings GmbH.

namespace PleskX\Api\Operator;

use PleskX\Api\Struct\Server as Struct;
use PleskX\Api\Exception;


class Server extends \PleskX\Api\Operator
{
Expand Down Expand Up @@ -168,4 +171,62 @@ private function _getInfo($operation)
return $response->$operation;
}


/**
* Restituisce i dati della licenza eventualmente installata sul server
* @return Struct\LicenseInfo
*/
public function getLicenseInfo() {
$packet = $this->_client->getPacket();
$packet->addChild( $this->_wrapperTag )->addChild( 'get' )->addChild( 'key' );

$response = $this->_client->request( $packet );

return new Struct\LicenseInfo( $response );
}


/**
* Restituisce i dati della licenze aggiuntive eventualmente installate sul server
* @return Struct\LicenseAdditionalInfo
*/
public function getAdditionalLicensesInfo() {
$packet = $this->_client->getPacket();
$packet->addChild( $this->_wrapperTag )->addChild( 'get_additional_key' );

$response = new Struct\LicenseAdditionalInfo( $this->_client->request( $packet ) );

if( !is_null( $response->error_code ) or !empty( $response->error_message ) ) {
throw new Exception( $response->error_message, $response->error_code );
}

return $response;
}


/**
* Installa una licenza principale o aggiuntiva
* @param string $activationCode
* @param bool $isAdditionalLicense
* @return Struct\LicenseInstall
*/
public function installLicense( $activationCode, $isAdditionalLicense = false ) {
$packet = $this->_client->getPacket();
$server = $packet->addChild( $this->_wrapperTag );
$licInstall = $server->addChild( 'lic_install' );

$licInstall->addChild( 'activation-code', $activationCode );

if( $isAdditionalLicense ) {
$licInstall->addChild( 'additional_key' );
}

$response = new Struct\LicenseInstall( $this->_client->request( $packet ) );

if( !is_null( $response->error_code ) or !empty( $response->error_message ) ) {
throw new Exception( $response->error_message, $response->error_code );
}

return $response;
}
}
29 changes: 29 additions & 0 deletions src/PleskX/Api/Struct/Server/License/keyInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace PleskX\Api\Struct\Server\License;

use PleskX\Api\Struct\Server\LicensePropertyInfo;


/**
* Struttura dati per le informazioni su una licenza
*/
class keyInfo extends \PleskX\Api\Struct {

/** @var \PleskX\Api\Struct\Server\LicensePropertyInfo[] Collezione di proprietà della licenza */
public $properties;


/**
* @param \SimpleXMLElement $apiResponse
*/
public function __construct( $apiResponse ) {
$this->properties = [];

if( isset( $apiResponse->property ) ) {
foreach( $apiResponse->property as $property ) {
$this->properties[] = new LicensePropertyInfo( $property );
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace PleskX\Api\Struct\Server\LicenseAdditional;

use PleskX\Api\Struct\Server\LicensePropertyInfo;


/**
* Struttura dati per le informazioni su una licenza
*/
class keyAdditionalInfo extends \PleskX\Api\Struct {

/** @var string Numero completo della licenza */
public $key_number;

/** @var string Nome completo della licenza */
public $full_name;

/** @var bool Indica se la licenza è installata e funzionante. False se scaduta */
public $active;

/** @var string Data di scadenza licenza in formato YYYYMMDD */
public $date_expiry;

/** @var \PleskX\Api\Struct\Server\LicensePropertyInfo[] Collezione di proprietà della licenza */
public $properties;


/**
* @param \SimpleXMLElement $apiResponse
*/
public function __construct( $apiResponse ) {
$this->_initScalarProperties( $apiResponse, [
['number' => 'key_number'],
['name' => 'full_name'],
['active' => 'active'],
]);

$this->date_expiry = '';
if( isset( $apiResponse->lim_date ) ) {
$this->date_expiry = $apiResponse->lim_date;
}

$this->properties = [];

if( isset( $apiResponse->property ) ) {
foreach( $apiResponse->property as $property ) {
$this->properties[] = new LicensePropertyInfo( $property );
}
}
}
}
47 changes: 47 additions & 0 deletions src/PleskX/Api/Struct/Server/LicenseAdditionalInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace PleskX\Api\Struct\Server;

use PleskX\Api\Struct\Server\LicenseAdditional\keyAdditionalInfo;


/**
* Struttura dati per le informazioni su una licenza aggiuntiva
*/
class LicenseAdditionalInfo extends \PleskX\Api\Struct {

/** @var string Stato della licenza */
public $status;

/** @var int Codice di errore in caso di fallimento della richiesta (NULL se la richiesta è andata a buon fine) */
public $error_code;

/** @var string Messaggio di errore in caso di fallimento della richiesta */
public $error_message;

/** @var \PleskX\Api\Struct\Server\License\keyAdditionalInfo Licenza aggiuntiva */
public $key;


/**
* @param \SimpleXMLElement $apiResponse Oggetto xml a partire da <result>
*/
public function __construct( $apiResponse ) {
$this->_initScalarProperties( $apiResponse, [
'status',
]);

if( isset( $apiResponse->errcode ) ) {
$this->error_code = $apiResponse->errcode;
}

$this->error_message = '';
if( isset( $apiResponse->errtext ) ) {
$this->error_code = $apiResponse->errtext;
}

if( isset( $apiResponse->key_info ) ) {
$this->key = new keyAdditionalInfo( $apiResponse->key_info );
}
}
}
32 changes: 32 additions & 0 deletions src/PleskX/Api/Struct/Server/LicenseInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace PleskX\Api\Struct\Server;

use PleskX\Api\Struct\Server\License\keyInfo;


/**
* Struttura dati per le informazioni sulla licenza installata
*/
class LicenseInfo extends \PleskX\Api\Struct {

/** @var string Stato della licenza */
public $status;

/** @var \PleskX\Api\Struct\Server\License\keyInfo Licenza */
public $key;


/**
* @param \SimpleXMLElement $apiResponse Oggetto xml a partire da <result>
*/
public function __construct( $apiResponse ) {
$this->_initScalarProperties( $apiResponse, [
'status',
]);

if( isset( $apiResponse->key ) ) {
$this->key = new keyInfo( $apiResponse->key );
}
}
}
38 changes: 38 additions & 0 deletions src/PleskX/Api/Struct/Server/LicenseInstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace PleskX\Api\Struct\Server;


/**
* Struttura dati per la response di installazione licenza principale o aggiuntiva
*/
class LicenseInstall extends \PleskX\Api\Struct {

/** @var string Stato della licenza */
public $status;

/** @var int Codice di errore in caso di fallimento nell'installazione (NULL se la richiesta è andata a buon fine) */
public $error_code;

/** @var string Messaggio di errore in caso di fallimento nell'installazione */
public $error_message;


/**
* @param \SimpleXMLElement $apiResponse
*/
public function __construct( $apiResponse ) {
$this->_initScalarProperties( $apiResponse, [
[ 'status' => 'status'],
]);

if( isset( $apiResponse->errcode ) ) {
$this->error_code = $apiResponse->errcode;
}

$this->error_message = '';
if( isset( $apiResponse->errtext ) ) {
$this->error_code = $apiResponse->errtext;
}
}
}
27 changes: 27 additions & 0 deletions src/PleskX/Api/Struct/Server/LicensePropertyInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace PleskX\Api\Struct\Server;


/**
* Struttura dati per le informazioni su una proprietà di una licenza
*/
class LicensePropertyInfo extends \PleskX\Api\Struct {

/** @var string Nome della proprietà */
public $name;

/** @var string Valore della proprietà */
public $value;


/**
* @param \SimpleXMLElement $apiResponse
*/
public function __construct( $apiResponse ) {
$this->_initScalarProperties( $apiResponse, [
'name',
'value',
]);
}
}