Plugin Directory

Changeset 3448885


Ignore:
Timestamp:
01/28/2026 05:00:06 PM (2 months ago)
Author:
guestapp
Message:

Update to version 2.2.7 from GitHub

Location:
guestapp
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • guestapp/tags/2.2.7/README.txt

    r3374894 r3448885  
    22Tags: avis clients, e-réputation, guest suite
    33Requires at least: 4.6.1
    4 Tested up to: 6.8.0
     4Tested up to: 6.9
    55Requires PHP: 5.6
    6 Stable tag: 2.2.6
     6Stable tag: 2.2.7
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6060
    6161== Changelog ==
     62= 2.2.7 =
     63* Améliore la fiabilité de la popup d'import
    6264= 2.2.6 =
    6365* Corrige les affichages d'avis pour les nouveaux établissements
  • guestapp/tags/2.2.7/assets/js/gs-cron.js

    r3198976 r3448885  
    11jQuery(document).ready(function($) {
     2    // Debug logging function - only logs when debug mode is enabled
     3    var isDebug = gs_cron_vars.debug;
     4    function gsLog() {
     5        if (isDebug) {
     6            var args = ['[GuestSuite]'].concat(Array.prototype.slice.call(arguments));
     7            console.log.apply(console, args);
     8        }
     9    }
     10    function gsError() {
     11        if (isDebug) {
     12            var args = ['[GuestSuite]'].concat(Array.prototype.slice.call(arguments));
     13            console.error.apply(console, args);
     14        }
     15    }
     16
     17    gsLog('JS loaded');
    218    var currentUrl = window.location.href;
    319    var isVisible = jQuery('#setting-error-settings_updated').is(':visible');
     20    gsLog('Notice visible:', isVisible);
     21    gsLog('Current URL:', currentUrl);
    422    var previousPostCount = null;
    5     var initialPostCount = null;
     23    var initialPostCount = null;
     24    var popupStartTime = null;
     25    var stablePostCountTime = null;
     26    var lastPostCount = null;
     27    var TIMEOUT_MINUTES = 10;
     28    var STABLE_COUNT_SECONDS = 30; // Consider complete if count stable for 30 seconds
    629
    730    // Get guestsuite_import_state option via AJAX
    831    function getImportState() {
     32        gsLog('getImportState() called');
    933        return jQuery.ajax({
    1034            url: gs_cron_vars.ajax_url,
     
    1539            },
    1640            success: function(response) {
     41                gsLog('getImportState response:', response);
    1742                if (response.success) {
    1843                    return response.data;
    1944                }
    20             }
    21         });
    22     }
    23 
    24     // Update modal text when gs-cron is running
    25     function updatePopupText() {
    26         getImportState().then(function(importState) {
    27             localStorage.setItem("gs_import_state", importState.data);
    28         });
    29         jQuery.ajax({
     45            },
     46            error: function(xhr, status, error) {
     47                gsError('getImportState error:', status, error);
     48            }
     49        });
     50    }
     51
     52    // Get comprehensive import status for timeout/fallback detection
     53    function getImportStatus() {
     54        return jQuery.ajax({
    3055            url: gs_cron_vars.ajax_url,
    3156            type: 'POST',
    3257            data: {
    33                 action: 'guestsuite_count_post_count',
     58                action: 'guestsuite_get_import_status',
    3459                _wpnonce: gs_cron_vars.nonce
    35             },
    36             success: function(response) {
    37                 if (response.success) {
    38                     var postCount = response.data;
    39                     var popupText = "";
    40                     var state = localStorage.getItem("gs_import_state");
    41                     var progressBar = "";
    42                     var progressPercentage = 0;
    43                     if (initialPostCount === null) {
    44                         initialPostCount = postCount;
     60            }
     61        });
     62    }
     63
     64    // Check for timeout or fallback completion
     65    function checkTimeoutAndFallback() {
     66        gsLog('checkTimeoutAndFallback() called');
     67
     68        getImportStatus().then(function(response) {
     69            if (!response.success) return;
     70
     71            var status = response.data;
     72            gsLog('Import status:', status);
     73
     74            var currentPostCount = status.post_count;
     75            var expectedCount = parseInt(gs_cron_vars.count);
     76            var elapsedMinutes = popupStartTime ? (Date.now() - popupStartTime) / 60000 : 0;
     77
     78            gsLog('Elapsed minutes:', elapsedMinutes.toFixed(1), '| Post count:', currentPostCount, '| Expected:', expectedCount);
     79
     80            // Check if post count has been stable (import might be done but flags not set)
     81            if (lastPostCount !== null && currentPostCount === lastPostCount && currentPostCount > 0) {
     82                if (stablePostCountTime === null) {
     83                    stablePostCountTime = Date.now();
     84                    gsLog('Post count stable, starting timer');
     85                } else {
     86                    var stableSeconds = (Date.now() - stablePostCountTime) / 1000;
     87                    gsLog('Post count stable for', stableSeconds.toFixed(0), 'seconds');
     88
     89                    // If count has been stable for STABLE_COUNT_SECONDS and we have posts, consider it complete
     90                    if (stableSeconds >= STABLE_COUNT_SECONDS && currentPostCount >= expectedCount * 0.9) {
     91                        gsLog('Fallback: Import appears complete (stable count)');
     92                        showFallbackSuccess(currentPostCount);
     93                        return;
    4594                    }
    46                     if(state != "false" && state != null){
    47                         if (state == "cleaning") {
    48                             var postsDeleted = initialPostCount - postCount;
    49                             progressPercentage = Math.round((postsDeleted / initialPostCount) * 100);
    50                             popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_cleaning + ": " + postsDeleted + "/" + initialPostCount + "</p>";
    51                         }
    52                         if (state == "import") {
    53                             progressPercentage = Math.round((postCount / gs_cron_vars.count) * 100);
    54                             popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_importing + ": " + postCount + "/" + gs_cron_vars.count + "</p>";
    55                         }
    56                         progressBar = `
    57                             <div style="width: 100%; background-color: #f3f3f3; border-radius: 10px; margin-top: 10px;">
    58                                 <div style="width: ${progressPercentage}%; background-color: #da3768; height: 20px; border-radius: 10px;"></div>
    59                             </div>
    60                             <p style="text-align: center;">${progressPercentage}%</p>
    61                         `;
    62                         Swal.update({
    63                             html: popupText + progressBar,
    64                         });
    65                         previousPostCount = postCount;
    66                     }
    67                 }
    68             }
     95                }
     96            } else {
     97                stablePostCountTime = null;
     98                lastPostCount = currentPostCount;
     99            }
     100
     101            // Check for timeout
     102            if (elapsedMinutes >= TIMEOUT_MINUTES) {
     103                gsLog('Timeout reached after', TIMEOUT_MINUTES, 'minutes');
     104                showTimeoutMessage(currentPostCount, expectedCount);
     105                return;
     106            }
     107        });
     108    }
     109
     110    // Show fallback success message
     111    function showFallbackSuccess(postCount) {
     112        clearInterval(statusChecker);
     113        clearInterval(statusChecker2);
     114        clearInterval(timeoutChecker);
     115        localStorage.removeItem("gs_import_state");
     116
     117        Swal.fire({
     118            title: 'Import terminé',
     119            html: postCount + ' avis importés.<br><small>(Détection automatique)</small>',
     120            icon: 'success',
     121            confirmButtonText: 'Dashboard',
     122            confirmButtonColor: "#da3768",
     123            position: "center",
     124            showCloseButton: true,
     125            width: '40%',
     126            didOpen: () => {
     127                Swal.hideLoading();
     128            }
     129        }).then((result) => {
     130            if (result.isConfirmed) {
     131                window.location.href = 'options-general.php?page=gs_settings&tab=dashboard';
     132            }
     133        });
     134    }
     135
     136    // Show timeout message
     137    function showTimeoutMessage(currentCount, expectedCount) {
     138        clearInterval(statusChecker);
     139        clearInterval(statusChecker2);
     140        clearInterval(timeoutChecker);
     141        localStorage.removeItem("gs_import_state");
     142
     143        var message = 'L\'import semble prendre plus de temps que prévu.<br>';
     144        message += 'Avis actuellement importés: ' + currentCount + '/' + expectedCount + '<br>';
     145        message += '<small>Vérifiez le dashboard pour voir l\'état réel.</small>';
     146
     147        Swal.fire({
     148            title: 'Import en cours...',
     149            html: message,
     150            icon: 'warning',
     151            confirmButtonText: 'Voir le Dashboard',
     152            confirmButtonColor: "#da3768",
     153            position: "center",
     154            showCloseButton: true,
     155            width: '40%',
     156            didOpen: () => {
     157                Swal.hideLoading();
     158            }
     159        }).then((result) => {
     160            if (result.isConfirmed) {
     161                window.location.href = 'options-general.php?page=gs_settings&tab=dashboard';
     162            }
     163        });
     164    }
     165
     166    var statusChecker, statusChecker2, timeoutChecker;
     167
     168    // Update modal text when gs-cron is running
     169    function updatePopupText() {
     170        gsLog('updatePopupText() called');
     171
     172        // Use getImportStatus to get both state and initial count from PHP
     173        getImportStatus().then(function(response) {
     174            if (!response.success) return;
     175
     176            var status = response.data;
     177            var postCount = status.post_count;
     178            var state = status.import_state;
     179            var serverInitialCount = status.import_initial_count;
     180
     181            // Use server-side initial count if available (more accurate)
     182            if (serverInitialCount && parseInt(serverInitialCount) > 0) {
     183                initialPostCount = parseInt(serverInitialCount);
     184            } else if (initialPostCount === null) {
     185                initialPostCount = postCount;
     186            }
     187
     188            gsLog('State:', state, '| Post count:', postCount, '| Initial count (from server):', serverInitialCount, '| Used initial count:', initialPostCount);
     189
     190            // Store state in localStorage for compatibility
     191            localStorage.setItem("gs_import_state", state);
     192
     193            var popupText = "";
     194            var progressBar = "";
     195            var progressPercentage = 0;
     196
     197            if(state && state !== "false"){
     198                if (state == "cleaning") {
     199                    var postsDeleted = initialPostCount - postCount;
     200                    if (postsDeleted < 0) postsDeleted = 0;
     201                    progressPercentage = initialPostCount > 0 ? Math.round((postsDeleted / initialPostCount) * 100) : 0;
     202                    popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_cleaning + ": " + postsDeleted + "/" + initialPostCount + "</p>";
     203                    gsLog('Cleaning progress:', progressPercentage + '%', '(' + postsDeleted + '/' + initialPostCount + ')');
     204                }
     205                if (state == "import") {
     206                    var expectedCount = parseInt(gs_cron_vars.count);
     207                    progressPercentage = expectedCount > 0 ? Math.round((postCount / expectedCount) * 100) : 0;
     208                    popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_importing + ": " + postCount + "/" + expectedCount + "</p>";
     209                    gsLog('Import progress:', progressPercentage + '%', '(' + postCount + '/' + expectedCount + ')');
     210                }
     211                progressBar = `
     212                    <div style="width: 100%; background-color: #f3f3f3; border-radius: 10px; margin-top: 10px;">
     213                        <div style="width: ${progressPercentage}%; background-color: #da3768; height: 20px; border-radius: 10px;"></div>
     214                    </div>
     215                    <p style="text-align: center;">${progressPercentage}%</p>
     216                `;
     217                Swal.update({
     218                    html: popupText + progressBar,
     219                });
     220                previousPostCount = postCount;
     221            } else {
     222                gsLog('State is false or null, not updating popup');
     223            }
     224        }).catch(function(error) {
     225            gsError('updatePopupText error:', error);
    69226        });
    70227    }
     
    72229    //If Notice is displayed and current URL is plugin settings
    73230    if (isVisible && currentUrl.includes('options-general.php?page=gs_settings')) {
     231        gsLog('Conditions met, starting import monitoring');
     232        popupStartTime = Date.now();
     233
    74234        //2sec for cron status
    75         var statusChecker = setInterval(function() {
     235        statusChecker = setInterval(function() {
    76236            checkGSCronStatus();
    77237        }, 2000);
    78238        //1sec for modal text
    79         var statusChecker2 = setInterval(function() {
     239        statusChecker2 = setInterval(function() {
    80240            updatePopupText();
    81241        }, 1000);
     242        //5sec for timeout and fallback detection
     243        timeoutChecker = setInterval(function() {
     244            checkTimeoutAndFallback();
     245        }, 5000);
     246
    82247        //Display popup1 with loader
     248        gsLog('Displaying initial popup');
    83249        Swal.fire({
    84250            title: gs_cron_vars.popup_title + "...",
     
    95261            iconColor: '#da3768',
    96262            didOpen: () => {
     263                gsLog('Popup opened, showing loader');
    97264                Swal.showLoading(); //show loader
    98265            }
    99266        });
     267    } else {
     268        gsLog('Conditions not met - isVisible:', isVisible, '| URL match:', currentUrl.includes('options-general.php?page=gs_settings'));
    100269    }
    101270   
    102271    // Get cron status and update success / error modal
    103272    function checkGSCronStatus() {
     273        gsLog('checkGSCronStatus() called');
    104274        var ajax_url = gs_cron_vars.ajax_url;
    105275        $.ajax({
     
    111281            },
    112282            success: function(response) {
     283                gsLog('checkGSCronStatus response:', response);
    113284                if (response.success) {
     285                    gsLog('Import completed! Type:', response.data.type);
    114286                    //OK: Display popup2 with success message
    115287                    if (response.data.type === "success") {
     288                        gsLog('Displaying success popup');
    116289                        Swal.fire({
    117290                            title: response.data.title,
     
    128301                            footer: '<small>'+response.data.cron_status + '<br/>' + response.data.next_cron + '</small>',
    129302                            didOpen: () => {
     303                                gsLog('Success popup opened');
    130304                                Swal.hideLoading(); //hide loader
    131305                            }
     
    137311                    //KO: Display popup2 with error message
    138312                    } else if (response.data.type === "error") {
     313                        gsLog('Displaying error popup');
    139314                        Swal.fire({
    140315                            title: response.data.title,
    141                             html: response.data.message, 
     316                            html: response.data.message,
    142317                            icon: response.data.type,
    143318                            confirmButtonText: response.data.btn,
     
    148323                            footer: '<small>'+response.data.cron_status+'</small>',
    149324                            didOpen: () => {
     325                                gsLog('Error popup opened');
    150326                                Swal.hideLoading(); //hide loader
    151327                            }
     
    153329                    }
    154330                    localStorage.removeItem("gs_import_state");
     331                    gsLog('Stopping intervals');
    155332                    //Stop interval, because cron is finished
    156333                    clearInterval(statusChecker);
    157334                    clearInterval(statusChecker2);
    158                 }
    159             }
     335                    clearInterval(timeoutChecker);
     336                } else {
     337                    gsLog('Import not yet completed (response.success is false or undefined)');
     338                }
     339            },
     340            error: function(xhr, status, error) {
     341                gsError('checkGSCronStatus error:', status, error);
     342            }
    160343        });
    161344    }
  • guestapp/tags/2.2.7/guest-suite.php

    r3374894 r3448885  
    44 * Plugin URI:        https://www.guest-suite.com/
    55 * Description:       Afficher la satisfaction de vos clients sur votre site avec le plugin Guest Suite pour Wordpress.
    6  * Version:           2.2.6
     6 * Version:           2.2.7
    77 * Requires at least: 4.6.1
    88 * Requires PHP:      5.6
     
    167167            'wording_importing' => $wording_import,
    168168            'count' => $count,
     169            'debug' => get_option('guestsuite_debug', '0') === '1',
    169170        ));
    170171        wp_enqueue_script('gs-import-cron-js');
     
    387388}
    388389
     390/**
     391 * Returns comprehensive import status for timeout detection and fallback completion.
     392 */
     393add_action('wp_ajax_guestsuite_get_import_status', 'guestsuite_get_import_status');
     394function guestsuite_get_import_status()
     395{
     396    if (!current_user_can('manage_options')) {
     397        wp_send_json_error('Permission denied');
     398    }
     399
     400    $count_posts = wp_count_posts(GUESTSUITE_CPT_NAME);
     401    $published_posts = $count_posts->publish;
     402
     403    $import_initial_count = get_option('guestsuite_import_initial_count', 0);
     404    if (get_option('guestsuite_debug', '0') === '1') {
     405        error_log('[GuestSuite] AJAX guestsuite_get_import_status - import_initial_count from DB: ' . var_export($import_initial_count, true));
     406    }
     407
     408    $response = array(
     409        'import_in_progress' => get_option('import_in_progress'),
     410        'import_completed' => get_option('import_completed'),
     411        'import_state' => get_option('guestsuite_import_state'),
     412        'import_started_at' => get_option('import_started_at'),
     413        'import_initial_count' => intval($import_initial_count),
     414        'current_time' => time(),
     415        'post_count' => intval($published_posts),
     416        'last_import_code' => get_option('guestsuite_last_import_code'),
     417        'last_import_message' => get_option('guestsuite_last_import_message'),
     418    );
     419
     420    wp_send_json_success($response);
     421}
     422
    389423
    390424/**
  • guestapp/tags/2.2.7/includes/admin/functions.php

    r3369496 r3448885  
    339339            case 200: // OK
    340340                //Delete all before new import...
    341                 add_option('guestsuite_import_state', 'cleaning');
     341                // Only store initial count if not already set by manual mode
     342                $existing_initial_count = get_option('guestsuite_import_initial_count', 0);
     343                if (intval($existing_initial_count) <= 0) {
     344                    $count_posts = wp_count_posts(GUESTSUITE_CPT_NAME);
     345                    $initial_count = isset($count_posts->publish) ? intval($count_posts->publish) : 0;
     346                    update_option('guestsuite_import_initial_count', $initial_count);
     347                    guestsuite_gslog('Import', 'Initial post count before cleaning (cron fallback): ' . $initial_count);
     348                } else {
     349                    guestsuite_gslog('Import', 'Initial post count already set by manual mode: ' . $existing_initial_count);
     350                }
     351
     352                update_option('guestsuite_import_state', 'cleaning');
    342353                guestsuite_remove_all_reviews();
    343354                update_option('guestsuite_import_state', 'import');
     
    349360                //Batch
    350361                $batch_size = GUESTSUITE_BATCH_SIZE_IMPORT_REVIEWS;
    351                 //error_log("BATCH SIZE: " . $batch_size);
    352362                $reviews = $users["reviews"];
     363                $total_reviews = count($reviews);
     364                guestsuite_gslog('Import', 'Starting import of ' . $total_reviews . ' reviews (batch size: ' . $batch_size . ')');
    353365                $batches = array_chunk($reviews, $batch_size);
    354 
     366                $total_batches = count($batches);
     367                guestsuite_gslog('Import', 'Total batches: ' . $total_batches);
     368
     369                $batch_number = 0;
    355370                foreach ($batches as $batch) {
     371                    $batch_number++;
     372                    guestsuite_gslog('Import', 'Processing batch ' . $batch_number . '/' . $total_batches);
    356373                    //Use SQL transaction to optimisation
    357374                    $wpdb->query('START TRANSACTION');
     
    380397                        );
    381398                        //Insert post
    382                         $post_id = wp_insert_post($postarr);
     399                        $post_id = wp_insert_post($postarr, true);
     400                        if (is_wp_error($post_id)) {
     401                            guestsuite_gslog('Import ERROR', 'wp_insert_post failed: ' . $post_id->get_error_message());
     402                            throw new Exception("Échec de l'insertion du post: " . $post_id->get_error_message());
     403                        }
    383404                        if ($post_id) {
    384405                            //Update other fields gs_responses + gs_reviewUuid
     
    386407                        } else {
    387408                            //If error, rollback
     409                            guestsuite_gslog('Import ERROR', 'wp_insert_post returned 0');
    388410                            throw new Exception("Échec de l'insertion du post.");
    389411                        }
     
    391413                    }
    392414                    $wpdb->query('COMMIT');
     415                    guestsuite_gslog('Import', 'Batch ' . $batch_number . ' committed (' . $nouveaux_avis . ' reviews imported so far)');
    393416                }
    394417
     418                guestsuite_gslog('Import', 'All batches processed successfully');
    395419                if ($nouveaux_avis > 0) {
    396420                    $message = $nouveaux_avis . ' ' . __('avis récupérés', 'guestapp');
    397421                }
    398422                delete_option('guestsuite_import_state');
     423                delete_option('guestsuite_import_initial_count');
     424                guestsuite_gslog('Import', 'Returning success message: ' . $message);
    399425                return $message;
    400426                break;
     
    428454        // Rollback transaction if error
    429455        $wpdb->query('ROLLBACK');
    430         //error_log('Erreur lors de l\'import des avis : ' . $e->getMessage());
     456        guestsuite_gslog('Import ERROR', 'Exception: ' . $e->getMessage());
     457        guestsuite_gslog('Import ERROR', 'File: ' . $e->getFile() . ' Line: ' . $e->getLine());
    431458        return __('Erreur lors de l\'importation des avis. Consultez les logs pour plus d\'informations.', 'guestapp');
    432459    }
  • guestapp/tags/2.2.7/includes/admin/import_manual.php

    r3364049 r3448885  
    3333    guestsuite_gslog("Import " . $mode, 'Before');
    3434    update_option('import_in_progress', true);
     35    update_option('import_started_at', time());
    3536    if ($mode == "cron")
    3637        $message = "0 avis récupéré via l'import automatique";
     
    4344    //Force enable CRON if previous import is OK
    4445    if ($mode == "manual") {
     46        // Store initial post count BEFORE cron starts (for accurate progress tracking)
     47        $count_posts = wp_count_posts(GUESTSUITE_CPT_NAME);
     48        $initial_count = isset($count_posts->publish) ? intval($count_posts->publish) : 0;
     49
     50        // Debug: log to error_log to ensure this code runs
     51        if (get_option('guestsuite_debug', '0') === '1') {
     52            error_log('[GuestSuite] Manual mode - storing initial count: ' . $initial_count);
     53            error_log('[GuestSuite] Manual mode - count_posts object: ' . print_r($count_posts, true));
     54        }
     55
     56        update_option('guestsuite_import_initial_count', $initial_count);
     57        guestsuite_gslog('Import', 'Initial post count stored (manual mode): ' . $initial_count);
     58
    4559        guestsuite_force_cron_change_status("1");
    4660    }
     
    91105        update_option('import_in_progress', false);
    92106        update_option('import_completed', true);
     107        delete_option('import_started_at');
    93108    }
    94109}
  • guestapp/tags/2.2.7/includes/admin/logs.php

    r3202888 r3448885  
    2323function guestsuite_gslog($action, $message)
    2424{
     25    $date = gmdate("Y-m-d H:i:s");
     26    $log_entry = '[' . $date . '] ' . $action . ' ' . $message . PHP_EOL;
     27
     28    // Log to PHP error_log only in debug mode
     29    if (get_option('guestsuite_debug', '0') === '1') {
     30        error_log('[GuestSuite] ' . trim($log_entry));
     31    }
     32
     33    // Use direct file writing (more reliable than WP_Filesystem in cron context)
    2534    $log_file_path = GUESTSUITE_LOG_FILE;
    26     if (!function_exists('WP_Filesystem')) {
    27         require_once(ABSPATH . 'wp-admin/includes/file.php');
    28     }
    29     global $wp_filesystem;
    30     WP_Filesystem();
     35    $log_dir = dirname($log_file_path);
    3136
    32     $log_dir = dirname($log_file_path);
    33     if (!$wp_filesystem->is_dir($log_dir) || !$wp_filesystem->is_writable($log_dir)) {
    34         //error_log("Le répertoire des logs n'est pas accessible en écriture : $log_dir");
     37    if (!is_dir($log_dir) || !is_writable($log_dir)) {
    3538        return;
    3639    }
    3740
    38     if ($wp_filesystem->exists($log_file_path) && !$wp_filesystem->is_writable($log_file_path)) {
    39         //error_log("Le fichier de log n'est pas accessible en écriture : $log_file_path");
     41    if (file_exists($log_file_path) && !is_writable($log_file_path)) {
    4042        return;
    4143    }
    4244
    43     $date = gmdate("Y-m-d H:i:s");
    44     $log_entry = '[' . $date . '] ' . $action . ' ' . $message . PHP_EOL;
    45 
    46     if (!$wp_filesystem->exists($log_file_path)) {
    47         if (!$wp_filesystem->put_contents($log_file_path, '', FS_CHMOD_FILE)) {
    48             //error_log("Impossible de créer le fichier de log : $log_file_path");
    49             return;
    50         }
    51     }
    52 
    53     $current_content = $wp_filesystem->get_contents($log_file_path);
    54     if ($current_content === false) {
    55         //error_log("Impossible de lire le fichier de log : $log_file_path");
    56         return;
    57     }
    58 
    59     $new_content = $current_content . $log_entry;
    60     if (!$wp_filesystem->put_contents($log_file_path, $new_content, FS_CHMOD_FILE)) {
    61         //error_log("Impossible d'écrire dans le fichier de log.");
    62     }
     45    // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
     46    file_put_contents($log_file_path, $log_entry, FILE_APPEND | LOCK_EX);
    6347}
    6448
     
    8064function guestsuite_display_logs()
    8165{
    82     if (!function_exists('WP_Filesystem')) {
    83         require_once(ABSPATH . 'wp-admin/includes/file.php');
    84     }
    85     global $wp_filesystem;
    86     WP_Filesystem();
    8766    $log_file = GUESTSUITE_LOG_FILE;
    88     if (!$wp_filesystem->exists($log_file)) {
     67    if (!file_exists($log_file)) {
    8968        return "Le fichier de log n'existe pas.";
    9069    }
    91     $log_content = $wp_filesystem->get_contents($log_file);
     70    // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
     71    $log_content = file_get_contents($log_file);
    9272    if ($log_content === false) {
    9373        return "Impossible de lire le fichier de log.";
  • guestapp/trunk/README.txt

    r3374894 r3448885  
    22Tags: avis clients, e-réputation, guest suite
    33Requires at least: 4.6.1
    4 Tested up to: 6.8.0
     4Tested up to: 6.9
    55Requires PHP: 5.6
    6 Stable tag: 2.2.6
     6Stable tag: 2.2.7
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6060
    6161== Changelog ==
     62= 2.2.7 =
     63* Améliore la fiabilité de la popup d'import
    6264= 2.2.6 =
    6365* Corrige les affichages d'avis pour les nouveaux établissements
  • guestapp/trunk/assets/js/gs-cron.js

    r3198976 r3448885  
    11jQuery(document).ready(function($) {
     2    // Debug logging function - only logs when debug mode is enabled
     3    var isDebug = gs_cron_vars.debug;
     4    function gsLog() {
     5        if (isDebug) {
     6            var args = ['[GuestSuite]'].concat(Array.prototype.slice.call(arguments));
     7            console.log.apply(console, args);
     8        }
     9    }
     10    function gsError() {
     11        if (isDebug) {
     12            var args = ['[GuestSuite]'].concat(Array.prototype.slice.call(arguments));
     13            console.error.apply(console, args);
     14        }
     15    }
     16
     17    gsLog('JS loaded');
    218    var currentUrl = window.location.href;
    319    var isVisible = jQuery('#setting-error-settings_updated').is(':visible');
     20    gsLog('Notice visible:', isVisible);
     21    gsLog('Current URL:', currentUrl);
    422    var previousPostCount = null;
    5     var initialPostCount = null;
     23    var initialPostCount = null;
     24    var popupStartTime = null;
     25    var stablePostCountTime = null;
     26    var lastPostCount = null;
     27    var TIMEOUT_MINUTES = 10;
     28    var STABLE_COUNT_SECONDS = 30; // Consider complete if count stable for 30 seconds
    629
    730    // Get guestsuite_import_state option via AJAX
    831    function getImportState() {
     32        gsLog('getImportState() called');
    933        return jQuery.ajax({
    1034            url: gs_cron_vars.ajax_url,
     
    1539            },
    1640            success: function(response) {
     41                gsLog('getImportState response:', response);
    1742                if (response.success) {
    1843                    return response.data;
    1944                }
    20             }
    21         });
    22     }
    23 
    24     // Update modal text when gs-cron is running
    25     function updatePopupText() {
    26         getImportState().then(function(importState) {
    27             localStorage.setItem("gs_import_state", importState.data);
    28         });
    29         jQuery.ajax({
     45            },
     46            error: function(xhr, status, error) {
     47                gsError('getImportState error:', status, error);
     48            }
     49        });
     50    }
     51
     52    // Get comprehensive import status for timeout/fallback detection
     53    function getImportStatus() {
     54        return jQuery.ajax({
    3055            url: gs_cron_vars.ajax_url,
    3156            type: 'POST',
    3257            data: {
    33                 action: 'guestsuite_count_post_count',
     58                action: 'guestsuite_get_import_status',
    3459                _wpnonce: gs_cron_vars.nonce
    35             },
    36             success: function(response) {
    37                 if (response.success) {
    38                     var postCount = response.data;
    39                     var popupText = "";
    40                     var state = localStorage.getItem("gs_import_state");
    41                     var progressBar = "";
    42                     var progressPercentage = 0;
    43                     if (initialPostCount === null) {
    44                         initialPostCount = postCount;
     60            }
     61        });
     62    }
     63
     64    // Check for timeout or fallback completion
     65    function checkTimeoutAndFallback() {
     66        gsLog('checkTimeoutAndFallback() called');
     67
     68        getImportStatus().then(function(response) {
     69            if (!response.success) return;
     70
     71            var status = response.data;
     72            gsLog('Import status:', status);
     73
     74            var currentPostCount = status.post_count;
     75            var expectedCount = parseInt(gs_cron_vars.count);
     76            var elapsedMinutes = popupStartTime ? (Date.now() - popupStartTime) / 60000 : 0;
     77
     78            gsLog('Elapsed minutes:', elapsedMinutes.toFixed(1), '| Post count:', currentPostCount, '| Expected:', expectedCount);
     79
     80            // Check if post count has been stable (import might be done but flags not set)
     81            if (lastPostCount !== null && currentPostCount === lastPostCount && currentPostCount > 0) {
     82                if (stablePostCountTime === null) {
     83                    stablePostCountTime = Date.now();
     84                    gsLog('Post count stable, starting timer');
     85                } else {
     86                    var stableSeconds = (Date.now() - stablePostCountTime) / 1000;
     87                    gsLog('Post count stable for', stableSeconds.toFixed(0), 'seconds');
     88
     89                    // If count has been stable for STABLE_COUNT_SECONDS and we have posts, consider it complete
     90                    if (stableSeconds >= STABLE_COUNT_SECONDS && currentPostCount >= expectedCount * 0.9) {
     91                        gsLog('Fallback: Import appears complete (stable count)');
     92                        showFallbackSuccess(currentPostCount);
     93                        return;
    4594                    }
    46                     if(state != "false" && state != null){
    47                         if (state == "cleaning") {
    48                             var postsDeleted = initialPostCount - postCount;
    49                             progressPercentage = Math.round((postsDeleted / initialPostCount) * 100);
    50                             popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_cleaning + ": " + postsDeleted + "/" + initialPostCount + "</p>";
    51                         }
    52                         if (state == "import") {
    53                             progressPercentage = Math.round((postCount / gs_cron_vars.count) * 100);
    54                             popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_importing + ": " + postCount + "/" + gs_cron_vars.count + "</p>";
    55                         }
    56                         progressBar = `
    57                             <div style="width: 100%; background-color: #f3f3f3; border-radius: 10px; margin-top: 10px;">
    58                                 <div style="width: ${progressPercentage}%; background-color: #da3768; height: 20px; border-radius: 10px;"></div>
    59                             </div>
    60                             <p style="text-align: center;">${progressPercentage}%</p>
    61                         `;
    62                         Swal.update({
    63                             html: popupText + progressBar,
    64                         });
    65                         previousPostCount = postCount;
    66                     }
    67                 }
    68             }
     95                }
     96            } else {
     97                stablePostCountTime = null;
     98                lastPostCount = currentPostCount;
     99            }
     100
     101            // Check for timeout
     102            if (elapsedMinutes >= TIMEOUT_MINUTES) {
     103                gsLog('Timeout reached after', TIMEOUT_MINUTES, 'minutes');
     104                showTimeoutMessage(currentPostCount, expectedCount);
     105                return;
     106            }
     107        });
     108    }
     109
     110    // Show fallback success message
     111    function showFallbackSuccess(postCount) {
     112        clearInterval(statusChecker);
     113        clearInterval(statusChecker2);
     114        clearInterval(timeoutChecker);
     115        localStorage.removeItem("gs_import_state");
     116
     117        Swal.fire({
     118            title: 'Import terminé',
     119            html: postCount + ' avis importés.<br><small>(Détection automatique)</small>',
     120            icon: 'success',
     121            confirmButtonText: 'Dashboard',
     122            confirmButtonColor: "#da3768",
     123            position: "center",
     124            showCloseButton: true,
     125            width: '40%',
     126            didOpen: () => {
     127                Swal.hideLoading();
     128            }
     129        }).then((result) => {
     130            if (result.isConfirmed) {
     131                window.location.href = 'options-general.php?page=gs_settings&tab=dashboard';
     132            }
     133        });
     134    }
     135
     136    // Show timeout message
     137    function showTimeoutMessage(currentCount, expectedCount) {
     138        clearInterval(statusChecker);
     139        clearInterval(statusChecker2);
     140        clearInterval(timeoutChecker);
     141        localStorage.removeItem("gs_import_state");
     142
     143        var message = 'L\'import semble prendre plus de temps que prévu.<br>';
     144        message += 'Avis actuellement importés: ' + currentCount + '/' + expectedCount + '<br>';
     145        message += '<small>Vérifiez le dashboard pour voir l\'état réel.</small>';
     146
     147        Swal.fire({
     148            title: 'Import en cours...',
     149            html: message,
     150            icon: 'warning',
     151            confirmButtonText: 'Voir le Dashboard',
     152            confirmButtonColor: "#da3768",
     153            position: "center",
     154            showCloseButton: true,
     155            width: '40%',
     156            didOpen: () => {
     157                Swal.hideLoading();
     158            }
     159        }).then((result) => {
     160            if (result.isConfirmed) {
     161                window.location.href = 'options-general.php?page=gs_settings&tab=dashboard';
     162            }
     163        });
     164    }
     165
     166    var statusChecker, statusChecker2, timeoutChecker;
     167
     168    // Update modal text when gs-cron is running
     169    function updatePopupText() {
     170        gsLog('updatePopupText() called');
     171
     172        // Use getImportStatus to get both state and initial count from PHP
     173        getImportStatus().then(function(response) {
     174            if (!response.success) return;
     175
     176            var status = response.data;
     177            var postCount = status.post_count;
     178            var state = status.import_state;
     179            var serverInitialCount = status.import_initial_count;
     180
     181            // Use server-side initial count if available (more accurate)
     182            if (serverInitialCount && parseInt(serverInitialCount) > 0) {
     183                initialPostCount = parseInt(serverInitialCount);
     184            } else if (initialPostCount === null) {
     185                initialPostCount = postCount;
     186            }
     187
     188            gsLog('State:', state, '| Post count:', postCount, '| Initial count (from server):', serverInitialCount, '| Used initial count:', initialPostCount);
     189
     190            // Store state in localStorage for compatibility
     191            localStorage.setItem("gs_import_state", state);
     192
     193            var popupText = "";
     194            var progressBar = "";
     195            var progressPercentage = 0;
     196
     197            if(state && state !== "false"){
     198                if (state == "cleaning") {
     199                    var postsDeleted = initialPostCount - postCount;
     200                    if (postsDeleted < 0) postsDeleted = 0;
     201                    progressPercentage = initialPostCount > 0 ? Math.round((postsDeleted / initialPostCount) * 100) : 0;
     202                    popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_cleaning + ": " + postsDeleted + "/" + initialPostCount + "</p>";
     203                    gsLog('Cleaning progress:', progressPercentage + '%', '(' + postsDeleted + '/' + initialPostCount + ')');
     204                }
     205                if (state == "import") {
     206                    var expectedCount = parseInt(gs_cron_vars.count);
     207                    progressPercentage = expectedCount > 0 ? Math.round((postCount / expectedCount) * 100) : 0;
     208                    popupText = gs_cron_vars.popup_text + "<p>" + gs_cron_vars.wording_importing + ": " + postCount + "/" + expectedCount + "</p>";
     209                    gsLog('Import progress:', progressPercentage + '%', '(' + postCount + '/' + expectedCount + ')');
     210                }
     211                progressBar = `
     212                    <div style="width: 100%; background-color: #f3f3f3; border-radius: 10px; margin-top: 10px;">
     213                        <div style="width: ${progressPercentage}%; background-color: #da3768; height: 20px; border-radius: 10px;"></div>
     214                    </div>
     215                    <p style="text-align: center;">${progressPercentage}%</p>
     216                `;
     217                Swal.update({
     218                    html: popupText + progressBar,
     219                });
     220                previousPostCount = postCount;
     221            } else {
     222                gsLog('State is false or null, not updating popup');
     223            }
     224        }).catch(function(error) {
     225            gsError('updatePopupText error:', error);
    69226        });
    70227    }
     
    72229    //If Notice is displayed and current URL is plugin settings
    73230    if (isVisible && currentUrl.includes('options-general.php?page=gs_settings')) {
     231        gsLog('Conditions met, starting import monitoring');
     232        popupStartTime = Date.now();
     233
    74234        //2sec for cron status
    75         var statusChecker = setInterval(function() {
     235        statusChecker = setInterval(function() {
    76236            checkGSCronStatus();
    77237        }, 2000);
    78238        //1sec for modal text
    79         var statusChecker2 = setInterval(function() {
     239        statusChecker2 = setInterval(function() {
    80240            updatePopupText();
    81241        }, 1000);
     242        //5sec for timeout and fallback detection
     243        timeoutChecker = setInterval(function() {
     244            checkTimeoutAndFallback();
     245        }, 5000);
     246
    82247        //Display popup1 with loader
     248        gsLog('Displaying initial popup');
    83249        Swal.fire({
    84250            title: gs_cron_vars.popup_title + "...",
     
    95261            iconColor: '#da3768',
    96262            didOpen: () => {
     263                gsLog('Popup opened, showing loader');
    97264                Swal.showLoading(); //show loader
    98265            }
    99266        });
     267    } else {
     268        gsLog('Conditions not met - isVisible:', isVisible, '| URL match:', currentUrl.includes('options-general.php?page=gs_settings'));
    100269    }
    101270   
    102271    // Get cron status and update success / error modal
    103272    function checkGSCronStatus() {
     273        gsLog('checkGSCronStatus() called');
    104274        var ajax_url = gs_cron_vars.ajax_url;
    105275        $.ajax({
     
    111281            },
    112282            success: function(response) {
     283                gsLog('checkGSCronStatus response:', response);
    113284                if (response.success) {
     285                    gsLog('Import completed! Type:', response.data.type);
    114286                    //OK: Display popup2 with success message
    115287                    if (response.data.type === "success") {
     288                        gsLog('Displaying success popup');
    116289                        Swal.fire({
    117290                            title: response.data.title,
     
    128301                            footer: '<small>'+response.data.cron_status + '<br/>' + response.data.next_cron + '</small>',
    129302                            didOpen: () => {
     303                                gsLog('Success popup opened');
    130304                                Swal.hideLoading(); //hide loader
    131305                            }
     
    137311                    //KO: Display popup2 with error message
    138312                    } else if (response.data.type === "error") {
     313                        gsLog('Displaying error popup');
    139314                        Swal.fire({
    140315                            title: response.data.title,
    141                             html: response.data.message, 
     316                            html: response.data.message,
    142317                            icon: response.data.type,
    143318                            confirmButtonText: response.data.btn,
     
    148323                            footer: '<small>'+response.data.cron_status+'</small>',
    149324                            didOpen: () => {
     325                                gsLog('Error popup opened');
    150326                                Swal.hideLoading(); //hide loader
    151327                            }
     
    153329                    }
    154330                    localStorage.removeItem("gs_import_state");
     331                    gsLog('Stopping intervals');
    155332                    //Stop interval, because cron is finished
    156333                    clearInterval(statusChecker);
    157334                    clearInterval(statusChecker2);
    158                 }
    159             }
     335                    clearInterval(timeoutChecker);
     336                } else {
     337                    gsLog('Import not yet completed (response.success is false or undefined)');
     338                }
     339            },
     340            error: function(xhr, status, error) {
     341                gsError('checkGSCronStatus error:', status, error);
     342            }
    160343        });
    161344    }
  • guestapp/trunk/guest-suite.php

    r3374894 r3448885  
    44 * Plugin URI:        https://www.guest-suite.com/
    55 * Description:       Afficher la satisfaction de vos clients sur votre site avec le plugin Guest Suite pour Wordpress.
    6  * Version:           2.2.6
     6 * Version:           2.2.7
    77 * Requires at least: 4.6.1
    88 * Requires PHP:      5.6
     
    167167            'wording_importing' => $wording_import,
    168168            'count' => $count,
     169            'debug' => get_option('guestsuite_debug', '0') === '1',
    169170        ));
    170171        wp_enqueue_script('gs-import-cron-js');
     
    387388}
    388389
     390/**
     391 * Returns comprehensive import status for timeout detection and fallback completion.
     392 */
     393add_action('wp_ajax_guestsuite_get_import_status', 'guestsuite_get_import_status');
     394function guestsuite_get_import_status()
     395{
     396    if (!current_user_can('manage_options')) {
     397        wp_send_json_error('Permission denied');
     398    }
     399
     400    $count_posts = wp_count_posts(GUESTSUITE_CPT_NAME);
     401    $published_posts = $count_posts->publish;
     402
     403    $import_initial_count = get_option('guestsuite_import_initial_count', 0);
     404    if (get_option('guestsuite_debug', '0') === '1') {
     405        error_log('[GuestSuite] AJAX guestsuite_get_import_status - import_initial_count from DB: ' . var_export($import_initial_count, true));
     406    }
     407
     408    $response = array(
     409        'import_in_progress' => get_option('import_in_progress'),
     410        'import_completed' => get_option('import_completed'),
     411        'import_state' => get_option('guestsuite_import_state'),
     412        'import_started_at' => get_option('import_started_at'),
     413        'import_initial_count' => intval($import_initial_count),
     414        'current_time' => time(),
     415        'post_count' => intval($published_posts),
     416        'last_import_code' => get_option('guestsuite_last_import_code'),
     417        'last_import_message' => get_option('guestsuite_last_import_message'),
     418    );
     419
     420    wp_send_json_success($response);
     421}
     422
    389423
    390424/**
  • guestapp/trunk/includes/admin/functions.php

    r3369496 r3448885  
    339339            case 200: // OK
    340340                //Delete all before new import...
    341                 add_option('guestsuite_import_state', 'cleaning');
     341                // Only store initial count if not already set by manual mode
     342                $existing_initial_count = get_option('guestsuite_import_initial_count', 0);
     343                if (intval($existing_initial_count) <= 0) {
     344                    $count_posts = wp_count_posts(GUESTSUITE_CPT_NAME);
     345                    $initial_count = isset($count_posts->publish) ? intval($count_posts->publish) : 0;
     346                    update_option('guestsuite_import_initial_count', $initial_count);
     347                    guestsuite_gslog('Import', 'Initial post count before cleaning (cron fallback): ' . $initial_count);
     348                } else {
     349                    guestsuite_gslog('Import', 'Initial post count already set by manual mode: ' . $existing_initial_count);
     350                }
     351
     352                update_option('guestsuite_import_state', 'cleaning');
    342353                guestsuite_remove_all_reviews();
    343354                update_option('guestsuite_import_state', 'import');
     
    349360                //Batch
    350361                $batch_size = GUESTSUITE_BATCH_SIZE_IMPORT_REVIEWS;
    351                 //error_log("BATCH SIZE: " . $batch_size);
    352362                $reviews = $users["reviews"];
     363                $total_reviews = count($reviews);
     364                guestsuite_gslog('Import', 'Starting import of ' . $total_reviews . ' reviews (batch size: ' . $batch_size . ')');
    353365                $batches = array_chunk($reviews, $batch_size);
    354 
     366                $total_batches = count($batches);
     367                guestsuite_gslog('Import', 'Total batches: ' . $total_batches);
     368
     369                $batch_number = 0;
    355370                foreach ($batches as $batch) {
     371                    $batch_number++;
     372                    guestsuite_gslog('Import', 'Processing batch ' . $batch_number . '/' . $total_batches);
    356373                    //Use SQL transaction to optimisation
    357374                    $wpdb->query('START TRANSACTION');
     
    380397                        );
    381398                        //Insert post
    382                         $post_id = wp_insert_post($postarr);
     399                        $post_id = wp_insert_post($postarr, true);
     400                        if (is_wp_error($post_id)) {
     401                            guestsuite_gslog('Import ERROR', 'wp_insert_post failed: ' . $post_id->get_error_message());
     402                            throw new Exception("Échec de l'insertion du post: " . $post_id->get_error_message());
     403                        }
    383404                        if ($post_id) {
    384405                            //Update other fields gs_responses + gs_reviewUuid
     
    386407                        } else {
    387408                            //If error, rollback
     409                            guestsuite_gslog('Import ERROR', 'wp_insert_post returned 0');
    388410                            throw new Exception("Échec de l'insertion du post.");
    389411                        }
     
    391413                    }
    392414                    $wpdb->query('COMMIT');
     415                    guestsuite_gslog('Import', 'Batch ' . $batch_number . ' committed (' . $nouveaux_avis . ' reviews imported so far)');
    393416                }
    394417
     418                guestsuite_gslog('Import', 'All batches processed successfully');
    395419                if ($nouveaux_avis > 0) {
    396420                    $message = $nouveaux_avis . ' ' . __('avis récupérés', 'guestapp');
    397421                }
    398422                delete_option('guestsuite_import_state');
     423                delete_option('guestsuite_import_initial_count');
     424                guestsuite_gslog('Import', 'Returning success message: ' . $message);
    399425                return $message;
    400426                break;
     
    428454        // Rollback transaction if error
    429455        $wpdb->query('ROLLBACK');
    430         //error_log('Erreur lors de l\'import des avis : ' . $e->getMessage());
     456        guestsuite_gslog('Import ERROR', 'Exception: ' . $e->getMessage());
     457        guestsuite_gslog('Import ERROR', 'File: ' . $e->getFile() . ' Line: ' . $e->getLine());
    431458        return __('Erreur lors de l\'importation des avis. Consultez les logs pour plus d\'informations.', 'guestapp');
    432459    }
  • guestapp/trunk/includes/admin/import_manual.php

    r3364049 r3448885  
    3333    guestsuite_gslog("Import " . $mode, 'Before');
    3434    update_option('import_in_progress', true);
     35    update_option('import_started_at', time());
    3536    if ($mode == "cron")
    3637        $message = "0 avis récupéré via l'import automatique";
     
    4344    //Force enable CRON if previous import is OK
    4445    if ($mode == "manual") {
     46        // Store initial post count BEFORE cron starts (for accurate progress tracking)
     47        $count_posts = wp_count_posts(GUESTSUITE_CPT_NAME);
     48        $initial_count = isset($count_posts->publish) ? intval($count_posts->publish) : 0;
     49
     50        // Debug: log to error_log to ensure this code runs
     51        if (get_option('guestsuite_debug', '0') === '1') {
     52            error_log('[GuestSuite] Manual mode - storing initial count: ' . $initial_count);
     53            error_log('[GuestSuite] Manual mode - count_posts object: ' . print_r($count_posts, true));
     54        }
     55
     56        update_option('guestsuite_import_initial_count', $initial_count);
     57        guestsuite_gslog('Import', 'Initial post count stored (manual mode): ' . $initial_count);
     58
    4559        guestsuite_force_cron_change_status("1");
    4660    }
     
    91105        update_option('import_in_progress', false);
    92106        update_option('import_completed', true);
     107        delete_option('import_started_at');
    93108    }
    94109}
  • guestapp/trunk/includes/admin/logs.php

    r3202888 r3448885  
    2323function guestsuite_gslog($action, $message)
    2424{
     25    $date = gmdate("Y-m-d H:i:s");
     26    $log_entry = '[' . $date . '] ' . $action . ' ' . $message . PHP_EOL;
     27
     28    // Log to PHP error_log only in debug mode
     29    if (get_option('guestsuite_debug', '0') === '1') {
     30        error_log('[GuestSuite] ' . trim($log_entry));
     31    }
     32
     33    // Use direct file writing (more reliable than WP_Filesystem in cron context)
    2534    $log_file_path = GUESTSUITE_LOG_FILE;
    26     if (!function_exists('WP_Filesystem')) {
    27         require_once(ABSPATH . 'wp-admin/includes/file.php');
    28     }
    29     global $wp_filesystem;
    30     WP_Filesystem();
     35    $log_dir = dirname($log_file_path);
    3136
    32     $log_dir = dirname($log_file_path);
    33     if (!$wp_filesystem->is_dir($log_dir) || !$wp_filesystem->is_writable($log_dir)) {
    34         //error_log("Le répertoire des logs n'est pas accessible en écriture : $log_dir");
     37    if (!is_dir($log_dir) || !is_writable($log_dir)) {
    3538        return;
    3639    }
    3740
    38     if ($wp_filesystem->exists($log_file_path) && !$wp_filesystem->is_writable($log_file_path)) {
    39         //error_log("Le fichier de log n'est pas accessible en écriture : $log_file_path");
     41    if (file_exists($log_file_path) && !is_writable($log_file_path)) {
    4042        return;
    4143    }
    4244
    43     $date = gmdate("Y-m-d H:i:s");
    44     $log_entry = '[' . $date . '] ' . $action . ' ' . $message . PHP_EOL;
    45 
    46     if (!$wp_filesystem->exists($log_file_path)) {
    47         if (!$wp_filesystem->put_contents($log_file_path, '', FS_CHMOD_FILE)) {
    48             //error_log("Impossible de créer le fichier de log : $log_file_path");
    49             return;
    50         }
    51     }
    52 
    53     $current_content = $wp_filesystem->get_contents($log_file_path);
    54     if ($current_content === false) {
    55         //error_log("Impossible de lire le fichier de log : $log_file_path");
    56         return;
    57     }
    58 
    59     $new_content = $current_content . $log_entry;
    60     if (!$wp_filesystem->put_contents($log_file_path, $new_content, FS_CHMOD_FILE)) {
    61         //error_log("Impossible d'écrire dans le fichier de log.");
    62     }
     45    // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
     46    file_put_contents($log_file_path, $log_entry, FILE_APPEND | LOCK_EX);
    6347}
    6448
     
    8064function guestsuite_display_logs()
    8165{
    82     if (!function_exists('WP_Filesystem')) {
    83         require_once(ABSPATH . 'wp-admin/includes/file.php');
    84     }
    85     global $wp_filesystem;
    86     WP_Filesystem();
    8766    $log_file = GUESTSUITE_LOG_FILE;
    88     if (!$wp_filesystem->exists($log_file)) {
     67    if (!file_exists($log_file)) {
    8968        return "Le fichier de log n'existe pas.";
    9069    }
    91     $log_content = $wp_filesystem->get_contents($log_file);
     70    // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
     71    $log_content = file_get_contents($log_file);
    9272    if ($log_content === false) {
    9373        return "Impossible de lire le fichier de log.";
Note: See TracChangeset for help on using the changeset viewer.