@@ -126,18 +126,24 @@ public function push_to_queue( $data ) {
126126 /**
127127 * Save the process queue.
128128 *
129+ * @param string $group Group name.
130+ *
129131 * @since 1.0.0
132+ * @since 1.0.1 Added group option.
130133 * @access public
131134 *
132135 * @return Task $this
133136 */
134- public function save () {
137+ public function save ( $ group = ' default ' ) {
135138 // Generate key.
136139 $ key = $ this ->generate_key ();
137140
138141 // Save the data to database.
139142 if ( ! empty ( $ this ->data ) ) {
143+ // Save data.
140144 update_site_option ( $ key , $ this ->data );
145+ // Save group name too.
146+ update_site_option ( $ key . '_group ' , $ group );
141147 }
142148
143149 return $ this ;
@@ -175,6 +181,7 @@ public function update( $key, $data ) {
175181 */
176182 public function delete ( $ key ) {
177183 delete_site_option ( $ key );
184+ delete_site_option ( $ key . '_group ' );
178185
179186 return $ this ;
180187 }
@@ -375,9 +382,10 @@ protected function get_batch() {
375382 );
376383
377384 // 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 ' );
381389
382390 return $ batch ;
383391 }
@@ -406,7 +414,7 @@ protected function handle() {
406414 // Process each item in batch.
407415 foreach ( $ batch ->data as $ key => $ value ) {
408416 // Run task.
409- $ task = $ this ->task ( $ value );
417+ $ task = $ this ->task ( $ value, $ batch -> group );
410418
411419 // If task failed add to queue again.
412420 if ( false !== $ task ) {
@@ -699,12 +707,14 @@ public function cancel_process() {
699707 * in the next pass through. Or, return false to remove the
700708 * item from the queue.
701709 *
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).
703712 *
704713 * @since 1.0.0
714+ * @since 1.0.1 Added group option.
705715 * @access protected
706716 *
707717 * @return mixed
708718 */
709- abstract protected function task ( $ item );
719+ abstract protected function task ( $ item, $ group );
710720}
0 commit comments