AdminProductConfigFields.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (26.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Product;
  20. $hookManager->register(
  21. function ($args)
  22. {
  23. if(! \ModulesGarden\ProxmoxAddon\App\Models\ModuleSetting::where("setting","duplicateProduct")->count()){
  24. return;
  25. }
  26. if(!file_exists(\ModulesGarden\ProxmoxAddon\Core\ModuleConstants::getFullPathWhmcs('modules', 'servers','proxmoxVPS', 'core') . DIRECTORY_SEPARATOR . 'Bootstrap.php')){
  27. return;
  28. }
  29. $file = \ModulesGarden\ProxmoxAddon\Core\ModuleConstants::getFullPathWhmcs('modules', 'servers','proxmoxVPS', 'core') . DIRECTORY_SEPARATOR . 'Bootstrap.php';
  30. if(!file_exists($file))
  31. {
  32. return;
  33. }
  34. require_once $file;
  35. $provider = new \ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Providers\ProductProvider($args['pid']);
  36. /**
  37. * @var $setting ModuleSetting
  38. */
  39. $setting = \ModulesGarden\ProxmoxAddon\App\Models\ModuleSetting::where("setting","duplicateProduct")->firstOrFail();
  40. $setting->value = json_decode( $setting->value , true);
  41. if (!$provider->isSupportedModule())
  42. {
  43. $setting->delete();
  44. return;
  45. }elseif(!Product::where("id", $args['pid'])->where("name", $setting->value['newproductname'])->count() ){
  46. return;
  47. }
  48. $setting->delete();
  49. $provider->replicate($setting->value['existingproduct']);
  50. }, 1001);