How to update "changed" date for all nodes in Drupal 7 - the fastest way

The goal is to update ALL nodes "changed" or "updated" date with one SQL command. The reason behind this is called xmlsitemap. If you don't have any update on a node, you'll get something like "yearly" frequency in your sitemap for older nodes. What I really wanted was to refresh all nodes in a sitemap so that bots will see your nodes as fresh content. You can even fake it by adding something generic to all your nodes, and if you're lucky it won't look like spam. It's actually not spam, if we're talking about a new website. 

After 2 hours trying to run a query in phpMyAdmin without success (maybe some limitations, idk) I tried to run the same query in drush. Everything worked perfectly. So, for my own records, the following query updates all nodes as if they were all been modified within the last 7 days.

drush sqlq "UPDATE node SET changed = unix_timestamp('2017-03-28 01:00:00')-floor(rand()*604800)"

I don't recommend running this query IF you care about node revisions. They'll be out of sync. It's just a fast and dirty trick to avoid loading drupal bootstrap for each and every batch set (if you were using VBO). Actually, it took 30 seconds to run this query over 5+ million nodes. Pretty cool, is it?

If you know a better method but as fast as this one, please share it in a comment.

Rate this article: 

Average: 5 (2 votes)


Samples of work done for me or my customers, for free or not, like websites, repairs, photography etc.
View all my recent work



I'm giving away some knowledge in my areas of expertise. Did you like something here? Share it please!
View all tutorials



Useful Linux commands or other code snippets I often use.
View my useful shortcuts



Few bookmarks I find useful. Do you want website here? Give me a good reason and I can help you.
View my favourite web resources

About me

Hi there! My name is Marius Cârneală.

About me?

Loving husband, dad of one two three, drone pilot, web designer and administrator, SEO specialist, IT support guy, electronic hobbyist and content writer. This list is open.