I have a 'newsletter' node on my Drupal site.
In a submit handler, I save the data in the node to a campaign, via:
mailchimp_campaign_save_campaign()
My problem is, I need to save my node twice before my changes appear at the mailchimp end. (I am checking my mailchimp archive page at http://us7.campaign-archive2.com/?u=xxx to see if the changes arrive).
Any change I make at the drupal end consistently arrives at the mailchimp end, when I have saved my node for the second time.
I have tried clearing the theme registry cache and the mailchchimp campaign cache in code, it isn't giving me any success though.
cache_clear_all('theme_registry', 'cache', TRUE);
cache_clear_all('mailchimp_campaign_campaigns', 'cache');
Any clues about what might be happening here? Thanks!
Comment | File | Size | Author |
---|---|---|---|
#1 | mailchimp-debug.png | 81.05 KB | michaellenahan |
Comments
Comment #1
michaellenahan CreditAttribution: michaellenahan at erdfisch commentedDebugging this right now, if I put a dpm() in mailchimp_campaign.module, line 309 (version 7.x-3.4)
This dpm($content); is giving me the old data from my node, not the latest field data.
On a subsequent save of my node, the $content variable is correct.
Comment #2
michaellenahan CreditAttribution: michaellenahan at erdfisch commentedWow. I had fun fixing this.
The node being used by mailchimp_campaign_save_campaign() was a stale one from cache.
My first thought was to move my code out of my submit handler, because I'm thinking that the node isn't saved yet when we are still submitting.
So I moved my code to hook_node_insert() and hook_node_update() instead, but I was still getting the same problem.
The fix was to clear the node cache, just before calling mailchimp_campaign_save_campaign(). Now mailchimp_campaign_save_campaign() sees the saved node, not the old stale cached node.
In case it helps anyone out there, the fuller picture looks like this, and it's working for me now.