Plugin Directory

Changeset 2586216


Ignore:
Timestamp:
08/20/2021 11:27:02 PM (5 years ago)
Author:
winrid
Message:

3.9.8 - Improved support for re-running the sync multiple times without creating duplicate data.

Location:
fastcomments
Files:
34 added
3 edited

Legend:

Unmodified
Added
Removed
  • fastcomments/trunk/README.txt

    r2586120 r2586216  
    44Requires at least: 4.6
    55Tested up to: 5.8
    6 Stable tag: 3.9.7
     6Stable tag: 3.9.8
    77Requires PHP: 5.2.4
    88License: GPLv2 or later
     
    8484
    8585== Changelog ==
     86
     87= 3.9.8 =
     88* Improved support for re-running the sync multiple times without creating duplicate data.
    8689
    8790= 3.9.7 =
  • fastcomments/trunk/core/FastCommentsWordPressIntegration.php

    r2585075 r2586216  
    190190
    191191    public function fc_to_wp_comment($fc_comment) {
    192         $wp_comment = array();
    193192        /*
    194193            We intentionally don't send these fields, as they don't apply to us so they won't ever change on our side.
     
    200199         */
    201200
    202         // wordpress timestamp format is Y-m-d H:i:s (mysql date column type)
    203         $timestamp = strtotime($fc_comment->date);
    204         $date_formatted_gmt = date('Y-m-d H:i:s', $timestamp);
    205         $date_formatted = get_date_from_gmt($date_formatted_gmt);
    206 
    207         $this->log('debug', "Dates: got $date_formatted_gmt -> $date_formatted from $fc_comment->date -> $timestamp");
    208 
    209         $wp_id = $this->getWPCommentId($fc_comment->_id);
    210         $wp_parent_id = isset($fc_comment->parentId) && $fc_comment->parentId ? $this->getWPCommentId($fc_comment->parentId) : 0;
    211 
    212201        $post_id = null;
    213202        $user_id = null;
     
    220209                $user_id = $fc_comment->meta->wpUserId;
    221210            }
    222         } else {
    223             $post_id = (int) $fc_comment->urlId;
    224         }
     211        }
     212
     213        if (!$post_id) {
     214            return null; // don't try to set post id to a url... this is probably not a comment from the WP integration.
     215        }
     216
     217        $wp_comment = array();
     218
     219        // wordpress timestamp format is Y-m-d H:i:s (mysql date column type)
     220        $timestamp = strtotime($fc_comment->date);
     221        $date_formatted_gmt = date('Y-m-d H:i:s', $timestamp);
     222        $date_formatted = get_date_from_gmt($date_formatted_gmt);
     223
     224        $this->log('debug', "Dates: got $date_formatted_gmt -> $date_formatted from $fc_comment->date -> $timestamp");
     225
     226        $wp_id = $this->getWPCommentId($fc_comment->_id);
     227        $wp_parent_id = isset($fc_comment->parentId) && $fc_comment->parentId ? $this->getWPCommentId($fc_comment->parentId) : 0;
    225228
    226229        $wp_comment['comment_ID'] = is_numeric($wp_id) ? $wp_id : null;
     
    248251        $votes = $wp_comment->comment_karma;
    249252
     253        // Send the ID our backend knows about, to prevent duplicates in some scenarios.
     254        $meta_fc_id = get_comment_meta($wp_comment->comment_ID, 'fastcomments_id', true);
     255        if ($meta_fc_id) {
     256            $fc_comment['_id'] = $meta_fc_id;
     257        }
    250258        $fc_comment['tenantId'] = $this->getSettingValue('fastcomments_tenant_id');
    251259        $fc_comment['urlId'] = $wp_comment->comment_post_ID;
    252         $fc_comment['url'] = get_permalink($wp_comment->comment_post_ID);
     260        $permaLink = get_permalink($wp_comment->comment_post_ID);
     261        if ($permaLink) {
     262            $fc_comment['url'] = $permaLink;
     263        }
    253264        $fc_comment['pageTitle'] = get_the_title($wp_comment->comment_post_ID);
    254265        $fc_comment['userId'] = null;
     
    292303                        if (!$existingComment) {
    293304                            $this->log('debug', "Incoming comment $fcId");
    294                             $comment_id_or_false = wp_insert_comment($this->fc_to_wp_comment($eventData->comment));
    295                             if ($comment_id_or_false) {
    296                                 $this->addCommentIDMapEntry($fcId, $comment_id_or_false);
     305                            $new_wp_comment = $this->fc_to_wp_comment($eventData->comment);
     306                            if ($new_wp_comment) {
     307                                $comment_id_or_false = wp_insert_comment($new_wp_comment);
     308                                if ($comment_id_or_false) {
     309                                    $this->addCommentIDMapEntry($fcId, $comment_id_or_false);
     310                                    add_comment_meta($comment_id_or_false, 'fastcomments_id', $eventData->comment->_id, true);
     311                                } else {
     312                                    $debug_data = $event->data;
     313                                    $this->log('error', "Failed to save comment: $debug_data");
     314                                }
    297315                            } else {
    298                                 $debug_data = $event->data;
    299                                 $this->log('error', "Failed to save comment: $debug_data");
     316                                $this->log('debug', "Skipping sync of $fcId - is not from the WP integration.");
    300317                            }
    301318                        } else {
     
    307324                        $this->log('debug', "Updating comment $fcId");
    308325                        $wp_comment = $this->fc_to_wp_comment($eventData->comment);
    309                         wp_update_comment($wp_comment);
     326                        if ($wp_comment) {
     327                            wp_update_comment($wp_comment);
     328                            add_comment_meta($wp_comment->comment_ID, 'fastcomments_id', $eventData->comment->_id, true);
     329                        } else {
     330                            $this->log('debug', "Skipping sync of $fcId - is not from the WP integration.");
     331                        }
    310332                        break;
    311333                    case 'deleted-comment':
     
    362384//            return $wp_comments_count;
    363385//        } else {
    364             $count_result = wp_count_comments();
    365             return $count_result ? $count_result->total_comments : 0;
     386        $count_result = wp_count_comments();
     387        return $count_result ? $count_result->total_comments : 0;
    366388//        }
    367389    }
  • fastcomments/trunk/fastcomments-wordpress-plugin.php

    r2586120 r2586216  
    44Plugin URI: https://fastcomments.com
    55Description: Live Comments, Fast. A comment system that will delight your users and developers.
    6 Version: 3.9.7
     6Version: 3.9.8
    77Author: winrid @ FastComments
    88License: GPL-2.0+
     
    1414}
    1515
    16 $FASTCOMMENTS_VERSION = 3.97;
     16$FASTCOMMENTS_VERSION = 3.98;
    1717
    1818require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php';
Note: See TracChangeset for help on using the changeset viewer.