Files
crm.clientright.ru/crm_extensions/file_storage/scan_s3.php
Fedor 9245768987 🚀 CRM Files Migration & Real-time Features
 Features:
- Migrated ALL files to new S3 structure (Projects, Contacts, Accounts, HelpDesk, Invoice, etc.)
- Added Nextcloud folder buttons to ALL modules
- Fixed Nextcloud editor integration
- WebSocket server for real-time updates
- Redis Pub/Sub integration
- File path manager for organized storage
- Redis caching for performance (Functions.php)

📁 New Structure:
Documents/Project/ProjectName_ID/file_docID.ext
Documents/Contacts/FirstName_LastName_ID/file_docID.ext
Documents/Accounts/AccountName_ID/file_docID.ext

🔧 Technical:
- FilePathManager for standardized paths
- S3StorageService integration
- WebSocket server (Node.js + Docker)
- Redis cache for getBasicModuleInfo()
- Predis library for Redis connectivity

📝 Scripts:
- Migration scripts for all modules
- Test pages for WebSocket/SSE/Polling
- Documentation (MIGRATION_*.md, REDIS_*.md)

🎯 Result: 15,000+ files migrated successfully!
2025-10-24 19:59:28 +03:00

127 lines
4.1 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
/**
* Сканирование S3 структуры для анализа файлов
*/
require_once(__DIR__ . '/S3Client.php');
// S3 конфигурация
$s3Config = [
'version' => 'latest',
'region' => 'ru-1',
'endpoint' => 'https://s3.twcstorage.ru',
'bucket' => 'f9825c87-4e3558f6-f9b6-405c-ad3d-d1535c49b61c',
'use_path_style_endpoint' => true,
'key' => 'YCAJEfh7Z06ixD_9fFdVa3BUy',
'secret' => 'YCM9xQmPCOa3L1iO_LS08J0cYWiuUpk3s7q3VSmR'
];
$s3 = new S3Client($s3Config);
echo "🔍 Сканируем S3 структуру...\n";
echo "==========================================\n";
// Используем нативный AWS SDK для listObjects
require_once(__DIR__ . '/../vendor/autoload.php');
use Aws\S3\S3Client as AwsS3Client;
$awsClient = new AwsS3Client([
'version' => 'latest',
'region' => 'ru-1',
'endpoint' => 'https://s3.twcstorage.ru',
'use_path_style_endpoint' => true,
'credentials' => [
'key' => 'YCAJEfh7Z06ixD_9fFdVa3BUy',
'secret' => 'YCM9xQmPCOa3L1iO_LS08J0cYWiuUpk3s7q3VSmR',
],
]);
$bucket = 'f9825c87-4e3558f6-f9b6-405c-ad3d-d1535c49b61c';
$prefix = 'crm2/CRM_Active_Files/Documents/';
try {
$result = $awsClient->listObjectsV2([
'Bucket' => $bucket,
'Prefix' => $prefix,
'MaxKeys' => 1000 // Ограничиваем для начала
]);
$folders = [];
$files = [];
$totalObjects = 0;
foreach ($result['Contents'] as $object) {
$key = $object['Key'];
$relativePath = str_replace($prefix, '', $key);
$totalObjects++;
if (strpos($relativePath, '/') !== false) {
// Это файл в папке
$folder = explode('/', $relativePath)[0];
if (!isset($folders[$folder])) {
$folders[$folder] = 0;
}
$folders[$folder]++;
} else {
// Это файл в корне Documents/
$files[] = $relativePath;
}
}
echo "📁 ПАПКИ В DOCUMENTS/ (топ-20):\n";
echo "==========================================\n";
arsort($folders);
$count = 0;
foreach ($folders as $folder => $fileCount) {
if ($count++ >= 20) break;
echo sprintf("%-50s %d файлов\n", $folder, $fileCount);
}
if (count($folders) > 20) {
echo "... и еще " . (count($folders) - 20) . " папок\n";
}
echo "\n📄 ФАЙЛЫ В КОРНЕ DOCUMENTS/:\n";
echo "==========================================\n";
foreach ($files as $file) {
echo " $file\n";
}
echo "\n📊 СТАТИСТИКА:\n";
echo "==========================================\n";
echo "Всего объектов: $totalObjects\n";
echo "Всего папок: " . count($folders) . "\n";
echo "Всего файлов в корне: " . count($files) . "\n";
echo "Всего файлов в папках: " . array_sum($folders) . "\n";
// Анализ структуры папок
echo "\n🔍 АНАЛИЗ СТРУКТУРЫ ПАПОК:\n";
echo "==========================================\n";
$oldStructure = 0; // Только цифры (documentID)
$newStructure = 0; // Содержит название проекта
$projectStructure = 0; // Начинается с Project/
foreach ($folders as $folder => $fileCount) {
if (preg_match('/^[0-9]+$/', $folder)) {
$oldStructure += $fileCount;
} elseif (strpos($folder, 'Project/') === 0) {
$projectStructure += $fileCount;
} else {
$newStructure += $fileCount;
}
}
echo "Старая структура (только ID): $oldStructure файлов\n";
echo "Промежуточная структура (название_ID): $newStructure файлов\n";
echo "Новая структура (Project/название_ID): $projectStructure файлов\n";
} catch (Exception $e) {
echo "❌ Ошибка: " . $e->getMessage() . "\n";
}
?>