Skip to content

Commit

Permalink
Check that custom session path exists, create if not, if can't create…
Browse files Browse the repository at this point in the history
… then use default (#19431)
  • Loading branch information
Michael Babker authored and wilsonge committed Aug 8, 2018
1 parent a056d94 commit 7793ccf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions administrator/components/com_config/Model/ApplicationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Joomla\CMS\Access\Access;
use Joomla\CMS\Access\Rules;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\MVC\Model\FormModel;
use Joomla\CMS\Table\Asset;
use Joomla\CMS\Table\Table;
Expand Down Expand Up @@ -315,6 +317,43 @@ public function save($data)
}
}

// Ensure custom session file path exists or try to create it if changed
if (!empty($data['session_filesystem_path']))
{
$currentPath = $prev['session_filesystem_path'] ?? null;

if ($currentPath)
{
$currentPath = Path::clean($currentPath);
}

$data['session_filesystem_path'] = Path::clean($data['session_filesystem_path']);

if ($currentPath !== $data['session_filesystem_path'])
{
if (!Folder::exists($data['session_filesystem_path']) && !Folder::create($data['session_filesystem_path']))
{
try
{
\JLog::add(
\JText::sprintf('COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', $data['session_filesystem_path']),
\JLog::WARNING,
'jerror'
);
}
catch (\RuntimeException $logException)
{
$app->enqueueMessage(
\JText::sprintf('COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', $data['session_filesystem_path']),
'warning'
);
}

$data['session_filesystem_path'] = $currentPath;
}
}
}

// Set the shared session configuration
if (isset($data['shared_session']))
{
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/en-GB.com_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND="The Global Configuration extension
COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE="Could not make configuration.php unwritable."
COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE="Could not make configuration.php writable."
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."
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."
COM_CONFIG_ERROR_HELPREFRESH_ERROR_STORE="The new Help Sites list could not be saved."
COM_CONFIG_ERROR_HELPREFRESH_FETCH="The current Help Sites list could not be fetched from the remote server."
COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND="The asset for global configuration could not be found. Permissions have not been saved."
Expand Down

0 comments on commit 7793ccf

Please sign in to comment.