VmidHelper.php 995 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Helper;
  3. use Illuminate\Database\Capsule\Manager as DB;
  4. use ModulesGarden\ProxmoxAddon\App\Models\VmModel;
  5. trait VmidHelper
  6. {
  7. public function vmidExistInWhmcs($vmid)
  8. {
  9. //vps
  10. $cfv = 'tblcustomfieldsvalues';
  11. $cfn = 'tblcustomfields';
  12. $h = 'tblhosting';
  13. $query = DB::table($cfv)
  14. ->rightJoin($cfn, "{$cfn}.id", "=", "{$cfv}.fieldid")
  15. ->leftJoin($h, "{$h}.id", "=", "{$cfv}.relid")
  16. ->where("{$cfn}.fieldname", "like", "vmid%")
  17. ->where("{$cfv}.value", $vmid)
  18. ->whereIn("{$h}.domainstatus", ['Active', "Suspended"]);
  19. if ($query->count())
  20. {
  21. return true;
  22. }
  23. //cloud
  24. try
  25. {
  26. $query = VmModel::where("vmid", $vmid);
  27. return $query->count() > 0;
  28. }
  29. catch (\Exception $ex)
  30. { // table does not exist
  31. }
  32. return false;
  33. }
  34. }