From c86b90b33ab52f906817c70ee3b7cf5f88272db9 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Thu, 26 Aug 2021 15:25:59 -0700 Subject: [PATCH 1/3] fix: content sync issues (#188) * only override preview link when not doing gql requests * remove attempt to grab existing manifest id's. this results in outdated id's * Update CHANGELOG.md --- CHANGELOG.md | 5 +++ src/Admin/Preview.php | 77 +++++-------------------------------------- 2 files changed, 13 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 476193b..49b626a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Upcoming fixes + +- The uri field was being overwritten during GraphQL requests, resulting in post uri's that included the content sync URL. +- Some logic attempting to choose the correct manifest ID instead of regenerating it was causing manifest id's to be outdated during previews. + ## 1.1.2 - Fixed redirection to Gatsby Cloud Content Sync preview loader in Gutenberg diff --git a/src/Admin/Preview.php b/src/Admin/Preview.php index 9bc598f..fec5ade 100644 --- a/src/Admin/Preview.php +++ b/src/Admin/Preview.php @@ -23,8 +23,14 @@ function() { ); $use_cloud_loader = self::get_setting( 'use_gatsby_content_sync' ); - - if ( $use_cloud_loader === 'on' ) { + + if ( + $use_cloud_loader === 'on' && + // don't do this during graphql requests + // because that could override the post URI + // in Gatsby! meaning the content sync url could be added to the page path in Gatsby if pages are created from the uri. + ! ( defined( 'GRAPHQL_REQUEST' ) && true === GRAPHQL_REQUEST ) + ) { add_filter( 'preview_post_link', function( $link, $post ) { return self::get_gatsby_content_sync_url_for_post( $post ); }, 10, 2 ); @@ -33,73 +39,6 @@ function() { } public static function get_preview_manifest_id_for_post( $post ) { - $graphql_single_name = - get_post_type_object( $post->post_type ) - ->graphql_single_name; - - if ( !$graphql_single_name || $graphql_single_name === "" ) { - // if we don't have a graphql single name - // Gatsby can't use this post anyway. - // No need to return a manifest - return null; - } - - $action_monitor_posts = new \WP_Query( [ - 'post_type' => 'action_monitor', - 'post_status' => 'any', - 'posts_per_page' => 1, - 'no_found_rows' => true, - 'fields' => 'ids', - 'tax_query' => [ - 'relation' => 'AND', - [ - 'taxonomy' => 'gatsby_action_ref_node_dbid', - 'field' => 'name', - 'terms' => sanitize_text_field( $post->ID ), - ], - [ - 'taxonomy' => 'gatsby_action_ref_node_type', - 'field' => 'name', - 'terms' => sanitize_text_field( $graphql_single_name ), - ], - [ - 'taxonomy' => 'gatsby_action_stream_type', - 'field' => 'name', - 'terms' => 'PREVIEW', - ] - ], - ] ); - - if ( - isset( $action_monitor_posts->posts ) - && ! empty( $action_monitor_posts->posts ) - ) { - $action_monitor_post_id = $action_monitor_posts->posts[0]; - $referenced_node_preview_data = get_post_meta( - $action_monitor_post_id, - '_gatsby_preview_data', - true - ); - - $preview_data = false; - - if ( - $referenced_node_preview_data - && $referenced_node_preview_data !== "" - ) { - $preview_data = json_decode( $referenced_node_preview_data ); - } - - if ( - $preview_data - && property_exists( $preview_data, 'manifestIds' ) - && count( $preview_data->manifestIds ) > 0 - ) { - return $preview_data->manifestIds[0]; - } - } - - // if the above doesn't return a value we generate a new manifest ID from the post_modified date and post db id $revision = self::getPreviewablePostObjectByPostId( $post->ID ); $revision_modified = $revision->post_modified ?? null; From 2bd6b5460d5d7fbe227be41f8ffb0e92abad83b3 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Thu, 26 Aug 2021 15:29:17 -0700 Subject: [PATCH 2/3] release v1.1.3 --- CHANGELOG.md | 2 +- readme.txt | 2 +- wp-gatsby.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b626a..93601eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## Upcoming fixes +## 1.1.3 - The uri field was being overwritten during GraphQL requests, resulting in post uri's that included the content sync URL. - Some logic attempting to choose the correct manifest ID instead of regenerating it was causing manifest id's to be outdated during previews. diff --git a/readme.txt b/readme.txt index 2dff557..c7ead14 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: Gatsby, GatsbyJS, JavaScript, JAMStack, Static Site generator, GraphQL, He Requires at least: 5.4.2 Tested up to: 5.6 Requires PHP: 7.3 -Stable tag: 1.1.2 +Stable tag: 1.1.3 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/wp-gatsby.php b/wp-gatsby.php index eb17b46..4f0130f 100644 --- a/wp-gatsby.php +++ b/wp-gatsby.php @@ -2,7 +2,7 @@ /** * Plugin Name: WP Gatsby * Description: Optimize your WordPress site to be a source for Gatsby sites. - * Version: 1.1.2 + * Version: 1.1.3 * Author: GatsbyJS, Jason Bahl, Tyler Barnes * Author URI: https://gatsbyjs.org * Text Domain: wp-gatsby @@ -103,7 +103,7 @@ private function setup_constants() { // Plugin version. if (! defined('WPGATSBY_VERSION') ) { - define('WPGATSBY_VERSION', '1.1.2'); + define('WPGATSBY_VERSION', '1.1.3'); } // Plugin Folder Path. From 2f232b55fac5ed186b631d3ab9343c60b60feb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Baranowski?= Date: Fri, 27 Aug 2021 08:55:08 +0200 Subject: [PATCH 3/3] Changed wp_safe_remote_post to wp_remote_post in ActionMonitor. This is needed due to 'safe' variant preventing calls to private IP addresses. This does not compromise security, webhook URLs are not dynamic and are controlled by WordPress admins. --- src/ActionMonitor/ActionMonitor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ActionMonitor/ActionMonitor.php b/src/ActionMonitor/ActionMonitor.php index 297b65c..4811597 100644 --- a/src/ActionMonitor/ActionMonitor.php +++ b/src/ActionMonitor/ActionMonitor.php @@ -674,7 +674,7 @@ public function trigger_dispatch() { foreach ( $unique_webhooks as $webhook ) { $args = apply_filters( 'gatsby_trigger_dispatch_args', [], $webhook ); - wp_safe_remote_post( $webhook, $args ); + wp_remote_post( $webhook, $args ); } } @@ -718,7 +718,7 @@ public function trigger_dispatch() { $webhook ); - wp_safe_remote_post( $webhook, $args ); + wp_remote_post( $webhook, $args ); } } }