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

110 lines
3.3 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
/**
* Исправление поля filename для архивных проектов
* Обновляет filename чтобы он совпадал с s3_key
*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "🔧 ИСПРАВЛЕНИЕ FILENAME ДЛЯ АРХИВНЫХ ПРОЕКТОВ\n";
echo "============================================\n\n";
require_once '/var/www/fastuser/data/www/crm.clientright.ru/config.inc.php';
// Создаем PDO подключение
try {
$pdo = new PDO(
"mysql:host={$dbconfig['db_server']};port=3306;dbname={$dbconfig['db_name']};charset=utf8",
$dbconfig['db_username'],
$dbconfig['db_password'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
echo "✅ PDO подключен\n\n";
} catch (Exception $e) {
die("❌ Ошибка PDO: " . $e->getMessage() . "\n");
}
$bucket = 'f9825c87-4e3558f6-f9b6-405c-ad3d-d1535c49b61c';
// Получаем все файлы архивных проектов где s3_key содержит Project/, но filename - нет
$sql = "SELECT DISTINCT n.notesid, n.title, n.filename, n.s3_key
FROM vtiger_notes n
INNER JOIN vtiger_senotesrel sr ON n.notesid = sr.notesid
INNER JOIN vtiger_project p ON sr.crmid = p.projectid
WHERE p.projectstatus = 'archived'
AND n.filelocationtype = 'E'
AND n.s3_key LIKE '%Project/%'
AND n.filename NOT LIKE '%Project/%'
ORDER BY n.notesid";
$result = $pdo->query($sql);
$filesToFix = [];
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$filesToFix[] = $row;
}
echo "📊 НАЙДЕНО ФАЙЛОВ С НЕПРАВИЛЬНЫМ FILENAME: " . count($filesToFix) . "\n\n";
if (count($filesToFix) === 0) {
echo "Все файлы уже исправлены!\n";
exit;
}
// Показываем примеры
echo "📝 ПРИМЕРЫ:\n";
echo "==========\n";
for ($i = 0; $i < min(5, count($filesToFix)); $i++) {
$file = $filesToFix[$i];
echo "ID: {$file['notesid']}\n";
echo "Старый filename: {$file['filename']}\n";
echo "S3 Key: {$file['s3_key']}\n";
echo "Новый filename: https://s3.twcstorage.ru/{$bucket}/{$file['s3_key']}\n";
echo "---\n";
}
echo "\n❓ Обновить filename для " . count($filesToFix) . " файлов? (y/n): ";
$handle = fopen("php://stdin", "r");
$line = fgets($handle);
fclose($handle);
if (trim(strtolower($line)) !== 'y') {
echo "❌ Отменено\n";
exit;
}
echo "\n🚀 НАЧИНАЕМ ОБНОВЛЕНИЕ:\n";
echo "======================\n";
$updated = 0;
$errors = 0;
foreach ($filesToFix as $file) {
$notesId = $file['notesid'];
$s3Key = $file['s3_key'];
$newFilename = "https://s3.twcstorage.ru/{$bucket}/{$s3Key}";
try {
$updateSql = "UPDATE vtiger_notes SET filename = ? WHERE notesid = ?";
$stmt = $pdo->prepare($updateSql);
$stmt->execute([$newFilename, $notesId]);
echo "✅ ID {$notesId}: filename обновлен\n";
$updated++;
} catch (Exception $e) {
echo "❌ ID {$notesId}: Ошибка - " . $e->getMessage() . "\n";
$errors++;
}
}
echo "\n🎉 ОБНОВЛЕНИЕ ЗАВЕРШЕНО!\n";
echo "=======================\n";
echo "✅ Обновлено: $updated\n";
echo "❌ Ошибок: $errors\n";
?>