Files
crm.clientright.ru/crm_extensions/file_storage/find_broken_files_fast.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

148 lines
6.0 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
/**
* Fast search for broken files - optimized version
*/
$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 "=== Быстрый поиск битых файлов ===\n\n";
// 1. Считаем общее количество проблемных файлов
echo "1. Подсчет проблемных файлов...\n";
$count_queries = [
'truncated' => "SELECT COUNT(*) as count FROM vtiger_notes WHERE filelocationtype = 'E' AND filename LIKE '%s3.twcstorage.ru%' AND filename LIKE '%D0%B'",
'realfile' => "SELECT COUNT(*) as count FROM vtiger_notes WHERE filelocationtype = 'E' AND filename LIKE '%s3.twcstorage.ru%' AND filename LIKE '%#realfile%'",
'russian' => "SELECT COUNT(*) as count FROM vtiger_notes WHERE filelocationtype = 'E' AND filename LIKE '%s3.twcstorage.ru%' AND filename REGEXP '[А-Яа-я]'"
];
$counts = [];
foreach ($count_queries as $type => $query) {
$result = $mysqli->query($query);
if ($result) {
$row = $result->fetch_assoc();
$counts[$type] = $row['count'];
}
}
echo "Файлов с обрезанными ссылками: " . ($counts['truncated'] ?? 0) . "\n";
echo "Файлов с #realfile: " . ($counts['realfile'] ?? 0) . "\n";
echo "Файлов с русскими символами: " . ($counts['russian'] ?? 0) . "\n";
// 2. Получаем примеры каждого типа проблем
echo "\n2. Примеры проблемных файлов...\n";
// Обрезанные ссылки
if ($counts['truncated'] > 0) {
echo "\n--- Обрезанные ссылки ---\n";
$query = "SELECT notesid, title, LEFT(filename, 100) as filename_short, s3_key
FROM vtiger_notes
WHERE filelocationtype = 'E'
AND filename LIKE '%s3.twcstorage.ru%'
AND filename LIKE '%D0%B'
ORDER BY notesid DESC
LIMIT 5";
$result = $mysqli->query($query);
if ($result) {
while ($row = $result->fetch_assoc()) {
echo "ID: {$row['notesid']} - {$row['title']}\n";
echo "URL: {$row['filename_short']}...\n";
echo "S3 Key: " . ($row['s3_key'] ?: 'NULL') . "\n---\n";
}
}
}
// Файлы с #realfile
if ($counts['realfile'] > 0) {
echo "\n--- Файлы с #realfile ---\n";
$query = "SELECT notesid, title, LEFT(filename, 100) as filename_short, s3_key
FROM vtiger_notes
WHERE filelocationtype = 'E'
AND filename LIKE '%s3.twcstorage.ru%'
AND filename LIKE '%#realfile%'
ORDER BY notesid DESC
LIMIT 5";
$result = $mysqli->query($query);
if ($result) {
while ($row = $result->fetch_assoc()) {
echo "ID: {$row['notesid']} - {$row['title']}\n";
echo "URL: {$row['filename_short']}...\n";
echo "S3 Key: " . ($row['s3_key'] ?: 'NULL') . "\n---\n";
}
}
}
// Файлы с русскими символами
if ($counts['russian'] > 0) {
echo "\n--- Файлы с русскими символами ---\n";
$query = "SELECT notesid, title, LEFT(filename, 100) as filename_short, s3_key
FROM vtiger_notes
WHERE filelocationtype = 'E'
AND filename LIKE '%s3.twcstorage.ru%'
AND filename REGEXP '[А-Яа-я]'
ORDER BY notesid DESC
LIMIT 5";
$result = $mysqli->query($query);
if ($result) {
while ($row = $result->fetch_assoc()) {
echo "ID: {$row['notesid']} - {$row['title']}\n";
echo "URL: {$row['filename_short']}...\n";
echo "S3 Key: " . ($row['s3_key'] ?: 'NULL') . "\n---\n";
}
}
}
// 3. Проверяем доступность нескольких файлов каждого типа
echo "\n3. Проверка доступности (тест 10 файлов каждого типа)...\n";
$test_queries = [
'realfile' => "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 LIMIT 10",
'russian' => "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 LIMIT 10"
];
$broken_count = 0;
$total_tested = 0;
foreach ($test_queries as $type => $query) {
echo "\nТестирование типа: $type\n";
$result = $mysqli->query($query);
if ($result) {
while ($row = $result->fetch_assoc()) {
$total_tested++;
$headers = @get_headers($row['filename'], 1);
if (!$headers || strpos($headers[0], '200') === false) {
$broken_count++;
echo "❌ ID: {$row['notesid']} - {$row['title']}\n";
} else {
echo "✅ ID: {$row['notesid']} - {$row['title']}\n";
}
}
}
}
echo "\n=== ИТОГОВАЯ СТАТИСТИКА ===\n";
echo "Всего файлов с #realfile: " . ($counts['realfile'] ?? 0) . "\n";
echo "Всего файлов с русскими символами: " . ($counts['russian'] ?? 0) . "\n";
echo "Протестировано файлов: $total_tested\n";
echo "Битых файлов из тестовых: $broken_count\n";
if ($broken_count > 0) {
$estimated_broken = round(($broken_count / $total_tested) * ($counts['realfile'] + $counts['russian']));
echo "Примерное количество битых файлов в системе: $estimated_broken\n";
}
$mysqli->close();
echo "\n=== Быстрый поиск завершен ===\n";
?>