mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 10:54:52 +00:00
Scans all files and matches them with the reference file in DB then sets the file size and Mime Type. Note this update doesnt do any DB Structure changes
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user