Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
2f244f1c
Commit
2f244f1c
authored
Mar 02, 2016
by
Andrew Nicols
Browse files
MDL-30811 core: Initiate notifications on first use only
parent
ce878562
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/classes/notification.php
View file @
2f244f1c
...
@@ -81,6 +81,9 @@ class notification {
...
@@ -81,6 +81,9 @@ class notification {
// Add the notification directly to the session.
// Add the notification directly to the session.
// This will either be fetched in the header, or by JS in the footer.
// This will either be fetched in the header, or by JS in the footer.
if
(
!
isset
(
$SESSION
->
notifications
)
||
!
array
(
$SESSION
->
notifications
))
{
$SESSION
->
notifications
=
[];
}
$SESSION
->
notifications
[]
=
(
object
)
array
(
$SESSION
->
notifications
[]
=
(
object
)
array
(
'message'
=>
$message
,
'message'
=>
$message
,
'type'
=>
$level
,
'type'
=>
$level
,
...
@@ -100,7 +103,7 @@ class notification {
...
@@ -100,7 +103,7 @@ class notification {
}
}
$notifications
=
$SESSION
->
notifications
;
$notifications
=
$SESSION
->
notifications
;
$SESSION
->
notifications
=
[]
;
unset
(
$SESSION
->
notifications
)
;
$renderables
=
[];
$renderables
=
[];
foreach
(
$notifications
as
$notification
)
{
foreach
(
$notifications
as
$notification
)
{
...
...
lib/classes/session/manager.php
View file @
2f244f1c
...
@@ -157,9 +157,8 @@ class manager {
...
@@ -157,9 +157,8 @@ class manager {
public
static
function
init_empty_session
()
{
public
static
function
init_empty_session
()
{
global
$CFG
;
global
$CFG
;
// Backup notifications. These should be preserved across session changes until the user fetches and clears them.
$notifications
=
[];
if
(
isset
(
$GLOBALS
[
'SESSION'
]
->
notifications
))
{
if
(
isset
(
$GLOBALS
[
'SESSION'
]
->
notifications
))
{
// Backup notifications. These should be preserved across session changes until the user fetches and clears them.
$notifications
=
$GLOBALS
[
'SESSION'
]
->
notifications
;
$notifications
=
$GLOBALS
[
'SESSION'
]
->
notifications
;
}
}
$GLOBALS
[
'SESSION'
]
=
new
\
stdClass
();
$GLOBALS
[
'SESSION'
]
=
new
\
stdClass
();
...
@@ -167,8 +166,10 @@ class manager {
...
@@ -167,8 +166,10 @@ class manager {
$GLOBALS
[
'USER'
]
=
new
\
stdClass
();
$GLOBALS
[
'USER'
]
=
new
\
stdClass
();
$GLOBALS
[
'USER'
]
->
id
=
0
;
$GLOBALS
[
'USER'
]
->
id
=
0
;
// Restore notifications.
if
(
!
empty
(
$notifications
))
{
$GLOBALS
[
'SESSION'
]
->
notifications
=
$notifications
;
// Restore notifications.
$GLOBALS
[
'SESSION'
]
->
notifications
=
$notifications
;
}
if
(
isset
(
$CFG
->
mnet_localhost_id
))
{
if
(
isset
(
$CFG
->
mnet_localhost_id
))
{
$GLOBALS
[
'USER'
]
->
mnethostid
=
$CFG
->
mnet_localhost_id
;
$GLOBALS
[
'USER'
]
->
mnethostid
=
$CFG
->
mnet_localhost_id
;
}
else
{
}
else
{
...
...
lib/tests/session_manager_test.php
View file @
2f244f1c
...
@@ -59,7 +59,7 @@ class core_session_manager_testcase extends advanced_testcase {
...
@@ -59,7 +59,7 @@ class core_session_manager_testcase extends advanced_testcase {
\
core\session\manager
::
init_empty_session
();
\
core\session\manager
::
init_empty_session
();
$this
->
assertInstanceOf
(
'stdClass'
,
$SESSION
);
$this
->
assertInstanceOf
(
'stdClass'
,
$SESSION
);
$this
->
assert
Count
(
1
,
(
array
)
$SESSION
);
$this
->
assert
Empty
(
(
array
)
$SESSION
);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$SESSION
);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$SESSION
);
...
@@ -149,7 +149,7 @@ class core_session_manager_testcase extends advanced_testcase {
...
@@ -149,7 +149,7 @@ class core_session_manager_testcase extends advanced_testcase {
$this
->
assertEquals
(
0
,
$USER
->
id
);
$this
->
assertEquals
(
0
,
$USER
->
id
);
$this
->
assertInstanceOf
(
'stdClass'
,
$SESSION
);
$this
->
assertInstanceOf
(
'stdClass'
,
$SESSION
);
$this
->
assert
Count
(
1
,
(
array
)
$SESSION
);
$this
->
assert
Empty
(
(
array
)
$SESSION
);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$SESSION
);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$SESSION
);
...
...
lib/tests/sessionlib_test.php
View file @
2f244f1c
...
@@ -76,7 +76,7 @@ class core_sessionlib_testcase extends advanced_testcase {
...
@@ -76,7 +76,7 @@ class core_sessionlib_testcase extends advanced_testcase {
$this
->
assertSame
(
$PAGE
->
context
,
context_course
::
instance
(
$SITE
->
id
));
$this
->
assertSame
(
$PAGE
->
context
,
context_course
::
instance
(
$SITE
->
id
));
$this
->
assertNotSame
(
$adminsession
,
$SESSION
);
$this
->
assertNotSame
(
$adminsession
,
$SESSION
);
$this
->
assertObjectNotHasAttribute
(
'test1'
,
$SESSION
);
$this
->
assertObjectNotHasAttribute
(
'test1'
,
$SESSION
);
$this
->
assert
Count
(
1
,
(
array
)
$SESSION
);
$this
->
assert
Empty
(
(
array
)
$SESSION
);
$usersession1
=
$SESSION
;
$usersession1
=
$SESSION
;
$SESSION
->
test2
=
true
;
$SESSION
->
test2
=
true
;
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
...
@@ -99,7 +99,7 @@ class core_sessionlib_testcase extends advanced_testcase {
...
@@ -99,7 +99,7 @@ class core_sessionlib_testcase extends advanced_testcase {
$this
->
assertSame
(
$PAGE
->
context
,
context_course
::
instance
(
$SITE
->
id
));
$this
->
assertSame
(
$PAGE
->
context
,
context_course
::
instance
(
$SITE
->
id
));
$this
->
assertNotSame
(
$adminsession
,
$SESSION
);
$this
->
assertNotSame
(
$adminsession
,
$SESSION
);
$this
->
assertNotSame
(
$usersession1
,
$SESSION
);
$this
->
assertNotSame
(
$usersession1
,
$SESSION
);
$this
->
assert
Count
(
1
,
(
array
)
$SESSION
);
$this
->
assert
Empty
(
(
array
)
$SESSION
);
$usersession2
=
$SESSION
;
$usersession2
=
$SESSION
;
$usersession2
->
test3
=
true
;
$usersession2
->
test3
=
true
;
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
...
@@ -123,7 +123,7 @@ class core_sessionlib_testcase extends advanced_testcase {
...
@@ -123,7 +123,7 @@ class core_sessionlib_testcase extends advanced_testcase {
$this
->
assertSame
(
$PAGE
->
context
,
context_course
::
instance
(
$SITE
->
id
));
$this
->
assertSame
(
$PAGE
->
context
,
context_course
::
instance
(
$SITE
->
id
));
$this
->
assertNotSame
(
$adminsession
,
$SESSION
);
$this
->
assertNotSame
(
$adminsession
,
$SESSION
);
$this
->
assertNotSame
(
$usersession1
,
$SESSION
);
$this
->
assertNotSame
(
$usersession1
,
$SESSION
);
$this
->
assert
Count
(
1
,
(
array
)
$SESSION
);
$this
->
assert
Empty
(
(
array
)
$SESSION
);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$_SESSION
[
'SESSION'
]);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$SESSION
);
$this
->
assertSame
(
$GLOBALS
[
'SESSION'
],
$SESSION
);
$this
->
assertSame
(
$GLOBALS
[
'USER'
],
$_SESSION
[
'USER'
]);
$this
->
assertSame
(
$GLOBALS
[
'USER'
],
$_SESSION
[
'USER'
]);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment