Changeset 3448885
- Timestamp:
- 01/28/2026 05:00:06 PM (2 months ago)
- Location:
- guestapp
- Files:
-
- 12 edited
- 1 copied
-
tags/2.2.7 (copied) (copied from guestapp/trunk)
-
tags/2.2.7/README.txt (modified) (2 diffs)
-
tags/2.2.7/assets/js/gs-cron.js (modified) (9 diffs)
-
tags/2.2.7/guest-suite.php (modified) (3 diffs)
-
tags/2.2.7/includes/admin/functions.php (modified) (6 diffs)
-
tags/2.2.7/includes/admin/import_manual.php (modified) (3 diffs)
-
tags/2.2.7/includes/admin/logs.php (modified) (2 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/assets/js/gs-cron.js (modified) (9 diffs)
-
trunk/guest-suite.php (modified) (3 diffs)
-
trunk/includes/admin/functions.php (modified) (6 diffs)
-
trunk/includes/admin/import_manual.php (modified) (3 diffs)
-
trunk/includes/admin/logs.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
guestapp/tags/2.2.7/README.txt
r3374894 r3448885 2 2 Tags: avis clients, e-réputation, guest suite 3 3 Requires at least: 4.6.1 4 Tested up to: 6. 8.04 Tested up to: 6.9 5 5 Requires PHP: 5.6 6 Stable tag: 2.2. 66 Stable tag: 2.2.7 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 60 60 61 61 == Changelog == 62 = 2.2.7 = 63 * Améliore la fiabilité de la popup d'import 62 64 = 2.2.6 = 63 65 * Corrige les affichages d'avis pour les nouveaux établissements -
guestapp/tags/2.2.7/assets/js/gs-cron.js
r3198976 r3448885 1 1 jQuery(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'); 2 18 var currentUrl = window.location.href; 3 19 var isVisible = jQuery('#setting-error-settings_updated').is(':visible'); 20 gsLog('Notice visible:', isVisible); 21 gsLog('Current URL:', currentUrl); 4 22 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 6 29 7 30 // Get guestsuite_import_state option via AJAX 8 31 function getImportState() { 32 gsLog('getImportState() called'); 9 33 return jQuery.ajax({ 10 34 url: gs_cron_vars.ajax_url, … … 15 39 }, 16 40 success: function(response) { 41 gsLog('getImportState response:', response); 17 42 if (response.success) { 18 43 return response.data; 19 44 } 20 } 21 });22 }23 24 // Update modal text when gs-cron is running25 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({ 30 55 url: gs_cron_vars.ajax_url, 31 56 type: 'POST', 32 57 data: { 33 action: 'guestsuite_ count_post_count',58 action: 'guestsuite_get_import_status', 34 59 _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; 45 94 } 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); 69 226 }); 70 227 } … … 72 229 //If Notice is displayed and current URL is plugin settings 73 230 if (isVisible && currentUrl.includes('options-general.php?page=gs_settings')) { 231 gsLog('Conditions met, starting import monitoring'); 232 popupStartTime = Date.now(); 233 74 234 //2sec for cron status 75 varstatusChecker = setInterval(function() {235 statusChecker = setInterval(function() { 76 236 checkGSCronStatus(); 77 237 }, 2000); 78 238 //1sec for modal text 79 varstatusChecker2 = setInterval(function() {239 statusChecker2 = setInterval(function() { 80 240 updatePopupText(); 81 241 }, 1000); 242 //5sec for timeout and fallback detection 243 timeoutChecker = setInterval(function() { 244 checkTimeoutAndFallback(); 245 }, 5000); 246 82 247 //Display popup1 with loader 248 gsLog('Displaying initial popup'); 83 249 Swal.fire({ 84 250 title: gs_cron_vars.popup_title + "...", … … 95 261 iconColor: '#da3768', 96 262 didOpen: () => { 263 gsLog('Popup opened, showing loader'); 97 264 Swal.showLoading(); //show loader 98 265 } 99 266 }); 267 } else { 268 gsLog('Conditions not met - isVisible:', isVisible, '| URL match:', currentUrl.includes('options-general.php?page=gs_settings')); 100 269 } 101 270 102 271 // Get cron status and update success / error modal 103 272 function checkGSCronStatus() { 273 gsLog('checkGSCronStatus() called'); 104 274 var ajax_url = gs_cron_vars.ajax_url; 105 275 $.ajax({ … … 111 281 }, 112 282 success: function(response) { 283 gsLog('checkGSCronStatus response:', response); 113 284 if (response.success) { 285 gsLog('Import completed! Type:', response.data.type); 114 286 //OK: Display popup2 with success message 115 287 if (response.data.type === "success") { 288 gsLog('Displaying success popup'); 116 289 Swal.fire({ 117 290 title: response.data.title, … … 128 301 footer: '<small>'+response.data.cron_status + '<br/>' + response.data.next_cron + '</small>', 129 302 didOpen: () => { 303 gsLog('Success popup opened'); 130 304 Swal.hideLoading(); //hide loader 131 305 } … … 137 311 //KO: Display popup2 with error message 138 312 } else if (response.data.type === "error") { 313 gsLog('Displaying error popup'); 139 314 Swal.fire({ 140 315 title: response.data.title, 141 html: response.data.message, 316 html: response.data.message, 142 317 icon: response.data.type, 143 318 confirmButtonText: response.data.btn, … … 148 323 footer: '<small>'+response.data.cron_status+'</small>', 149 324 didOpen: () => { 325 gsLog('Error popup opened'); 150 326 Swal.hideLoading(); //hide loader 151 327 } … … 153 329 } 154 330 localStorage.removeItem("gs_import_state"); 331 gsLog('Stopping intervals'); 155 332 //Stop interval, because cron is finished 156 333 clearInterval(statusChecker); 157 334 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 } 160 343 }); 161 344 } -
guestapp/tags/2.2.7/guest-suite.php
r3374894 r3448885 4 4 * Plugin URI: https://www.guest-suite.com/ 5 5 * Description: Afficher la satisfaction de vos clients sur votre site avec le plugin Guest Suite pour Wordpress. 6 * Version: 2.2. 66 * Version: 2.2.7 7 7 * Requires at least: 4.6.1 8 8 * Requires PHP: 5.6 … … 167 167 'wording_importing' => $wording_import, 168 168 'count' => $count, 169 'debug' => get_option('guestsuite_debug', '0') === '1', 169 170 )); 170 171 wp_enqueue_script('gs-import-cron-js'); … … 387 388 } 388 389 390 /** 391 * Returns comprehensive import status for timeout detection and fallback completion. 392 */ 393 add_action('wp_ajax_guestsuite_get_import_status', 'guestsuite_get_import_status'); 394 function 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 389 423 390 424 /** -
guestapp/tags/2.2.7/includes/admin/functions.php
r3369496 r3448885 339 339 case 200: // OK 340 340 //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'); 342 353 guestsuite_remove_all_reviews(); 343 354 update_option('guestsuite_import_state', 'import'); … … 349 360 //Batch 350 361 $batch_size = GUESTSUITE_BATCH_SIZE_IMPORT_REVIEWS; 351 //error_log("BATCH SIZE: " . $batch_size);352 362 $reviews = $users["reviews"]; 363 $total_reviews = count($reviews); 364 guestsuite_gslog('Import', 'Starting import of ' . $total_reviews . ' reviews (batch size: ' . $batch_size . ')'); 353 365 $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; 355 370 foreach ($batches as $batch) { 371 $batch_number++; 372 guestsuite_gslog('Import', 'Processing batch ' . $batch_number . '/' . $total_batches); 356 373 //Use SQL transaction to optimisation 357 374 $wpdb->query('START TRANSACTION'); … … 380 397 ); 381 398 //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 } 383 404 if ($post_id) { 384 405 //Update other fields gs_responses + gs_reviewUuid … … 386 407 } else { 387 408 //If error, rollback 409 guestsuite_gslog('Import ERROR', 'wp_insert_post returned 0'); 388 410 throw new Exception("Échec de l'insertion du post."); 389 411 } … … 391 413 } 392 414 $wpdb->query('COMMIT'); 415 guestsuite_gslog('Import', 'Batch ' . $batch_number . ' committed (' . $nouveaux_avis . ' reviews imported so far)'); 393 416 } 394 417 418 guestsuite_gslog('Import', 'All batches processed successfully'); 395 419 if ($nouveaux_avis > 0) { 396 420 $message = $nouveaux_avis . ' ' . __('avis récupérés', 'guestapp'); 397 421 } 398 422 delete_option('guestsuite_import_state'); 423 delete_option('guestsuite_import_initial_count'); 424 guestsuite_gslog('Import', 'Returning success message: ' . $message); 399 425 return $message; 400 426 break; … … 428 454 // Rollback transaction if error 429 455 $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()); 431 458 return __('Erreur lors de l\'importation des avis. Consultez les logs pour plus d\'informations.', 'guestapp'); 432 459 } -
guestapp/tags/2.2.7/includes/admin/import_manual.php
r3364049 r3448885 33 33 guestsuite_gslog("Import " . $mode, 'Before'); 34 34 update_option('import_in_progress', true); 35 update_option('import_started_at', time()); 35 36 if ($mode == "cron") 36 37 $message = "0 avis récupéré via l'import automatique"; … … 43 44 //Force enable CRON if previous import is OK 44 45 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 45 59 guestsuite_force_cron_change_status("1"); 46 60 } … … 91 105 update_option('import_in_progress', false); 92 106 update_option('import_completed', true); 107 delete_option('import_started_at'); 93 108 } 94 109 } -
guestapp/tags/2.2.7/includes/admin/logs.php
r3202888 r3448885 23 23 function guestsuite_gslog($action, $message) 24 24 { 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) 25 34 $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); 31 36 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)) { 35 38 return; 36 39 } 37 40 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)) { 40 42 return; 41 43 } 42 44 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); 63 47 } 64 48 … … 80 64 function guestsuite_display_logs() 81 65 { 82 if (!function_exists('WP_Filesystem')) {83 require_once(ABSPATH . 'wp-admin/includes/file.php');84 }85 global $wp_filesystem;86 WP_Filesystem();87 66 $log_file = GUESTSUITE_LOG_FILE; 88 if (! $wp_filesystem->exists($log_file)) {67 if (!file_exists($log_file)) { 89 68 return "Le fichier de log n'existe pas."; 90 69 } 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); 92 72 if ($log_content === false) { 93 73 return "Impossible de lire le fichier de log."; -
guestapp/trunk/README.txt
r3374894 r3448885 2 2 Tags: avis clients, e-réputation, guest suite 3 3 Requires at least: 4.6.1 4 Tested up to: 6. 8.04 Tested up to: 6.9 5 5 Requires PHP: 5.6 6 Stable tag: 2.2. 66 Stable tag: 2.2.7 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 60 60 61 61 == Changelog == 62 = 2.2.7 = 63 * Améliore la fiabilité de la popup d'import 62 64 = 2.2.6 = 63 65 * Corrige les affichages d'avis pour les nouveaux établissements -
guestapp/trunk/assets/js/gs-cron.js
r3198976 r3448885 1 1 jQuery(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'); 2 18 var currentUrl = window.location.href; 3 19 var isVisible = jQuery('#setting-error-settings_updated').is(':visible'); 20 gsLog('Notice visible:', isVisible); 21 gsLog('Current URL:', currentUrl); 4 22 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 6 29 7 30 // Get guestsuite_import_state option via AJAX 8 31 function getImportState() { 32 gsLog('getImportState() called'); 9 33 return jQuery.ajax({ 10 34 url: gs_cron_vars.ajax_url, … … 15 39 }, 16 40 success: function(response) { 41 gsLog('getImportState response:', response); 17 42 if (response.success) { 18 43 return response.data; 19 44 } 20 } 21 });22 }23 24 // Update modal text when gs-cron is running25 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({ 30 55 url: gs_cron_vars.ajax_url, 31 56 type: 'POST', 32 57 data: { 33 action: 'guestsuite_ count_post_count',58 action: 'guestsuite_get_import_status', 34 59 _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; 45 94 } 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); 69 226 }); 70 227 } … … 72 229 //If Notice is displayed and current URL is plugin settings 73 230 if (isVisible && currentUrl.includes('options-general.php?page=gs_settings')) { 231 gsLog('Conditions met, starting import monitoring'); 232 popupStartTime = Date.now(); 233 74 234 //2sec for cron status 75 varstatusChecker = setInterval(function() {235 statusChecker = setInterval(function() { 76 236 checkGSCronStatus(); 77 237 }, 2000); 78 238 //1sec for modal text 79 varstatusChecker2 = setInterval(function() {239 statusChecker2 = setInterval(function() { 80 240 updatePopupText(); 81 241 }, 1000); 242 //5sec for timeout and fallback detection 243 timeoutChecker = setInterval(function() { 244 checkTimeoutAndFallback(); 245 }, 5000); 246 82 247 //Display popup1 with loader 248 gsLog('Displaying initial popup'); 83 249 Swal.fire({ 84 250 title: gs_cron_vars.popup_title + "...", … … 95 261 iconColor: '#da3768', 96 262 didOpen: () => { 263 gsLog('Popup opened, showing loader'); 97 264 Swal.showLoading(); //show loader 98 265 } 99 266 }); 267 } else { 268 gsLog('Conditions not met - isVisible:', isVisible, '| URL match:', currentUrl.includes('options-general.php?page=gs_settings')); 100 269 } 101 270 102 271 // Get cron status and update success / error modal 103 272 function checkGSCronStatus() { 273 gsLog('checkGSCronStatus() called'); 104 274 var ajax_url = gs_cron_vars.ajax_url; 105 275 $.ajax({ … … 111 281 }, 112 282 success: function(response) { 283 gsLog('checkGSCronStatus response:', response); 113 284 if (response.success) { 285 gsLog('Import completed! Type:', response.data.type); 114 286 //OK: Display popup2 with success message 115 287 if (response.data.type === "success") { 288 gsLog('Displaying success popup'); 116 289 Swal.fire({ 117 290 title: response.data.title, … … 128 301 footer: '<small>'+response.data.cron_status + '<br/>' + response.data.next_cron + '</small>', 129 302 didOpen: () => { 303 gsLog('Success popup opened'); 130 304 Swal.hideLoading(); //hide loader 131 305 } … … 137 311 //KO: Display popup2 with error message 138 312 } else if (response.data.type === "error") { 313 gsLog('Displaying error popup'); 139 314 Swal.fire({ 140 315 title: response.data.title, 141 html: response.data.message, 316 html: response.data.message, 142 317 icon: response.data.type, 143 318 confirmButtonText: response.data.btn, … … 148 323 footer: '<small>'+response.data.cron_status+'</small>', 149 324 didOpen: () => { 325 gsLog('Error popup opened'); 150 326 Swal.hideLoading(); //hide loader 151 327 } … … 153 329 } 154 330 localStorage.removeItem("gs_import_state"); 331 gsLog('Stopping intervals'); 155 332 //Stop interval, because cron is finished 156 333 clearInterval(statusChecker); 157 334 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 } 160 343 }); 161 344 } -
guestapp/trunk/guest-suite.php
r3374894 r3448885 4 4 * Plugin URI: https://www.guest-suite.com/ 5 5 * Description: Afficher la satisfaction de vos clients sur votre site avec le plugin Guest Suite pour Wordpress. 6 * Version: 2.2. 66 * Version: 2.2.7 7 7 * Requires at least: 4.6.1 8 8 * Requires PHP: 5.6 … … 167 167 'wording_importing' => $wording_import, 168 168 'count' => $count, 169 'debug' => get_option('guestsuite_debug', '0') === '1', 169 170 )); 170 171 wp_enqueue_script('gs-import-cron-js'); … … 387 388 } 388 389 390 /** 391 * Returns comprehensive import status for timeout detection and fallback completion. 392 */ 393 add_action('wp_ajax_guestsuite_get_import_status', 'guestsuite_get_import_status'); 394 function 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 389 423 390 424 /** -
guestapp/trunk/includes/admin/functions.php
r3369496 r3448885 339 339 case 200: // OK 340 340 //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'); 342 353 guestsuite_remove_all_reviews(); 343 354 update_option('guestsuite_import_state', 'import'); … … 349 360 //Batch 350 361 $batch_size = GUESTSUITE_BATCH_SIZE_IMPORT_REVIEWS; 351 //error_log("BATCH SIZE: " . $batch_size);352 362 $reviews = $users["reviews"]; 363 $total_reviews = count($reviews); 364 guestsuite_gslog('Import', 'Starting import of ' . $total_reviews . ' reviews (batch size: ' . $batch_size . ')'); 353 365 $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; 355 370 foreach ($batches as $batch) { 371 $batch_number++; 372 guestsuite_gslog('Import', 'Processing batch ' . $batch_number . '/' . $total_batches); 356 373 //Use SQL transaction to optimisation 357 374 $wpdb->query('START TRANSACTION'); … … 380 397 ); 381 398 //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 } 383 404 if ($post_id) { 384 405 //Update other fields gs_responses + gs_reviewUuid … … 386 407 } else { 387 408 //If error, rollback 409 guestsuite_gslog('Import ERROR', 'wp_insert_post returned 0'); 388 410 throw new Exception("Échec de l'insertion du post."); 389 411 } … … 391 413 } 392 414 $wpdb->query('COMMIT'); 415 guestsuite_gslog('Import', 'Batch ' . $batch_number . ' committed (' . $nouveaux_avis . ' reviews imported so far)'); 393 416 } 394 417 418 guestsuite_gslog('Import', 'All batches processed successfully'); 395 419 if ($nouveaux_avis > 0) { 396 420 $message = $nouveaux_avis . ' ' . __('avis récupérés', 'guestapp'); 397 421 } 398 422 delete_option('guestsuite_import_state'); 423 delete_option('guestsuite_import_initial_count'); 424 guestsuite_gslog('Import', 'Returning success message: ' . $message); 399 425 return $message; 400 426 break; … … 428 454 // Rollback transaction if error 429 455 $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()); 431 458 return __('Erreur lors de l\'importation des avis. Consultez les logs pour plus d\'informations.', 'guestapp'); 432 459 } -
guestapp/trunk/includes/admin/import_manual.php
r3364049 r3448885 33 33 guestsuite_gslog("Import " . $mode, 'Before'); 34 34 update_option('import_in_progress', true); 35 update_option('import_started_at', time()); 35 36 if ($mode == "cron") 36 37 $message = "0 avis récupéré via l'import automatique"; … … 43 44 //Force enable CRON if previous import is OK 44 45 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 45 59 guestsuite_force_cron_change_status("1"); 46 60 } … … 91 105 update_option('import_in_progress', false); 92 106 update_option('import_completed', true); 107 delete_option('import_started_at'); 93 108 } 94 109 } -
guestapp/trunk/includes/admin/logs.php
r3202888 r3448885 23 23 function guestsuite_gslog($action, $message) 24 24 { 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) 25 34 $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); 31 36 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)) { 35 38 return; 36 39 } 37 40 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)) { 40 42 return; 41 43 } 42 44 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); 63 47 } 64 48 … … 80 64 function guestsuite_display_logs() 81 65 { 82 if (!function_exists('WP_Filesystem')) {83 require_once(ABSPATH . 'wp-admin/includes/file.php');84 }85 global $wp_filesystem;86 WP_Filesystem();87 66 $log_file = GUESTSUITE_LOG_FILE; 88 if (! $wp_filesystem->exists($log_file)) {67 if (!file_exists($log_file)) { 89 68 return "Le fichier de log n'existe pas."; 90 69 } 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); 92 72 if ($log_content === false) { 93 73 return "Impossible de lire le fichier de log.";
Note: See TracChangeset
for help on using the changeset viewer.