Problem/Motivation

Site was have already 50+ users without enabled pathauto pattern for user entity. I create new pathatuto pattern for user entity, and start bulk update of Users with "Regenerate URL aliases for all paths".

As result, I see that only new users (created after creating pattern) get new aliases, matched to pattern.

All old users after bulk update have empty path alias, and unchecked 'Generate automatic URL alias' checkbox, even if I repeat bulk update many times.

If I uncheck 'Generate automatic URL alias' checkbox manually for several users, they aliases becomes updated normally.

Where is 'Generate automatic URL alias' checkbox data saved in database? How can I delete (reset) it for old users?

Steps to reproduce

1) go to /admin/config/development/generate (require Devel module):
1.1) generate 3 users (content editor)
1.2) generate 3 nodes (article)

2) go to /admin/config/search/path/patterns and add new pathauto patterns:

2.1) E.g. pattern type: user
path pattern: editedpathforusers/[current-user:account-name]
label: edited path for users

2.2) E.g. pattern type: content
path pattern: editedpathfornodes/[node:author]
content type: article
label: edited path for nodes

3) create a new user and node after set patterns

4) edit a user and a node, unmarking "Generate automatic URL alias" and setting manually a URL alias
4.1) E.g. set "/editedpathforusers2/dechevu" and "/editedpathfornodes2/anonymous"

5) go to bulk generate tab (/admin/config/search/path/update_bulk):

5.1)
Select the types of paths for which to generate URL aliases: content and user
Select which URL aliases to generate: Regenerate URL aliases for all paths

6) go to /admin/config/development/performance and clear all caches

7) Check the paths generated for users and nodes:
6.1) for those created before set pattern;
6.2) for those created after set pattern;
6.3) for those edited (with URL alias manually set).

Comments

Murz created an issue. See original summary.

murz’s picture

StatusFileSize
new511 bytes

Quick ugly hack for solve this problem is temporary force 'Generate automatic URL alias' checkbox checked on all entities via src/PathautoFieldItemList.php file:

  protected function computeValue() {
    parent::computeValue();

    // For a new entity, default to creating a new alias.
    if ($this->getEntity()->isNew()) {
      $this->list[0]->set('pathauto', PathautoState::CREATE);
    }
+    // Force 'Generate automatic URL alias' checkbox checked for all entities
+    $this->list[0]->set('pathauto', PathautoState::CREATE);
  }

after this - run bulk update of all user aliases, and after bulk update finished - remove those lines.

Patch is attached.

kbrodej’s picture

Hi. Tested on the latest dev branch, indeed aliases do not get recreated for users created prior to setting pattern:
In my case 'Generate automatic URL alias' checkbox was checked on by default for all users.
All users created prior to enabling pattern would not have alias generated until they logged in or Admin updated any of the user settings.

murz’s picture

Seems same problem exists with nodes, that created before pathauto pattern created, and maybe for other entity types too. Maybe, as workarond, add some button "Reset all entities" that will do this thing, that patch do?

djween’s picture

#4 confirmed, having same issue with nodes.

kwfinken’s picture

To directly answer the original question, the value is saved in the key_value table. Running the query: update key_value set value='i:1;' where collection = 'pathauto_state.user'; will make it so all users receive an auto-generated URL. Similar options can be executed for collection = 'pathauto_state.media', collection = 'pathauto_state.node' and collection = 'pathauto_state.taxonomy_term'.

It seems like the easiest fix for this would be to add an option under "Select which URL aliases to generate" which says "Regenerate URL aliases for all paths INCLUDING manually named paths" and change "Regenerate URL aliases for all paths" to "Regenerate URL aliases for all paths EXCLUDING manually named paths". If the option of "Including" is chosen, it first updates the key_value for the selected type of path to set all items to "i:1;" and then executes the generate URL aliases for all paths option.

Note, this is just a basic idea, I have not tested in code.

iryston’s picture

Thanks, Murz!
Patch #2 works like a charm on Drupal 9.2 and Pathauto 8.x-1.8.
Fixes problem #4 with nodes, created with custom aliases before pathauto pattern was created.

ramonma1989’s picture

Patch #2 works for me and fixes also #4 when working with old nodes, but i believe this should be a feature not something to add, use and then remove. Thanks.

lubwn’s picture

Patch from #2 works flawlessly for me as well. My installation somehow does not have pathauto_state table at all so I do not even know where it saves all the data but okay. This works. Thanks a lot. Should be a checkbox somewhere in settings.

anjali rathod’s picture

Status: Active » Reviewed & tested by the community

Patch #2 works for me. Thanks .

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: pathauto_3100248_user-alias-update-2.patch, failed testing. View results

sophiavs’s picture

Assigned: Unassigned » sophiavs

I'll check what is failing on those tests.

sophiavs’s picture

I tested the dev branch and all the option "Regenerate URL aliases for all paths" created paths for all users even those created before setting the pattern. The path only wasn't changed on the user that had the paths manually named.

I will try to work on the suggestion made in #6

sophiavs’s picture

Version: 8.x-1.6-beta1 » 8.x-1.x-dev
Assigned: sophiavs » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.99 KB

I inserted the database change when the user select to change the URL including the manually named. Tested with multiple types (each one individually and in groups) and it worked.

Status: Needs review » Needs work

The last submitted patch, 14: 3100248-14.patch, failed testing. View results

sophiavs’s picture

Status: Needs work » Needs review
StatusFileSize
new1.99 KB
new3.87 KB

Since i changed the name of "Regenerate URL aliases for all paths." the test was calling the other action and receiving a wrong message. I corrected this.

lucassc’s picture

Assigned: Unassigned » lucassc
lucassc’s picture

Assigned: lucassc » Unassigned

I checked out 8.x-1.x-dev for drupal 10.0.0-alpha7 (without apply patches yet) and my tests reveal the same as @sophiavs checked in #13:

The path only wasn't changed on the user that had the paths manually named.

Here's what I did:

1) I went to /admin/config/development/generate (require Devel module):
1.1) I generated 3 users (content editor)
1.2) I generated 3 nodes (article)

2) then I went to /admin/config/search/path/patterns and added new pathauto patterns:

2.1) pattern type: user
path pattern: editedpathforusers/[current-user:account-name]
label: edited path for users

2.2) pattern type: content
path pattern: editedpathfornodes/[node:author]
content type: article
label: edited path for nodes

3) I created a new user and node after set patterns

4) I edited a user and a node, unmarking "Generate automatic URL alias" and setting manually a URL alias
4.1) I set "/editedpathforusers2/dechevu" and "/editedpathfornodes2/anonymous"

5) Then I went to bulk generate tab (/admin/config/search/path/update_bulk):

5.1)
Select the types of paths for which to generate URL aliases: content and user
Select which URL aliases to generate: Regenerate URL aliases for all paths

6) Went to /admin/config/development/performance and clear all caches

Results before patch:
7) I checked users generate (before set patterns) and users created/edited after:
7.1) edited user (with URL alias manually set) not updated (/editedpathforusers2/dechevu)
7.2) new user updated (/editedpathforusers/admin-0)
7.3) old users updated (ex. 1: /editedpathforusers/admin-2)

8) I checked nodes generate (before set patterns) and nodes created/edited after:
8.1) edited node (with URL alias manually set) not updated (still /editedpathfornodes2/anonymous)
8.2) new node updated (/editedpathfornodes/admin)
8.3) old nodes updated (ex. 1: /editedpathfornodes/pagokacl-0)

Then I applied @sophiavs' patch in #16 cleanly.

Results after patch:
- In the step 5 I selected "Regenerate URL aliases for all paths including manually named path" in the "Select which URL aliases to generate" field. This time both edited user and edited node was updated;

- I also checked that "Regenerate URL aliases for all paths excluding manually named path" is working fine, after bulk update neither user or node with URL alias manually set was changed.

It still needs a code review.

lucassc’s picture

Issue summary: View changes

Added "Steps to reproduce" in the IS.

lucassc’s picture

StatusFileSize
new89.51 KB
new93.97 KB

Attaching screenshots as the issue changes the UI.

Before patch:

Existing UI

After patch:

Proposed UI

lucassc’s picture

StatusFileSize
new3.86 KB
new520 bytes

I checked the code in patch #16 and looks great!

I'm just removing the unused $update variable in /src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php.

lucassc’s picture

Issue summary: View changes

Added missing reference to Devel.

dancbatista’s picture

Assigned: Unassigned » dancbatista

I will review it!

dancbatista’s picture

Status: Needs review » Reviewed & tested by the community

I followed the steps described in 18#, and worked perfectly for me!

balagan’s picture

StatusFileSize
new3.97 KB

Adding a reroll, as 457aa312a1a468cae88e3cf447aefad08c7f264f modernizes Drush commands.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

Contributions need to be merge requests.

mably’s picture

Status: Needs work » Closed (duplicate)

Closing as a duplicate of #3068140.

First you'll use the above issue feature to toggle "on" the automatic generation of aliases for your contents.

And then you'll use one of the two first bulk update options to regenerate your missing aliases (unaliased or old alias).

Not sure we want to automatically toggle the pathauto state to "on" using a low-level SQL query when regenerating aliases for all contents.

Feel free to reopen if I missed something.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.