Files
crm.clientright.ru/extract_file_from_archive.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

155 lines
6.0 KiB
PHP

<?php
/**
* Извлечение файла 391075 из S3 архива
*/
require_once 'crm_extensions/shared/EnvLoader.php';
require_once 'crm_extensions/vendor/autoload.php';
use Aws\S3\S3Client;
// Загружаем переменные окружения
EnvLoader::load();
// S3 настройки
$s3Endpoint = EnvLoader::get('S3_ENDPOINT');
$s3Bucket = EnvLoader::get('S3_BUCKET');
$s3AccessKey = EnvLoader::get('S3_ACCESS_KEY');
$s3SecretKey = EnvLoader::get('S3_SECRET_KEY');
$s3Region = EnvLoader::get('S3_REGION');
echo "=== Извлечение файла 391075 из архива ===\n\n";
// Создаем S3 клиент
$s3Client = new S3Client([
'version' => 'latest',
'region' => $s3Region,
'endpoint' => $s3Endpoint,
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $s3AccessKey,
'secret' => $s3SecretKey,
],
'http' => [
'verify' => false,
]
]);
$archivePath = 'backups/storage_full_2025-09-26.tar.gz';
$targetFile = 'storage/2025/August/week5/722fb330f1bcbfa6dc3975013fbf9b4a.docx';
echo "Архив: {$archivePath}\n";
echo "Ищем файл: {$targetFile}\n\n";
// Создаем временную папку для работы
$tempDir = '/tmp/extract_' . uniqid();
mkdir($tempDir, 0755, true);
echo "Временная папка: {$tempDir}\n";
try {
// Скачиваем архив
$archiveFile = $tempDir . '/storage_full_2025-09-26.tar.gz';
echo "Скачиваем архив...\n";
$s3Client->getObject([
'Bucket' => $s3Bucket,
'Key' => $archivePath,
'SaveAs' => $archiveFile
]);
echo "✅ Архив скачан: {$archiveFile}\n";
echo "Размер архива: " . filesize($archiveFile) . " байт\n\n";
// Проверяем содержимое архива без распаковки
echo "Проверяем содержимое архива...\n";
$listCommand = "tar -tzf " . escapeshellarg($archiveFile) . " | grep " . escapeshellarg($targetFile);
$listOutput = shell_exec($listCommand);
if (!empty($listOutput)) {
echo "✅ Файл найден в архиве:\n";
echo trim($listOutput) . "\n\n";
// Извлекаем только нужный файл
echo "Извлекаем файл...\n";
$extractCommand = "cd " . escapeshellarg($tempDir) . " && tar -xzf " . escapeshellarg($archiveFile) . " " . escapeshellarg($targetFile);
$extractResult = shell_exec($extractCommand . " 2>&1");
$extractedFile = $tempDir . '/' . $targetFile;
if (file_exists($extractedFile)) {
echo "✅ Файл извлечен: {$extractedFile}\n";
echo "Размер: " . filesize($extractedFile) . " байт\n\n";
// Восстанавливаем в локальное хранилище
echo "Восстанавливаем в локальное хранилище...\n";
$restorePath = "/var/www/fastuser/data/www/crm.clientright.ru/storage/2025/August/week5/";
if (!is_dir($restorePath)) {
mkdir($restorePath, 0755, true);
echo "Создана папка: {$restorePath}\n";
}
$finalPath = $restorePath . '722fb330f1bcbfa6dc3975013fbf9b4a.docx';
copy($extractedFile, $finalPath);
echo "✅ Файл восстановлен: {$finalPath}\n";
echo "Размер: " . filesize($finalPath) . " байт\n\n";
// Обновляем БД
echo "Обновляем базу данных...\n";
include_once 'config.inc.php';
$mysqli = new mysqli($dbconfig['db_server'], $dbconfig['db_username'], $dbconfig['db_password'], $dbconfig['db_name']);
if ($mysqli->connect_error) {
echo "❌ Ошибка подключения к БД: " . $mysqli->connect_error . "\n";
} else {
$stmt = $mysqli->prepare("UPDATE vtiger_attachments SET path = ? WHERE attachmentsid = 391075");
$stmt->bind_param("s", $restorePath);
if ($stmt->execute()) {
echo "✅ База данных обновлена\n";
} else {
echo "❌ Ошибка обновления БД: " . $stmt->error . "\n";
}
$stmt->close();
$mysqli->close();
}
echo "\n🎉 ФАЙЛ 391075 УСПЕШНО ВОССТАНОВЛЕН ИЗ АРХИВА!\n";
echo "Теперь файл доступен по ссылке: https://crm.clientright.ru/index.php?module=ModComments&action=DownloadFile&record=391074&fileid=391075\n";
} else {
echo "❌ Файл не извлечен. Вывод команды:\n";
echo $extractResult . "\n";
}
} else {
echo "❌ Файл не найден в архиве\n";
echo "Проверим какие файлы августа есть в архиве...\n";
$augustListCommand = "tar -tzf " . escapeshellarg($archiveFile) . " | grep '2025/August' | head -10";
$augustListOutput = shell_exec($augustListCommand);
if (!empty($augustListOutput)) {
echo "Файлы августа 2025 в архиве:\n";
echo $augustListOutput . "\n";
} else {
echo "Файлы августа 2025 не найдены в архиве\n";
}
}
} catch (Exception $e) {
echo "❌ Ошибка: " . $e->getMessage() . "\n";
} finally {
// Очищаем временные файлы
echo "\nОчищаем временные файлы...\n";
if (is_dir($tempDir)) {
shell_exec("rm -rf " . escapeshellarg($tempDir));
echo "✅ Временные файлы удалены\n";
}
}
echo "\n=== Готово ===\n";
?>