Notification Messages not showing

Hello All,

I’m attempting to have a notification appear after a function runs in my plugin. I have the function run, and then I have the following code:


		$notification                = new Notification("The cache has been cleared!");
		$notification->context      = Notification::CONTEXT_SUCCESS;
		$notification->type           = Notification::TYPE_TOAST;
		Notification\Manager::notify('General_CacheCleared', $notification);
		
		Url::redirectToReferrer();

But I’m not seeing the message appear. This plugin adds a link to the top of all screens (cacheBuster plugin), so the message would appear on any page. Is it wrong to assume that the notify() function is globally enabled, ie I should just be able to do the above ::notify and have it recognized?

If not, any idea why this message would not be appearing?

Hi JohnSka7,

your assumption is right, it should work. The problem is when you delete all the directories within the tmp folder you also delete all existing sessions. Causing a new session to start on the next page load and losing a previous persisted notification as each notification is stored in the session until we show it. Maybe you can exclude the session directory when cleaning the cache?

BTW:
Had a quick look at your plugin. I think you can also use this method to clean the directories recursively instead of manually doing it using “rmdir” and “rm -rf”: http://developer.piwik.org/api-reference/Piwik/Filesystem#unlinkrecursive . This should work on all operating systems.

Nice work!

Thomas,

Thanks a bunch! I updated the code so that it will ignore the sessions dir, and the messages now appear. Never got that far into the API docs either, so thanks for pointing out the filesystem methods. I updated the code to use that and it looks good on my end, hopefully some windows folks will chime in if doesn’t work for them.