8000 Refactor change stage campaign action to use batches by mohit-rocks · Pull Request #8969 · mautic/mautic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor change stage campaign action to use batches #8969

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

Conversation

mohit-rocks
Copy link
Contributor
@mohit-rocks mohit-rocks commented Jun 29, 2020

closes #8521

Original PR by Alan: #7812

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

Description:

If an email is unpublished or if a contact fails to move a stage, the event triggered a failure that would lead to notifications to users and campaigns being unpublished. This fixes that.

Steps to reproduce the bug:

  1. Create a campaign that sends an email that is delayed by a few minutes
  2. Unpublish the email
  3. Execute the campaign
  4. Notice that the campaign will unpublish
  5. Add a bunch of contacts to a stage
  6. Create a campaign that moves a contact into that same stage
  7. The campaign will unpublish

Steps to test this PR:

  1. Load up this PR
  2. Repeat the above and this time the campaign will not unpublish but the errors will be recorded in the contact's timeline

List deprecations along with the new alternative:

List backwards compatibility breaks:

Prevent unpublished emails from triggering unpublished campaigns.
@TravisBuddy
Copy link

Travis tests have failed

Hey @mohit-rocks,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

2nd Build

View build log

if [ ${TRAVIS_PHP_VERSION:0:3} == "7.3" ]; then composer test -- --coverage-clover=coverage.xml && bash <(curl -s https://codecov.io/bash); else composer test; fi
> bin/phpunit --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist '--coverage-clover=coverage.xml'
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

................EFFFFFF......................................   61 / 1738 (  3%)
.............................................................  122 / 1738 (  7%)
..............E..............................................  183 / 1738 ( 10%)
.............................................................  244 / 1738 ( 14%)
...........................................................SS  305 / 1738 ( 17%)
.............................................................  366 / 1738 ( 21%)
.............................................................  427 / 1738 ( 24%)
..SS.........................................................  488 / 1738 ( 28%)
.............................................................  549 / 1738 ( 31%)
.............................................................  610 / 1738 ( 35%)
.............................................................  671 / 1738 ( 38%)
.............................................................  732 / 1738 ( 42%)
.............................................................  793 / 1738 ( 45%)
...........S.................................................  854 / 1738 ( 49%)
.............................................................  915 / 1738 ( 52%)
.............................................................  976 / 1738 ( 56%)
............................................................. 1037 / 1738 ( 59%)
............................................................. 1098 / 1738 ( 63%)
............................................................. 1159 / 1738 ( 66%)
............................................................. 1220 / 1738 ( 70%)
............................................................. 1281 / 1738 ( 73%)
............................................................. 1342 / 1738 ( 77%)
............................................................. 1403 / 1738 ( 80%)
............................................................. 1464 / 1738 ( 84%)
............................................................. 1525 / 1738 ( 87%)
............................................................. 1586 / 1738 ( 91%)
............................................................. 1647 / 1738 ( 94%)
............................................................. 1708 / 1738 ( 98%)
..............................                                1738 / 1738 (100%)

Time: 14.44 minutes, Memory: 939.00 MB

There were 2 errors:

1) Mautic\CampaignBundle\Tests\Command\ExecuteEventCommandTest::testEventsAreExecutedForInactiveEventWithSingleContact
TypeError: Argument 3 passed to Mautic\StageBundle\EventListener\CampaignSubscriber::__construct() must be an instance of Recurr\Transformer\TranslatorInterface, instance of Symfony\Component\Translation\DataCollectorTranslator given, called in /home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/getMautic_Stage_Campaignbundle_SubscriberService.php on line 8

/home/travis/build/mautic/mautic/app/bundles/StageBundle/EventListener/CampaignSubscriber.php:45
/home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/getMautic_Stage_Campaignbundle_SubscriberService.php:8
/home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/appTestDebugProjectContainer.php:5857
/home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/appTestDebugProjectContainer.php:7933
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/EventDispatcher.php:231
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/EventDispatcher.php:61
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php:129
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:259
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:137
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/EventCollector/EventCollector.php:108
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/EventCollector/EventCollector.php:60
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/EventCollector/EventCollector.php:75
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Executioner/Scheduler/EventScheduler.php:101
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Executioner/Scheduler/EventScheduler.php:359
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Executioner/KickoffExecutioner.php:209
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Executioner/KickoffExecutioner.php:122
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Command/TriggerCampaignCommand.php:372
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Command/TriggerCampaignCommand.php:328
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Command/TriggerCampaignCommand.php:260
/home/travis/build/mautic/mautic/vendor/symfony/console/Command/Command.php:255
/home/travis/build/mautic/mautic/vendor/symfony/console/Application.php:1005
/home/travis/build/mautic/mautic/vendor/symfony/framework-bundle/Console/Application.php:86
/home/travis/build/mautic/mautic/vendor/symfony/console/Application.php:255
/home/travis/build/mautic/mautic/vendor/symfony/framework-bundle/Console/Application.php:74
/home/travis/build/mautic/mautic/vendor/symfony/console/Application.php:148
/home/travis/build/mautic/mautic/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php:190
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Command/ExecuteEventCommandTest.php:20

2) Mautic\CampaignBundle\Tests\Functional\Campaign\DetailsTest::testDetailsPageLoadCorrectly
TypeError: Argument 3 passed to Mautic\StageBundle\EventListener\CampaignSubscriber::__construct() must be an instance of Recurr\Transformer\TranslatorInterface, instance of Symfony\Component\Translation\DataCollectorTranslator given, called in /home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/getMautic_Stage_Campaignbundle_SubscriberService.php on line 8

/home/travis/build/mautic/mautic/app/bundles/StageBundle/EventListener/CampaignSubscriber.php:45
/home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/getMautic_Stage_Campaignbundle_SubscriberService.php:8
/home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/appTestDebugProjectContainer.php:5857
/home/travis/build/mautic/mautic/var/cache/test/ContainerG5hs3jd/appTestDebugProjectContainer.php:7933
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/EventDispatcher.php:231
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/EventDispatcher.php:61
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php:129
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:259
/home/travis/build/mautic/mautic/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:137
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/EventCollector/EventCollector.php:108
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/EventCollector/EventCollector.php:90
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Controller/CampaignController.php:748
/home/travis/build/mautic/mautic/app/bundles/CoreBundle/Controller/AbstractStandardFormController.php:1191
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Controller/CampaignContro
8000
ller.php:193
/home/travis/build/mautic/mautic/app/bundles/CoreBundle/Controller/CommonController.php:449
/home/travis/build/mautic/mautic/vendor/symfony/http-kernel/HttpKernel.php:151
/home/travis/build/mautic/mautic/vendor/symfony/http-kernel/HttpKernel.php:68
/home/travis/build/mautic/mautic/vendor/symfony/http-kernel/Kernel.php:200
/home/travis/build/mautic/mautic/app/AppKernel.php:104
/home/travis/build/mautic/mautic/vendor/symfony/http-kernel/Client.php:68
/home/travis/build/mautic/mautic/vendor/symfony/framework-bundle/Client.php:131
/home/travis/build/mautic/mautic/vendor/symfony/browser-kit/Client.php:318
/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Functional/Campaign/DetailsTest.php:27

--

There were 6 failures:

1) Mautic\CampaignBundle\Tests\Command\TriggerCampaignCommandTest::testCampaignExecutionForAll
Failed asserting that actual size 0 matches expected size 50.

/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php:43

2) Mautic\CampaignBundle\Tests\Command\TriggerCampaignCommandTest::testCampaignExecutionForOne
Failed asserting that actual size 0 matches expected size 1.

/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php:208

3) Mautic\CampaignBundle\Tests\Command\TriggerCampaignCommandTest::testCampaignExecutionForSome
Failed asserting that actual size 0 matches expected size 5.

/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php:367

4) Mautic\CampaignBundle\Tests\Command\ValidateEventCommandTest::testEventsAreExecutedForInactiveEventWithSingleContact
Failed asserting that actual size 0 matches expected size 1.

/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Command/ValidateEventCommandTest.php:35

5) Mautic\CampaignBundle\Tests\Command\ValidateEventCommandTest::testEventsAreExecutedForInactiveEventWithMultipleContact
Failed asserting that actual size 0 matches expected size 3.

/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Command/ValidateEventCommandTest.php:59

6) Mautic\CampaignBundle\Tests\Command\ValidateEventCommandTest::testContactsRemovedFromTheCampaignAreNotExecutedForInactiveEvents
Failed asserting that actual size 0 matches expected size 2.

/home/travis/build/mautic/mautic/app/bundles/CampaignBundle/Tests/Command/ValidateEventCommandTest.php:90

ERRORS!
Tests: 1738, Assertions: 4971, Errors: 2, Failures: 6, Skipped: 5.

Generating code coverage report in Clover XML format ... done

THE ERROR HANDLER HAS CHANGED!
Script bin/phpunit --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist handling the test event returned with error code 2
TravisBuddy Request Identifier: c09b4c50-ba29-11ea-a74d-ef5d1a577ce8

@dennisameling dennisameling added bug Issues or PR's relating to bugs campaigns Anything related to campaigns and campaign builder ready-to-test PR's that are ready to test labels Jun 29, 2020
@dennisameling dennisameling added this to the 3.0.2 milestone Jun 29, 2020
@dennisameling
Copy link
Member

@mohit-rocks Can you please update the tests for Travis to pass? Thanks! 😊

@dennisameling dennisameling added the pending-feedback PR's and issues that are awaiting feedback from the author label Jun 29, 2020
@codecov
Copy link
codecov bot commented Jun 30, 2020

Codecov Re 8000 port

Merging #8969 (d09a530) into 3.3 (965e5f2) will increase coverage by 0.05%.
The diff coverage is 97.14%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.3    #8969      +/-   ##
============================================
+ Coverage     40.22%   40.27%   +0.05%     
- Complexity    34043    34044       +1     
============================================
  Files          1990     1990              
  Lines        105412   105419       +7     
============================================
+ Hits          42404    42460      +56     
+ Misses        63008    62959      -49     
Impacted Files Coverage Δ Complexity Δ
...s/EmailBundle/EventListener/CampaignSubscriber.php 66.08% <0.00%> (ø) 37.00 <0.00> (ø)
...s/StageBundle/EventListener/CampaignSubscriber.php 100.00% <100.00%> (+62.50%) 12.00 <10.00> (+1.00)
app/bundles/CampaignBundle/Entity/Event.php 65.14% <0.00%> (+1.30%) 81.00% <0.00%> (ø%)
app/bundles/LeadBundle/Entity/Lead.php 81.27% <0.00%> (+1.30%) 233.00% <0.00%> (ø%)
app/bundles/CampaignBundle/Event/PendingEvent.php 79.74% <0.00%> (+3.79%) 34.00% <0.00%> (ø%)
app/bundles/StageBundle/Entity/Stage.php 40.54% <0.00%> (+17.56%) 22.00% <0.00%> (ø%)

@RCheesley RCheesley added essential This must be done to close the milestone needs-automated-tests PR's that need automated tests before they can be merged labels Jul 1, 2020
Copy link
Member
@kuzmany kuzmany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works 👍

@kuzmany kuzmany added pending-test-confirmation PR's that require one test before they can be merged and removed ready-to-test PR's that are ready to test labels Jul 17, 2020
@RCheesley
Copy link
Member

@mohit-rocks I tested the bug on mautibox.com/staging to ensure I could replicate it before I applied the PR, and I do not experience the bug you are referencing.

Take a look at this screencast: https://youtu.be/QG6JlcUF2QA

In short:

  • The campaign fires
  • The email and stages which have been unpublished are flagged as an error on the contact activity log - the email one says that the email is not found or unpublished, but the stages one has a generic error (which we should maybe address)
  • The campaigns are not being unpublished per the bug report. There are no notifications either.

@kuzmany were you able to reproduce the bug before you tested the PR?

I think we need another test on this before we can decide whether the PR is required.

@RCheesley RCheesley removed the essential This must be done to close the milestone label Jul 19, 2020
@kuzmany
Copy link
Member
kuzmany commented Jul 20, 2020

@RCheesley Nope, I didn't test reproduce. I just test If both actions works properly after patch PR. I don't think before PR campaign was unpublished, but this PR improve other stuff, and this is reason why I approved.
@alanhartless is author of code, could make it more clear.

@dennisameling dennisameling modified the milestones: 3.0.2, 3.1.0 Jul 21, 2020
@dennisameling
Copy link
Member

Original issue was already fixed in #8907 - nevertheless this PR might still be relevant. Maybe @alanhartless could explain a bit more like @kuzmany mentioned?

@RCheesley
Copy link
Member
8000

Bumping to 3.1.1 due to the lack of response from original poster and PR author.

@RCheesley RCheesley modified the milestones: 3.1.0, 3.1.1 Aug 16, 2020
@RCheesley
Copy link
Member

@cla-bot check

@cla-bot
Copy link
cla-bot bot commented Aug 25, 2020

We require contributors to sign our Contributor License Agreement, and we do not have a record of your signature on file. In order for us to review and merge your code, please head over to https://www.mautic.org/contributor-agreement and complete the form. There may be a short delay while the team add you as a contributor - please be patient :). Any problems contact @RCheesley. CLA has not been signed by @mohit-rocks.

@cla-bot
Copy link
cla-bot bot commented Aug 25, 2020

The CLA Bot has been sent on a mission to check against the latest list and will be back shortly with its findings!

@npracht npracht modified the milestones: 3.2.2, 3.2.3 Dec 21, 2020
@npracht npracht modified the milestones: 3.2.3, 3.2.5, 3.3.1 Jan 15, 2021
@RCheesley RCheesley changed the base branch from 3.2 to features January 19, 2021 17:30
@RCheesley RCheesley modified the milestones: 3.3.1, 3.3.2 Feb 23, 2021
@RCheesley RCheesley changed the base branch from features to 3.3 March 2, 2021 16:55
@RCheesley RCheesley added the has-conflicts Pull requests that cannot be merged until conflicts have been resolved label Mar 11, 2021
@RCheesley
Copy link
Member

@mohit-rocks @kuzmany this one has a conflict to be addressed and I am not sure if we got to the bottom of whether this is needed as a couple of testers were not able to reproduce the issue. @alanhartless could you review the issue and PR and give your thoughts?

@RCheesley RCheesley requested a review from alanhartless March 11, 2021 11:29
@RCheesley RCheesley modified the milestones: 3.3.2, 3.3.3 Mar 15, 2021
Copy link
Member
@escopecz escopecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR refactors the change stage campaign action to work in batches instead of one event at a time. So it improves performance but should not change the behavior.

Other than adding back the translation string this is good to go based on the code review. I did not test it but we (Acquia) use this in production for 2 years and Zdeno tested it.

@mohit-rocks try to keep the original author of the commit. It creates confusion on who is the author and who should answer questions about the code change.

@escopecz escopecz changed the title Prevent unpublished emails from triggering unpublished campaigns. Refactor change stage campaign action to use batches Apr 16, 2021
@escopecz escopecz removed the has-conflicts Pull requests that cannot be merged until conflicts have been resolved label Apr 16, 2021
escopecz
escopecz previously approved these changes Apr 16, 2021
Copy link
Member
@escopecz escopecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I covered the new methods with unit tests. This is good to go 👍

@escopecz escopecz added ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged and removed needs-automated-tests PR's that need automated tests before they can be merged pending-test-confirmation PR's that require one test before they can be merged labels Apr 16, 2021
@RCheesley RCheesley merged commit 0dce7ee into mautic:3.3 Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs campaigns Anything related to campaigns and campaign builder cla-signed The PR contributors have signed the contributors agreement ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Campaign "change contact stage" event does not work due to use of a non-existing method
9 participants
0