Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system

- Added comprehensive AI Assistant system (aiassist/ directory):
  * Vector search and embedding capabilities
  * Typebot proxy integration
  * Elastic search functionality
  * Message classification and chat history
  * MCP proxy for external integrations

- Implemented Court Status API (GetCourtStatus.php):
  * Real-time court document status checking
  * Integration with external court systems
  * Comprehensive error handling and logging

- Enhanced S3 integration:
  * Improved file backup system with metadata
  * Batch processing capabilities
  * Enhanced error logging and recovery
  * Copy operations with URL fixing

- Added Telegram contact creation API
- Improved error logging across all modules
- Enhanced callback system for AI responses
- Extensive backup file storage with timestamps
- Updated documentation and README files

- File storage improvements:
  * Thousands of backup files with proper metadata
  * Fix operations for broken file references
  * Project-specific backup and recovery systems
  * Comprehensive file integrity checking

Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
This commit is contained in:
Fedor
2025-10-16 11:17:21 +03:00
parent dabcd43a00
commit ac7467f0b4
26580 changed files with 50860 additions and 3261 deletions

238
modules/ModComments/actions/DownloadFile.php Executable file → Normal file
View File

@@ -1,107 +1,133 @@
<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
class ModComments_DownloadFile_Action extends Vtiger_Action_Controller {
public function checkPermission(Vtiger_Request $request) {
$moduleName = $request->getModule();
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
$currentUserPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
if(!$currentUserPrivilegesModel->hasModulePermission($moduleModel->getId())) {
throw new AppException(vtranslate('LBL_PERMISSION_DENIED'));
}
}
public function process(Vtiger_Request $request) {
$fileId = $request->get('fileid');
$recordId = $request->get('record');
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD: recordId=' . $recordId . ', fileId=' . $fileId . PHP_EOL, FILE_APPEND);
if (empty($fileId)) {
throw new AppException('File ID is required');
}
// Проверяем что файл связан с этим комментарием
global $adb;
$query = "SELECT COUNT(*) as count FROM vtiger_seattachmentsrel WHERE crmid = ? AND attachmentsid = ?";
$result = $adb->pquery($query, array($recordId, $fileId));
$row = $adb->fetchByAssoc($result);
if ($row['count'] == 0) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_ERROR: File not linked to comment' . PHP_EOL, FILE_APPEND);
throw new AppException('File not found or not accessible');
}
// Получаем информацию о файле
$query = "SELECT * FROM vtiger_attachments WHERE attachmentsid = ?";
$result = $adb->pquery($query, array($fileId));
if ($adb->num_rows($result) == 0) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_ERROR: File not found in attachments' . PHP_EOL, FILE_APPEND);
throw new AppException('File not found');
}
$fileInfo = $adb->fetchByAssoc($result);
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_INFO: ' . print_r($fileInfo, true) . PHP_EOL, FILE_APPEND);
// Проверяем есть ли S3 URL в vtiger_notes
$query = "SELECT s3_url FROM vtiger_notes WHERE notesid = ?";
$result = $adb->pquery($query, array($fileId));
if ($adb->num_rows($result) > 0) {
$noteInfo = $adb->fetchByAssoc($result);
if (!empty($noteInfo['s3_url'])) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_S3: ' . $noteInfo['s3_url'] . PHP_EOL, FILE_APPEND);
// Перенаправляем на S3 URL
header('Location: ' . $noteInfo['s3_url']);
exit;
}
}
// Если S3 URL не найден в notes, пытаемся собрать его из attachments
if (!empty($fileInfo['path']) && !empty($fileInfo['storedname'])) {
// Проверяем что это S3 путь
if (strpos($fileInfo['path'], 's3://') === 0) {
// Извлекаем bucket из path
$bucket = str_replace('s3://', '', $fileInfo['path']);
// Собираем S3 URL
$s3Url = 'https://s3.twcstorage.ru/' . $bucket . '/' . $fileInfo['storedname'];
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_S3_CONSTRUCTED: ' . $s3Url . PHP_EOL, FILE_APPEND);
// Перенаправляем на S3 URL
header('Location: ' . $s3Url);
exit;
}
}
// Если S3 URL нет, пытаемся найти локальный файл
$filePath = $fileInfo['path'] . $fileInfo['attachmentsid'] . '_' . $fileInfo['name'];
if (file_exists($filePath)) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_LOCAL: ' . $filePath . PHP_EOL, FILE_APPEND);
header('Content-Type: ' . $fileInfo['type']);
header('Content-Disposition: attachment; filename="' . $fileInfo['name'] . '"');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
exit;
}
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_ERROR: File not found anywhere' . PHP_EOL, FILE_APPEND);
throw new AppException('File not found on server');
}
}
<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
class ModComments_DownloadFile_Action extends Vtiger_Action_Controller {
public function checkPermission(Vtiger_Request $request) {
$moduleName = $request->getModule();
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
$currentUserPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
if(!$currentUserPrivilegesModel->hasModulePermission($moduleModel->getId())) {
throw new AppException(vtranslate('LBL_PERMISSION_DENIED'));
}
}
public function process(Vtiger_Request $request) {
$fileId = $request->get('fileid');
$recordId = $request->get('record');
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD: recordId=' . $recordId . ', fileId=' . $fileId . PHP_EOL, FILE_APPEND);
if (empty($fileId)) {
throw new AppException('File ID is required');
}
// Проверяем что файл связан с этим комментарием
global $adb;
$query = "SELECT COUNT(*) as count FROM vtiger_seattachmentsrel WHERE crmid = ? AND attachmentsid = ?";
$result = $adb->pquery($query, array($recordId, $fileId));
$row = $adb->fetchByAssoc($result);
if ($row['count'] == 0) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_ERROR: File not linked to comment' . PHP_EOL, FILE_APPEND);
throw new AppException('File not found or not accessible');
}
// Получаем информацию о файле
$query = "SELECT * FROM vtiger_attachments WHERE attachmentsid = ?";
$result = $adb->pquery($query, array($fileId));
if ($adb->num_rows($result) == 0) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_ERROR: File not found in attachments' . PHP_EOL, FILE_APPEND);
throw new AppException('File not found');
}
$fileInfo = $adb->fetchByAssoc($result);
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_INFO: ' . print_r($fileInfo, true) . PHP_EOL, FILE_APPEND);
// Проверяем есть ли S3 URL в vtiger_notes
$query = "SELECT s3_url, filename, filelocationtype FROM vtiger_notes WHERE notesid = ?";
$result = $adb->pquery($query, array($fileId));
if ($adb->num_rows($result) > 0) {
$noteInfo = $adb->fetchByAssoc($result);
// Если filelocationtype = 'E', используем filename как прямую ссылку
if ($noteInfo['filelocationtype'] == 'E' && !empty($noteInfo['filename'])) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_EXTERNAL: ' . $noteInfo['filename'] . PHP_EOL, FILE_APPEND);
// Перенаправляем на внешнюю ссылку
header('Location: ' . $noteInfo['filename']);
exit;
}
// Иначе проверяем s3_url
if (!empty($noteInfo['s3_url'])) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_S3: ' . $noteInfo['s3_url'] . PHP_EOL, FILE_APPEND);
// Перенаправляем на S3 URL
header('Location: ' . $noteInfo['s3_url']);
exit;
}
}
// Если S3 URL не найден в notes, пытаемся собрать его из attachments
if (!empty($fileInfo['path']) && !empty($fileInfo['storedname'])) {
// Проверяем что это S3 путь
if (strpos($fileInfo['path'], 's3://') === 0) {
// Извлекаем bucket из path
$bucket = str_replace('s3://', '', $fileInfo['path']);
// Собираем S3 URL
$s3Url = 'https://s3.twcstorage.ru/' . $bucket . '/' . $fileInfo['storedname'];
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_S3_CONSTRUCTED: ' . $s3Url . PHP_EOL, FILE_APPEND);
// Перенаправляем на S3 URL
header('Location: ' . $s3Url);
exit;
}
}
// Если S3 URL нет, пытаемся найти локальный файл
// Сначала пробуем путь с storedname (новый формат)
$filePath = $fileInfo['path'] . $fileInfo['storedname'];
if (file_exists($filePath)) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_LOCAL_STORED: ' . $filePath . PHP_EOL, FILE_APPEND);
header('Content-Type: ' . $fileInfo['type']);
header('Content-Disposition: attachment; filename="' . $fileInfo['name'] . '"');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
exit;
}
// Если не найден, пробуем старый формат
$filePath = $fileInfo['path'] . $fileInfo['attachmentsid'] . '_' . $fileInfo['name'];
if (file_exists($filePath)) {
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_LOCAL_OLD: ' . $filePath . PHP_EOL, FILE_APPEND);
header('Content-Type: ' . $fileInfo['type']);
header('Content-Disposition: attachment; filename="' . $fileInfo['name'] . '"');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
exit;
}
file_put_contents('logs/debug.log', '[' . date('Y-m-d H:i:s') . '] MODCOMMENTS_DOWNLOAD_ERROR: File not found anywhere. Tried: ' . $fileInfo['path'] . $fileInfo['storedname'] . ' and ' . $fileInfo['path'] . $fileInfo['attachmentsid'] . '_' . $fileInfo['name'] . PHP_EOL, FILE_APPEND);
throw new AppException('File not found on server');
}
}
?>