Skip to content

Commit 363bac7

Browse files
authored
Merge pull request #11 from integer-net/keep-session-open-when-messages-exist
Keep session open if messages are queued
2 parents 0a54a5c + 1c8d172 commit 363bac7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Plugin/SectionLoadControllerPlugin.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,31 @@ public function __construct(
4040
GenericSession $genericSession,
4141
array $additionalSessions = []
4242
) {
43-
/*
43+
/**
4444
* This is earliest moment where we can close the session,
4545
* after we initialised all sessions we think will be needed
4646
*
4747
* Should there ever be an additional Session-type that's needed,
4848
* nothing breaks, but the new session-type will open a new session
4949
* and therefore block other requests
5050
*/
51-
$genericSession->writeClose();
51+
$hasMessages = 0;
52+
foreach ($additionalSessions as $session) {
53+
if ($session instanceOf \Magento\Framework\Message\Session){
54+
// @param \Magento\Framework\Message\Collection $messageCollection
55+
foreach ($session->getData() as $messageCollection){
56+
$hasMessages += count($messageCollection->getItems());
57+
}
58+
}
59+
}
60+
/**
61+
* We've checked if there were no messages in the current session
62+
* because the session then needs to stay open to allow the messages
63+
* to be removed after loading them
64+
*/
65+
if ($hasMessages === 0 ) {
66+
$genericSession->writeClose();
67+
}
5268
}
5369

5470
//phpcs:ignore MEQP2.Classes.PublicNonInterfaceMethods.PublicMethodFound

0 commit comments

Comments
 (0)