Skip to content

Implement database-driven configuration management with admin UI - #138

Merged
itshypax merged 10 commits into
mainfrom
copilot/add-config-database-storage
Nov 4, 2025
Merged

Implement database-driven configuration management with admin UI#138
itshypax merged 10 commits into
mainfrom
copilot/add-config-database-storage

Conversation

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Configuration per Database - Implementation Complete ✅

This PR implements database-driven configuration management for intraRP with all requirements fulfilled.

Requirements Completed

Core Requirements:

  • Configuration stored in database (intra_config table)
  • Individual entries editable by administrators in frontend
  • config.php loads definitions from database automatically
  • Preview functionality for visual config items (colors, logos, meta images)
  • Custom color picker (not browser/Windows default)
  • All config changes logged in audit log with global=1

Additional Requirements:

  • First user receives notification directing to configuration page
  • Frontend does not allow creating new config options
  • System supports database-driven creation for future updates
  • Code review feedback addressed
  • All validation checks pass
  • UI feedback addressed (preview backgrounds, duplicate color preview, META_IMAGE preview, LANG removal)
  • Audit log global flag set correctly
  • Only changed values logged (no duplicate logs for unchanged values)

Implementation Summary

Database:

  • intra_config table with metadata fields
  • 5 migration files registered in database-init.php
  • Preserves user customizations on updates
  • LANG field removed as it's not in use

Backend:

  • ConfigManager class with caching and type conversion
  • Graceful fallback to hardcoded values
  • Transaction-safe batch updates
  • Strict type comparisons
  • String-based value comparison to prevent false-positive changes

Frontend:

  • Admin UI at /settings/system/config.php
  • Organized by 4 categories (Basis, Server, RP, Funktionen)
  • HTML5 color picker (no duplicate preview)
  • Logo preview with error handling
  • META_IMAGE_URL preview with error handling
  • Preview backgrounds match dark theme (#212529, #2b3035)
  • Boolean switches, dropdowns, text inputs
  • Form validation and helpful descriptions
  • 18 configurable settings (LANG removed)

Integration:

  • config.php automatically loads from database
  • Navigation link added to settings menu
  • NotificationManager supports 'system' type
  • First user notification implemented
  • All changes logged to audit_log with global=1
  • Only actual changes logged (no false positives)

Key Features

Backward Compatible - Existing code using define() works unchanged
🔒 Secure - Admin-only, audit logged with global flag, SQL injection protected
Performance - Cached in memory, single query per request
🎨 User Friendly - Live previews, validation, clear descriptions, matching dark theme
🔧 Maintainable - New config via migrations, type-safe, well-documented
📝 Accurate Logging - Only logs actual changes, no false positives

Recent Changes

Commit 4ea6a68:

  1. ✅ Added preview for META_IMAGE_URL field
  2. ✅ Fixed preview backgrounds to match dark theme (#212529 for containers, #2b3035 for images)
  3. ✅ Removed duplicate color preview (kept only the HTML5 color picker)
  4. ✅ Removed LANG field (not currently in use)
  5. ✅ Updated JavaScript functions to handle new preview
  6. ✅ Updated migrations to exclude LANG field

Commit 89c958b:
7. ✅ Set global=1 for config update audit log entries

Commit [current]:
8. ✅ Fixed comparison logic to use raw string values from database instead of converted values, preventing false-positive change detection for boolean and other typed values

Files Changed

Created (6 files):

  • src/Config/ConfigManager.php - Configuration management class
  • settings/system/config.php - Admin configuration UI
  • assets/database/create_intra_config_04112025.php - Table schema
  • assets/database/insert_intra_config_defaults_04112025.php - Default values (18 configs)
  • assets/database/alter_intra_notifications_type_04112025.php - Notification type
  • assets/database/remove_lang_config_04112025.php - Remove unused LANG field

Modified (5 files):

  • assets/config/config.php - Database integration
  • setup/database-init.php - Migration registration
  • src/Notifications/NotificationManager.php - System type support
  • auth/callback.php - First user notification
  • assets/components/navbar.php - Navigation link

Validation Results

✅ All PHP syntax checks pass
✅ All migrations registered
✅ ConfigManager integration verified
✅ Notification system updated
✅ Navigation link added
✅ First user notification implemented
✅ Code review feedback addressed
✅ UI feedback addressed
✅ Audit log global flag set correctly
✅ Change detection logic corrected (no false positives)
✅ No security vulnerabilities detected

Deployment

  1. Run migrations: composer db:migrate
  2. Configuration UI available at: Settings → Konfiguration
  3. First admin user receives notification
  4. All existing functionality preserved
  5. All config changes logged with global=1 for system-wide visibility
  6. Audit log only shows actual changes (no duplicate entries)
Original prompt

This section details on the original issue you should resolve

<issue_title>Konfiguration per Datenbank</issue_title>
<issue_description>## Bezieht sich die Anfrage einer Funktion auf ein Problem? Bitte beschreiben.
Aktuell müssen alle Konfigurationssachen in /assets/config/config.php geändert werden.

Beschreibung der gewünschten Lösung

  1. Die config sollte in der Datenbank hinterlegt werden und einzelne Einträge sollten durch Administratoren im Frontend bearbeitet werden können
  2. Die config.php sollte bestehen bleiben, aber einfach automatisch die definitions aus der Datenbank laden.
  3. Für die Frontend-Bearbeitung der config variablen sollte es an geeigneten stellen eine preview geben und die Farbauswahl nicht der Browser/Windows standard sein.
  4. Änderungen an der config sollten im Audit-Log gespeichert werden.

Zusätzlicher Kontext

//
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 4, 2025 18:58
Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>
Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>
…logic

Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>
Copilot AI changed the title [WIP] Add configuration storage in database with frontend editing Implement database-driven configuration management with admin UI Nov 4, 2025
Copilot AI requested a review from itshypax November 4, 2025 19:07
@itshypax

itshypax commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

@copilot [04-Nov-2025 19:09:49 UTC] PHP Fatal error: Uncaught Error: Undefined constant "SYSTEM_NAME" in F:\GitKraken Projects\intraRP\assets\components_base\admin\head.php:8
Stack trace:
#0 F:\GitKraken Projects\intraRP\index.php(25): include()
#1 {main}
thrown in F:\GitKraken Projects\intraRP\assets\components_base\admin\head.php on line 8

@itshypax

itshypax commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

@copilot Error was on my side. "Bild für Link-Vorschau (als Link angeben)" should have a preview aswell. Also the backgroundof the previews dont match the rest of the style and the color preview of "Hauptfarbe des Systems" is doubled (one left and one right). Also the language currently has no usage so it can be removed

…e duplicate color preview, remove LANG field

Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Error was on my side. "Bild für Link-Vorschau (als Link angeben)" should have a preview aswell. Also the backgroundof the previews dont match the rest of the style and the color preview of "...

Fixed in commit 4ea6a68:

  1. ✅ Added preview for "Bild für Link-Vorschau" (META_IMAGE_URL) - works exactly like the logo preview
  2. ✅ Fixed preview backgrounds to match dark theme:
    • Preview containers: #212529 (dark background)
    • Image backgrounds: #2b3035 (slightly lighter for contrast)
  3. ✅ Removed duplicate color preview - now only shows the HTML5 color picker and text input (the extra preview box on the right is gone)
  4. ✅ Removed LANG field - removed from database, UI, and fallback config since it's not currently in use

The configuration UI now has:

  • HTML5 color picker with text input (no duplicate preview)
  • Logo preview with dark background
  • META_IMAGE_URL preview with dark background
  • All previews styled to match the dark theme
  • 18 total config fields (LANG removed)

@itshypax

itshypax commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

@copilot Config updates should have global 1 in the audit log

Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Config updates should have global 1 in the audit log

Fixed in commit 89c958b - config update audit log entries now have global=1 set, making them visible system-wide in the audit log.

@itshypax

itshypax commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

@copilot 04.11.2025 20:28:41 System config_update {"key":"ENOTF_REQUIRE_USER_AUTH","old_value":false,"new_value":"false"} hypax (ID: 122)
04.11.2025 20:28:41 System config_update {"key":"ENOTF_USE_PIN","old_value":true,"new_value":"true"} hypax (ID: 122)
04.11.2025 20:28:41 System config_update {"key":"ENOTF_PREREG","old_value":true,"new_value":"true"} hypax (ID: 122)
04.11.2025 20:28:41 System config_update {"key":"CHAR_ID","old_value":true,"new_value":"true"} hypax (ID: 122)
04.11.2025 20:28:41 System config_update {"key":"SYSTEM_URL","old_value":"test.de","new_value":"CHANGE_ME"} hypax (ID: 1

Some things get logged even though the value did not change

…values

Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

@copilot 04.11.2025 20:28:41 System config_update {"key":"ENOTF_REQUIRE_USER_AUTH","old_value":false,"new_value":"false"} hypax (ID: 122)
04.11.2025 20:28:41 System config_update {"key":"ENOTF_USE_PIN...

Fixed in commit 6ffa8d8 - the issue was that boolean values were being compared as PHP boolean (true) vs string ("true"), causing false-positive change detection. Now compares raw string values from the database before and after, so only actual changes are logged to the audit log.

Refactors document creation and config update processes to use the `AuditLogger` class instead of the old `logAction` function.
This change provides a more structured and maintainable approach to audit logging.
Also, it enhances the readability of audit log messages by providing more descriptive details.
@itshypax
itshypax marked this pull request as ready for review November 4, 2025 19:58
@itshypax
itshypax merged commit 27cb7a6 into main Nov 4, 2025
1 check passed
@itshypax
itshypax deleted the copilot/add-config-database-storage branch November 4, 2025 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Konfiguration per Datenbank

2 participants