Drupal and how to disable notifications for programmatic node updates

Known for his open source and JavaScript security initiatives, Liran Tal is an award-winning software developer, security researcher, and open source champion in the JavaScript community. He's an internationally recognized GitHub Star, acknowledged for his open source advocacy, and has received the OpenJS Foundation's Pathfinder for Security for his work on Node.js security. His contributions to developer security education include leading OWASP projects, building supply chain security tools, participation in CNCF and OpenSSF initiatives, and authoring books such as O'Reilly's Serverless Security. He leads the developer advocacy team at Snyk.io and is on a mission to empower developers with better application security skills.
Feb 5, 2013 ~ 1 min read
Drupal and how to disable notifications for programmatic node updates
share this story on

More than often, we Drupal developers find ourselves doing programmatic node modifications via the
node_save()
function. If you’re doing that as well as have messaging and notifications modules enabled in your site then given the case that your users have subscribed to content-type updates and you’re doing these ‘behind the scenes’
node_save()
stuff then you’re effectively spamming them with email updates each time you run that function.
To mitigate this issue, when saving a node programmatically you can set an attribute for the notifications module to understand that it needs not to send updates for this operation. It’s a quick and easy one:
function probably_your_hook(&$node) { // ... code ...
// Disable announcements for this operation $node->notifications_content_disable = 1; node_save($node);
// ... code ... }




