From a06cbbc74e56e16805817b3c1a5ca5d7c7007cb0 Mon Sep 17 00:00:00 2001 From: Evgenii Ruzavin Date: Fri, 9 Oct 2020 11:57:18 +0700 Subject: [PATCH] FEATURE SVM-3051 WHMCS8 support --- modules/servers/solusvmpro/VERSION | 2 +- modules/servers/solusvmpro/lib/SolusVM.php | 22 ++++++++++++++++++++-- modules/servers/solusvmpro/solusvmpro.php | 9 +++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/servers/solusvmpro/VERSION b/modules/servers/solusvmpro/VERSION index 2582ddd..cd9b8f5 100644 --- a/modules/servers/solusvmpro/VERSION +++ b/modules/servers/solusvmpro/VERSION @@ -1 +1 @@ -4.1.1 \ No newline at end of file +4.1.2 \ No newline at end of file diff --git a/modules/servers/solusvmpro/lib/SolusVM.php b/modules/servers/solusvmpro/lib/SolusVM.php index b9f7488..a350374 100644 --- a/modules/servers/solusvmpro/lib/SolusVM.php +++ b/modules/servers/solusvmpro/lib/SolusVM.php @@ -4,7 +4,8 @@ use SolusVM\Curl; use Illuminate\Database\Capsule\Manager as Capsule; - +use Illuminate\Support\Collection as Collection; +use Exception; class SolusVM { protected $url; @@ -975,7 +976,7 @@ public static function getParamsFromServiceID( $servid, $uid = null ) { public static function getParamsFromVserviceID( $vserverid, $uid ) { /** @var stdClass $hosting */ - foreach ( Capsule::table( 'tblhosting' )->where( 'userid', $uid )->get() as $hosting ) { + foreach ( SolusVM::collectionToArray(Capsule::table( 'tblhosting' )->where( 'userid', $uid )->get()) as $hosting ) { $vserverFieldRow = Capsule::table( 'tblcustomfields' )->where( 'relid', $hosting->packageid )->where( 'fieldname', 'vserverid' )->first(); if ( ! $vserverFieldRow ) { @@ -1091,5 +1092,22 @@ public function isSuccessResponse( $result ) { $this->debugLog( 'solusvmpro', 'isSuccessResponse', '', $result, '', array() ); return false; } + + /** + * Converts Collection to array if required + * + * @param array|Collection|any $object arbitrary object. + * + * @return array + */ + public function collectionToArray($object) { + if (is_array($object)) { + return $object; + } + if ($object instanceof Collection) { + return $object->toArray(); + } + throw new Exception('Object is not an array or Illuminate\Support\Collection'); + } } diff --git a/modules/servers/solusvmpro/solusvmpro.php b/modules/servers/solusvmpro/solusvmpro.php index 697b1a4..5967f7f 100644 --- a/modules/servers/solusvmpro/solusvmpro.php +++ b/modules/servers/solusvmpro/solusvmpro.php @@ -25,10 +25,11 @@ function initConfigOption() { if(!isset($_POST['id'])){ - $data = Capsule::table('tblproducts')->where('servertype', 'solusvmpro')->where('id', $_GET['id'])->get(); + $data = SolusVM::collectionToArray(Capsule::table('tblproducts')->where('servertype', 'solusvmpro')->where('id', $_GET['id'])->get()); }else{ - $data = Capsule::table('tblproducts')->where('servertype', 'solusvmpro')->where('id', $_POST['id'])->get(); + $data = SolusVM::collectionToArray(Capsule::table('tblproducts')->where('servertype', 'solusvmpro')->where('id', $_POST['id'])->get()); } + $packageconfigoption = []; if(is_array($data) && count($data) > 0) { $packageconfigoption[1] = $data[0]->configoption1; @@ -47,7 +48,7 @@ function solusvmpro_ConfigOptions() { $master_array = array(); /** @var stdClass $row */ - foreach ( Capsule::table( 'tblservers' )->where( 'type', 'solusvmpro' )->get() as $row ) { + foreach ( SolusVM::collectionToArray(Capsule::table( 'tblservers' )->where( 'type', 'solusvmpro' )->get()) as $row ) { $master_array[] = $row->id . " - " . $row->name; } @@ -724,7 +725,7 @@ function solusvmpro_ChangePackage( $params ) { if ( $cextraip > 0 ){ //first() function doesn't work - $ipaddresses = Capsule::table('tblhosting')->select('assignedips')->where( 'id', $params['serviceid'] )->get(); + $ipaddresses = SolusVM::collectionToArray(Capsule::table('tblhosting')->select('assignedips')->where( 'id', $params['serviceid'] )->get()); $ips = $ipaddresses[0]->assignedips; $lines_arr = explode(PHP_EOL, $ips);