@@ -126,18 +126,24 @@ public function push_to_queue( $data ) {
126
126
/**
127
127
* Save the process queue.
128
128
*
129
+ * @param string $group Group name.
130
+ *
129
131
* @since 1.0.0
132
+ * @since 1.0.1 Added group option.
130
133
* @access public
131
134
*
132
135
* @return Task $this
133
136
*/
134
- public function save () {
137
+ public function save ( $ group = ' default ' ) {
135
138
// Generate key.
136
139
$ key = $ this ->generate_key ();
137
140
138
141
// Save the data to database.
139
142
if ( ! empty ( $ this ->data ) ) {
143
+ // Save data.
140
144
update_site_option ( $ key , $ this ->data );
145
+ // Save group name too.
146
+ update_site_option ( $ key . '_group ' , $ group );
141
147
}
142
148
143
149
return $ this ;
@@ -175,6 +181,7 @@ public function update( $key, $data ) {
175
181
*/
176
182
public function delete ( $ key ) {
177
183
delete_site_option ( $ key );
184
+ delete_site_option ( $ key . '_group ' );
178
185
179
186
return $ this ;
180
187
}
@@ -375,9 +382,10 @@ protected function get_batch() {
375
382
);
376
383
377
384
// Create new object.
378
- $ batch = new stdClass ();
379
- $ batch ->key = $ query ->$ column ;
380
- $ batch ->data = maybe_unserialize ( $ query ->$ value_column );
385
+ $ batch = new stdClass ();
386
+ $ batch ->key = $ query ->$ column ;
387
+ $ batch ->data = maybe_unserialize ( $ query ->$ value_column );
388
+ $ batch ->group = get_site_option ( $ batch ->key . '_group ' , 'default ' );
381
389
382
390
return $ batch ;
383
391
}
@@ -406,7 +414,7 @@ protected function handle() {
406
414
// Process each item in batch.
407
415
foreach ( $ batch ->data as $ key => $ value ) {
408
416
// Run task.
409
- $ task = $ this ->task ( $ value );
417
+ $ task = $ this ->task ( $ value, $ batch -> group );
410
418
411
419
// If task failed add to queue again.
412
420
if ( false !== $ task ) {
@@ -699,12 +707,14 @@ public function cancel_process() {
699
707
* in the next pass through. Or, return false to remove the
700
708
* item from the queue.
701
709
*
702
- * @param mixed $item Queue item to iterate over.
710
+ * @param mixed $item Queue item to iterate over.
711
+ * @param string $group Group name of the task (Useful when processing multiple tasks).
703
712
*
704
713
* @since 1.0.0
714
+ * @since 1.0.1 Added group option.
705
715
* @access protected
706
716
*
707
717
* @return mixed
708
718
*/
709
- abstract protected function task ( $ item );
719
+ abstract protected function task ( $ item, $ group );
710
720
}
0 commit comments