BxDolCronQuery.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Database queries for Cron
  11. * @see BxDolCron
  12. */
  13. class BxDolCronQuery extends BxDolDb implements iBxDolSingleton
  14. {
  15. protected function __construct()
  16. {
  17. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  18. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  19. parent::__construct();
  20. }
  21. /**
  22. * Prevent cloning the instance
  23. */
  24. public function __clone()
  25. {
  26. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  27. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  28. }
  29. /**
  30. * Get singleton instance of the class
  31. */
  32. static function getInstance()
  33. {
  34. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  35. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolCronQuery();
  36. return $GLOBALS['bxDolClasses'][__CLASS__];
  37. }
  38. public function getJobs()
  39. {
  40. return $this->fromCache('sys_cron_jobs', 'getAll', "SELECT * FROM `sys_cron_jobs`");
  41. }
  42. public function addTransientJobClass($sName, $sClass, $sFile)
  43. {
  44. $sQuery = $this->prepare("INSERT INTO `sys_cron_jobs` SET `name`=?, `time`='transient', `class`=?, `file`=?", $sName, $sClass, $sFile);
  45. return (int)$this->query($sQuery) > 0;
  46. }
  47. public function addTransientJobService($sName, $mixedService)
  48. {
  49. if(is_array($mixedService))
  50. $mixedService = call_user_func_array('BxDolService::getSerializedService', $mixedService);
  51. if(!BxDolService::isSerializedService($mixedService))
  52. return false;
  53. $sQuery = $this->prepare("INSERT INTO `sys_cron_jobs` SET `name`=?, `time`='transient', `service_call`=?", $sName, $mixedService);
  54. return (int)$this->query($sQuery) > 0;
  55. }
  56. public function getTransientJobs()
  57. {
  58. return $this->getAllWithKey("SELECT * FROM `sys_cron_jobs` WHERE `time`='transient'", 'name');
  59. }
  60. public function deleteTransientJobs()
  61. {
  62. return $this->query("DELETE FROM `sys_cron_jobs` WHERE `time`='transient'");
  63. }
  64. }
  65. /** @} */