Mit neuen Manfest
This commit is contained in:
@@ -4,43 +4,55 @@ 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
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Eingabe
|
||||
$pdfPath = $input->getString('pdf_path', '');
|
||||
|
||||
// Existiert ein Eintrag?
|
||||
$query = $db->getQuery(true)
|
||||
->select('COUNT(*)')
|
||||
->from($db->quoteName('#__eis_settings'));
|
||||
$db->setQuery($query);
|
||||
$exists = (int) $db->loadResult() > 0;
|
||||
|
||||
if ($exists) {
|
||||
// Update
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__eis_settings'))
|
||||
->set($db->quoteName('pdf_path') . ' = ' . $db->quote($pdfPath));
|
||||
} else {
|
||||
// Insert
|
||||
$query = $db->getQuery(true)
|
||||
->insert($db->quoteName('#__eis_settings'))
|
||||
->columns([$db->quoteName('pdf_path')])
|
||||
->values($db->quote($pdfPath));
|
||||
// CSRF
|
||||
if (!Session::checkToken('post')) {
|
||||
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
}
|
||||
|
||||
$db->setQuery($query)->execute();
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
|
||||
$app->enqueueMessage('Pfad gespeichert: ' . $pdfPath, 'message');
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user