- 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.
135 lines
6.0 KiB
PHP
135 lines
6.0 KiB
PHP
<?php
|
||
/**
|
||
* Fix PDFmaker files with Russian characters in S3 keys
|
||
*/
|
||
|
||
$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 "=== Исправление файлов PDFmaker с русскими символами ===\n\n";
|
||
|
||
// Находим файлы с русскими символами в S3 ключах
|
||
$russian_query = "SELECT notesid, title, filename, filesize, s3_key, s3_bucket
|
||
FROM vtiger_notes
|
||
WHERE filelocationtype = 'E'
|
||
AND notesid >= 394400
|
||
AND (filename REGEXP '[А-Яа-я]')
|
||
AND filename NOT LIKE '%#realfile%'
|
||
ORDER BY notesid DESC";
|
||
|
||
$russian_result = $mysqli->query($russian_query);
|
||
$broken_files = [];
|
||
|
||
if ($russian_result && $russian_result->num_rows > 0) {
|
||
echo "Найдено файлов с русскими символами: " . $russian_result->num_rows . "\n\n";
|
||
|
||
while ($row = $russian_result->fetch_assoc()) {
|
||
echo "Проверка файла ID: " . $row['notesid'] . "\n";
|
||
echo "Название: " . $row['title'] . "\n";
|
||
echo "Текущий URL: " . substr($row['filename'], 0, 80) . "...\n";
|
||
|
||
// Проверяем доступность текущего URL
|
||
$headers = @get_headers($row['filename'], 1);
|
||
if (!$headers || strpos($headers[0], '200') === false) {
|
||
echo "❌ Файл недоступен - добавляем к исправлению\n";
|
||
$broken_files[] = $row;
|
||
} else {
|
||
echo "✅ Файл доступен - пропускаем\n";
|
||
}
|
||
echo "---\n";
|
||
}
|
||
|
||
if (!empty($broken_files)) {
|
||
echo "\n=== ИСПРАВЛЕНИЕ БИТЫХ ФАЙЛОВ ===\n";
|
||
echo "Найдено файлов для исправления: " . count($broken_files) . "\n\n";
|
||
|
||
$fixed_count = 0;
|
||
$error_count = 0;
|
||
|
||
foreach ($broken_files as $file) {
|
||
echo "Исправление файла ID: " . $file['notesid'] . "\n";
|
||
echo "Название: " . $file['title'] . "\n";
|
||
|
||
$s3_key = $file['s3_key'];
|
||
$s3_bucket = $file['s3_bucket'];
|
||
$current_filename = $file['filename'];
|
||
|
||
// Создаем правильный URL с правильной кодировкой S3 ключа
|
||
$encoded_key = implode('/', array_map('rawurlencode', explode('/', $s3_key)));
|
||
$correct_url = "https://s3.twcstorage.ru/$s3_bucket/$encoded_key";
|
||
|
||
echo " Правильный URL: " . substr($correct_url, 0, 80) . "...\n";
|
||
|
||
// Проверяем доступность правильного URL
|
||
$headers = @get_headers($correct_url, 1);
|
||
if ($headers && strpos($headers[0], '200') !== false) {
|
||
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_pdfmaker_backup_' . $file['notesid'] . '_' . date('Ymd_His') . '.json';
|
||
$backup = [
|
||
'notesid' => $file['notesid'],
|
||
'title' => $file['title'],
|
||
'original_filename' => $current_filename,
|
||
'corrected_filename' => $correct_url,
|
||
's3_key' => $s3_key,
|
||
's3_bucket' => $s3_bucket,
|
||
'timestamp' => date('c'),
|
||
'reason' => 'Fixed S3 URL encoding for PDFmaker files with Russian characters'
|
||
];
|
||
file_put_contents($backup_file, json_encode($backup, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||
|
||
// Обновляем URL в базе данных
|
||
$update_query = "UPDATE vtiger_notes SET filename = ? WHERE notesid = ?";
|
||
$update_stmt = $mysqli->prepare($update_query);
|
||
$update_stmt->bind_param('si', $correct_url, $file['notesid']);
|
||
|
||
if ($update_stmt->execute()) {
|
||
echo " ✅ URL исправлен в базе данных\n";
|
||
$fixed_count++;
|
||
} else {
|
||
echo " ❌ Ошибка обновления БД: " . $update_stmt->error . "\n";
|
||
$error_count++;
|
||
}
|
||
$update_stmt->close();
|
||
|
||
} else {
|
||
echo " ❌ Файл недоступен даже с правильной кодировкой\n";
|
||
$error_count++;
|
||
}
|
||
echo "---\n";
|
||
}
|
||
|
||
echo "\n=== РЕЗУЛЬТАТ ===\n";
|
||
echo "✅ Исправлено файлов: $fixed_count\n";
|
||
echo "❌ Ошибок: $error_count\n";
|
||
echo "📊 Всего обработано: " . count($broken_files) . "\n";
|
||
|
||
if ($fixed_count > 0) {
|
||
echo "\n🎉 Файлы PDFmaker с русскими символами исправлены!\n";
|
||
echo "📁 Резервные копии сохранены в: crm_extensions/file_storage/backups/\n";
|
||
}
|
||
|
||
} else {
|
||
echo "\n🎉 Все файлы с русскими символами уже доступны!\n";
|
||
}
|
||
|
||
} else {
|
||
echo "Файлов с русскими символами не найдено.\n";
|
||
}
|
||
|
||
$mysqli->close();
|
||
echo "\n=== Исправление завершено ===\n";
|
||
?>
|
||
|