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

57 lines
2.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
/**
* Исправление несоответствий между s3_key и filename
* Синхронизируем filename с реальным s3_key
*/
require_once '/var/www/fastuser/data/www/crm.clientright.ru/config.inc.php';
echo "🚀 Исправляем несоответствия filename и s3_key...\n\n";
try {
$pdo = new PDO("mysql:host={$dbconfig['db_server']};dbname={$dbconfig['db_name']};charset=utf8mb4", $dbconfig['db_username'], $dbconfig['db_password']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("SET NAMES utf8mb4");
echo "✅ Подключение к БД установлено\n\n";
// Загружаем S3 bucket из .env
$envFile = '/var/www/fastuser/data/www/crm.clientright.ru/crm_extensions/.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '=') !== false && strpos($line, '#') !== 0) {
list($key, $value) = explode('=', $line, 2);
$_ENV[trim($key)] = trim($value);
}
}
}
$bucket = $_ENV['S3_BUCKET'];
$baseUrl = 'https://s3.twcstorage.ru/' . $bucket . '/';
// Обновляем все записи где filename не соответствует s3_key
$sql = "
UPDATE vtiger_notes
SET filename = CONCAT(?, s3_key)
WHERE filelocationtype = 'E'
AND s3_key IS NOT NULL
AND filename IS NOT NULL
AND SUBSTRING_INDEX(filename, '/', -1) != SUBSTRING_INDEX(s3_key, '/', -1)
";
$stmt = $pdo->prepare($sql);
$result = $stmt->execute([$baseUrl]);
$count = $stmt->rowCount();
echo "✅ Обновлено записей: {$count}\n";
echo "\n🎉 ГОТОВО! Все filename синхронизированы с s3_key!\n";
} catch (Exception $e) {
echo "❌ ОШИБКА: " . $e->getMessage() . "\n";
exit(1);
}