Changeset 2576755
- Timestamp:
- 08/02/2021 07:58:00 PM (5 years ago)
- Location:
- fastcomments
- Files:
-
- 34 added
- 6 edited
-
tags/3.9 (added)
-
tags/3.9/.gitignore (added)
-
tags/3.9/LICENSE (added)
-
tags/3.9/README.md (added)
-
tags/3.9/README.txt (added)
-
tags/3.9/admin (added)
-
tags/3.9/admin/fastcomments-admin-setup-view.js (added)
-
tags/3.9/admin/fastcomments-admin-setup-view.php (added)
-
tags/3.9/admin/fastcomments-admin-sso-view.css (added)
-
tags/3.9/admin/fastcomments-admin-sso-view.js (added)
-
tags/3.9/admin/fastcomments-admin-sso-view.php (added)
-
tags/3.9/admin/fastcomments-admin-support-view.php (added)
-
tags/3.9/admin/fastcomments-admin-view.php (added)
-
tags/3.9/admin/fastcomments-admin.css (added)
-
tags/3.9/admin/fastcomments-admin.php (added)
-
tags/3.9/admin/images (added)
-
tags/3.9/admin/images/api.png (added)
-
tags/3.9/admin/images/crown.png (added)
-
tags/3.9/admin/images/css.png (added)
-
tags/3.9/admin/images/debugging.png (added)
-
tags/3.9/admin/images/download.png (added)
-
tags/3.9/admin/images/home.png (added)
-
tags/3.9/admin/images/logo-50.png (added)
-
tags/3.9/admin/images/logo.png (added)
-
tags/3.9/admin/images/support.png (added)
-
tags/3.9/admin/images/sync.png (added)
-
tags/3.9/core (added)
-
tags/3.9/core/FastCommentsIntegrationCore.php (added)
-
tags/3.9/core/FastCommentsWordPressIntegration.php (added)
-
tags/3.9/fastcomments-wordpress-plugin.php (added)
-
tags/3.9/public (added)
-
tags/3.9/public/fastcomments-public.php (added)
-
tags/3.9/public/fastcomments-widget-view.php (added)
-
tags/3.9/uninstall.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/fastcomments-admin-setup-view.js (modified) (2 diffs)
-
trunk/admin/fastcomments-admin-setup-view.php (modified) (1 diff)
-
trunk/core/FastCommentsIntegrationCore.php (modified) (6 diffs)
-
trunk/core/FastCommentsWordPressIntegration.php (modified) (11 diffs)
-
trunk/fastcomments-wordpress-plugin.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fastcomments/trunk/README.txt
r2575553 r2576755 4 4 Requires at least: 4.6 5 5 Tested up to: 5.8 6 Stable tag: 3. 86 Stable tag: 3.9 7 7 Requires PHP: 5.2.4 8 8 License: GPLv2 or later … … 85 85 == Changelog == 86 86 87 = 3.9 = 88 * Sync of comments from WordPress to FastComments when there are many comments improved. 89 87 90 = 3.8 = 88 91 * Improvements for when upgrading from 2.1. -
fastcomments/trunk/admin/fastcomments-admin-setup-view.js
r2575412 r2576755 13 13 } 14 14 function tick(cb) { 15 var called = false; 16 function next() { 17 if (!called) { 18 called = true; 19 cb(); 20 } 21 } 15 22 jQuery.ajax({ 16 23 url: window.FC_DATA.siteUrl + '/index.php?rest_route=/fastcomments/v1/api/tick', 17 24 method: 'GET', 18 25 dataType: 'json', 19 success: cb,20 error: cb,26 success: next, 27 error: next, 21 28 xhrFields: { 22 29 withCredentials: true … … 35 42 }, function error(response) { 36 43 console.error('Could not fetch FastComments configuration', response); 44 checkNext(); 37 45 }); 38 46 39 47 // Check for setup being complete every couple seconds and then reload the page when it is to show the new admin page with all the fancy options. 40 48 function checkNext() { 49 var called = false; 41 50 function tickAndCheckNext() { 42 tick(function() { 43 setTimeout(checkNext, 2000); 44 }); 51 if (!called) { 52 called = true; 53 tick(function() { 54 setTimeout(checkNext, 2000); 55 }); 56 } 45 57 } 46 58 getFCConfig(function success(response) { -
fastcomments/trunk/admin/fastcomments-admin-setup-view.php
r2575412 r2576755 10 10 </ol> 11 11 <h2>Do you have a FastComments Account?</h2> 12 <a class="button-primary "12 <a class="button-primary button-has-account" 13 13 href="https://fastcomments.com/auth/my-account/integrations/v1/setup?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true" 14 14 target="_blank">Yes</a> 15 <a class="button-primary "15 <a class="button-primary button-no-account" 16 16 href="https://fastcomments.com/auth/my-account/integrations/v1/setup?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=false" 17 17 target="_blank">No</a> -
fastcomments/trunk/core/FastCommentsIntegrationCore.php
r2575553 r2576755 113 113 114 114 public function tick() { 115 $this->log('debug', "BEGIN Tick"); 115 116 $nextStateMachineName = 'integrationStateInitial'; 116 117 while ($nextStateMachineName) { … … 118 119 $nextStateMachineName = call_user_func(array($this, $nextStateMachineName)); 119 120 } 121 $this->log('debug', "END Tick"); 120 122 } 121 123 … … 171 173 if ($response->status === 'success' && $response->commands) { 172 174 foreach ($response->commands as $command) { 175 $this->log('debug', "Processing command $command->command"); 173 176 switch ($command->command) { 174 177 case 'FetchEvents': … … 218 221 $startedAt = time(); 219 222 $hasMore = true; 220 $countSyncedSoFar = 0;223 $countSyncedSoFar = $this->getSettingValue('fastcomments_comment_sent_count') ? $this->getSettingValue('fastcomments_comment_sent_count') : 0; 221 224 $commentCount = $this->getCommentCount(); 222 225 if ($commentCount == 0) { … … 241 244 $this->log('info', "Got comments to send count=[$count] hasMore=[$hasMore]"); 242 245 if ($getCommentsResponse['comments'] && count($getCommentsResponse['comments']) > 0) { 243 $countRemaining = max($commentCount - count($getCommentsResponse['comments']) + $countSyncedSoFar, 0);246 $countRemaining = max($commentCount - (count($getCommentsResponse['comments']) + $countSyncedSoFar), 0); 244 247 $requestBody = json_encode( 245 248 array( … … 256 259 $this->setSettingValue('fastcomments_stream_last_send_timestamp', $fromDateTime); 257 260 $countSyncedSoFar += count($getCommentsResponse['comments']); 258 if (!$hasMore) { 261 $this->setSettingValue('fastcomments_comment_sent_count', $countSyncedSoFar); 262 if (!$hasMore || $countRemaining === 0) { 259 263 $this->setSetupDone(); 260 264 break; -
fastcomments/trunk/core/FastCommentsWordPressIntegration.php
r2575553 r2576755 26 26 update_option('fc_fastcomments_comment_ids_version', '1.0'); 27 27 28 $timestamp = wp_next_scheduled('fastcomments_cron'); 28 global $FASTCOMMENTS_VERSION; 29 $this->setSettingValue('fastcomments_version', $FASTCOMMENTS_VERSION); 30 31 $timestamp = wp_next_scheduled('fastcomments_cron_hook'); 29 32 if (!$timestamp) { 30 wp_schedule_event(time() + 86400, 'daily', 'fastcomments_cron ');33 wp_schedule_event(time() + 86400, 'daily', 'fastcomments_cron_hook'); 31 34 } 32 35 } … … 37 40 38 41 public function update() { 39 $is_old_version = !get_option('fc_fastcomments_comment_ids_version'); 40 if ($is_old_version) { 41 // force setup, but allow comment widget to load 42 delete_option('fastcomments_setup'); 43 delete_option('fastcomments_token_validated'); 44 } 45 46 $this->ensure_plugin_dependencies(); 42 global $FASTCOMMENTS_VERSION; 43 44 if ((string) $FASTCOMMENTS_VERSION !== (string) $this->getSettingValue('fastcomments_version')) { 45 $is_old_version = !get_option('fc_fastcomments_comment_ids_version'); 46 if ($is_old_version) { 47 // force setup, but allow comment widget to load 48 delete_option('fastcomments_setup'); 49 delete_option('fastcomments_token_validated'); 50 } 51 52 $timestamp = wp_next_scheduled('fastcomments_cron_hook'); 53 wp_unschedule_event($timestamp, 'fastcomments_cron_hook'); 54 $this->ensure_plugin_dependencies(); 55 $this->setSettingValue('fastcomments_version', $FASTCOMMENTS_VERSION); 56 } 47 57 } 48 58 … … 63 73 delete_option('fastcomments_sso_key'); 64 74 delete_option('fastcomments_sso_enabled'); 75 delete_option('fastcomments_cron'); 76 delete_option('fastcomments_version'); 77 delete_option('fastcomments_stream_last_fetch_timestamp'); 78 delete_option('fastcomments_stream_last_send_timestamp'); 79 delete_option('fastcomments_comment_sent_count'); 65 80 66 81 $timestamp = wp_next_scheduled('fastcomments_cron'); … … 99 114 100 115 private function addCommentIDMapEntry($fcId, $wpId) { 116 $this->log('debug', "addCommentIDMapEntry $fcId -> $wpId"); 101 117 global $wpdb; 102 118 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids"; 103 $insert_result = $wpdb->insert( 104 $id_map_table_name, 105 array( 106 'id' => $fcId, 107 'wp_id' => $wpId, 108 ) 109 ); 110 if ($insert_result === false) { 111 $this->log('error', "Was not able to map $fcId to $wpId"); 119 $existing_wp_id = $this->getWPCommentId($fcId); 120 if ($existing_wp_id !== null) { 121 $insert_result = $wpdb->insert( 122 $id_map_table_name, 123 array( 124 'id' => $fcId, 125 'wp_id' => $wpId, 126 ) 127 ); 128 if ($insert_result === false) { 129 $this->log('error', "Was not able to map $fcId to $wpId"); 130 } 131 } else { 132 $this->log('debug', "Skipped mapping $fcId to $wpId - mapping already exists."); 112 133 } 113 134 } … … 116 137 global $wpdb; 117 138 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids"; 118 $id_row = $wpdb->get_row( 119 $id_map_table_name, 120 array( 121 'id' => $fcId 122 ) 123 ); 124 if ($id_row) { 139 $this->log('debug', "getWPCommentId $fcId"); 140 $id_row = $wpdb->get_row("SELECT wp_id FROM $id_map_table_name WHERE id = \"$fcId\""); 141 if ($id_row !== false) { 125 142 return $id_row->wp_id; 126 143 } … … 207 224 208 225 $wp_id = $this->getWPCommentId($fc_comment->_id); 209 $wp_parent_id = $ this->getWPCommentId($fc_comment->parentId);226 $wp_parent_id = $fc_comment->parentId ? $this->getWPCommentId($fc_comment->parentId) : null; 210 227 211 228 $wp_comment['comment_ID'] = is_numeric($wp_id) ? $wp_id : null; … … 267 284 switch ($eventData->type) { 268 285 case 'new-comment': 286 $fcId = $eventData->comment->_id; 287 $this->log('debug', "Incoming comment $fcId"); 269 288 $comment_id_or_false = wp_insert_comment($this->fc_to_wp_comment($eventData->comment)); 270 289 if ($comment_id_or_false) { … … 276 295 break; 277 296 case 'updated-comment': 297 $fcId = $eventData->comment->_id; 298 $this->log('debug', "Updating comment $fcId"); 278 299 $wp_comment = $this->fc_to_wp_comment($eventData->comment); 279 $wp_id = $this->getWPCommentId($ eventData->comment->_id);300 $wp_id = $this->getWPCommentId($fcId); 280 301 $wp_comment['comment_ID'] = $wp_id; 281 302 wp_update_comment($wp_comment); 282 303 break; 283 304 case 'deleted-comment': 305 $this->log('debug', "Deleting comment $fcId"); 284 306 $wp_id = $this->getWPCommentId($eventData->comment->_id); 285 307 if ($wp_id != null) { … … 288 310 break; 289 311 case 'new-vote': 290 $wp_id = $this->getWPCommentId($eventData->vote->commentId); 312 $fcId = $eventData->vote->commentId; 313 $this->log('debug', "New vote for comment $fcId"); 314 $wp_id = $this->getWPCommentId($fcId); 291 315 $wp_comment = get_comment($wp_id, ARRAY_A); 292 316 if (!$wp_comment['comment_karma']) { … … 300 324 break; 301 325 case 'deleted-vote': 302 $wp_id = $this->getWPCommentId($eventData->vote->commentId); 326 $fcId = $eventData->vote->commentId; 327 $this->log('debug', "New vote for comment $fcId"); 328 $wp_id = $this->getWPCommentId($fcId); 303 329 $wp_comment = get_comment($wp_id, ARRAY_A); 304 330 if ($wp_comment['comment_karma']) { … … 329 355 'after' => date('c', $startFromDateTime ? $startFromDateTime / 1000 : 0), 330 356 'inclusive' => true 331 ) 357 ), 358 'orderby' => 'comment_date', 359 'order' => 'ASC' 332 360 ); 333 361 $wp_comments = get_comments($args); -
fastcomments/trunk/fastcomments-wordpress-plugin.php
r2575553 r2576755 4 4 Plugin URI: https://fastcomments.com 5 5 Description: Live Comments, Fast. A comment system that will delight your users and developers. 6 Version: 3. 86 Version: 3.9 7 7 Author: winrid @ FastComments 8 8 License: GPL-2.0+ … … 14 14 } 15 15 16 $FASTCOMMENTS_VERSION = 3. 8;16 $FASTCOMMENTS_VERSION = 3.9; 17 17 18 18 … … 21 21 $fastcomments_public = new FastCommentsPublic(); 22 22 $fastcomments_public->setup_api_listeners(); // TODO able to do this without new()? 23 23 24 24 25 // Returns the FastComments embed comments template … … 40 41 require_once plugin_dir_path(__FILE__) . 'core/FastCommentsWordPressIntegration.php'; 41 42 $fastcomments = new FastCommentsWordPressIntegration(); 43 $fastcomments->log('debug', 'Begin cron tick.'); 42 44 $fastcomments->tick(); 45 $fastcomments->log('debug', 'End cron tick.'); 43 46 } 47 add_action('fastcomments_cron_hook', 'fastcomments_cron'); 44 48 45 49 function fastcomments_activate() {
Note: See TracChangeset
for help on using the changeset viewer.