diff --git a/admin_fix.php b/admin_fix.php new file mode 100644 index 00000000..b4b758ec --- /dev/null +++ b/admin_fix.php @@ -0,0 +1,70 @@ +isFile()) { + $file_path = $file->getPathname(); + $file_name = $file->getFilename(); + // Process the file + processFile($file_path, $file_name, $mysqli); + } + } +} + +function processFile($file_path, $file_name, $mysqli) { + // Get the file size + $file_size = filesize($file_path); + // Get the MIME type + $file_mime_type = mime_content_type($file_path); + + // Prepare a statement to check if the file exists in the database + $stmt_select = mysqli_prepare($mysqli, "SELECT file_id FROM files WHERE file_reference_name = ?"); + mysqli_stmt_bind_param($stmt_select, 's', $file_name); + mysqli_stmt_execute($stmt_select); + mysqli_stmt_store_result($stmt_select); + + if (mysqli_stmt_num_rows($stmt_select) > 0) { + // File exists in the database, proceed to update + $stmt_update = mysqli_prepare($mysqli, "UPDATE files SET file_mime_type = ?, file_size = ? WHERE file_reference_name = ?"); + mysqli_stmt_bind_param($stmt_update, 'sis', $file_mime_type, $file_size, $file_name); + + if (mysqli_stmt_execute($stmt_update)) { + echo "Updated: $file_name\n"; + } else { + echo "Error updating $file_name: " . mysqli_stmt_error($stmt_update) . "\n"; + } + mysqli_stmt_close($stmt_update); + } else { + echo "No database entry found for: $file_name\n"; + } + mysqli_stmt_close($stmt_select); +} + +// Define the uploads directory (modify the path if necessary) +$uploads_dir = __DIR__ . '/uploads'; + +// Start scanning from the uploads directory +scanDirectory($uploads_dir, $mysqli); + +// Close the database connection +mysqli_close($mysqli); + +$_SESSION['alert_message'] = "Files Fixed"; + +header("Location: " . $_SERVER["HTTP_REFERER"]); diff --git a/database_updates.php b/database_updates.php index d504e8d9..6a219324 100644 --- a/database_updates.php +++ b/database_updates.php @@ -2364,10 +2364,68 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.3'"); } - // if (CURRENT_DATABASE_VERSION == '1.6.3') { - // // Insert queries here required to update to DB version 1.6.4 + if (CURRENT_DATABASE_VERSION == '1.6.3') { + + // Find Files and update the Mime Type and File Size + + function scanDirectory($dir, $mysqli) { + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::SELF_FIRST + ); + + foreach ($iterator as $file) { + if ($file->isFile()) { + $file_path = $file->getPathname(); + $file_name = $file->getFilename(); + // Process the file + processFile($file_path, $file_name, $mysqli); + } + } + } + + function processFile($file_path, $file_name, $mysqli) { + // Get the file size + $file_size = filesize($file_path); + // Get the MIME type + $file_mime_type = mime_content_type($file_path); + + // Prepare a statement to check if the file exists in the database + $stmt_select = mysqli_prepare($mysqli, "SELECT file_id FROM files WHERE file_reference_name = ?"); + mysqli_stmt_bind_param($stmt_select, 's', $file_name); + mysqli_stmt_execute($stmt_select); + mysqli_stmt_store_result($stmt_select); + + if (mysqli_stmt_num_rows($stmt_select) > 0) { + // File exists in the database, proceed to update + $stmt_update = mysqli_prepare($mysqli, "UPDATE files SET file_mime_type = ?, file_size = ? WHERE file_reference_name = ?"); + mysqli_stmt_bind_param($stmt_update, 'sis', $file_mime_type, $file_size, $file_name); + + if (mysqli_stmt_execute($stmt_update)) { + echo "Updated: $file_name\n"; + } else { + echo "Error updating $file_name: " . mysqli_stmt_error($stmt_update) . "\n"; + } + mysqli_stmt_close($stmt_update); + } else { + echo "No database entry found for: $file_name\n"; + } + mysqli_stmt_close($stmt_select); + } + + // Define the uploads directory (modify the path if necessary) + $uploads_dir = __DIR__ . '/uploads'; + + // Start scanning from the uploads directory + scanDirectory($uploads_dir, $mysqli); + + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.4'"); + } + + // if (CURRENT_DATABASE_VERSION == '1.6.4') { + // // Insert queries here required to update to DB version 1.6.5 // // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.4'"); + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.6.5'"); // } } else { diff --git a/database_version.php b/database_version.php index 038ae48d..999b9a9c 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "1.6.3"); +DEFINE("LATEST_DATABASE_VERSION", "1.6.4");