MaximumVmRateJob.php 1.3 KB

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