I have set my timestamp as “Australia Melbourne” i.e. UTC +11
When I look at a contact’s history, the event timestamps are displayed correctly (i.e. correct timezone)
However the “Last active” column in the contact listing page seems to utilise a different timezone.
Any ideas?
Excellent. Thanks @ninjoan I updated the file mentioned and “last active” is now showing the correct timezone.
Same here. Updated the page code and it still shows incorrectly. I suspect it is also the culprit in my ability to not send campaign email.
Can you run sql? try select now();
to see what mysql reports back. If not correct time, you can ask your host to set it up… Assuming you’ve looked through the forum and no one else is having similar issues.
Yep, that returns yet another timezone (Chicago US, UTC -5) which is where the server is located. This is as expected.
see if your sessions are the same, in sql:
SELECT @@global.time_zone, @@session.time_zone;
it’s possible to change session time zone with:
SET time_zone = timezone;
One quick way to set this might be using triggers on updates… just a thought.
@balkee thanks for your time on this.
Database uses system time (global & session timezones)
I am denied from changing timezone globally.
I changed the session timezone, but this has no effect (as far as my issue goes).
What’s strange is that contacts’ event timestamps are displayed correctly.
But things like “Last active” column and the default (pre-populated) note timestamps are consistently incorrect.
Don’t know if this helps, but I’m seeing the same error.
If you look at a contact’s Event Timestamps, they’re based on the timezone that I’ve set in Mautic.
If I sort the events, the timezone changes to UTC.
@yalcin no problem. I’m not sure what @jwrobbs is saying, is it a data issue or display? So why don’t you select from contacts and see what the actual timestamps are on the records – rule out if it’s a display issue. The session timezone change is only valid through that session. A simple fix could be creating a trigger on update of the contacts, so the trigger would set the timezone and it would be valid until it updates. This is worth a try, wish I had time to implement and test it. If you want to try, just look up creating db triggers, you’ll create a trigger for insert and update on contacts table. And test in your test env, don’t run in production.
@yalcin @jwrobbs Problem solved here https://github.com/mautic/mautic/pull/2397
Thanks @ninjoan
Now to figure out github
Go to your Mautic Folder and find this file
app/bundles/CoreBundle/EventListener/CoreSubscriber.php
And remplace with this code.
[code]<?php
/**
- @package Mautic
- @copyright 2014 Mautic Contributors. All rights reserved.
- @author Mautic
- @link http://mautic.org
-
@license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
/
namespace MauticCoreBundleEventListener;
use MauticCoreBundleControllerMauticController;
use MauticCoreBundleCoreEvents;
use MauticCoreBundleEventMenuEvent;
use MauticCoreBundleEventRouteEvent;
use MauticCoreBundleEventIconEvent;
use MauticApiBundleEvent as ApiEvents;
use MauticInstallBundleControllerInstallController;
use MauticUserBundleEntityUser;
use MauticUserBundleEventLoginEvent;
use MauticUserBundleUserEvents;
use SymfonyComponentHttpKernelEventFilterControllerEvent;
use SymfonyComponentHttpKernelEventGetResponseEvent;
use SymfonyComponentHttpKernelKernelEvents;
use SymfonyComponentSecurityHttpEventInteractiveLoginEvent;
use SymfonyComponentSecurityHttpSecurityEvents;
/* - Class CoreSubscriber
/
class CoreSubscriber extends CommonSubscriber
{
/*-
{@inheritdoc}
/
public static function getSubscribedEvents()
{
return array(
KernelEvents::CONTROLLER => array(‘onKernelController’, 0),
KernelEvents::REQUEST => [
[‘onKernelRequestSetTimezone’, 100],
[‘onKernelRequestSetLocale’, 15], // Must be 15 to load after Symfony’s default Locale listener
[‘onKernelRequestAddGlobalJS’, 0]
],
CoreEvents::BUILD_MENU => array(‘onBuildMenu’, 9999),
CoreEvents::BUILD_ROUTE => array(‘onBuildRoute’, 0),
CoreEvents::FETCH_ICONS => array(‘onFetchIcons’, 9999),
SecurityEvents::INTERACTIVE_LOGIN => array(‘onSecurityInteractiveLogin’, 0)
);
}
/* -
Set timezone
-
@param GetResponseEvent $event
*/
public function onKernelRequestSetTimezone(GetResponseEvent $event)
{$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
// Set date/time
date_default_timezone_set($request->getSession()->get(’_timezone’, $this->params[‘default_timezone’]));
// Set a cookie with session name for filemanager
$sessionName = $request->cookies->get(‘mautic_session_name’);
if ($sessionName != session_name()) {
/** @var MauticCoreBundleHelperCookieHelper $cookieHelper /
$cookieHelper = $this->factory->getHelper(‘cookie’);
$cookieHelper->setCookie(‘mautic_session_name’, session_name(), null);
}
}
/* -
Set default locale
-
@param GetResponseEvent $event
-
@return void
/
public function onKernelRequestSetLocale(GetResponseEvent $event)
{
// Set the user’s default locale
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
// Set locale
if ($locale = $request->attributes->get(’_locale’)) {
$request->getSession()->set(’_locale’, $locale);
} else {
$request->setLocale($request->getSession()->get(’_locale’, $this->params[‘locale’]));
}
}
/* -
Add mauticForms in js script tag for Froala
-
@param GetResponseEvent $event
/
public function onKernelRequestAddGlobalJS(GetResponseEvent $event)
{
if (defined(‘MAUTIC_INSTALLER’)) {
return;
}
$list = $this->factory->getEntityManager()->getRepository(‘MauticFormBundle:Form’)->getSimpleList();
$mauticForms = json_encode($list, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT);
$this->factory->getHelper(‘template.assets’)->addScriptDeclaration(“var mauticForms = {$mauticForms};”);
}
/* -
Set vars on login
-
@param InteractiveLoginEvent $event
-
@return void
/
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
{
if (defined(‘MAUTIC_INSTALLER’)) {
return;
}
$session = $event->getRequest()->getSession();
$securityContext = $this->factory->getSecurityContext();
if ($securityContext->isGranted(‘IS_AUTHENTICATED_FULLY’) || $securityContext->isGranted(‘IS_AUTHENTICATED_REMEMBERED’)) {
$user = $event->getAuthenticationToken()->getUser();
//set a session var for filemanager to know someone is logged in
$session->set(‘mautic.user’, $user->getId());
//mark the user as last logged in
$user = $this->factory->getUser();
if ($user instanceof User) {
/* @var MauticUserBundleModelUserModel $userModel /
$userModel = $this->factory->getModel(‘user’);
$userModel->setOnlineStatus(‘online’);
$userModel->getRepository()->setLastLogin($user);
// Set the timezone and locale in session while we have it since Symfony dispatches the onKernelRequest prior to the
// firewall setting the known user
$tz = $user->getTimezone();
if (empty($tz)) {
$tz = $this->params[‘default_timezone’];
}
$session->set(’_timezone’, $tz);
$locale = $user->getLocale();
if (empty($locale)) {
$locale = $this->params[‘locale’];
}
$session->set(’_locale’, $locale);
}
//dispatch on login events
$dispatcher = $this->factory->getDispatcher();
if ($dispatcher->hasListeners(UserEvents::USER_LOGIN)) {
$event = new LoginEvent($this->factory->getUser());
$dispatcher->dispatch(UserEvents::USER_LOGIN, $event);
}
} else {
$session->remove(‘mautic.user’);
}
//set a couple variables used by filemanager
$session->set(‘mautic.docroot’, $event->getRequest()->server->get(‘DOCUMENT_ROOT’));
$session->set(‘mautic.basepath’, $event->getRequest()->getBasePath());
$session->set(‘mautic.imagepath’, $this->factory->getParameter(‘image_path’));
}
/* -
Populates namespace, bundle, controller, and action into request to be used throughout application
-
@param FilterControllerEvent $event
-
@return void
/
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
//only affect Mautic controllers
if ($controller[0] instanceof MauticController) {
$request = $event->getRequest();
//also set the request for easy access throughout controllers
$controller[0]->setRequest($request);
//set the factory for easy use access throughout the controllers
$controller[0]->setFactory($this->factory);
//run any initialize functions
$controller[0]->initialize($event);
//update the user’s activity marker
if (!($controller[0] instanceof InstallController) && !defined(‘MAUTIC_ACTIVITY_CHECKED’) && !defined(‘MAUTIC_INSTALLER’)) {
//prevent multiple updates
$user = $this->factory->getUser();
//slight delay to prevent too many updates
//note that doctrine will return in current timezone so we do not have to worry about that
$delay = new DateTime();
$delay->setTimestamp(strtotime(‘2 minutes ago’));
/* @var MauticUserBundleModelUserModel $userModel /
$userModel = $this->factory->getModel(‘user’);
if ($user instanceof User && $user->getLastActive() < $delay && $user->getId()) {
$userModel->getRepository()->setLastActive($user);
}
$session = $this->factory->getSession();
$delay = new DateTime();
$delay->setTimestamp(strtotime(‘15 minutes ago’));
$lastOnlineStatusCleanup = $session->get(‘mautic.online.status.cleanup’, $delay);
if ($lastOnlineStatusCleanup <= $delay) {
$userModel->getRepository()->updateOnlineStatuses();
$session->set(‘mautic.online.status.cleanup’, new DateTime());
}
define(‘MAUTIC_ACTIVITY_CHECKED’, 1);
}
}
}
/* -
@param MenuEvent $event
-
@return void
/
public function onBuildMenu(MenuEvent $event)
{
$this->buildMenu($event);
}
/* -
@param RouteEvent $event
-
@return void
/
public function onBuildRoute(RouteEvent $event)
{
$this->buildRoute($event);
}
/* -
@param IconEvent $event
-
@return void
*/
public function onFetchIcons(IconEvent $event)
{
$this->buildIcons($event);
}
}[/code]
-
Thanks, @ninjoan!
Hello,
I’ve made change in the file but…
I’ve cleared cache (mautic and firefox and Chrome)
My timezone is Europe/Paris in settings and in my account, in my php.ini (php 7.10)
I’ve formated time like H:i T
-
In “CONTACTS”, anonymous, in last active column, the display is
Aujourd’hui, 7:50 am
And the label is :
22 september 2016 07.50 CEST
The time in “Paris” is 07:50 then the display must be 07:50 CEST -
In “CONTACTS”, contact identified , in event timestamp column, the display is
Hier, 1:30 pm
The time in “Paris” must be Hier, 13:30 CEST -
I see another issue in upcoming emails on the dashboard or in a contact identified :
The display is :
22 september 2016 11:26 CEST
BUT : 11:26 is UTC time
I have this problem since i upgraded to 2.1.1
I have set my timestamp as “Australia Melbourne” i.e. UTC +11
When I look at a contact’s history, the event timestamps are displayed correctly (i.e. correct timezone)
However the “Last active” column in the contact listing page seems to utilise a different timezone.
Any ideas?
I haven’t had this issue, but I would make sure both the server timezone and mautic settings are the same. Example setting timezone on your server:
cp /usr/share/zoneinfo/America/New_York /etc/localtime
As a precaution, also restart mysql and web server, clear the cache.
Thanks for the tip.
I’m n a shared host, no CLI
I cleared the cache, but can’t restart the servers (shared).
Prior to 2.1.1 upgrade, I was running 1.3.1 on the same server, and the timezone settings never gave me grief.
Something strange is happening.
Hi,
Upgraded to 2.2.0 have solved some issues with timezone but…
Last active in contact list have wrong timezone yet