# Cron-job for Campaigns buggy (5.1.0)

**URL:** <https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217>\
**Category:** Product Support\
**Created:** [August 22, 2024, 5:23pm UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217 "2024-08-22T17:23:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![imihandstand](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/imihandstand/32/1499_2.png) [@imihandstand](https://forum.mautic.org/u/imihandstand)\
**Post date:** [August 22, 2024, 5:23pm UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/1 "2024-08-22T17:23:13Z")

</div>

**Your software**  
My Mautic version is: 5.1.0 (same issue with 5.0.4)  
My PHP version is: 8.0.30  
My Database type and version is: 10.3.39-MariaDB

**Your problem**  
My problem is:  
My campaigns don’t get triggered as they should (despite correct cron-job setup). Even triggering them manually via Terminal with “_php bin/console mautic:campaigns:update_” and “_php bin/console mautic:campaigns:trigger_” doesn’t work correctly. **The campaigns seem just to trigger (more or less) correctly if I ran the cron-jobs with for example " --campaign-id=12".**

These errors are showing in the log:

In the Mautic admin-area the log is empty.

**Here is a part of “var/logs/prod-2024-08-22.php” (every few minutes new such entries are added):**

`[2024-08-22T09:40:03.232683+00:00] app.ERROR: CAMPAIGN: Multiple non-persisted new entities were found through the given association graph: * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#campaign' that was not configured to cascade persist operations for entity: Mautic\CampaignBundle\Entity\Campaign with ID #18. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#campaign' that was not configured to cascade persist operations for entity: Mautic\CampaignBundle\Entity\Campaign with ID #15. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #542. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#campaign' that was not configured to cascade persist operations for entity: Mautic\CampaignBundle\Entity\Campaign with ID #21. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #543. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #544. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #546. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #547. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #548. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #550. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #551. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #552. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #553. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #554. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #555. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #556. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #557. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #558. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #559. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #560. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #561. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #562. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\LeadEventLog#lead' that was not configured to cascade persist operations for entity: Proxies\ __CG__ \Mautic\LeadBundle\Entity\Lead with ID #563. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). * A new entity was found through the relationship 'Mautic\CampaignBundle\Entity\Lead#campaign' that was not configured to cascade persist operations for entity: Mautic\CampaignBundle\Entity\Campaign with ID #12. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). [] {"hostname":"server.verfuehren-befriedigen-tipps.de","pid":13372}`

**Steps I have tried to fix the problem:**

Despite not understanding the error-code at all, I tried all kinds of AI (chatGTP, etc.) to solve this errors, but with no luck. They say things I don’t understand either, like:

“The error message you’re encountering indicates that Mautic is having trouble persisting certain entities within your campaigns. Specifically, it’s struggling to handle relationships between entities like `LeadEventLog`, `Campaign`, and `Lead` due to missing `cascade={"persist"}` configurations in the Doctrine ORM mappings.”

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 8, 2025, 9:19am UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/2 "2025-01-08T09:19:51Z")

</div>

This is happening to me as well on 5.2.1

---

<div class="post-metadata">

**Author:** ![miki](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/miki/32/12678_2.png) [@miki](https://forum.mautic.org/u/miki)\
**Post date:** [January 23, 2025, 9:19am UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/3 "2025-01-23T09:19:51Z")

</div>

Same on 5.1.1.

What’s the solution? Because the effect of it is huge. All of our campaigns stopped working.

---

<div class="post-metadata">

**Author:** ![miki](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/miki/32/12678_2.png) [@miki](https://forum.mautic.org/u/miki)\
**Post date:** [January 23, 2025, 9:36am UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/4 "2025-01-23T09:36:02Z")

</div>

I could fix it with putting the -\>cascadePersist() option in the related class mentioned in the log, but there are too many ManyToOne relations in the code. So it should be a global solution I think.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 23, 2025, 10:12am UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/5 "2025-01-23T10:12:19Z")

</div>

Can you check (somehow) if it happens to new segments as well? Created after the upgrade.

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [January 23, 2025, 10:51am UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/6 "2025-01-23T10:51:49Z")

</div>

Hi folks,

I think this is related to a bug already reported and fixed according to the logs which are mentioned a few comments down:

> <https://github.com/mautic/mautic/issues/14034>
>
> \### Mautic Version
> 
> 5.0.x series
> 
> \### Way of installing
> 
> Other (please spe…cify if relevant in the bug report)
> 
> \### PHP version
> 
> 8.0.30
> 
> \### What browsers are you seeing the problem on?
> 
> Not relevant
> 
> \### What happened?
> 
> \*\*MAIN PROBLEM:\*\*
> After adding contacts to the campaigns, the flow/tasks don't start (despite the campaign being active for that contact in his profile). It does not matter how the contact is added to the campaign (via another campaign or directly in his profile-settings).
> 
> \*\*EXPLANATION:\*\*
> I have 2 campaigns:
> 
> \*\*1. Camp. "\*REAKT6-01\*":\*\* When I add contacts to this campaign \[via adding them to the segment "\*REAKT-01\*"\], following things should happen:
> !\[Screenshot 2024-07-31 at 12 36 32\](https://github.com/user-attachments/assets/64713c30-ea57-4690-8ef7-67c772f11ad0)
> 
> So:
> \-- Getting the tag "\*Started campaign: REAKT6-01\*" (this works)
> \-- Sending email #135 (also works)
> \-- 2 days later adding contact to campaign "\*MASTER\*":
> !\[Screenshot 2024-07-31 at 12 36 43\](https://github.com/user-attachments/assets/d4090730-ebb0-4cfb-ac9e-b38018af2302)
> This does NOT work, instead he gets added every 15 minutes to that MASTER-campaign (based on the contact's History), but that MASTER-campaign does still not start
> !\[Screenshot 2024-07-31 at 12 37 50\](https://github.com/user-attachments/assets/91ac1d8d-7aa5-4166-b045-9056260efd51)
> \-- Stopping this "\*REAKT6-01\*" campaign (this does NOT work, it's not reached, as the flow stucks at the previous step
> 
> \*\*2. Camp. "\*MASTER\*":\*\* This has as starter the empty segment "\*NOBODY\*", as I want to start it just via other campaigns (like campaign "\*REAKT6-01\*").
> 
> The contact's "Upcoming Events" shows following (the date "July 30, 2024 8:18 pm CEST" is of course already over, but for many contacts \*\*it still tries to add it to the MASTER-campaign every 15 minutes\*\*, already 25+ times):
> !\[Screenshot 2024-07-31 at 12 51 21\](https://github.com/user-attachments/assets/2822c4bf-9dce-4d3d-8ce3-aad0add0c473)
> 
> And checking the contact's Campaigns, that MASTER campaign IS active:
> !\[Screenshot 2024-07-31 at 12 55 43\](https://github.com/user-attachments/assets/1bb759d8-fb0b-42a2-9fd3-03ce2f953946)
> 
> So it looks like that the MASTER-campaign just got "kinda" started, not fully - so it got activated for the contact, but the flow doesn't start. Not just this campaign, some for others.
> 
> \### How can we reproduce this issue?
> 
> I don't know, as I cloned that MASTER-campaign as test and when I added a test-contact to it, that clone-campaign fired correctly. However just cloning and replacing the original with this clone can't really be a solution, as (as I just realized) other campaigns have also this issue (that despite being added to them, their flow doesn't start)
> 
> \### Relevant log output
> 
> \`\`\`shell
> Log is empty
> \`\`\`
> 
> 
> \### Code of Conduct
> 
> \- \[X\] I confirm that I have read and agree to follow this project's Code of Conduct
> 
> \<br /\>\<hr\>
> Care about this issue? Want to get it resolved sooner? If you are a \<a href='https://www.mautic.org/become-a-member-of-mautic'\>member of Mautic\</a\>, you can add some funds to the \<a href='https://opencollective.com/mautic/projects/bounties'\>Bounties Project\</a\> so that the person who completes this task can claim those funds once it is merged by a member of the core team! Read the docs \<a href='https://contribute.mautic.org/product-team/mautic-bounty-programme'\>here.\</a\>

Please test the fix:

> <https://github.com/mautic/mautic/pull/14497>
>
> | Q | A
> | --------------------------------…------ | ---
> | Bug fix? (use the a.b branch) | 🟢 
> | New feature/enhancement? (use the a.x branch) | 🔴
> | Deprecations? | 🔴
> | BC breaks? (use the c.x branch) | 🔴
> | Automated tests included? | 🟢 
> | Related user documentation PR URL | mautic/user-documentation#... 
> | Related developer documentation PR URL | mautic/developer-documentation-new#... 
> | Issue(s) addressed | Fixes #14034
> 
> 
> 
> \## Description
> The campaign execution was getting stuck due to an issue with lead detachment in the change membership action. The previous implementation was detaching all contacts, including those newly added to the campaign, which caused problems while trying to save the campaign log after detach.
> 
> This PR also addresses an issue in the \`testCampaignActionChangeMembership\` test. Previously, the test was incorrectly set up: it was adding the contact to both campaigns before executing the campaign action. 
> 
> 
> 
> 
> 
> 
> 
> \---
> \### 📋 Steps to test this PR:
> 
> 
> 1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs \[here\](https://contribute.mautic.org/contributing-to-mautic/tester))
> 2. Create two empty segments in Mautic.
> 
> 3. Create Campaign 1:
> - Start with Segment 1
> - Add an action (e.g., add tag to contact)
> 
> 4. Create Campaign 2:
> - Start with Segment 2
> - Add "Change Campaigns" action
> - Select "Add to Campaign 1" in the action settings
> 
> 5. Add a contact to Segment 2 and run the campaigns:
> \`\`\`
> php bin/console m:ca:u
> php bin/console m:ca:t
> \`\`\`
> 
> 6. Verify that the campaign execution was successful.
> 
> 7. Check if the created contact is now a member of Campaign 1.

---

<div class="post-metadata">

**Author:** ![miki](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/miki/32/12678_2.png) [@miki](https://forum.mautic.org/u/miki)\
**Post date:** [January 23, 2025, 9:18pm UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/7 "2025-01-23T21:18:25Z")

</div>

Thank you! 🙂 I will test it!

---

<div class="post-metadata">

**Author:** ![miki](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/miki/32/12678_2.png) [@miki](https://forum.mautic.org/u/miki)\
**Post date:** [January 24, 2025, 10:15am UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/8 "2025-01-24T10:15:25Z")

</div>

@silavapi it seems to be working! Thank you! 🙂

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [January 24, 2025, 11:51am UTC](https://forum.mautic.org/t/cron-job-for-campaigns-buggy-5-1-0/33217/9 "2025-01-24T11:51:07Z")

</div>

That’s great @miki - it’s very important that you leave a review so we can get this PR merged. Here’s how to do that: [https://contribute.mautic.org/contributing-to-mautic/tester#leaving-your-review](https://contribute.mautic.org/contributing-to-mautic/tester#leaving-your-review) - thanks in advance!
