File indexing completed on 2024-12-22 05:36:57
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Queue 0017 * @subpackage Message 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Queue_Message 0025 */ 0026 // require_once 'Zend/Queue/Message.php'; 0027 0028 /** 0029 * Class for managing Zend Platform JobQueue jobs via Zend_Queue 0030 * 0031 * @category Zend 0032 * @package Zend_Queue 0033 * @subpackage Message 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Queue_Message_PlatformJob extends Zend_Queue_Message 0038 { 0039 /** 0040 * @var ZendApi_Job 0041 */ 0042 protected $_job; 0043 0044 /** 0045 * Job identifier 0046 * @var string 0047 */ 0048 protected $_id = null; 0049 0050 /** 0051 * Constructor 0052 * 0053 * The constructor should be an array of options. 0054 * 0055 * If the option 'data' is provided, and is an instance of ZendApi_Job, 0056 * that object will be used as the internal job; if that option is not a 0057 * ZendApi_Job instance, an exception will be thrown. 0058 * 0059 * Alternately, you may specify the 'script' parameter, which should be a 0060 * JobQueue script the job will request. A new ZendApi_Job object will then 0061 * be created using that script and any options you provide. 0062 * 0063 * @param array $options 0064 * @return void 0065 * @throws Zend_Queue_Exception 0066 */ 0067 public function __construct(array $options = array()) 0068 { 0069 if (isset($options['data'])) { 0070 if (!($options['data'] instanceof ZendApi_Job)) { 0071 // require_once 'Zend/Queue/Exception.php'; 0072 throw new Zend_Queue_Exception('Data must be an instance of ZendApi_Job'); 0073 } 0074 $this->_job = $options['data']; 0075 parent::__construct($this->_job->getProperties()); 0076 } else { 0077 parent::__construct($options); 0078 0079 if (!isset($options['script'])) { 0080 // require_once 'Zend/Queue/Exception.php'; 0081 throw new Zend_Queue_Exception('The script is mandatory data'); 0082 } 0083 0084 $this->_job = new ZendApi_Job($options['script']); 0085 $this->_setJobProperties(); 0086 } 0087 } 0088 0089 /** 0090 * Set the job identifier 0091 * 0092 * Used within Zend_Queue only. 0093 * 0094 * @param string $id 0095 * @return Zend_Queue_Message_PlatformJob 0096 */ 0097 public function setJobId($id) 0098 { 0099 $this->_id = $id; 0100 return $this; 0101 } 0102 0103 /** 0104 * Retrieve the job identifier 0105 * 0106 * @return string 0107 */ 0108 public function getJobId() 0109 { 0110 return (($this->_id) ? $this->_id : $this->_job->getID()); 0111 } 0112 0113 /** 0114 * Retrieve the internal ZendApi_Job instance 0115 * 0116 * @return ZendApi_Job 0117 */ 0118 public function getJob() 0119 { 0120 return $this->_job; 0121 } 0122 0123 /** 0124 * Store queue and data in serialized object 0125 * 0126 * @return array 0127 */ 0128 public function __sleep() 0129 { 0130 return serialize('_job', '_id', '_data'); 0131 } 0132 0133 /** 0134 * Query the class name of the Queue object for which this 0135 * Message was created. 0136 * 0137 * @return string 0138 */ 0139 public function getQueueClass() 0140 { 0141 return 'Zend_Queue_Adapter_Platform_JQ'; 0142 } 0143 0144 /** 0145 * Sets properties on the ZendApi_Job instance 0146 * 0147 * Any options in the {@link $_data} array will be checked. Those matching 0148 * options in ZendApi_Job will be used to set those options in that 0149 * instance. 0150 * 0151 * @return void 0152 */ 0153 protected function _setJobProperties() { 0154 0155 if (isset($this->_data['script'])) { 0156 $this->_job->setScript($this->_data['script']); 0157 } 0158 0159 if (isset($this->_data['priority'])) { 0160 $this->_job->setJobPriority($this->_data['priority']); 0161 } 0162 0163 if (isset($this->_data['name'])) { 0164 $this->_job->setJobName($this->_data['name']); 0165 } 0166 0167 if (isset($this->_data['predecessor'])) { 0168 $this->_job->setJobDependency($this->_data['predecessor']); 0169 } 0170 0171 if (isset($this->_data['preserved'])) { 0172 $this->_job->setPreserved($this->_data['preserved']); 0173 } 0174 0175 if (isset($this->_data['user_variables'])) { 0176 $this->_job->setUserVariables($this->_data['user_variables']); 0177 } 0178 0179 if (!empty($this->_data['interval'])) { 0180 $endTime = isset($this->_data['end_time']) ? $this->_data['end_time'] : null; 0181 $this->_job->setRecurrenceData($this->_data['interval'], $endTime); 0182 } elseif (isset($this->_data['interval']) && ($this->_data['interval'] === '')) { 0183 $this->_job->setRecurrenceData(0,0); 0184 } 0185 0186 if (isset($this->_data['scheduled_time'])) { 0187 $this->_job->setScheduledTime($this->_data['scheduled_time']); 0188 } 0189 0190 if (isset($this->_data['application_id'])) { 0191 $this->_job->setApplicationID($this->_data['application_id']); 0192 } 0193 } 0194 }