Skip to content

Commit

Permalink
FEATURE SVM-3051 WHMCS8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Ruzavin committed Oct 12, 2020
1 parent fc49808 commit a06cbbc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/servers/solusvmpro/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.1
4.1.2
22 changes: 20 additions & 2 deletions modules/servers/solusvmpro/lib/SolusVM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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');
}
}

9 changes: 5 additions & 4 deletions modules/servers/solusvmpro/solusvmpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a06cbbc

Please sign in to comment.