0

I want to update many of my node's aliases. I have seen many questions here at Drupal Answers, but nothing I can use, as far as I can see.

What I want to do: I want to update a big portion of URLs (mostly forum nodes) to a new alias and still keeping the old aliases. I can do this by using VBO. However, when I update the URL alias using VBO, all forum nodes as well as other nodes will get the "Has new content" marker saying "updated". I want to avoid the nodes getting this "updated" marker since I have around +10,000 nodes.

I have looked in Rules trying to figure if there is I way I can set the nodes to being marked as "read" when I update the URL alias, but I can't see a way to do this.

The reason I'm not just deleting all aliases and then bulk generate them again, is that it won't keep my current aliases thus giving me many 404 errors in the future.

Is there a way to update the node's alias and still keeping the old alias and not having all the nodes marked as "updated"?

1 Answer 1

1

Ultimately, a VBO action affecting a node is going to call node_save() which will change the changed node property that determines when the updated marker appears.

To get around this, you'll need to preserve the node changed timestamps following your bulk alias updating. You can do this by directly updating the node.changed column in the database.

Depending on your preferences, there's many ways to backup/restore database data. For example, executing a Drush snippet before node alias bulk updating could dump a JSON file with your nid/updated timestamps:

drush ev '$nodes = db_select("node", "n")
  ->fields("n", array("nid", "changed"))->execute();
$timestamps = array();
foreach ($nodes as $node) {
  $timestamps[$node->nid] = $node->changed;
}
echo json_encode($timestamps);' > my_node_timestamps.json

Following bulk alias updating, another snippet could restore it from the JSON:

cat my_node_timestamps.json | drush ev '
$timestamps = json_decode(file_get_contents("php://stdin"));
foreach ($timestamps as $nid => $timestamp) {
  db_update("node")
    ->fields(array("changed" => $timestamp))->condition("nid", $nid)->execute();
}
'

As the case with any operations directly touching your database directly, make sure to perform backups before performing any such bulk operation.

2
  • Thank you for you comprehensive answer with a nice explanation about the node.changed column in the database. I will see if I can use Drush on my host. Thanks!
    – hjorslev
    Oct 27, 2016 at 13:35
  • 1
    Sure! Drush was the example here, but you could also use a SQL client to generate an export then build UPDATE queries to perform the same effect.
    – Shawn Conn
    Oct 27, 2016 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.