PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/concrete/libraries/3rdparty/Zend/Queue/Message/PlatformJob.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 194 lines | 79 code | 21 blank | 94 comment | 14 complexity | 54b3980a66cbd29c53458d6f470b595e MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Queue
  17. * @subpackage Message
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: PlatformJob.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. /**
  23. * @see Zend_Queue_Message
  24. */
  25. require_once 'Zend/Queue/Message.php';
  26. /**
  27. * Class for managing Zend Platform JobQueue jobs via Zend_Queue
  28. *
  29. * @category Zend
  30. * @package Zend_Queue
  31. * @subpackage Message
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Queue_Message_PlatformJob extends Zend_Queue_Message
  36. {
  37. /**
  38. * @var ZendApi_Job
  39. */
  40. protected $_job;
  41. /**
  42. * Job identifier
  43. * @var string
  44. */
  45. protected $_id = null;
  46. /**
  47. * Constructor
  48. *
  49. * The constructor should be an array of options.
  50. *
  51. * If the option 'data' is provided, and is an instance of ZendApi_Job,
  52. * that object will be used as the internal job; if that option is not a
  53. * ZendApi_Job instance, an exception will be thrown.
  54. *
  55. * Alternately, you may specify the 'script' parameter, which should be a
  56. * JobQueue script the job will request. A new ZendApi_Job object will then
  57. * be created using that script and any options you provide.
  58. *
  59. * @param array $options
  60. * @return void
  61. * @throws Zend_Queue_Exception
  62. */
  63. public function __construct(array $options = array())
  64. {
  65. if (isset($options['data'])) {
  66. if (!($options['data'] instanceof ZendApi_Job)) {
  67. require_once 'Zend/Queue/Exception.php';
  68. throw new Zend_Queue_Exception('Data must be an instance of ZendApi_Job');
  69. }
  70. $this->_job = $options['data'];
  71. parent::__construct($this->_job->getProperties());
  72. } else {
  73. parent::__construct($options);
  74. if (!isset($options['script'])) {
  75. require_once 'Zend/Queue/Exception.php';
  76. throw new Zend_Queue_Exception('The script is mandatory data');
  77. }
  78. $this->_job = new ZendApi_Job($options['script']);
  79. $this->_setJobProperties();
  80. }
  81. }
  82. /**
  83. * Set the job identifier
  84. *
  85. * Used within Zend_Queue only.
  86. *
  87. * @param string $id
  88. * @return Zend_Queue_Message_PlatformJob
  89. */
  90. public function setJobId($id)
  91. {
  92. $this->_id = $id;
  93. return $this;
  94. }
  95. /**
  96. * Retrieve the job identifier
  97. *
  98. * @return string
  99. */
  100. public function getJobId()
  101. {
  102. return (($this->_id) ? $this->_id : $this->_job->getID());
  103. }
  104. /**
  105. * Retrieve the internal ZendApi_Job instance
  106. *
  107. * @return ZendApi_Job
  108. */
  109. public function getJob()
  110. {
  111. return $this->_job;
  112. }
  113. /**
  114. * Store queue and data in serialized object
  115. *
  116. * @return array
  117. */
  118. public function __sleep()
  119. {
  120. return serialize('_job', '_id', '_data');
  121. }
  122. /**
  123. * Query the class name of the Queue object for which this
  124. * Message was created.
  125. *
  126. * @return string
  127. */
  128. public function getQueueClass()
  129. {
  130. return 'Zend_Queue_Adapter_Platform_JQ';
  131. }
  132. /**
  133. * Sets properties on the ZendApi_Job instance
  134. *
  135. * Any options in the {@link $_data} array will be checked. Those matching
  136. * options in ZendApi_Job will be used to set those options in that
  137. * instance.
  138. *
  139. * @return void
  140. */
  141. protected function _setJobProperties() {
  142. if (isset($this->_data['script'])) {
  143. $this->_job->setScript($this->_data['script']);
  144. }
  145. if (isset($this->_data['priority'])) {
  146. $this->_job->setJobPriority($this->_data['priority']);
  147. }
  148. if (isset($this->_data['name'])) {
  149. $this->_job->setJobName($this->_data['name']);
  150. }
  151. if (isset($this->_data['predecessor'])) {
  152. $this->_job->setJobDependency($this->_data['predecessor']);
  153. }
  154. if (isset($this->_data['preserved'])) {
  155. $this->_job->setPreserved($this->_data['preserved']);
  156. }
  157. if (isset($this->_data['user_variables'])) {
  158. $this->_job->setUserVariables($this->_data['user_variables']);
  159. }
  160. if (!empty($this->_data['interval'])) {
  161. $endTime = isset($this->_data['end_time']) ? $this->_data['end_time'] : null;
  162. $this->_job->setRecurrenceData($this->_data['interval'], $endTime);
  163. } elseif (isset($this->_data['interval']) && ($this->_data['interval'] === '')) {
  164. $this->_job->setRecurrenceData(0,0);
  165. }
  166. if (isset($this->_data['scheduled_time'])) {
  167. $this->_job->setScheduledTime($this->_data['scheduled_time']);
  168. }
  169. if (isset($this->_data['application_id'])) {
  170. $this->_job->setApplicationID($this->_data['application_id']);
  171. }
  172. }
  173. }