Plugin Directory

Changeset 2678152


Ignore:
Timestamp:
02/14/2022 04:23:42 AM (4 years ago)
Author:
winrid
Message:

3.11.0 - Sync and setup improvements.

Location:
fastcomments
Files:
40 added
8 edited

Legend:

Unmodified
Added
Removed
  • fastcomments/trunk/README.txt

    r2661187 r2678152  
    33Tags: live comments, comments, comment spam, comment system, fast comments, live commenting
    44Requires at least: 4.6
    5 Tested up to: 5.8
    6 Stable tag: 3.10.5
     5Tested up to: 5.9
     6Stable tag: 3.11.0
    77Requires PHP: 5.2.5
    88License: GPLv2 or later
     
    8686== Changelog ==
    8787
     88= 3.11.0 =
     89* Option to opt out of initial sync during setup.
     90* Ability to perform full sync manually at any time.
     91* Sync improvements (no longer misses first comment in database...).
     92
    8893= 3.10.5 =
    8994* Improvements to the chunk splitting algorithm for initial setup. No longer gets stuck on sites with very large number of large comments.
  • fastcomments/trunk/admin/fastcomments-admin-manual-sync-view.js

    r2660486 r2678152  
    11(function () {
    22
    3     const enableButton = document.getElementById('fc-sync-to-wp');
    4     const enableCancellationButton = document.getElementById('fc-sync-to-wp-cancel-button');
    5     const enableCancellationButtonInProgress = document.getElementById('fc-sync-to-wp-cancel-button-in-progress');
    6     const enableConfirmationButton = document.getElementById('fc-sync-to-wp-confirm-button');
    7     const confirmationArea = document.querySelector('#dialog-sync-to-wp .confirmation');
    8     const inProgressArea = document.querySelector('#dialog-sync-to-wp .in-progress');
    9     const inProgressStatusText = document.getElementById('in-progress-status-text');
    10 
    11     jQuery('#dialog-sync-to-wp').dialog({
    12         title: 'Sync To WordPress Confirmation',
    13         dialogClass: 'wp-dialog',
    14         autoOpen: false,
    15         draggable: false,
    16         width: 'auto',
    17         modal: true,
    18         resizable: true,
    19         closeOnEscape: true,
    20         position: {
    21             my: "center",
    22             at: "center",
    23             of: window
    24         },
    25         open: function () {
    26             // close dialog by clicking the overlay behind it
    27             jQuery('.ui-widget-overlay').bind('click', function () {
    28                 jQuery('#dialog-sync-to-wp').dialog('close');
    29             });
    30         },
    31         create: function () {
    32             // style fix for WordPress admin
    33             jQuery('.ui-dialog-titlebar-close').addClass('ui-button');
    34         },
    35     });
    36 
    37     enableButton.addEventListener('click', function () {
    38         jQuery('#dialog-sync-to-wp').dialog('open');
    39     });
    40 
    41     enableCancellationButton.addEventListener('click', function () {
    42         jQuery('#dialog-sync-to-wp').dialog('close');
    43     });
    44 
    45     let cancelled = false;
    46     enableCancellationButtonInProgress.addEventListener('click', function () {
    47         cancelled = true;
    48         jQuery('#dialog-sync-to-wp').dialog('close');
    49     });
    50 
    51     function centerDialog() {
    52         jQuery('#dialog-sync-to-wp').dialog('option', 'position', {my: "center", at: "center", of: window});
     3    function setupFCToWPUI() {
     4        const enableButton = document.getElementById('fc-sync-to-wp');
     5        const enableCancellationButton = document.getElementById('fc-sync-to-wp-cancel-button');
     6        const enableCancellationButtonInProgress = document.getElementById('fc-sync-to-wp-cancel-button-in-progress');
     7        const enableConfirmationButton = document.getElementById('fc-sync-to-wp-confirm-button');
     8        const confirmationArea = document.querySelector('#dialog-sync-to-wp .confirmation');
     9        const inProgressArea = document.querySelector('#dialog-sync-to-wp .in-progress');
     10        const inProgressStatusText = document.getElementById('fc-sync-to-wp-in-progress-status-text');
     11
     12        jQuery('#dialog-sync-to-wp').dialog({
     13            title: 'Sync To WordPress Confirmation',
     14            dialogClass: 'wp-dialog',
     15            autoOpen: false,
     16            draggable: false,
     17            width: 'auto',
     18            modal: true,
     19            resizable: true,
     20            closeOnEscape: true,
     21            position: {
     22                my: "center",
     23                at: "center",
     24                of: window
     25            },
     26            open: function () {
     27                // close dialog by clicking the overlay behind it
     28                jQuery('.ui-widget-overlay').bind('click', function () {
     29                    jQuery('#dialog-sync-to-wp').dialog('close');
     30                });
     31            },
     32            create: function () {
     33                // style fix for WordPress admin
     34                jQuery('.ui-dialog-titlebar-close').addClass('ui-button');
     35            },
     36        });
     37
     38        enableButton.addEventListener('click', function () {
     39            jQuery('#dialog-sync-to-wp').dialog('open');
     40        });
     41
     42        enableCancellationButton.addEventListener('click', function () {
     43            jQuery('#dialog-sync-to-wp').dialog('close');
     44        });
     45
     46        let cancelled = false;
     47        enableCancellationButtonInProgress.addEventListener('click', function () {
     48            cancelled = true;
     49            jQuery('#dialog-sync-to-wp').dialog('close');
     50        });
     51
     52        function centerDialog() {
     53            jQuery('#dialog-sync-to-wp').dialog('option', 'position', {my: "center", at: "center", of: window});
     54        }
     55
     56        enableConfirmationButton.addEventListener('click', function () {
     57            cancelled = false;
     58            jQuery('#dialog-sync-to-wp').dialog('option', 'title', 'Downloading Comments to WordPress...');
     59
     60            confirmationArea.classList.add('hidden');
     61            inProgressArea.classList.remove('hidden');
     62            inProgressStatusText.innerHTML = 'Beginning the sync, determining how many comments we need to download...';
     63            centerDialog();
     64
     65            function onError() {
     66                inProgressStatusText.innerHTML = 'Sync failed. Please try again. If this persists, reach out to support.';
     67                enableCancellationButtonInProgress.innerHTML = 'Close';
     68                centerDialog();
     69            }
     70
     71            let countSoFar = 0;
     72            let totalCount = 0;
     73
     74            function onDone() {
     75                if (cancelled) {
     76                    return;
     77                }
     78                jQuery('#dialog-sync-to-wp').dialog('option', 'title', 'Downloaded Comments to WordPress!');
     79                inProgressStatusText.innerHTML = '✔ Sync complete! Downloaded ' + Number(countSoFar).toLocaleString() + ' of ' + Number(totalCount).toLocaleString() + ' Comments.';
     80                enableCancellationButtonInProgress.innerHTML = 'Close';
     81                centerDialog();
     82            }
     83
     84            function next(includeCount) {
     85                if (cancelled) {
     86                    return;
     87                }
     88                let url = window.FC_DATA.siteUrl + '/index.php?rest_route=/fastcomments/v1/api/sync-to-wp';
     89                if (includeCount) {
     90                    url += '&includeCount=true';
     91                }
     92                if (countSoFar) {
     93                    url += '&skip=' + countSoFar;
     94                }
     95                jQuery.ajax({
     96                    url: url,
     97                    method: 'PUT',
     98                    dataType: 'json',
     99                    success: function success(response) {
     100                        if (response && response.status === 'success') {
     101                            if (response.totalCount !== null) {
     102                                totalCount = response.totalCount;
     103                            }
     104                            if (response.count) {
     105                                countSoFar += response.count;
     106                            }
     107                            inProgressStatusText.innerHTML = 'Downloading... Downloaded ' + Number(countSoFar).toLocaleString() + ' out of ' + Number(totalCount).toLocaleString() + ' comments.';
     108                            if (response.hasMore) {
     109                                setTimeout(function () {
     110                                    next();
     111                                }, 100);
     112                            } else {
     113                                onDone();
     114                            }
     115                        } else {
     116                            onError();
     117                        }
     118                    },
     119                    error: onError,
     120                    beforeSend: function (xhr) {
     121                        xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce);
     122                    }
     123                });
     124            }
     125
     126            next(true);
     127        });
    53128    }
    54129
    55     enableConfirmationButton.addEventListener('click', function () {
    56         cancelled = false;
    57         jQuery('#dialog-sync-to-wp').dialog('option', 'title', 'Downloading Comments to WordPress...');
    58 
    59         confirmationArea.classList.add('hidden');
    60         inProgressArea.classList.remove('hidden');
    61         inProgressStatusText.innerHTML = 'Beginning the sync, determining how many comments we need to download...';
    62         centerDialog();
    63 
    64         function onError() {
    65             inProgressStatusText.innerHTML = 'Sync failed. Please try again. If this persists, reach out to support.';
    66             enableCancellationButtonInProgress.innerHTML = 'Close';
     130    function setupWPToFCUI() {
     131        const enableButton = document.getElementById('wp-sync-to-fc');
     132        const enableCancellationButton = document.getElementById('wp-sync-to-fc-cancel-button');
     133        const enableCancellationButtonInProgress = document.getElementById('wp-sync-to-fc-cancel-button-in-progress');
     134        const enableConfirmationButton = document.getElementById('wp-sync-to-fc-confirm-button');
     135        const confirmationArea = document.querySelector('#dialog-sync-to-fc .confirmation');
     136        const inProgressArea = document.querySelector('#dialog-sync-to-fc .in-progress');
     137        const inProgressStatusText = document.getElementById('wp-sync-to-fc-in-progress-status-text');
     138
     139        jQuery('#dialog-sync-to-fc').dialog({
     140            title: 'Sync To FastComments.com Confirmation',
     141            dialogClass: 'wp-dialog',
     142            autoOpen: false,
     143            draggable: false,
     144            width: 'auto',
     145            modal: true,
     146            resizable: true,
     147            closeOnEscape: true,
     148            position: {
     149                my: "center",
     150                at: "center",
     151                of: window
     152            },
     153            open: function () {
     154                // close dialog by clicking the overlay behind it
     155                jQuery('.ui-widget-overlay').bind('click', function () {
     156                    jQuery('#dialog-sync-to-fc').dialog('close');
     157                });
     158            },
     159            create: function () {
     160                // style fix for WordPress admin
     161                jQuery('.ui-dialog-titlebar-close').addClass('ui-button');
     162            },
     163        });
     164
     165        enableButton.addEventListener('click', function () {
     166            jQuery('#dialog-sync-to-fc').dialog('open');
     167        });
     168
     169        enableCancellationButton.addEventListener('click', function () {
     170            jQuery('#dialog-sync-to-fc').dialog('close');
     171        });
     172
     173        let cancelled = false;
     174        enableCancellationButtonInProgress.addEventListener('click', function () {
     175            cancelled = true;
     176            jQuery('#dialog-sync-to-fc').dialog('close');
     177        });
     178
     179        function centerDialog() {
     180            jQuery('#dialog-sync-to-fc').dialog('option', 'position', {my: "center", at: "center", of: window});
     181        }
     182
     183        enableConfirmationButton.addEventListener('click', function () {
     184            cancelled = false;
     185            jQuery('#dialog-sync-to-fc').dialog('option', 'title', 'Uploading Comments to FastComments.com...');
     186
     187            confirmationArea.classList.add('hidden');
     188            inProgressArea.classList.remove('hidden');
     189            inProgressStatusText.innerHTML = 'Beginning the sync, determining how many comments we need to upload...';
    67190            centerDialog();
    68         }
    69 
    70         let countSoFar = 0;
    71         let totalCount = 0;
    72 
    73         function onDone() {
    74             if (cancelled) {
    75                 return;
    76             }
    77             jQuery('#dialog-sync-to-wp').dialog('option', 'title', 'Downloaded Comments to WordPress!');
    78             inProgressStatusText.innerHTML = '✔ Sync complete! Downloaded ' + Number(countSoFar).toLocaleString() + ' of ' + Number(totalCount).toLocaleString() + ' Comments.';
    79             enableCancellationButtonInProgress.innerHTML = 'Close';
    80             centerDialog();
    81         }
    82 
    83         function next(includeCount) {
    84             if (cancelled) {
    85                 return;
    86             }
    87             let url = window.FC_DATA.siteUrl + '/index.php?rest_route=/fastcomments/v1/api/sync-to-wp';
    88             if (includeCount) {
    89                 url += '&includeCount=true';
    90             }
    91             if (countSoFar) {
    92                 url += '&skip=' + countSoFar;
    93             }
    94             jQuery.ajax({
    95                 url: url,
    96                 method: 'PUT',
    97                 dataType: 'json',
    98                 success: function success(response) {
    99                     if (response && response.status === 'success') {
    100                         if (response.totalCount !== null) {
    101                             totalCount = response.totalCount;
     191
     192            function onError() {
     193                inProgressStatusText.innerHTML = 'Sync failed. Please try again. If this persists, reach out to support.';
     194                enableCancellationButtonInProgress.innerHTML = 'Close';
     195                centerDialog();
     196            }
     197
     198            let countSoFar = 0;
     199            let totalCount = 0;
     200
     201            function onDone() {
     202                if (cancelled) {
     203                    return;
     204                }
     205                jQuery('#dialog-sync-to-fc').dialog('option', 'title', 'Uploaded Comments to FastComments.com!');
     206                // countSoFar can be > totalCount in the event of retries or chunking
     207                inProgressStatusText.innerHTML = '✔ Sync complete! Uploaded ' + Number(Math.min(countSoFar, totalCount)).toLocaleString() + ' of ' + Number(totalCount).toLocaleString() + ' Comments.';
     208                enableCancellationButtonInProgress.innerHTML = 'Close';
     209                centerDialog();
     210            }
     211
     212            function next(isFirst) {
     213                if (cancelled) {
     214                    return;
     215                }
     216                let url = window.FC_DATA.siteUrl + '/index.php?rest_route=/fastcomments/v1/api/sync-to-fc';
     217                if (isFirst) {
     218                    url += '&includeCount=true';
     219                    url += '&reset=true';
     220                }
     221                jQuery.ajax({
     222                    url: url,
     223                    method: 'PUT',
     224                    dataType: 'json',
     225                    success: function success(response) {
     226                        if (response && response.status === 'success') {
     227                            if (response.totalCount !== null) {
     228                                totalCount = response.totalCount;
     229                            }
     230                            if (typeof response.commandResult === 'number') {
     231                                countSoFar += response.commandResult;
     232                            }
     233                            inProgressStatusText.innerHTML = 'Uploading... Uploaded ' + Number(countSoFar).toLocaleString() + ' out of ' + Number(totalCount).toLocaleString() + ' comments.';
     234                            if (response.hasMore) {
     235                                setTimeout(function () {
     236                                    next();
     237                                }, 100);
     238                            } else {
     239                                onDone();
     240                            }
     241                        } else {
     242                            onError();
    102243                        }
    103                         if (response.count) {
    104                             countSoFar += response.count;
    105                         }
    106                         inProgressStatusText.innerHTML = 'Downloading... Downloaded ' + Number(countSoFar).toLocaleString() + ' out of ' + Number(totalCount).toLocaleString() + ' comments.';
    107                         if (response.hasMore) {
    108                             setTimeout(function() {
    109                                 next();
    110                             }, 100);
    111                         } else {
    112                             onDone();
    113                         }
    114                     } else {
    115                         onError();
     244                    },
     245                    error: onError,
     246                    beforeSend: function (xhr) {
     247                        xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce);
    116248                    }
    117                 },
    118                 error: onError,
    119                 beforeSend: function (xhr) {
    120                     xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce);
    121                 }
    122             });
    123         }
    124         next(true);
    125     });
     249                });
     250            }
     251
     252            next(true);
     253        });
     254    }
     255
     256    setupFCToWPUI();
     257    setupWPToFCUI();
    126258})();
  • fastcomments/trunk/admin/fastcomments-admin-manual-sync-view.php

    r2660486 r2678152  
    1616    </noscript>
    1717
     18    <p>If you didn't upload your comments during the initial setup, or would like to do it anyway, you can do it now here.</p>
     19    <button class="button-primary" id="wp-sync-to-fc">Run Upload WordPress Comments → <b>to</b> → FastComments.com.</button>
     20
    1821    <p>FastComments automatically keeps your comments synced to your WordPress installation. However, the option exists to re-download all comments from FastComments to WordPress.</p>
    19     <button class="button-primary" id="fc-sync-to-wp">Run Sync FastComments.com → <b>to</b> → WordPress.</button>
     22    <button class="button-primary" id="fc-sync-to-wp">Run Download FastComments.com → <b>to</b> → WordPress.</button>
     23
     24    <div id="dialog-sync-to-fc" class="hidden">
     25        <div class="confirmation">
     26            <h3>Are you sure?</h3>
     27            <p>
     28                Running the sync from WordPress to FastComments will incrementally **upload** all your comments to your FastComments.com account.
     29            </p>
     30            <p>
     31                It will not remove any comments from your WordPress installation.
     32            </p>
     33            <p>
     34                This is not needed to keep your WordPress install up to date. This is only to upload your comments <b>from</b> WordPress <b>to</b> FastComments.com.
     35            </p>
     36            <p>After clicking "Yes, Perform The Sync", you must keep this page open for it to complete.</p>
     37            <p class="submit">
     38                <button type="button" class="button button-primary" id="wp-sync-to-fc-confirm-button">Yes, perform the upload.</button>
     39                <button type="button" class="button" id="wp-sync-to-fc-cancel-button">Cancel</button>
     40            </p>
     41        </div>
     42        <div class="in-progress hidden">
     43            <p id="wp-sync-to-fc-in-progress-status-text"></p>
     44            <p class="submit">
     45                <button type="button" class="button" id="wp-sync-to-fc-cancel-button-in-progress">Cancel</button>
     46            </p>
     47        </div>
     48    </div>
    2049
    2150    <div id="dialog-sync-to-wp" class="hidden">
     
    4069        </div>
    4170        <div class="in-progress hidden">
    42             <p id="in-progress-status-text"></p>
     71            <p id="fc-sync-to-wp-in-progress-status-text"></p>
    4372            <p class="submit">
    4473                <button type="button" class="button" id="fc-sync-to-wp-cancel-button-in-progress">Cancel</button>
  • fastcomments/trunk/admin/fastcomments-admin-setup-view.php

    r2660486 r2678152  
    1111        <h2>Do you have a FastComments Account?</h2>
    1212        <a class="button-primary button-has-account"
    13            href="https://fastcomments.com/auth/my-account/integrations/v1/setup?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true"
     13           href="https://fastcomments.com/auth/my-account/integrations/v1/confirm?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true"
    1414           target="_blank">Yes</a>
    1515        <a class="button-primary button-no-account"
    16            href="https://fastcomments.com/auth/my-account/integrations/v1/setup?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=false"
     16           href="https://fastcomments.com/auth/my-account/integrations/v1/confirm?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=false"
    1717           target="_blank">No</a>
    1818    <?php } else if (!get_option('fastcomments_setup')) { ?>
     
    2323
    2424        <a class="button-primary"
    25            href="https://fastcomments.com/auth/my-account/integrations/v1/setup?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true"
     25           href="https://fastcomments.com/auth/my-account/integrations/v1/confirm?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true"
    2626           target="_blank">Re-Run Setup</a>
    2727    <?php } else { ?>
     
    3333
    3434        <a class="button-primary"
    35            href="https://fastcomments.com/auth/my-account/integrations/v1/setup?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true"
     35           href="https://fastcomments.com/auth/my-account/integrations/v1/confirm?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true"
    3636           target="_blank">Re-Run Setup</a>
    3737    <?php } ?>
  • fastcomments/trunk/core/FastCommentsIntegrationCore.php

    r2661187 r2678152  
    183183                                $this->commandSendComments($token);
    184184                                break;
     185                            case 'SetSyncDone':
     186                                $this->commandSetSyncDone();
     187                                break;
    185188                        }
    186189                    }
     
    242245    public function commandSendComments($token) {
    243246        /**
    244          * Fetch 500 comments a time from the DB.
    245          * Split them up into chunks of 100.
     247         * Fetch 100 comments a time from the DB.
    246248         * If the server complains the payload is too large, recursively split the chunk by / 10.
    247249         */
     
    249251        if (!$this->canAckLock("commandSendComments", 60)) {
    250252            $this->log('debug', 'Can not send right now, waiting for previous attempt to finish.');
    251             return;
     253            return 'LOCK_WAITING';
    252254        }
    253255        $lastSendDate = $this->getSettingValue('fastcomments_stream_last_send_timestamp');
    254256        $lastSentId = $this->getSettingValue('fastcomments_stream_last_send_id');
    255         $commentCount = $this->getCommentCount($lastSentId ? $lastSentId : 0);
     257        $commentCount = $this->getCommentCount($lastSentId ? $lastSentId : -1);
    256258        if ($commentCount == 0) {
    257259            $this->log('debug', "No comments to send. Telling server. lastSendDate=[$lastSendDate] lastSentId=[$lastSentId]");
     260            // TODO abstract out and use for initial setup to skip upload
    258261            $requestBody = json_encode(
    259262                array(
     
    265268            $this->log('debug', "Got POST /comments response status code=[$httpResponse->responseStatusCode]");
    266269            $this->setSetupDone();
    267             return;
     270            return 0;
    268271        }
    269272        $this->log('debug', 'Send comments command loop...');
    270         $getCommentsResponse = $this->getComments($lastSentId ? $lastSentId : 0);
     273        $getCommentsResponse = $this->getComments($lastSentId ? $lastSentId : -1);
     274        $countSynced = 0;
    271275        if ($getCommentsResponse['status'] === 'success') {
    272276            $count = count($getCommentsResponse['comments']);
     
    296300                            $dynamicChunkSizeActual = count($dynamicChunk);
    297301                            $httpResponse = $this->makeHTTPRequest('POST', "$this->baseUrl/comments?token=$token", $requestBody);
    298                             $this->log('debug', "Got POST /comments response status code=[$httpResponse->responseStatusCode] and chunk size $dynamicChunkSize");
     302                            $this->log('debug', "Got POST /comments response status code=[$httpResponse->responseStatusCode] and chunk size $dynamicChunkSize (actual=$dynamicChunkSizeActual)");
    299303                            if ($httpResponse->responseStatusCode === 200) {
    300304                                $response = json_decode($httpResponse->responseBody);
    301305                                if ($response->status === 'success') {
    302306                                    foreach ($response->commentIds as $wpId => $fcId) {
    303                                         update_comment_meta((int) $wpId, 'fastcomments_id', $fcId);
     307                                        update_comment_meta((int)$wpId, 'fastcomments_id', $fcId);
    304308                                    }
    305309                                    $countRemaining = $countRemainingIfSuccessful;
     
    328332                $this->setSetupDone();
    329333            }
     334            $countSynced = $count;
    330335        } else {
    331336            $status = $getCommentsResponse['status'];
     
    335340        $this->clearLock("commandSendComments");
    336341        $this->log('debug', 'Done sending comments');
     342        return $countSynced;
     343    }
     344
     345    public function commandSetSyncDone() {
     346        $this->setSetupDone();
    337347    }
    338348
    339349    private function setSetupDone() {
     350        /**
     351         * Note - important we don't set the last stream fetch timestamp here to now(), because our timestamps
     352         * will be different than the server's, and that has no impact on setting the setup as done anyway.
     353         * The fastcomments_stream_last_fetch_timestamp should be set whenever we actually fetch the stream.
     354         */
    340355        $this->setSettingValue('fastcomments_setup', true);
    341         $this->setSettingValue('fastcomments_stream_last_fetch_timestamp', time() * 1000);
    342356        $this->clearLock("commandSendComments");
    343357    }
  • fastcomments/trunk/core/FastCommentsWordPressIntegration.php

    r2660486 r2678152  
    499499        $where = $this->getCommentQueryWhere($afterId);
    500500        global $wpdb;
     501        // Ordering by comment_ID makes the sort stable through pagination.
    501502        $sql = "SELECT * FROM $wpdb->comments WHERE $where ORDER BY comment_ID ASC LIMIT 100";
    502503        $query_result = $wpdb->get_results($sql);
  • fastcomments/trunk/fastcomments-wordpress-plugin.php

    r2661187 r2678152  
    44Plugin URI: https://fastcomments.com
    55Description: Live Comments, Fast. A comment system that will delight your users and developers.
    6 Version: 3.10.5
     6Version: 3.11.0
    77Author: winrid @ FastComments
    88License: GPL-2.0+
     
    1414}
    1515
    16 $FASTCOMMENTS_VERSION = 3.105;
     16$FASTCOMMENTS_VERSION = 3.110;
    1717
    1818require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php';
  • fastcomments/trunk/public/fastcomments-public.php

    r2660486 r2678152  
    2929                'methods' => 'PUT',
    3030                'callback' => array($this, 'handle_sync_to_wp_request'),
     31                'permission_callback' => function () {
     32                    return current_user_can('activate_plugins');
     33                }
     34            ));
     35            register_rest_route('fastcomments/v1', '/api/sync-to-fc', array(
     36                'methods' => 'PUT',
     37                'callback' => array($this, 'handle_sync_to_fc_request'),
    3138                'permission_callback' => function () {
    3239                    return current_user_can('activate_plugins');
     
    103110    }
    104111
     112    public function handle_sync_to_fc_request(WP_REST_Request $request) {
     113        $includeCount = $request->get_param('includeCount');
     114        $reset = $request->get_param('reset');
     115
     116        require_once plugin_dir_path(__FILE__) . '../core/FastCommentsWordPressIntegration.php';
     117        $fastcomments = new FastCommentsWordPressIntegration();
     118
     119        if ($reset) {
     120            $fastcomments->setSettingValue('fastcomments_stream_last_send_timestamp', null);
     121            $fastcomments->setSettingValue('fastcomments_stream_last_send_id', null);
     122        }
     123
     124        $token = $fastcomments->getSettingValue('fastcomments_token');
     125        $countSyncedOrErrorMessage = $fastcomments->commandSendComments($token);
     126
     127        return new WP_REST_Response(array('status' => 'success', 'hasMore' => $countSyncedOrErrorMessage === 'LOCK_WAITING' || $countSyncedOrErrorMessage > 0, 'totalCount' => $includeCount ? $fastcomments->getCommentCount(-1) : null, 'commandResult' => $countSyncedOrErrorMessage), 200);
     128    }
     129
    105130    public static function get_config_for_post($post) {
    106131        $ssoKey = get_option('fastcomments_sso_key');
Note: See TracChangeset for help on using the changeset viewer.