Malin 37cf714058 WebP Express CloudHost.es Fix v0.25.9-cloudhost
 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>
2025-09-23 10:22:32 +02:00

46 lines
1.2 KiB
PHP

<?php
namespace WebPExpress;
use \WebPExpress\Option;
/**
* Store state in db
* We are using update_option WITHOUT autoloading.
* So this class is not intended for storing stuff that is needed on every page load.
* For such things, use update_option / get_option directly
*/
class State
{
public static function getStateObj() {
// TODO: cache
$json = Option::getOption('webp-express-state', '[]');
return json_decode($json, true);
}
/**
* Return state by key. Returns supplied default if key doesn't exist, or state object is corrupt
*/
public static function getState($key, $default = null) {
$obj = self::getStateObj();
if ($obj != false) {
if (isset($obj[$key])) {
return $obj[$key];
}
}
return $default;
}
public static function setState($key, $value) {
$currentStateObj = self::getStateObj();
$currentStateObj[$key] = $value;
$json = json_encode($currentStateObj, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
// Store in db. No autoloading.
Option::updateOption('webp-express-state', $json, false);
}
}