From 0e560fd8fade2f9f031599fcae987f82941f3869 Mon Sep 17 00:00:00 2001 From: Mikhail Korsakov Date: Tue, 26 Oct 2021 18:48:45 +0700 Subject: [PATCH] BUGFIX SIO-3639 fix product upgrade/downgrade --- README.md | 17 +++++++++++------ .../solusiovps/docs => docs}/account.png | Bin .../docs => docs}/option-location.png | Bin .../solusiovps/docs => docs}/option-os.png | Bin .../solusiovps/docs => docs}/product.png | Bin .../solusiovps/docs => docs}/server-group.png | Bin .../solusiovps/docs => docs}/server.png | Bin .../solusiovps/lib/WhmcsAPI/Product.php | 8 +++----- tests/lib/WhmcsAPI/ProductTest.php | 10 +++++----- 9 files changed, 19 insertions(+), 16 deletions(-) rename {modules/servers/solusiovps/docs => docs}/account.png (100%) rename {modules/servers/solusiovps/docs => docs}/option-location.png (100%) rename {modules/servers/solusiovps/docs => docs}/option-os.png (100%) rename {modules/servers/solusiovps/docs => docs}/product.png (100%) rename {modules/servers/solusiovps/docs => docs}/server-group.png (100%) rename {modules/servers/solusiovps/docs => docs}/server.png (100%) diff --git a/README.md b/README.md index 4779ed4..83a0a70 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Minimum required **PHP** version is 7.4. Open the Account page in the SolusIO user-area to generate an API Token. -![Account](./modules/servers/solusiovps/docs/account.png) +![Account](./docs/account.png) Configure SolusIO API access by adding a new server in WHMCS. Required fields are `Hostname` and `Password`. @@ -35,15 +35,15 @@ Configure SolusIO API access by adding a new server in WHMCS. Required fields ar SolusIO API Token should be saved in the password field. -![Server](./modules/servers/solusiovps/docs/server.png) +![Server](./docs/server.png) Create a server group in WHMCS and assign the server which was created on the previous step. -![Server group](./modules/servers/solusiovps/docs/server-group.png) +![Server group](./docs/server-group.png) ## Product Configuration -![Product](./modules/servers/solusiovps/docs/product.png) +![Product](./docs/product.png) Create a product in WHMCS and select `SolusIO VPS` as the linked module and the server group you configured previous. @@ -55,7 +55,7 @@ Select the `Plan`, `Default Location` and `Default Operating System` or `Applica The module gives the ability to select a specific location on ordering of a product. This is done in the form of configurable options. -![Location](./modules/servers/solusiovps/docs/option-location.png) +![Location](./docs/option-location.png) Create a configurable option named `Location`. Add options with the following convention: `locationId|locationName`. This will take priority over selected location in product module settings. @@ -63,7 +63,7 @@ Create a configurable option named `Location`. Add options with the following co The module gives the ability to select a specific operating system on ordering of a product. This is done in the form of configurable options. -![Operating System](./modules/servers/solusiovps/docs/option-os.png) +![Operating System](./docs/option-os.png) Create a configurable option named `Operating System`. Add options with the following convention: `osId|osName`. This will take priority over selected operating system in product module settings. @@ -77,6 +77,11 @@ Create a custom field named `SSH Key` and type `Text Area`. Create corresponding product custom fields for applications with the same property names as defined in SolusIO. +## Product upgrade/downgrade + +It is possible to use product Upgrade/Downgrade feature to change product type in admin area. To do this select `New Product/Service` with another SolusIO package in Upgrade/Downgrade dialog of admin area. +After order is complete this will trigger server resize action on SolusIO side. + ## Other configurations There are several options that can be configured within module config file `config.php` diff --git a/modules/servers/solusiovps/docs/account.png b/docs/account.png similarity index 100% rename from modules/servers/solusiovps/docs/account.png rename to docs/account.png diff --git a/modules/servers/solusiovps/docs/option-location.png b/docs/option-location.png similarity index 100% rename from modules/servers/solusiovps/docs/option-location.png rename to docs/option-location.png diff --git a/modules/servers/solusiovps/docs/option-os.png b/docs/option-os.png similarity index 100% rename from modules/servers/solusiovps/docs/option-os.png rename to docs/option-os.png diff --git a/modules/servers/solusiovps/docs/product.png b/docs/product.png similarity index 100% rename from modules/servers/solusiovps/docs/product.png rename to docs/product.png diff --git a/modules/servers/solusiovps/docs/server-group.png b/docs/server-group.png similarity index 100% rename from modules/servers/solusiovps/docs/server-group.png rename to docs/server-group.png diff --git a/modules/servers/solusiovps/docs/server.png b/docs/server.png similarity index 100% rename from modules/servers/solusiovps/docs/server.png rename to docs/server.png diff --git a/modules/servers/solusiovps/lib/WhmcsAPI/Product.php b/modules/servers/solusiovps/lib/WhmcsAPI/Product.php index 93b8816..bd2adaa 100644 --- a/modules/servers/solusiovps/lib/WhmcsAPI/Product.php +++ b/modules/servers/solusiovps/lib/WhmcsAPI/Product.php @@ -18,7 +18,7 @@ class Product { public const MODULE_NAME = 'solusiovps'; - public const CONFIG_OPTIONS_TYPE = 'configoptions'; + public const PACKAGE_OPTIONS_TYPE = 'package'; public static function updateDomain(int $serviceId, string $domain): void { @@ -33,18 +33,16 @@ public static function upgrade(int $upgradeId): void $upgrade = Upgrade::getById($upgradeId); $serviceId = (int) $upgrade->relid; - if ($upgrade->type !== self::CONFIG_OPTIONS_TYPE) { + if ($upgrade->type !== self::PACKAGE_OPTIONS_TYPE) { return; } - list($newProductId, $paymentType) = explode(',', $upgrade->newvalue); $newProduct = ProductModel::getById($newProductId); - if (empty($newProduct) || $newProduct->type !== self::MODULE_NAME) { + if (empty($newProduct) || $newProduct->servertype !== self::MODULE_NAME) { return; } - $newPlanId = (int) $newProduct->configoption1; $hosting = Hosting::getByServiceId($serviceId); $server = SolusServer::getByServiceId($serviceId); diff --git a/tests/lib/WhmcsAPI/ProductTest.php b/tests/lib/WhmcsAPI/ProductTest.php index 80ff763..123aa44 100644 --- a/tests/lib/WhmcsAPI/ProductTest.php +++ b/tests/lib/WhmcsAPI/ProductTest.php @@ -39,7 +39,7 @@ public function testUpgrade(): void $newPlanId = 25; $this->upgrade->shouldReceive('getById')->with($this->upgradeId) ->andReturn((object)[ - 'type' => Product::CONFIG_OPTIONS_TYPE, + 'type' => Product::PACKAGE_OPTIONS_TYPE, 'relid' => $this->relid, 'newvalue' => implode(',', [ (string)$this->newProductId, $this->paymentType ]), ]); @@ -47,7 +47,7 @@ public function testUpgrade(): void $productModel = Mockery::mock('overload:WHMCS\Module\Server\SolusIoVps\Database\Models\Product'); $productModel->shouldReceive('getById')->with($this->newProductId) ->andReturn((object)[ - 'type' => Product::MODULE_NAME, + 'servertype' => Product::MODULE_NAME, 'configoption1' => $newPlanId, ]); @@ -78,14 +78,14 @@ public function testUpgradeWrongModuleName(): void { $this->upgrade->shouldReceive('getById')->with($this->upgradeId) ->andReturn((object)[ - 'type' => Product::CONFIG_OPTIONS_TYPE, + 'type' => Product::PACKAGE_OPTIONS_TYPE, 'relid' => $this->relid, 'newvalue' => implode(',', [ (string)$this->newProductId, $this->paymentType ]), ]); $productModel = Mockery::mock('overload:WHMCS\Module\Server\SolusIoVps\Database\Models\Product'); $productModel->shouldReceive('getById')->with($this->newProductId) - ->andReturn((object)[ 'type' => 'other module' ]); + ->andReturn((object)[ 'servertype' => 'other module' ]); self::assertNull(Product::upgrade($this->upgradeId)); } @@ -94,7 +94,7 @@ public function testUpgradeNoProduct(): void $this->upgrade->shouldReceive('getById')->with($this->upgradeId) ->andReturn((object)[ - 'type' => Product::CONFIG_OPTIONS_TYPE, + 'type' => Product::PACKAGE_OPTIONS_TYPE, 'relid' => $this->relid, 'newvalue' => implode(',', [ (string)$this->newProductId, $this->paymentType ]), ]);