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

88 lines
3.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)
*/
// Подключаемся к БД
$db = new mysqli('localhost', 'ci20465_72new', 'EcY979Rn', 'ci20465_72new');
if ($db->connect_error) {
die("❌ Ошибка подключения к БД: " . $db->connect_error);
}
$db->set_charset('utf8mb4');
echo "🔄 === ЗАМЕНА ПРОБЕЛОВ НА ПОДЧЁРКИВАНИЯ В БД ===\n\n";
// Находим все файлы с пробелами и проблемными символами в путях
$query = "
SELECT
n.notesid,
n.filename,
sr.crmid as project_id
FROM vtiger_notes n
INNER JOIN vtiger_senotesrel sr ON n.notesid = sr.notesid
WHERE n.filename LIKE '%/Documents/%_%/%'
AND (n.filename LIKE '% %' OR n.filename LIKE '%\"%' OR n.filename LIKE '%,%' OR n.filename LIKE '% %')
AND sr.crmid IN (SELECT projectid FROM vtiger_project)
ORDER BY sr.crmid, n.notesid
";
$result = $db->query($query);
if (!$result) {
die("❌ Ошибка запроса: " . $db->error);
}
$total = $result->num_rows;
$updated = 0;
$errors = 0;
echo "📊 Найдено файлов с пробелами: {$total}\n\n";
while ($row = $result->fetch_assoc()) {
$notesid = $row['notesid'];
$oldPath = $row['filename'];
// Заменяем пробелы и проблемные символы в пути
$newPath = $oldPath;
// Разделяем базовый путь и относительный путь
$parts = explode('/Documents/', $newPath);
if (count($parts) == 2) {
$basePath = $parts[0] . '/Documents/';
$relativePath = $parts[1];
// Применяем ВСЕ замены к относительному пути:
// 1. Заменяем кавычки на подчёркивания
$relativePath = str_replace('"', '_', $relativePath);
// 2. Заменяем запятые на подчёркивания
$relativePath = str_replace(',', '_', $relativePath);
// 3. Заменяем все пробелы (одинарные и множественные) на подчёркивания
$relativePath = preg_replace('/\s+/', '_', $relativePath);
$newPath = $basePath . $relativePath;
}
// Обновляем БД
$stmt = $db->prepare("UPDATE vtiger_notes SET filename = ? WHERE notesid = ?");
$stmt->bind_param('si', $newPath, $notesid);
if ($stmt->execute()) {
$updated++;
if ($updated % 100 == 0) {
echo "✅ Обновлено: {$updated}/{$total}\n";
}
} else {
$errors++;
echo "❌ Ошибка обновления {$notesid}: " . $stmt->error . "\n";
}
$stmt->close();
}
echo "\n📊 === ИТОГОВАЯ СТАТИСТИКА ===\n";
echo "✅ Обновлено: {$updated} записей\n";
echo "❌ Ошибок: {$errors} записей\n";
echo "\n✅ Обновление завершено!\n";
$db->close();