From f34d1a7b04aa7553935e3ad665e68c60ad475645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Barbosa?= Date: Tue, 1 Oct 2024 12:08:30 -0300 Subject: [PATCH] Changes the error Blaze shows during sync to be a warning (#39515) * Changes the error Blaze shows during sync to be a warning --- .../update-blaze-post-not-ready-behavior | 4 +++ .../src/class-dashboard-rest-controller.php | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 projects/packages/blaze/changelog/update-blaze-post-not-ready-behavior diff --git a/projects/packages/blaze/changelog/update-blaze-post-not-ready-behavior b/projects/packages/blaze/changelog/update-blaze-post-not-ready-behavior new file mode 100644 index 0000000000000..2be9dad32f1db --- /dev/null +++ b/projects/packages/blaze/changelog/update-blaze-post-not-ready-behavior @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Changes the error Blaze shows during sync to be a warning diff --git a/projects/packages/blaze/src/class-dashboard-rest-controller.php b/projects/packages/blaze/src/class-dashboard-rest-controller.php index 826b13a6d6dbd..de30672bf3e98 100644 --- a/projects/packages/blaze/src/class-dashboard-rest-controller.php +++ b/projects/packages/blaze/src/class-dashboard-rest-controller.php @@ -329,10 +329,6 @@ public function get_blaze_posts( $req ) { return array(); } - if ( ! $this->are_posts_ready() ) { - return new WP_Error( 'posts_not_ready', 'Posts are not synced yet.' ); - } - // We don't use sub_path in the blaze posts, only query strings if ( isset( $req['sub_path'] ) ) { unset( $req['sub_path'] ); @@ -353,6 +349,24 @@ public function get_blaze_posts( $req ) { $response['posts'] = $this->add_prices_in_posts( $response['posts'] ); } + $response = $this->add_warnings_to_posts_response( $response ); + + return $response; + } + + /** + * Adds warning flags to the posts response. + * + * @param array $response The response object. + * @return array + */ + private function add_warnings_to_posts_response( $response ) { + if ( ! $this->are_posts_ready() && is_array( $response ) ) { + $response['warnings'] = array_merge( + array( 'sync_in_progress' ), + $response['warnings'] ?? array() + ); + } return $response; } @@ -392,10 +406,6 @@ public function get_dsp_blaze_posts( $req ) { return array(); } - if ( ! $this->are_posts_ready() ) { - return new WP_Error( 'posts_not_ready', 'Posts are not synced yet.' ); - } - // We don't use sub_path in the blaze posts, only query strings if ( isset( $req['sub_path'] ) ) { unset( $req['sub_path'] ); @@ -412,6 +422,8 @@ public function get_dsp_blaze_posts( $req ) { $response['results'] = $this->add_prices_in_posts( $response['results'] ); } + $response = $this->add_warnings_to_posts_response( $response ); + return $response; }