Skip to content

Commit

Permalink
Do not start a PHP session when a new comment is added
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 5, 2019
1 parent fdab247 commit 28e4051
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions comments-bundle/src/Resources/contao/classes/Comments.php
Expand Up @@ -293,17 +293,19 @@ protected function renderCommentForm(FrontendTemplate $objTemplate, \stdClass $o
$objTemplate->formId = $strFormId;
$objTemplate->hasError = $doNotSubmit;

$session = System::getContainer()->get('session');
$flashBag = $session->getFlashBag();

// Do not index or cache the page with the confirmation message
if ($_SESSION['TL_COMMENT_ADDED'])
if ($session->isStarted() && $flashBag->has('comment_added'))
{
/** @var PageModel $objPage */
global $objPage;

$objPage->noSearch = 1;
$objPage->cache = 0;

$objTemplate->confirm = $GLOBALS['TL_LANG']['MSC']['com_confirm'];
unset($_SESSION['TL_COMMENT_ADDED']);
$objTemplate->confirm = $flashBag->get('comment_added')[0];
}

// Store the comment
Expand Down Expand Up @@ -415,7 +417,7 @@ protected function renderCommentForm(FrontendTemplate $objTemplate, \stdClass $o
// Pending for approval
if ($objConfig->moderate)
{
$_SESSION['TL_COMMENT_ADDED'] = true;
$flashBag->set('comment_added', $GLOBALS['TL_LANG']['MSC']['com_confirm']);
}
else
{
Expand Down

0 comments on commit 28e4051

Please sign in to comment.