Files
crm.clientright.ru/crm_extensions/file_storage/find_all_broken_files.php
Fedor ac7467f0b4 Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system
- Added comprehensive AI Assistant system (aiassist/ directory):
  * Vector search and embedding capabilities
  * Typebot proxy integration
  * Elastic search functionality
  * Message classification and chat history
  * MCP proxy for external integrations

- Implemented Court Status API (GetCourtStatus.php):
  * Real-time court document status checking
  * Integration with external court systems
  * Comprehensive error handling and logging

- Enhanced S3 integration:
  * Improved file backup system with metadata
  * Batch processing capabilities
  * Enhanced error logging and recovery
  * Copy operations with URL fixing

- Added Telegram contact creation API
- Improved error logging across all modules
- Enhanced callback system for AI responses
- Extensive backup file storage with timestamps
- Updated documentation and README files

- File storage improvements:
  * Thousands of backup files with proper metadata
  * Fix operations for broken file references
  * Project-specific backup and recovery systems
  * Comprehensive file integrity checking

Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
2025-10-16 11:17:21 +03:00

170 lines
7.5 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
/**
* Find all broken files in the entire CRM system
*/
$ROOT = '/var/www/fastuser/data/www/crm.clientright.ru/';
require_once $ROOT . 'config.inc.php';
// Database connection
$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");
echo "=== Поиск всех битых файлов в системе CRM ===\n\n";
// 1. Ищем файлы с обрезанными ссылками (заканчиваются на %D0%B)
echo "1. Поиск файлов с обрезанными ссылками...\n";
$truncated_query = "SELECT notesid, title, filename, s3_key, s3_bucket
FROM vtiger_notes
WHERE filelocationtype = 'E'
AND filename LIKE '%s3.twcstorage.ru%'
AND filename LIKE '%D0%B'
ORDER BY notesid DESC";
$truncated_result = $mysqli->query($truncated_query);
$truncated_files = [];
if ($truncated_result && $truncated_result->num_rows > 0) {
while ($row = $truncated_result->fetch_assoc()) {
$truncated_files[] = $row;
}
echo "Найдено файлов с обрезанными ссылками: " . count($truncated_files) . "\n";
} else {
echo "Файлов с обрезанными ссылками не найдено.\n";
}
// 2. Ищем файлы с #realfile в URL
echo "\n2. Поиск файлов с #realfile в URL...\n";
$realfile_query = "SELECT notesid, title, filename, s3_key, s3_bucket
FROM vtiger_notes
WHERE filelocationtype = 'E'
AND filename LIKE '%s3.twcstorage.ru%'
AND filename LIKE '%#realfile%'
ORDER BY notesid DESC";
$realfile_result = $mysqli->query($realfile_query);
$realfile_files = [];
if ($realfile_result && $realfile_result->num_rows > 0) {
while ($row = $realfile_result->fetch_assoc()) {
$realfile_files[] = $row;
}
echo "Найдено файлов с #realfile: " . count($realfile_files) . "\n";
} else {
echo "Файлов с #realfile не найдено.\n";
}
// 3. Ищем файлы с неправильной кодировкой URL
echo "\n3. Поиск файлов с неправильной кодировкой URL...\n";
$encoding_query = "SELECT notesid, title, filename, s3_key, s3_bucket
FROM vtiger_notes
WHERE filelocationtype = 'E'
AND filename LIKE '%s3.twcstorage.ru%'
AND filename NOT LIKE '%#realfile%'
AND filename NOT LIKE '%D0%B'
ORDER BY notesid DESC
LIMIT 50";
$encoding_result = $mysqli->query($encoding_query);
$encoding_files = [];
if ($encoding_result && $encoding_result->num_rows > 0) {
while ($row = $encoding_result->fetch_assoc()) {
// Проверяем доступность файла
$headers = @get_headers($row['filename'], 1);
if (!$headers || strpos($headers[0], '200') === false) {
$encoding_files[] = $row;
}
}
echo "Найдено файлов с неправильной кодировкой: " . count($encoding_files) . "\n";
} else {
echo "Файлов с неправильной кодировкой не найдено.\n";
}
// 4. Ищем файлы с русскими символами в URL без правильной кодировки
echo "\n4. Поиск файлов с русскими символами без кодировки...\n";
$russian_query = "SELECT notesid, title, filename, s3_key, s3_bucket
FROM vtiger_notes
WHERE filelocationtype = 'E'
AND filename LIKE '%s3.twcstorage.ru%'
AND (filename REGEXP '[А-Яа-я]')
ORDER BY notesid DESC";
$russian_result = $mysqli->query($russian_query);
$russian_files = [];
if ($russian_result && $russian_result->num_rows > 0) {
while ($row = $russian_result->fetch_assoc()) {
// Проверяем доступность файла
$headers = @get_headers($row['filename'], 1);
if (!$headers || strpos($headers[0], '200') === false) {
$russian_files[] = $row;
}
}
echo "Найдено файлов с русскими символами без кодировки: " . count($russian_files) . "\n";
} else {
echo "Файлов с русскими символами без кодировки не найдено.\n";
}
// 5. Собираем все проблемные файлы
$all_broken_files = array_merge($truncated_files, $realfile_files, $encoding_files, $russian_files);
// Убираем дубликаты по notesid
$unique_broken_files = [];
$seen_ids = [];
foreach ($all_broken_files as $file) {
if (!in_array($file['notesid'], $seen_ids)) {
$unique_broken_files[] = $file;
$seen_ids[] = $file['notesid'];
}
}
echo "\n=== ИТОГОВАЯ СТАТИСТИКА ===\n";
echo "Файлов с обрезанными ссылками: " . count($truncated_files) . "\n";
echo "Файлов с #realfile: " . count($realfile_files) . "\n";
echo "Файлов с неправильной кодировкой: " . count($encoding_files) . "\n";
echo "Файлов с русскими символами: " . count($russian_files) . "\n";
echo "Всего уникальных битых файлов: " . count($unique_broken_files) . "\n";
if (!empty($unique_broken_files)) {
echo "\n=== СПИСОК ВСЕХ БИТЫХ ФАЙЛОВ ===\n";
foreach ($unique_broken_files as $file) {
echo "ID: " . $file['notesid'] . " - " . $file['title'] . "\n";
echo "URL: " . substr($file['filename'], 0, 80) . "...\n";
echo "S3 Key: " . ($file['s3_key'] ?: 'NULL') . "\n";
// Определяем тип проблемы
if (strpos($file['filename'], '#realfile') !== false) {
echo "Проблема: #realfile в URL\n";
} elseif (strpos($file['filename'], '%D0%B') !== false) {
echo "Проблема: Обрезанная ссылка\n";
} elseif (preg_match('/[А-Яа-я]/', $file['filename'])) {
echo "Проблема: Русские символы без кодировки\n";
} else {
echo "Проблема: Неправильная кодировка URL\n";
}
echo "---\n";
}
// Сохраняем список в файл для дальнейшего исправления
$report_file = $ROOT . 'crm_extensions/file_storage/broken_files_report.json';
$report_data = [
'timestamp' => date('c'),
'total_broken_files' => count($unique_broken_files),
'truncated_files' => count($truncated_files),
'realfile_files' => count($realfile_files),
'encoding_files' => count($encoding_files),
'russian_files' => count($russian_files),
'broken_files' => $unique_broken_files
];
file_put_contents($report_file, json_encode($report_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
echo "\n📄 Отчет сохранен в: crm_extensions/file_storage/broken_files_report.json\n";
} else {
echo "\n🎉 Битых файлов не найдено! Все файлы работают корректно.\n";
}
$mysqli->close();
echo "\n=== Поиск завершен ===\n";
?>