Skip to content

Commit 7793ccf

Browse files
Michael Babkerwilsonge
authored andcommitted
Check that custom session path exists, create if not, if can't create then use default (#19431)
1 parent a056d94 commit 7793ccf

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

administrator/components/com_config/Model/ApplicationModel.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Joomla\CMS\Access\Access;
1515
use Joomla\CMS\Access\Rules;
1616
use Joomla\CMS\Component\ComponentHelper;
17+
use Joomla\CMS\Filesystem\Folder;
18+
use Joomla\CMS\Filesystem\Path;
1719
use Joomla\CMS\MVC\Model\FormModel;
1820
use Joomla\CMS\Table\Asset;
1921
use Joomla\CMS\Table\Table;
@@ -315,6 +317,43 @@ public function save($data)
315317
}
316318
}
317319

320+
// Ensure custom session file path exists or try to create it if changed
321+
if (!empty($data['session_filesystem_path']))
322+
{
323+
$currentPath = $prev['session_filesystem_path'] ?? null;
324+
325+
if ($currentPath)
326+
{
327+
$currentPath = Path::clean($currentPath);
328+
}
329+
330+
$data['session_filesystem_path'] = Path::clean($data['session_filesystem_path']);
331+
332+
if ($currentPath !== $data['session_filesystem_path'])
333+
{
334+
if (!Folder::exists($data['session_filesystem_path']) && !Folder::create($data['session_filesystem_path']))
335+
{
336+
try
337+
{
338+
\JLog::add(
339+
\JText::sprintf('COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', $data['session_filesystem_path']),
340+
\JLog::WARNING,
341+
'jerror'
342+
);
343+
}
344+
catch (\RuntimeException $logException)
345+
{
346+
$app->enqueueMessage(
347+
\JText::sprintf('COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', $data['session_filesystem_path']),
348+
'warning'
349+
);
350+
}
351+
352+
$data['session_filesystem_path'] = $currentPath;
353+
}
354+
}
355+
}
356+
318357
// Set the shared session configuration
319358
if (isset($data['shared_session']))
320359
{

administrator/language/en-GB/en-GB.com_config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND="The Global Configuration extension
1919
COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE="Could not make configuration.php unwritable."
2020
COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE="Could not make configuration.php writable."
2121
COM_CONFIG_ERROR_CUSTOM_CACHE_PATH_NOTWRITABLE_USING_DEFAULT="The folder at %1$s is not writable and cannot be used for the cache, using the default %2$s instead."
22+
COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT="The folder at %s is not writable and cannot be used to store session data, the default PHP path will be used instead."
2223
COM_CONFIG_ERROR_HELPREFRESH_ERROR_STORE="The new Help Sites list could not be saved."
2324
COM_CONFIG_ERROR_HELPREFRESH_FETCH="The current Help Sites list could not be fetched from the remote server."
2425
COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND="The asset for global configuration could not be found. Permissions have not been saved."

0 commit comments

Comments
 (0)