Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2016-02-01 17:52:20 +0300
committerThomas Steur <thomas.steur@gmail.com>2016-02-13 12:28:03 +0300
commitbe4ff3c091cff13af49041b59f12f97a466b0040 (patch)
tree8d242db72c0cd08cee26d26a229263ff765bc064 /core/Notification
parente3c9440292d420dd9409d45bd2870976c8436e3b (diff)
show error message in case we deactivate a plugin because of missing dependencies
Diffstat (limited to 'core/Notification')
-rw-r--r--core/Notification/Manager.php59
1 files changed, 44 insertions, 15 deletions
diff --git a/core/Notification/Manager.php b/core/Notification/Manager.php
index e7eafec49e..bdf1f130dd 100644
--- a/core/Notification/Manager.php
+++ b/core/Notification/Manager.php
@@ -24,6 +24,11 @@ class Manager
private static $session = null;
/**
+ * @var Notification[]
+ */
+ private static $notifications = array();
+
+ /**
* Posts a notification that will be shown in Piwik's status bar. If a notification with the same ID
* has been posted and has not been closed/removed, it will be replaced with `$notification`.
*
@@ -105,12 +110,21 @@ class Manager
private static function addNotification($id, Notification $notification)
{
- if (!self::isEnabled()) {
- return;
- }
+ self::saveNotificationAcrossUiRequestsIfNeeded($id, $notification);
- $session = static::getSession();
- $session->notifications[$id] = $notification;
+ // we store all kinda notifications here so in case the session is not enabled or disabled later there is still
+ // a chance it gets delivered to the UI during the same request.
+ self::$notifications[$id] = $notification;
+ }
+
+ private static function saveNotificationAcrossUiRequestsIfNeeded($id, Notification $notification)
+ {
+ $isPersistent = $notification->type === Notification::TYPE_PERSISTENT;
+
+ if ($isPersistent && self::isSessionEnabled()) {
+ $session = static::getSession();
+ $session->notifications[$id] = $notification;
+ }
}
private static function removeOldestNotificationsIfThereAreTooMany()
@@ -126,28 +140,43 @@ class Manager
private static function getAllNotifications()
{
- if (!self::isEnabled()) {
+ if (!self::isSessionEnabled()) {
return array();
}
- $session = static::getSession();
+ $notifications = self::$notifications;
+
+ foreach ($notifications as $id => $notification) {
+ // we copy them over to the session if possible and persist it in case the session was not yet
+ // writable / enabled at the time the notification was added.
+ self::saveNotificationAcrossUiRequestsIfNeeded($id, $notification);
+ }
- return $session->notifications;
+ if (self::isSessionEnabled()) {
+ $session = static::getSession();
+ foreach ($session->notifications as $id => $notification) {
+ $notifications[$id] = $notification;
+ }
+ }
+
+ return $notifications;
}
private static function removeNotification($id)
{
- if (!self::isEnabled()) {
- return;
+ if (array_key_exists($id, self::$notifications)) {
+ unset(self::$notifications[$id]);
}
- $session = static::getSession();
- if (array_key_exists($id, $session->notifications)) {
- unset($session->notifications[$id]);
+ if (self::isSessionEnabled()) {
+ $session = static::getSession();
+ if (array_key_exists($id, $session->notifications)) {
+ unset($session->notifications[$id]);
+ }
}
}
- private static function isEnabled()
+ private static function isSessionEnabled()
{
return Session::isWritable() && Session::isReadable();
}
@@ -161,7 +190,7 @@ class Manager
static::$session = new SessionNamespace('notification');
}
- if (empty(static::$session->notifications) && self::isEnabled()) {
+ if (empty(static::$session->notifications) && self::isSessionEnabled()) {
static::$session->notifications = array();
}