Files
Fedor ac7467f0b4 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.
2025-10-16 11:17:21 +03:00

109 lines
3.6 KiB
PHP

<?php
/**
* Created by JetBrains PhpStorm.
* User: Stefan Warnat <support@stefanwarnat.de>
* Date: 15.10.14 10:32
* You must not use this file without permission.
*/
namespace Workflow;
class DbCheck {
public static function checkColumn($table, $colum, $type, $default = false, $resetType = false, $callbackIfNew = false) {
global $adb;
if(!\Workflow\DbCheck::existTable($table)) {
return false;
}
$result = $adb->query("SHOW COLUMNS FROM `".$table."` LIKE '".$colum."'");
$exists = ($adb->num_rows($result))?true:false;
if($exists == false) {
echo "Add column '".$table."'.'".$colum."'<br>";
$adb->query("ALTER TABLE `".$table."` ADD `".$colum."` ".$type." NOT NULL".($default !== false && $type != 'TEXT'?" DEFAULT '".$default."'":""), false);
if($callbackIfNew !== false && is_callable($callbackIfNew)) {
$callbackIfNew();
}
} elseif($resetType == true) {
$existingType = strtolower(html_entity_decode($adb->query_result($result, 0, 'type'), ENT_QUOTES));
$existingType = str_replace(' ', '', $existingType);
if($existingType != strtolower(str_replace(' ', '', $type))) {
$sql = "ALTER TABLE `".$table."` CHANGE `".$colum."` `".$colum."` ".$type.";";
$adb->query($sql);
}
}
return $exists;
}
private static $tableCache = array();
public static function clearTableCache() {
self::$tableCache = array();
}
public static function existTable($tableName) {
global $adb;
if(empty(self::$tableCache)) {
global $dbconfig;
$sql = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = "BASE TABLE" AND TABLE_SCHEMA = "' . $dbconfig['db_name'] . '"';
$result = $adb->query($sql);
while ($row = $adb->fetchByAssoc($result)) {
$tables[] = $row['table_name'];
}
self::$tableCache = $tables;
}
foreach(self::$tableCache as $table) {
if($table == $tableName)
return true;
}
return false;
}
public function lowercaseColumn($table, $column) {
$adb = \PearDatabase::getInstance();
if(!\Workflow\DbCheck::existTable($table)) {
return false;
}
$result = $adb->query("SHOW COLUMNS FROM `".$table."` LIKE '".$column."'");
$exists = ($adb->num_rows($result))?true:false;
if($exists == true) {
$data = $adb->fetchByAssoc($result);
if($data['Field'] == $column) {
$sql = 'ALTER TABLE `'.$table.'` CHANGE `'.$column.'` `'.strtolower($column).'` '.$data['Type'].' '.($data['Null'] == 'NO'?'NOT NULL':'').';';
$adb->query($sql);
}
}
}
public static function checkRepositoryDB() {
$initRepository = false;
$adb = \PearDatabase::getInstance();
}
public static function tableToUtf8($tableName) {
global $dbconfig;
$adb = \PearDatabase::getInstance();
$sql = 'SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = "BASE TABLE" AND TABLE_SCHEMA = "'.$dbconfig['db_name'].'"';
$result = $adb->query($sql);
while($row = $adb->fetchByAssoc($result)) {
$tables[$row['table_name']] = $row;
}
if(substr($tables[$tableName]['table_collation'], 0, 7) == 'latin1_') {
$sql = 'ALTER TABLE '.$tableName.' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;';
$adb->query($sql);
}
}
}
?>