BxDolCronQuery.php 2.3 KB

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