| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Table Definition for queue_item | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | require_once 'DB/DataObject.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-15 15:55:13 -04:00
										 |  |  | class Queue_item extends DB_DataObject  | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     ###START_AUTOCODE
 | 
					
						
							|  |  |  |     /* the code below is auto generated do not remove the above tag */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public $__table = 'queue_item';                      // table name
 | 
					
						
							|  |  |  |     public $notice_id;                       // int(4)  primary_key not_null
 | 
					
						
							| 
									
										
										
										
											2008-08-27 17:12:39 -04:00
										 |  |  |     public $transport;                       // varchar(8)  primary_key not_null
 | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  |     public $created;                         // datetime()   not_null
 | 
					
						
							| 
									
										
										
										
											2008-07-15 15:55:13 -04:00
										 |  |  |     public $claimed;                         // datetime()  
 | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Static get */ | 
					
						
							|  |  |  |     function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Queue_item',$k,$v); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* the code above is auto generated do not remove the tag below */ | 
					
						
							|  |  |  |     ###END_AUTOCODE
 | 
					
						
							| 
									
										
										
										
											2008-07-09 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-04 04:24:18 -04:00
										 |  |  |     function sequenceKey() { return array(false, false); } | 
					
						
							| 
									
										
										
										
											2008-08-27 16:54:07 -04:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	static function top($transport) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qi = new Queue_item(); | 
					
						
							|  |  |  | 		$qi->transport = $transport; | 
					
						
							|  |  |  | 		$qi->orderBy('created'); | 
					
						
							|  |  |  | 		$qi->whereAdd('claimed is NULL'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$qi->limit(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$cnt = $qi->find(TRUE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($cnt) { | 
					
						
							|  |  |  | 			# XXX: potential race condition
 | 
					
						
							|  |  |  | 			# can we force it to only update if claimed is still NULL
 | 
					
						
							|  |  |  | 			# (or old)?
 | 
					
						
							| 
									
										
										
										
											2008-08-30 01:49:33 -04:00
										 |  |  | 			common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport); | 
					
						
							| 
									
										
										
										
											2008-08-27 16:54:07 -04:00
										 |  |  | 			$orig = clone($qi); | 
					
						
							|  |  |  | 			$qi->claimed = common_sql_now(); | 
					
						
							|  |  |  | 			$result = $qi->update($orig); | 
					
						
							|  |  |  | 			if ($result) { | 
					
						
							| 
									
										
										
										
											2008-08-27 20:45:03 -04:00
										 |  |  | 				common_log(LOG_INFO, 'claim succeeded.'); | 
					
						
							| 
									
										
										
										
											2008-08-27 16:54:07 -04:00
										 |  |  | 				return $qi; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2008-08-27 20:45:03 -04:00
										 |  |  | 				common_log(LOG_INFO, 'claim failed.'); | 
					
						
							| 
									
										
										
										
											2008-08-27 16:54:07 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		$qi = NULL; | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | } |