MaximumVmRateJob.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Jobs\Cloud\NetworkRate;
  3. use ModulesGarden\ProxmoxAddon\App\Jobs\BaseJob;
  4. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  5. use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\ConfigurableOption;
  6. use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;
  7. class MaximumVmRateJob extends BaseJob
  8. {
  9. use ProductService;
  10. public function handle($text = null)
  11. {
  12. $this->initParams();
  13. $this->initServices();
  14. $this->api();
  15. $this->initVm();
  16. $container = [];
  17. $rate = null;
  18. if ($this->getWhmcsConfigOption(ConfigurableOption::NETWORK_RATE,$this->configuration()->getRate()) &&
  19. $this->getWhmcsConfigOption(ConfigurableOption::NETWORK_RATE,$this->configuration()->getRate()) != "-1")
  20. {
  21. $rate = $this->getWhmcsConfigOption(ConfigurableOption::NETWORK_RATE,$this->configuration()->getRate()) ;
  22. }
  23. foreach (sl('Vm')->getVm()->getNetworkDevices($this->configuration()->getBridge()) as $entity)
  24. {
  25. $hash = $entity->getHashCode();
  26. if ($entity->getRate() != $rate)
  27. {
  28. $entity->setRate($rate);
  29. }
  30. if ($hash != $entity->getHashCode())
  31. {
  32. $container[$entity->getId()] = $entity->asConfig();
  33. }
  34. }
  35. if (!empty($container))
  36. {
  37. sl('Vm')->getVm()->updateConfig($container);
  38. }
  39. }
  40. }