From 1c022ff81e7ed5d9543a5e2065cf445c35f1dc0e Mon Sep 17 00:00:00 2001 From: Eduardo Humberto Date: Fri, 7 Dec 2018 21:32:49 -0200 Subject: [PATCH] Bg process feedback - list all processes ( ref. #130 ) --- .../class-tainacan-bg-importer-heartbeat.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/importer/class-tainacan-bg-importer-heartbeat.php b/src/importer/class-tainacan-bg-importer-heartbeat.php index 86392eac6..f96bb2015 100644 --- a/src/importer/class-tainacan-bg-importer-heartbeat.php +++ b/src/importer/class-tainacan-bg-importer-heartbeat.php @@ -5,7 +5,9 @@ use Tainacan; class Background_Importer_Heartbeat { public function __construct() { - add_filter( 'heartbeat_received', array( &$this, 'bg_process_feedback' ), 10, 2 ); + global $wpdb; + $this->table = $wpdb->prefix . 'tnc_bg_process'; + add_filter( 'heartbeat_no_priv_received', array( &$this, 'bg_process_feedback' ), 10, 2 ); } /** @@ -17,9 +19,17 @@ class Background_Importer_Heartbeat { * @param array $data Data received from the front end (unslashed). */ public function bg_process_feedback( $response, $data ){ - $response['bg_process_feedback'] = true; + global $wpdb; - //TODO: list all bg process + $user_q = $wpdb->prepare("AND user_id = %d", get_current_user_id()); + $status_q = ""; + + $base_query = "FROM $this->table WHERE 1=1 $status_q $user_q ORDER BY priority DESC, queued_on DESC"; + + $query = "SELECT * $base_query"; + $result = $wpdb->get_results($query); + + $response['bg_process_feedback'] = $result; return $response; }