62 lines
No EOL
1.5 KiB
PHP
62 lines
No EOL
1.5 KiB
PHP
<?php
|
|
// Reset script for debugging
|
|
// This will clear the log file and any local storage
|
|
|
|
include 'logger.php';
|
|
|
|
// Clear log file
|
|
file_put_contents('app.log', "Log reset at " . date('Y-m-d H:i:s') . PHP_EOL);
|
|
chmod('app.log', 0666); // Make writable by web server
|
|
|
|
// Log the reset
|
|
logMessage("Application reset started");
|
|
|
|
// Clear local storage
|
|
$sourcePath = 'local_storage/source-documents';
|
|
$targetPath = 'local_storage/translated-documents';
|
|
|
|
function clearDirectory($dir) {
|
|
if (!is_dir($dir)) {
|
|
return;
|
|
}
|
|
|
|
$files = array_diff(scandir($dir), ['.', '..']);
|
|
|
|
foreach ($files as $file) {
|
|
$path = $dir . '/' . $file;
|
|
if (is_dir($path)) {
|
|
clearDirectory($path);
|
|
rmdir($path);
|
|
} else {
|
|
unlink($path);
|
|
logMessage("Removed file: $path");
|
|
}
|
|
}
|
|
|
|
logMessage("Cleared directory: $dir");
|
|
}
|
|
|
|
// Ensure local storage directories exist
|
|
if (!is_dir('local_storage')) {
|
|
mkdir('local_storage', 0777, true);
|
|
logMessage("Created local_storage directory");
|
|
}
|
|
|
|
if (!is_dir($sourcePath)) {
|
|
mkdir($sourcePath, 0777, true);
|
|
logMessage("Created source documents directory");
|
|
} else {
|
|
clearDirectory($sourcePath);
|
|
}
|
|
|
|
if (!is_dir($targetPath)) {
|
|
mkdir($targetPath, 0777, true);
|
|
logMessage("Created translated documents directory");
|
|
} else {
|
|
clearDirectory($targetPath);
|
|
}
|
|
|
|
logMessage("Application reset completed");
|
|
|
|
echo "Application reset complete. Log file and local storage have been cleared.";
|
|
?>
|