✅ Fixed bulk conversion getting stuck on missing files ✅ Added robust error handling and timeout protection ✅ Improved JavaScript response parsing ✅ Added file existence validation ✅ Fixed missing PHP class imports ✅ Added comprehensive try-catch error recovery 🔧 Key fixes: - File existence checks before conversion attempts - 30-second timeout protection per file - Graceful handling of 500 errors and JSON parsing issues - Automatic continuation to next file on failures - Cache busting for JavaScript updates 🎯 Result: Bulk conversion now completes successfully even with missing files 🚀 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
|
|
function openDeleteConvertedFilesPopup() {
|
|
var html = '';
|
|
html += '<p>To delete all converted files, click this button:<br>';
|
|
html += '<button onclick="purgeCache(false)" class="button button-secondary" type="button">Delete all converted files</button>';
|
|
html += '</p>';
|
|
html += '<p>Or perhaps, you only want to delete the converted <i>PNGs</i>? Then this button is for you:<br>';
|
|
html += '<button onclick="purgeCache(true)" class="button button-secondary" type="button">Delete converted PNGs</button>';
|
|
html += '</p>';
|
|
|
|
document.getElementById('purgecachecontent').innerHTML = html;
|
|
tb_show('Purge cache', '#TB_inline?inlineId=purgecachepopup');
|
|
// purgeCache();
|
|
}
|
|
|
|
function purgeCache(onlyPng) {
|
|
var data = {
|
|
'action': 'webpexpress_purge_cache',
|
|
'nonce' : window.webpExpress['ajax-nonces']['purge-cache'],
|
|
'only-png': onlyPng
|
|
};
|
|
jQuery.post(ajaxurl, data, function(response) {
|
|
if ((typeof response == 'object') && (response['success'] == false)) {
|
|
if (response['data'] && ((typeof response['data']) == 'string')) {
|
|
alert(response['data']);
|
|
} else {
|
|
alert('Something failed');
|
|
}
|
|
return;
|
|
}
|
|
|
|
var result = JSON.parse(response);
|
|
//console.log(result);
|
|
|
|
if (result['fail-count'] == 0) {
|
|
if (result['delete-count'] == 0) {
|
|
alert('No webp files were found, so none was deleted.');
|
|
} else {
|
|
alert('Successfully deleted ' + result['delete-count'] + ' webp files');
|
|
}
|
|
} else {
|
|
if (result['delete-count'] == 0) {
|
|
alert('Failed deleting ' + result['fail-count'] + ' webp files. None was deleted, in fact.');
|
|
} else {
|
|
alert('Deleted ' + result['delete-count'] + ' webp files. However, failed deleting ' + result['fail-count'] + ' webp files.');
|
|
}
|
|
}
|
|
|
|
});
|
|
}
|