Files
EIS/com_eis/administrator/src/Controller/ConfigController.php
2025-08-26 20:28:35 +02:00

59 lines
2.3 KiB
PHP

<?php
namespace EIS\Component\EIS\Administrator\Controller;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use EIS\Component\EIS\Administrator\Helper\SettingsHelper;
class ConfigController extends BaseController
{
public function save(): void
{
// CSRF
if (!Session::checkToken('post')) {
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
}
$app = Factory::getApplication();
$input = $app->getInput();
// Feldname aus dem Config-Template
$path = (string) $input->post->get('document_root', '', 'string');
$path = trim($path);
// Minimal-Validierung & Normalisierung
// (Hier kein striktes is_readable(), damit man den Pfad auch erst konfigurieren kann,
// wenn das Verzeichnis später angelegt/umgehängt wird. Warnen ist aber hilfreich.)
if ($path === '') {
$app->enqueueMessage(Text::_('COM_EIS_MSG_INVALID_PATH') ?: 'Bitte einen gültigen Pfad angeben.', 'warning');
$this->setRedirect(Route::_('index.php?option=com_eis&view=config', false));
return;
}
// Doppelte Slashes und trailing Slash bereinigen
$path = preg_replace('#/+#', '/', $path);
// Lass den Root-Slash stehen, entferne sonst trailing Slash
if ($path !== '/' && str_ends_with($path, '/')) {
$path = rtrim($path, '/');
}
// Optional: Hinweise zur Existenz/Lesbarkeit (nur Hinweis, kein Hard-Error)
if (!is_dir($path)) {
$app->enqueueMessage(Text::sprintf('COM_EIS_MSG_PATH_NOT_EXISTS', $path) ?: "Hinweis: Verzeichnis existiert nicht: {$path}", 'notice');
} elseif (!is_readable($path)) {
$app->enqueueMessage(Text::sprintf('COM_EIS_MSG_PATH_NOT_READABLE', $path) ?: "Hinweis: Verzeichnis nicht lesbar: {$path}", 'notice');
}
// Persistieren
SettingsHelper::setSetting('document_root', $path);
$app->enqueueMessage(Text::_('COM_EIS_MSG_SAVED_SUCCESS') ?: 'Einstellungen wurden gespeichert.', 'message');
$this->setRedirect(Route::_('index.php?option=com_eis&view=config', false));
}
}