{"action":"created","issue":{"url":"https://api.github.com/repos/mautic/mautic/issues/4482","repository_url":"https://api.github.com/repos/mautic/mautic","labels_url":"https://api.github.com/repos/mautic/mautic/issues/4482/labels{/name}","comments_url":"https://api.github.com/repos/mautic/mautic/issues/4482/comments","events_url":"https://api.github.com/repos/mautic/mautic/issues/4482/events","html_url":"https://github.com/mautic/mautic/pull/4482","id":244561677,"number":4482,"title":"Bugfix - Update segment excluding/including membership","user":{"login":"virlatinus","id":2924026,"avatar_url":"https://avatars3.githubusercontent.com/u/2924026?v=4","gravatar_id":"","url":"https://api.github.com/users/virlatinus","html_url":"https://github.com/virlatinus","followers_url":"https://api.github.com/users/virlatinus/followers","following_url":"https://api.github.com/users/virlatinus/following{/other_user}","gists_url":"https://api.github.com/users/virlatinus/gists{/gist_id}","starred_url":"https://api.github.com/users/virlatinus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/virlatinus/subscriptions","organizations_url":"https://api.github.com/users/virlatinus/orgs","repos_url":"https://api.github.com/users/virlatinus/repos","events_url":"https://api.github.com/users/virlatinus/events{/privacy}","received_events_url":"https://api.github.com/users/virlatinus/received_events","type":"User","site_admin":false},"labels":[{"id":154414515,"url":"https://api.github.com/repos/mautic/mautic/labels/Bug","name":"Bug","color":"e11d21","default":false},{"id":557054577,"url":"https://api.github.com/repos/mautic/mautic/labels/P0","name":"P0","color":"fbca04","default":false},{"id":197691504,"url":"https://api.github.com/repos/mautic/mautic/labels/Ready%20To%20Test","name":"Ready To Test","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":{"login":"dongilbert","id":718028,"avatar_url":"https://avatars2.githubusercontent.com/u/718028?v=4","gravatar_id":"","url":"https://api.github.com/users/dongilbert","html_url":"https://github.com/dongilbert","followers_url":"https://api.github.com/users/dongilbert/followers","following_url":"https://api.github.com/users/dongilbert/following{/other_user}","gists_url":"https://api.github.com/users/dongilbert/gists{/gist_id}","starred_url":"https://api.github.com/users/dongilbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dongilbert/subscriptions","organizations_url":"https://api.github.com/users/dongilbert/orgs","repos_url":"https://api.github.com/users/dongilbert/repos","events_url":"https://api.github.com/users/dongilbert/events{/privacy}","received_events_url":"https://api.github.com/users/dongilbert/received_events","type":"User","site_admin":false},"assignees":[{"login":"dongilbert","id":718028,"avatar_url":"https://avatars2.githubusercontent.com/u/718028?v=4","gravatar_id":"","url":"https://api.github.com/users/dongilbert","html_url":"https://github.com/dongilbert","followers_url":"https://api.github.com/users/dongilbert/followers","following_url":"https://api.github.com/users/dongilbert/following{/other_user}","gists_url":"https://api.github.com/users/dongilbert/gists{/gist_id}","starred_url":"https://api.github.com/users/dongilbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dongilbert/subscriptions","organizations_url":"https://api.github.com/users/dongilbert/orgs","repos_url":"https://api.github.com/users/dongilbert/repos","events_url":"https://api.github.com/users/dongilbert/events{/privacy}","received_events_url":"https://api.github.com/users/dongilbert/received_events","type":"User","site_admin":false},{"login":"escopecz","id":1235442,"avatar_url":"https://avatars2.githubusercontent.com/u/1235442?v=4","gravatar_id":"","url":"https://api.github.com/users/escopecz","html_url":"https://github.com/escopecz","followers_url":"https://api.github.com/users/escopecz/followers","following_url":"https://api.github.com/users/escopecz/following{/other_user}","gists_url":"https://api.github.com/users/escopecz/gists{/gist_id}","starred_url":"https://api.github.com/users/escopecz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/escopecz/subscriptions","organizations_url":"https://api.github.com/users/escopecz/orgs","repos_url":"https://api.github.com/users/escopecz/repos","events_url":"https://api.github.com/users/escopecz/events{/privacy}","received_events_url":"https://api.github.com/users/escopecz/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/mautic/mautic/milestones/34","html_url":"https://github.com/mautic/mautic/milestone/34","labels_url":"https://api.github.com/repos/mautic/mautic/milestones/34/labels","id":2616259,"number":34,"title":"2.9.1","description":"","creator":{"login":"alanhartless","id":63312,"avatar_url":"https://avatars3.githubusercontent.com/u/63312?v=4","gravatar_id":"","url":"https://api.github.com/users/alanhartless","html_url":"https://github.com/alanhartless","followers_url":"https://api.github.com/users/alanhartless/followers","following_url":"https://api.github.com/users/alanhartless/following{/other_user}","gists_url":"https://api.github.com/users/alanhartless/gists{/gist_id}","starred_url":"https://api.github.com/users/alanhartless/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alanhartless/subscriptions","organizations_url":"https://api.github.com/users/alanhartless/orgs","repos_url":"https://api.github.com/users/alanhartless/repos","events_url":"https://api.github.com/users/alanhartless/events{/privacy}","received_events_url":"https://api.github.com/users/alanhartless/received_events","type":"User","site_admin":false},"open_issues":16,"closed_issues":6,"state":"open","created_at":"2017-07-01T15:26:02Z","updated_at":"2017-07-21T14:30:06Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2017-07-21T04:32:00Z","updated_at":"2017-07-21T16:03:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mautic/mautic/pulls/4482","html_url":"https://github.com/mautic/mautic/pull/4482","diff_url":"https://github.com/mautic/mautic/pull/4482.diff","patch_url":"https://github.com/mautic/mautic/pull/4482.patch"},"body":"| Q  | A\r\n| --- | ---\r\n| Bug fix? | Y\r\n| New feature? | N\r\n| Related user documentation PR URL | N/A\r\n| Related developer documentation PR URL | N/A\r\n| Issues addressed (#s or URLs) | N/A\r\n| BC breaks? | N/A\r\n| Deprecations? | N/A\r\n\r\n#### Description:\r\nWhen there are two or more segments with filters that match a contact but one of those segments includes a filter to exclude the other segments that also match, it will be after the next `mautic:segment:update` command execution that the segments will be updated correctly.\r\n\r\nThis is because right now the including/excluding filters work by joining with the `lead_lists_leads` table and using `EXISTS` or `NOR EXISTS` SQL operators. But because the segments have not been populated yet, the subqueries return no results until the next mautic:segment:update command is executed.\r\n\r\nThis only happens if the segment with the including/excluding filter is updated before the other segments (the order in which the segments are updated is alphabetical)\r\n\r\nThis PR fixes that behaviour by taking the filters in the including/excluding segments and then appending those filters to the segment SQL query at once. (If it is an excluding segment it negates the filters before appending them). That way it doesn't matter if the contact already exists or not in the segments.\r\n\r\n#### Steps to reproduce the bug:\r\n1. Create a contact with First Name = Mario\r\n2. Create a segment **s2** with filter: First Name = Mario\r\n3. Create a segment **s1** with filters:\r\n  First Name like m%\r\n  Segment membership excluding **s2**\r\n4. Run the command `php app/console m:s:u`\r\n5. Check the contacts segments, it will belong to **s1** and **s2** because the contact still doesn't belong to **s2** and the first name begins with m.\r\n6. Run the command `php app/console m:s:u` again\r\n7. Check the contact segments, it will belong only to **s2**\r\n\r\n#### Steps to test this PR:\r\n1. Apply this PR\r\n2. Delete the segments **s1** and **s2** that were created previously\r\n2. Follow the steps to reproduce the bug from step 2 to step 4\r\n3. Check the contact segments, it will belong only to **s2**\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/mautic/mautic/issues/comments/317041538","html_url":"https://github.com/mautic/mautic/pull/4482#issuecomment-317041538","issue_url":"https://api.github.com/repos/mautic/mautic/issues/4482","id":317041538,"user":{"login":"virlatinus","id":2924026,"avatar_url":"https://avatars3.githubusercontent.com/u/2924026?v=4","gravatar_id":"","url":"https://api.github.com/users/virlatinus","html_url":"https://github.com/virlatinus","followers_url":"https://api.github.com/users/virlatinus/followers","following_url":"https://api.github.com/users/virlatinus/following{/other_user}","gists_url":"https://api.github.com/users/virlatinus/gists{/gist_id}","starred_url":"https://api.github.com/users/virlatinus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/virlatinus/subscriptions","organizations_url":"https://api.github.com/users/virlatinus/orgs","repos_url":"https://api.github.com/users/virlatinus/repos","events_url":"https://api.github.com/users/virlatinus/events{/privacy}","received_events_url":"https://api.github.com/users/virlatinus/received_events","type":"User","site_admin":false},"created_at":"2017-07-21T16:03:27Z","updated_at":"2017-07-21T16:03:27Z","body":"What are the filters for the All K*s segment? Are you sure they don't conflict with the \"First Name like m%\" condition?"}}
{"actor":{"display_login":"virlatinus"}}