Have you ever needed to set the status of the pathauto checkbox in nodes or other entities to unchecked, for existing nodes?
Locking the generated path alias for new nodes and also for certain roles works well using modules like Node keep.
But how to mass / bulk change the status of that checkbox for existing nodes, so that re-saving them doesn't influence the existing URLs?
There's a way!
Pathauto state is saved as key-value setting
The hardest part to solve this, was finding out, where pathauto stores this flag.
I finally found it in the key_value
database table of Drupal. Pathauto creates collections there by the name of the entity type. For example the collection for nodes is: pathauto_state.node
where the name
value is the node ID.
Same is done for all other entity types, like media, taxonomy term, etc.. The checkbox value is saved as a serialized binary integer:
Enabled: i:1;
Disabled: i:0;
You can list the existing entries in your database using:
SELECT * FROM `key_value` WHERE `collection` LIKE 'pathauto_state.%';
Setting the pathauto state for all existing nodes in the database
To set all enabled pathauto state checkboxes to disabled (unchecked), use:
UPDATE `key_value` SET `value`='i:0;' WHERE `collection` LIKE 'pathauto_state.node' AND `value`='i:1;';
To set all disabled pathauto state checkboxes to enabled (checked), use:
UPDATE `key_value` SET `value`='i:1;' WHERE `collection` LIKE 'pathauto_state.node' AND `value`='i:0;';
The same works accordingly for all other entity types and if you need to, you can add further WHERE conditions for your entities.
Of course the same can be done using PHP and iterating over the entity objects, modifying the values, but I didn't try that, as for my case this was the best and most simple solution.
Of course, first try this in a dev environment and never on production sites ;)