JobProvider.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* * ********************************************************************
  3. * Proxmox Addon product developed. (Oct 12, 2018)
  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. namespace ModulesGarden\ProxmoxAddon\App\UI\Jobs\Providers;
  20. use ModulesGarden\ProxmoxAddon as main;
  21. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
  22. use ModulesGarden\ProxmoxAddon\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  23. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\DataProviders\BaseModelDataProvider;
  24. use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;
  25. /**
  26. * Description of InstanceImageProvider
  27. *
  28. * @author Pawel Kopec <pawelk@modulesgardne.com>
  29. */
  30. class JobProvider extends BaseModelDataProvider implements AdminArea
  31. {
  32. public function __construct()
  33. {
  34. parent::__construct(main\Core\Queue\Models\Job::class);
  35. }
  36. public function read()
  37. {
  38. parent::read();
  39. $job = $this->data['job'];
  40. $this->data['job'] = sl('lang')->tr($job);
  41. }
  42. public function create()
  43. {
  44. }
  45. public function update()
  46. {
  47. }
  48. public function deleteMass()
  49. {
  50. foreach ($this->getRequestValue('massActions') as $id)
  51. {
  52. $this->model->where('id', $id)->delete();
  53. }
  54. return (new HtmlDataJsonResponse())->setMessageAndTranslate('The selected jobs have been deleted successfully');
  55. }
  56. public function delete()
  57. {
  58. parent::delete();
  59. sl('lang')->addReplacementConstant('job', $this->formData['job']);
  60. return (new HtmlDataJsonResponse())->setMessageAndTranslate('Job :job: has been deleted successfully');
  61. }
  62. public function run(){
  63. sl('lang')->addReplacementConstant('job', $this->formData['job']);
  64. $task = main\App\Models\Job::findOrFail($this->formData['id']);
  65. $manager = new main\Core\Queue\Manager($task);
  66. $manager->fire();
  67. return (new HtmlDataJsonResponse())->setMessageAndTranslate('Job :job: has been ran successfully');
  68. }
  69. }