✅ 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>
41 lines
1.0 KiB
PHP
41 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace FileUtil;
|
|
|
|
use ExecWithFallback\ExecWithFallback;
|
|
|
|
/**
|
|
* A fileExist implementation using exec()
|
|
*
|
|
* @package FileUtil
|
|
* @author Bjørn Rosell <it@rosell.dk>
|
|
*/
|
|
class FileExistsUsingExec
|
|
{
|
|
|
|
/**
|
|
* A fileExist based on an exec call.
|
|
*
|
|
* @throws \Exception If exec cannot be called
|
|
* @return boolean|null True if file exists. False if it doesn't.
|
|
*/
|
|
public static function fileExists($path)
|
|
{
|
|
if (!ExecWithFallback::anyAvailable()) {
|
|
throw new \Exception(
|
|
'cannot determine if file exists using exec() or similar - the function is unavailable'
|
|
);
|
|
}
|
|
|
|
// Lets try to find out by executing "ls path/to/cwebp"
|
|
ExecWithFallback::exec('ls ' . $path, $output, $returnCode);
|
|
if (($returnCode == 0) && (isset($output[0]))) {
|
|
return true;
|
|
}
|
|
|
|
// We assume that "ls" command is general available!
|
|
// As that failed, we can conclude the file does not exist.
|
|
return false;
|
|
}
|
|
}
|