Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some Pull UI errors #703

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/classes/PullListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public function column_name( $item ) {
public function prepare_items() {
global $connection_now;

if ( empty( $connection_now ) ) {
if ( empty( $connection_now ) || empty( $connection_now->pull_post_type ) ) {
return;
}

Expand Down
23 changes: 18 additions & 5 deletions includes/pull-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ function( $remote_post_id ) use ( $post_type ) {
if ( 'external' === $_GET['connection_type'] ) {
$connection = \Distributor\ExternalConnection::instantiate( intval( $_GET['connection_id'] ) );
$new_posts = $connection->pull( $posts );
$error_key = "external_{$connection->id}";

foreach ( $posts as $key => $post_array ) {
if ( is_wp_error( $new_posts[ $key ] ) ) {
Expand All @@ -232,6 +233,7 @@ function( $remote_post_id ) use ( $post_type ) {
$site = get_site( intval( $_GET['connection_id'] ) );
$connection = new \Distributor\InternalConnections\NetworkSiteConnection( $site );
$new_posts = $connection->pull( $posts );
$error_key = "internal_{$connection->site->blog_id}";
}

$post_id_mappings = array();
Expand All @@ -253,7 +255,7 @@ function( $remote_post_id ) use ( $post_type ) {
}

if ( ! empty( $pull_errors ) ) {
set_transient( 'dt_connection_pull_errors_' . $connection->id, $pull_errors, DAY_IN_SECONDS );
set_transient( 'dt_connection_pull_errors_' . $error_key, $pull_errors, DAY_IN_SECONDS );
}

$connection->log_sync( $post_id_mappings );
Expand Down Expand Up @@ -409,9 +411,14 @@ function dashboard() {
<?php
$connection_now->pull_post_types = \Distributor\Utils\available_pull_post_types( $connection_now, $connection_type );

// Set the post type we want to pull
// Ensure we have at least one post type to pull
$connection_now->pull_post_type = '';
if ( ! empty( $connection_now->pull_post_types ) ) {
$connection_now->pull_post_type = $connection_now->pull_post_types[0]['slug'];
}

// Set the post type we want to pull (if any)
// This is either from a query param, "post" post type, or the first in the list
$connection_now->pull_post_type = $connection_now->pull_post_types[0]['slug'];
foreach ( $connection_now->pull_post_types as $post_type ) {
if ( isset( $_GET['pull_post_type'] ) ) { // @codingStandardsIgnoreLine No nonce needed here.
if ( $_GET['pull_post_type'] === $post_type['slug'] ) { // @codingStandardsIgnoreLine Comparing values, no nonce needed.
Expand Down Expand Up @@ -486,13 +493,19 @@ function output_pull_errors() {
return;
}

$pull_errors = get_transient( 'dt_connection_pull_errors_' . $connection_now->id );
if ( is_a( $connection_now, '\Distributor\ExternalConnection' ) ) {
$error_key = "external_{$connection_now->id}";
} else {
$error_key = "internal_{$connection_now->site->blog_id}";
}

$pull_errors = get_transient( 'dt_connection_pull_errors_' . $error_key );

if ( empty( $pull_errors ) ) {
return;
}

delete_transient( 'dt_connection_pull_errors_' . $connection_now->id );
delete_transient( 'dt_connection_pull_errors_' . $error_key );

$post_ids = array_keys( $pull_errors );

Expand Down