Files
crm.clientright.ru/crm_extensions/file_storage/find_real_files.php

92 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Поиск реальных файлов в storage, которые не мигрированы в S3
*/
require_once '/var/www/fastuser/data/www/crm.clientright.ru/config.inc.php';
$mysqli = new mysqli($dbconfig['db_server'], $dbconfig['db_username'], $dbconfig['db_password'], $dbconfig['db_name']);
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
$mysqli->set_charset("utf8");
$storageDir = '/var/www/fastuser/data/www/crm.clientright.ru/storage/';
// Получаем все записи из базы данных
$result = $mysqli->query("SELECT notesid, filename FROM vtiger_notes WHERE filelocationtype = 'I' AND (s3_key IS NULL OR s3_key = '') ORDER BY notesid DESC LIMIT 50");
$foundFiles = [];
$notFoundFiles = [];
echo "Поиск реальных файлов в storage...\n";
echo "=====================================\n";
while ($row = $result->fetch_assoc()) {
$notesid = $row['notesid'];
$filename = $row['filename'];
// Список возможных путей для поиска
$searchPaths = [
$storageDir . $filename,
$storageDir . $notesid . '_' . $filename,
];
// Добавляем поиск по годам
for ($year = 2023; $year <= 2025; $year++) {
$searchPaths[] = $storageDir . $year . '/' . $filename;
$searchPaths[] = $storageDir . $year . '/' . $notesid . '_' . $filename;
// Поиск по месяцам
$months = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
foreach ($months as $month) {
$searchPaths[] = $storageDir . $year . '/' . $month . '/' . $filename;
$searchPaths[] = $storageDir . $year . '/' . $month . '/' . $notesid . '_' . $filename;
// Поиск по неделям
for ($week = 1; $week <= 5; $week++) {
$searchPaths[] = $storageDir . $year . '/' . $month . '/week' . $week . '/' . $filename;
$searchPaths[] = $storageDir . $year . '/' . $month . '/week' . $week . '/' . $notesid . '_' . $filename;
}
}
}
// Ищем файл
$found = false;
foreach ($searchPaths as $path) {
if (file_exists($path) && is_readable($path)) {
$foundFiles[] = [
'notesid' => $notesid,
'filename' => $filename,
'path' => $path,
'size' => filesize($path)
];
echo "✅ ID: $notesid, File: $filename, Path: $path, Size: " . filesize($path) . " bytes\n";
$found = true;
break;
}
}
if (!$found) {
$notFoundFiles[] = [
'notesid' => $notesid,
'filename' => $filename
];
echo "❌ ID: $notesid, File: $filename - NOT FOUND\n";
}
}
echo "\n=====================================\n";
echo "ИТОГИ:\n";
echo "Найдено файлов: " . count($foundFiles) . "\n";
echo "Не найдено файлов: " . count($notFoundFiles) . "\n";
if (count($foundFiles) > 0) {
echo "\nФайлы для миграции:\n";
foreach ($foundFiles as $file) {
echo "ID: {$file['notesid']}, File: {$file['filename']}, Size: {$file['size']} bytes\n";
}
}
$mysqli->close();
?>