OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)

This commit is contained in:
wangruiguo
2026-09-03 18:49:20 +08:00
commit d647428529
3501 changed files with 1988906 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace Leantime\Core\Database;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class DatabaseManager
{
/**
* Switch the database connection to use the given configuration.
*
* @param array $config Database configuration with keys: dbHost, dbDatabase, dbUser, dbPassword
*/
public static function switchConnection(array $config): void
{
try {
$connectionName = config('database.default', 'mysql');
// Purge existing connections
DB::purge($connectionName);
// Update the configuration
config([
"database.connections.{$connectionName}.host" => $config['dbHost'],
"database.connections.{$connectionName}.database" => $config['dbDatabase'],
"database.connections.{$connectionName}.username" => $config['dbUser'],
"database.connections.{$connectionName}.password" => $config['dbPassword'],
]);
// Reconnect with new configuration
DB::reconnect($connectionName);
// Verify connection
DB::connection($connectionName)->getPdo();
} catch (\Exception $e) {
Log::error('Database connection failed: '.$e->getMessage());
throw new \RuntimeException('Failed to establish database connection: '.$e->getMessage());
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Leantime\Core\Database;
use Illuminate\Database\Connection;
use Illuminate\Database\DatabaseServiceProvider as LaravelDatabaseServiceProvider;
class DatabaseServiceProvider extends LaravelDatabaseServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// Register Laravel's database service first
parent::register();
// Register custom PostgreSQL connection that handles empty-string-to-null conversion.
// MySQL silently coerces '' to NULL/zero for non-string columns; PostgreSQL does not.
Connection::resolverFor('pgsql', function ($connection, $database, $prefix, $config) {
return new LtPostgresConnection($connection, $database, $prefix, $config);
});
// Register Db as a singleton with proper dependency injection
app()->singleton(\Leantime\Core\Db\Db::class, function ($app) {
return new \Leantime\Core\Db\Db($app);
});
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Leantime\Core\Database;
use Illuminate\Database\PostgresConnection;
/**
* Custom PostgreSQL connection that handles MySQL-isms in the Leantime codebase.
*
* MySQL silently coerces empty strings to appropriate zero/null values for
* non-string column types (datetime, integer, float). PostgreSQL does not.
* This connection class converts empty string bindings to null so that
* existing repository code works without modification on PostgreSQL.
*
* String columns that legitimately need empty strings should be defined as
* nullable() in the SchemaBuilder so they accept null gracefully.
*/
class LtPostgresConnection extends PostgresConnection
{
/**
* Prepare the query bindings for execution.
*
* Converts empty strings to null for PostgreSQL compatibility.
* MySQL treats '' as NULL/zero for datetime, int, and float columns,
* but PostgreSQL rejects them with type errors.
*
* @return array
*/
public function prepareBindings(array $bindings)
{
$bindings = parent::prepareBindings($bindings);
foreach ($bindings as $key => $value) {
if ($value === '') {
$bindings[$key] = null;
}
}
return $bindings;
}
}