MDL-30811 output: Add support for session notifications
[moodle.git] / lib / classes / session / manager.php
index d565a22..4dd205e 100644 (file)
@@ -157,10 +157,18 @@ class manager {
     public static function init_empty_session() {
         global $CFG;
 
     public static function init_empty_session() {
         global $CFG;
 
+        // Backup notifications. These should be preserved across session changes until the user fetches and clears them.
+        $notifications = [];
+        if (isset($GLOBALS['SESSION']->notifications)) {
+            $notifications = $GLOBALS['SESSION']->notifications;
+        }
         $GLOBALS['SESSION'] = new \stdClass();
 
         $GLOBALS['USER'] = new \stdClass();
         $GLOBALS['USER']->id = 0;
         $GLOBALS['SESSION'] = new \stdClass();
 
         $GLOBALS['USER'] = new \stdClass();
         $GLOBALS['USER']->id = 0;
+
+        // Restore notifications.
+        $GLOBALS['SESSION']->notifications = $notifications;
         if (isset($CFG->mnet_localhost_id)) {
             $GLOBALS['USER']->mnethostid = $CFG->mnet_localhost_id;
         } else {
         if (isset($CFG->mnet_localhost_id)) {
             $GLOBALS['USER']->mnethostid = $CFG->mnet_localhost_id;
         } else {