| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Table Definition for queue_item | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-09-26 12:18:24 -04:00
										 |  |  | require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 14:38:34 -04:00
										 |  |  | class Queue_item extends Memcached_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
 | 
					
						
							| 
									
										
										
										
											2009-06-28 14:38:34 -04:00
										 |  |  |     public $claimed;                         // datetime()
 | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Static get */ | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function staticGet($k,$v=null) | 
					
						
							|  |  |  |     { return Memcached_DataObject::staticGet('Queue_item',$k,$v); } | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* the code above is auto generated do not remove the tag below */ | 
					
						
							|  |  |  |     ###END_AUTOCODE
 | 
					
						
							| 
									
										
										
										
											2008-07-09 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     function sequenceKey() | 
					
						
							|  |  |  |     { return array(false, false); } | 
					
						
							| 
									
										
										
										
											2009-06-28 14:38:34 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |     static function top($transport) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $qi = new Queue_item(); | 
					
						
							|  |  |  |         $qi->transport = $transport; | 
					
						
							|  |  |  |         $qi->orderBy('created'); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:21:29 -05:00
										 |  |  |         $qi->whereAdd('claimed is null'); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $qi->limit(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:44:28 -05:00
										 |  |  |         $cnt = $qi->find(true); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($cnt) { | 
					
						
							|  |  |  |             # XXX: potential race condition
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:21:29 -05:00
										 |  |  |             # can we force it to only update if claimed is still null
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |             # (or old)?
 | 
					
						
							|  |  |  |             common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport); | 
					
						
							|  |  |  |             $orig = clone($qi); | 
					
						
							|  |  |  |             $qi->claimed = common_sql_now(); | 
					
						
							|  |  |  |             $result = $qi->update($orig); | 
					
						
							|  |  |  |             if ($result) { | 
					
						
							|  |  |  |                 common_log(LOG_INFO, 'claim succeeded.'); | 
					
						
							|  |  |  |                 return $qi; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 common_log(LOG_INFO, 'claim failed.'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-12-23 14:21:29 -05:00
										 |  |  |         $qi = null; | 
					
						
							|  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-28 14:38:34 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-06 14:28:40 -08:00
										 |  |  |     function pkeyGet($kv) | 
					
						
							| 
									
										
										
										
											2009-06-28 14:38:34 -04:00
										 |  |  |     { | 
					
						
							|  |  |  |         return Memcached_DataObject::pkeyGet('Queue_item', $kv); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-07-04 00:07:46 -04:00
										 |  |  | } |