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

144 lines
5.9 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
/**
* Fix file 394503 - PDFmaker issue
*/
$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 "=== Исправление файла 394503 ===\n\n";
// Получаем данные файла
$query = "SELECT notesid, title, filename, filetype, filesize, s3_key, s3_bucket, s3_etag, nc_path
FROM vtiger_notes
WHERE notesid = 394503";
$result = $mysqli->query($query);
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
echo "Текущее состояние файла:\n";
echo "ID: " . $row['notesid'] . "\n";
echo "Название: " . $row['title'] . "\n";
echo "URL: " . ($row['filename'] ?: 'ПУСТОЙ') . "\n";
echo "Размер: " . $row['filesize'] . " байт\n";
echo "S3 Key: " . ($row['s3_key'] ?: 'NULL') . "\n";
echo "S3 Bucket: " . ($row['s3_bucket'] ?: 'NULL') . "\n\n";
// Проверяем, есть ли локальная копия файла
echo "Поиск локальной копии файла...\n";
// Возможные пути для поиска файла
$possible_paths = [
$ROOT . 'storage/' . $row['notesid'] . '/',
$ROOT . 'cache/' . $row['notesid'] . '/',
$ROOT . 'uploads/' . $row['notesid'] . '/',
$ROOT . 'tmp/' . $row['notesid'] . '/',
];
$found_file = null;
foreach ($possible_paths as $path) {
if (is_dir($path)) {
$files = glob($path . '*');
if (!empty($files)) {
$found_file = $files[0];
echo "✅ Найден файл: " . $found_file . "\n";
break;
}
}
}
if (!$found_file) {
echo "❌ Локальная копия файла не найдена\n";
// Проверяем, может быть файл есть в S3, но неправильно записан в БД
echo "\nПроверка возможных S3 путей...\n";
// Генерируем возможные S3 пути на основе названия файла
$title_clean = preg_replace('/[^a-zA-Z0-9а-яА-Я\s]/u', '_', $row['title']);
$title_clean = preg_replace('/\s+/', '_', $title_clean);
$possible_s3_paths = [
"crm2/CRM_Active_Files/Documents/" . $row['notesid'] . "/" . $title_clean . ".pdf",
"crm2/CRM_Active_Files/Documents/" . $row['notesid'] . "/" . $row['notesid'] . "_" . $title_clean . ".pdf",
"crm2/CRM_Active_Files/Documents/" . $row['notesid'] . "/" . $title_clean . "_" . date('m-d-Y-H-i-s') . ".pdf",
"crm2/CRM_Active_Files/Documents/" . $row['notesid'] . "/doc_" . $row['notesid'] . "_" . substr(md5($row['title']), 0, 8) . ".pdf",
];
$s3_bucket = 'f9825c87-4e3558f6-f9b6-405c-ad3d-d1535c49b61c';
foreach ($possible_s3_paths as $s3_path) {
$test_url = "https://s3.twcstorage.ru/" . $s3_bucket . "/" . $s3_path;
echo "Проверка: " . $test_url . "\n";
$headers = @get_headers($test_url, 1);
if ($headers && strpos($headers[0], '200') !== false) {
echo "✅ Файл найден в S3!\n";
// Исправляем запись в БД
echo "Исправление записи в базе данных...\n";
// Создаем резервную копию
$backup_dir = $ROOT . 'crm_extensions/file_storage/backups/';
if (!is_dir($backup_dir)) mkdir($backup_dir, 0755, true);
$backup_file = $backup_dir . 'fix_394503_backup_' . date('Ymd_His') . '.json';
$backup = [
'notesid' => $row['notesid'],
'title' => $row['title'],
'original_data' => $row,
'found_s3_path' => $s3_path,
'found_url' => $test_url,
'timestamp' => date('c'),
'reason' => 'Fixed PDFmaker file 394503 - found correct S3 path'
];
file_put_contents($backup_file, json_encode($backup, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
// Обновляем запись в БД
$update_query = "UPDATE vtiger_notes SET
filename = ?,
s3_key = ?,
s3_bucket = ?,
filelocationtype = 'E'
WHERE notesid = ?";
$stmt = $mysqli->prepare($update_query);
$stmt->bind_param('sssi', $test_url, $s3_path, $s3_bucket, $row['notesid']);
if ($stmt->execute()) {
echo "✅ Запись в БД исправлена!\n";
echo "URL: " . $test_url . "\n";
echo "S3 Key: " . $s3_path . "\n";
echo "S3 Bucket: " . $s3_bucket . "\n";
} else {
echo "❌ Ошибка обновления БД: " . $stmt->error . "\n";
}
$stmt->close();
break;
} else {
echo "❌ Файл не найден\n";
}
}
} else {
echo "✅ Локальная копия найдена, можно загрузить в S3\n";
}
} else {
echo "❌ Файл 394503 не найден в базе данных\n";
}
$mysqli->close();
echo "\n=== Исправление завершено ===\n";
?>