✨ 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!
102 lines
2.8 KiB
PHP
102 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* SSE (Server-Sent Events) endpoint для синхронизации файлов в реальном времени
|
|
*
|
|
* Использование:
|
|
* - Подключение: new EventSource('/crm_extensions/file_storage/api/sse_events.php')
|
|
* - Webhook от Nextcloud: POST /crm_extensions/file_storage/api/nextcloud_webhook.php
|
|
*/
|
|
|
|
// Подключаем CRM
|
|
require_once('../../../../config.inc.php');
|
|
require_once('../../../../include/utils/utils.php');
|
|
require_once('../../../../include/utils/CommonUtils.php');
|
|
|
|
// Настройки SSE
|
|
header('Content-Type: text/event-stream');
|
|
header('Cache-Control: no-cache');
|
|
header('Connection: keep-alive');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Headers: Cache-Control');
|
|
|
|
// Отключаем буферизацию
|
|
if (ob_get_level()) {
|
|
ob_end_clean();
|
|
}
|
|
|
|
// Функция для отправки SSE события
|
|
function sendSSEEvent($type, $data) {
|
|
$event = [
|
|
'type' => $type,
|
|
'data' => $data,
|
|
'timestamp' => time()
|
|
];
|
|
|
|
echo "data: " . json_encode($event) . "\n\n";
|
|
flush();
|
|
}
|
|
|
|
// Функция для отправки heartbeat
|
|
function sendHeartbeat() {
|
|
echo "data: {\"type\":\"heartbeat\",\"timestamp\":" . time() . "}\n\n";
|
|
flush();
|
|
}
|
|
|
|
// Проверяем подключение
|
|
if (connection_aborted()) {
|
|
exit();
|
|
}
|
|
|
|
// Отправляем начальное событие
|
|
sendSSEEvent('connected', [
|
|
'message' => 'SSE подключение установлено',
|
|
'server_time' => date('Y-m-d H:i:s')
|
|
]);
|
|
|
|
// Основной цикл SSE
|
|
$lastHeartbeat = time();
|
|
$heartbeatInterval = 30; // Heartbeat каждые 30 секунд
|
|
|
|
while (true) {
|
|
// Проверяем подключение
|
|
if (connection_aborted()) {
|
|
break;
|
|
}
|
|
|
|
// Отправляем heartbeat
|
|
if (time() - $lastHeartbeat >= $heartbeatInterval) {
|
|
sendHeartbeat();
|
|
$lastHeartbeat = time();
|
|
}
|
|
|
|
// Проверяем новые события из Redis/файла/БД
|
|
// Пока используем простую проверку файла
|
|
$eventsFile = '/tmp/crm_sse_events.json';
|
|
|
|
if (file_exists($eventsFile)) {
|
|
$events = json_decode(file_get_contents($eventsFile), true);
|
|
|
|
if ($events && is_array($events)) {
|
|
foreach ($events as $event) {
|
|
sendSSEEvent($event['type'], $event['data']);
|
|
}
|
|
|
|
// Очищаем файл после отправки
|
|
unlink($eventsFile);
|
|
}
|
|
}
|
|
|
|
// Пауза между проверками
|
|
sleep(1);
|
|
}
|
|
|
|
// Закрываем соединение
|
|
sendSSEEvent('disconnected', [
|
|
'message' => 'SSE подключение закрыто'
|
|
]);
|
|
?>
|
|
|
|
|
|
|
|
|