Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relative date segment filter and add support for datetime relative filter #8044

Open
wants to merge 4 commits into
base: staging
from

Conversation

@kuzmany
Copy link
Contributor

kuzmany commented Oct 30, 2019

Please be sure you are submitting this against the staging branch.

Q A
Bug fix?
New feature?
Automated tests included?
Related user documentation PR URL
Related developer documentation PR URL
Issues addressed (#s or URLs) #7967
BC breaks?
Deprecations?

Description:

This PR is ongoing solution to relative date segment filter issue.
This PR require before testing merge this #7752
This PR continue on un-resolving issue write by core member team @anton-vlasenko #7967
This PR also include support for datetime in segment filter resolved in already closed #7122

Solution is easy:

Before DateTimeHelper.php load localTimezone from server date_default_timezone_get
After load from local.php

https://github.com/mautic/mautic/pull/8044/files#diff-36ed844b46ee77f22d7c9a23897b4053R58

Steps to reproduce the bug:

Apply this fix first #7752

  1. Setup local timezone on server to UTC
  2. Setup timezone in Mautic configuration or in local.php to Paris
  3. Create two custom field date and datetime format
  4. Then create segment filter with both fields and relative dates
  • equal = 2 days
  • greater/equal 2 days

image

  1. Run segment rebuild
  2. Check sql query in logs on your dev enviroment (or in Mautibox logs)
  3. If today is 30. 10. 2019, you should see

SELECT count(leadIdPrimary) count, max(leadIdPrimary) maxId, min(leadIdPrimary) minId FROM (SELECT DISTINCT orp.lead_id as leadIdPrimary, orp.lead_id as id, orp.leadlist_id FROM lead_lists_leads orp LEFT JOIN (SELECT l.id FROM leads l WHERE ((l.custom_date LIKE '2019-10-31%') AND (l.custom_date_time LIKE '2019-11-01%')) OR ((l.custom_date >= '2019-10-31') AND (l.custom_date_time >= '2019-11-01'))) members ON members.id=orp.lead_id WHERE (orp.leadlist_id = 9) AND (members.id IS NULL) AND (orp.manually_added = '0')) sss

Steps to test this PR:

  1. Apply this PR and don't forget apply #7752
  2. Run segment:rebuild
  3. You should see now

SELECT count(leadIdPrimary) count, max(leadIdPrimary) maxId, min(leadIdPrimary) minId FROM (SELECT DISTINCT orp.lead_id as leadIdPrimary, orp.lead_id as id, orp.leadlist_id FROM lead_lists_leads orp LEFT JOIN (SELECT l.id FROM leads l WHERE ((l.custom_date LIKE '2019-11-01%') AND (l.custom_date_time LIKE '2019-11-01%')) OR ((l.custom_date >= '2019-11-01') AND (l.custom_date_time >= '2019-11-01 11:48:12'))) members ON members.id=orp.lead_id WHERE (orp.leadlist_id = 9) AND (members.id IS NULL) AND (orp.manually_added = '0')) sss

  • l.custom_date LIKE '2019-11-01%' - ✔️
  • l.custom_date_time LIKE '2019-11-01%' - ✔️
  • l.custom_date >= '2019-11-01' - ✔️
  • l.custom_date_time >= '2019-11-01 11:48:12' ✔️

This is what we expect

List deprecations along with the new alternative:

List backwards compatibility breaks:

@kuzmany kuzmany added this to the 2.16.0 milestone Oct 30, 2019
@kuzmany kuzmany added WIP and removed Ready To Test labels Oct 30, 2019
kuzmany added 3 commits Oct 30, 2019
@kuzmany kuzmany added Ready To Test and removed WIP labels Oct 30, 2019
@kuzmany kuzmany changed the title Fix relative date segment filter (like -3 days/+3 days) Fix relative date segment filter and add support for datetime relative filter Oct 30, 2019
Copy link

florentpetitjean left a comment

Fix is working and date displayed in report are correct. Thanks for this fix one again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.