diff --git a/.env.example b/.env.example index f15fe88d..554b3b44 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,7 @@ DB_PORT=3306 DB_DATABASE=nexusphp DB_USERNAME=nexusphp DB_PASSWORD=nexusphp +DB_SCHEMA=public BROADCAST_DRIVER=log CACHE_DRIVER=redis diff --git a/app/Filament/Resources/User/UserPasskeyResource.php b/app/Filament/Resources/User/UserPasskeyResource.php index 115d197e..97833874 100644 --- a/app/Filament/Resources/User/UserPasskeyResource.php +++ b/app/Filament/Resources/User/UserPasskeyResource.php @@ -51,7 +51,7 @@ class UserPasskeyResource extends Resource ->formatStateUsing(fn($state) => username_for_admin($state)) ->label(__('label.username')) , - Tables\Columns\TextColumn::make('AAGUID') + Tables\Columns\TextColumn::make('aaguid') ->label("AAGUID") , Tables\Columns\TextColumn::make('credential_id') diff --git a/app/Models/Passkey.php b/app/Models/Passkey.php index ad0c8f78..dd7627d1 100644 --- a/app/Models/Passkey.php +++ b/app/Models/Passkey.php @@ -9,7 +9,7 @@ class Passkey extends NexusModel public $timestamps = true; protected $fillable = [ - 'id', 'user_id', 'AAGUID', 'credential_id', 'public_key', 'counter', + 'id', 'user_id', 'aaguid', 'credential_id', 'public_key', 'counter', ]; public function user() @@ -17,8 +17,9 @@ class Passkey extends NexusModel return $this->belongsTo(User::class, 'user_id'); } - public function AAGUID() { - $guid = $this->AAGUID; + public function getAaguidFormatted(): string + { + $guid = $this->aaguid; return sprintf( '%s-%s-%s-%s-%s', substr($guid, 0, 8), diff --git a/app/Repositories/ExamRepository.php b/app/Repositories/ExamRepository.php index 8d789b83..c0318351 100644 --- a/app/Repositories/ExamRepository.php +++ b/app/Repositories/ExamRepository.php @@ -269,8 +269,12 @@ class ExamRepository extends BaseRepository $now = Carbon::now(); $query = Exam::query() ->where('status', Exam::STATUS_ENABLED) - ->whereRaw("if(begin is not null and end is not null, begin <= '$now' and end >= '$now', duration > 0 or recurring is not null)") - ; + ->whereRaw(' + CASE + WHEN begin IS NOT NULL AND "end" IS NOT NULL + THEN begin <= ? AND "end" >= ? + ELSE duration > 0 OR recurring IS NOT NULL + END', [$now, $now]); if (!is_null($excludeId)) { $query->whereNotIn('id', Arr::wrap($excludeId)); @@ -1139,10 +1143,22 @@ class ExamRepository extends BaseRepository ->orderBy("$examUserTable.id", "asc"); if (!$ignoreTimeRange) { $whenThens = []; - $whenThens[] = "when $examUserTable.`end` is not null then $examUserTable.`end` < '$now'"; - $whenThens[] = "when $examTable.`end` is not null then $examTable.`end` < '$now'"; - $whenThens[] = "when $examTable.duration > 0 then date_add($examUserTable.created_at, interval $examTable.duration day) < '$now'"; - $baseQuery->whereRaw(sprintf("case %s else false end", implode(" ", $whenThens))); + $params = []; + + $whenThens[] = "WHEN $examUserTable.\"end\" IS NOT NULL THEN $examUserTable.\"end\" < ?"; + $params[] = $now; + + $whenThens[] = "WHEN $examTable.\"end\" IS NOT NULL THEN $examTable.\"end\" < ?"; + $params[] = $now; + + if (NexusDB::isMysql()) { + $whenThens[] = "when $examTable.duration > 0 then date_add($examUserTable.created_at, interval $examTable.duration day) < ?"; + } elseif (NexusDB::isPgsql()) { + $whenThens[] = "WHEN $examTable.duration > 0 THEN ($examUserTable.created_at + ($examTable.duration || ' day')::INTERVAL) < ?"; + } + $params[] = $now; + + $baseQuery->whereRaw(sprintf("CASE %s ELSE false END", implode(" ", $whenThens)), $params); } $size = 1000; diff --git a/app/Repositories/UserPasskeyRepository.php b/app/Repositories/UserPasskeyRepository.php index e9128b03..de537c0b 100644 --- a/app/Repositories/UserPasskeyRepository.php +++ b/app/Repositories/UserPasskeyRepository.php @@ -219,7 +219,7 @@ class UserPasskeyRepository extends BaseRepository
AAGUID()]; + $meta = $AAGUIDS[$passkey->getAaguidFormatted()]; if (isset($meta)) { printf('%s
%s (%s)', $meta['icon_dark'], $meta['name'], $meta['name'], $passkey->credential_id); } else { diff --git a/config/database.php b/config/database.php index f545a3fa..d3da16c4 100644 --- a/config/database.php +++ b/config/database.php @@ -74,7 +74,7 @@ return [ 'charset' => 'utf8', 'prefix' => '', 'prefix_indexes' => true, - 'schema' => 'public', + 'schema' => env('DB_SCHEMA', 'public'), 'sslmode' => 'prefer', ], diff --git a/config/nexus.php b/config/nexus.php index 957fc93e..b309caa4 100644 --- a/config/nexus.php +++ b/config/nexus.php @@ -41,7 +41,7 @@ return [ 'charset' => 'utf8', 'prefix' => '', 'prefix_indexes' => true, - 'schema' => 'public', + 'schema' => nexus_env('DB_SCHEMA', 'public'), 'sslmode' => 'prefer', ], ], diff --git a/database/migrations/2026_04_23_014825_change_user_passkeys_table_aaguid_field_lower_case.php b/database/migrations/2026_04_23_014825_change_user_passkeys_table_aaguid_field_lower_case.php new file mode 100644 index 00000000..1a243b5c --- /dev/null +++ b/database/migrations/2026_04_23_014825_change_user_passkeys_table_aaguid_field_lower_case.php @@ -0,0 +1,27 @@ +renameColumn('AAGUID', 'aaguid'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/public/messages.php b/public/messages.php index ddee3bd2..7bd101be 100644 --- a/public/messages.php +++ b/public/messages.php @@ -245,7 +245,7 @@ $subject = $lang_messages['text_no_subject']; } // Mark message unread -sql_query("UPDATE messages SET unread='no' WHERE id=" . sqlesc($pm_id) . " AND receiver=" . sqlesc($CURUSER['id']) . " LIMIT 1"); +sql_query("UPDATE messages SET unread='no' WHERE id=" . sqlesc($pm_id) . " AND receiver=" . sqlesc($CURUSER['id'])); $Cache->delete_value('user_'.$CURUSER['id'].'_unread_message_count'); // Display message stdhead("PM ($subject)"); ?>