Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I would like to be able to delete and rebuild path aliases with Drush.
Comment | File | Size | Author |
---|---|---|---|
#21 | interdiff.txt | 779 bytes | pfrenssen |
#21 | 2717721-21.patch | 12.85 KB | pfrenssen |
|
Comments
Comment #2
lammensj CreditAttribution: lammensj at iO commentedCreated a patch, based on the work done in https://www.drupal.org/node/867578.
Comment #3
lammensj CreditAttribution: lammensj at iO commentedComment #4
Berdirwe don't need this as it is part of the pathauto 8.x module.
This looks pretty good, thanks.
Can we include the new features from #2451307: Delete bulk aliases also deletes custom url paths and #2678558: Bulk generate should be able to recreate aliases to have feature parity between the drush commands and the UI? should be fairly simple to add some options for this?
Comment #5
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedFixed the minor issue.
Comment #6
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #7
lammensj CreditAttribution: lammensj at iO commentedI refactored the drush commands so they can work with an AliasCliAction-service and implemented the feedback provided by @Berdir.
Comment #8
r.nabiullin CreditAttribution: r.nabiullin at Skilld commentedI tested last patch with D 8.3.4 by unit test - all tests are passed.
Comment #9
BerdirThanks for working on this. Did not expect to actually make this services as well, but that's an option of course. But I think we can simplify the architecture a bit, see my review below.
we don't use @package in Drupal.
I prefer function arguments to be on the same line, there is no strict 80 character limit in Drupal, (except for comments).
Also, the current coding standard still requires to use underscore ($config_factory) for local variables/method arguments.
static:: should be used instead self:: when possible.
I'm not sure we really need an interface. That's always a question and I think it's enough to add interfaces in case we actually expect to have multiple alternative implementations. Especially since the result is that the interface is very generic and its documentation not very meaningful.
My recommendation would be to have a single service/class with a bulkGenerate() and bulkDelete() method instead of an interface and a generic execute() method.
Interesting use of sprintf(), haven't seen that before. I personally would just use PathautoAdminDelete::class . '::batchProcess' but I can live with this.
shouldn't be that backend instead of bachend? :)
Comment #10
Ada Hernandez CreditAttribution: Ada Hernandez at MTech, LLC commentedFor #9
1. removed @package, but maybe We need a new description
2. done
3. done
4. pending
5.
6. done
Comment #11
Yaazkal CreditAttribution: Yaazkal commentedThis is pretty good. It will help a lot running staging/deployment scripts now in the era of config/sync. I wonder if that will also update the information for redirect, I guess yes?.
Congrats.
Comment #12
Prashant.cPatch applies successfully on
Drupal Core Version - 8.5.x
Pathauto Version - 8.x-1.x
But facing following error on running the drush command to generate alias.
i chose
2
i chose 3
It is throwing PHP Fatal error
From the UI Bulk Generate is working fine for me
admin/config/search/path/update_bulk
However
is working fine.
Comment #13
claudiu.cristeaWe need to adapt to Drush 9
Comment #14
pfrenssenStarted to adapt this for Drush 9. This still needs work.
Comment #15
pfrenssenFinished an initial implementation of the Drush 9 integration. This is ready for a first look.
Please note when testing that there is some additional output being generated at the very end when executing the Drush commands, for example an integer can be output that represents the number of aliases that were updated, or the word
Array
may be output.This is not caused by this patch but rather by the fact that the batch processing in Pathauto is not implemented correctly. The current implementation abuses the
$context['results']
array to pass structured data to functions such asPathautoBulkUpdateForm::batchFinished()
which then use this data to generate appropriate messages. This is not valid according to the Drupal Batch API which expects the results to be a flat list of strings (or translatable markup). Fixing this is out of scope for this issue.Comment #16
idimopoulos CreditAttribution: idimopoulos at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedIs "force" the right word here? It is not that something is persistent. Maybe
--purge
or something similar? or--include-manual
.Is there a specific reason we are logging everything here? When trying to update using the UI and the form itself, nothing is logged. Here, it is more or less the same. A direct action taken from the admin.
In case this is used from a cron job, the cron job should be responsible for possibly logging changes.
Plus, the other actions don't seem to log anything.
The
::getSourcePrefix()
method already returns a string according to the interface and the couple of methods that implement it. No need for typecasting. It won't be a markup class, or shouldn't at least.Since we are adopting to Drush 9, we can also go with the new naming of the commands. Now, the commands are prefixed with the module name followed by a column, so the corresponding commands would be something like
pathauto:aliases-generate
Currently, both pathauto commands are listed under
_global
when running thedrush list
command.canonical_entities:node|user|whatever
and not simply node/user/blah?Array
printed in the terminal as such:otherwise, there is a number printed.
Comment #17
pfrenssenThanks for the review!
--purge
, thanks for the suggestion!$this->messenger()->addMessage()
inPathautoAdminDelete::submitForm()
.You can verify this by executing the command
$ drush pad all --purge
, this will output the message in the console rather than log it to the watchdog.PathautoAdminDelete::submitForm()
so I didn't question it, but you're right, the interface dictates that a string should be returned.Comment #18
idimopoulos CreditAttribution: idimopoulos at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commented@pfrenssen it seems that while you agreed with it, you forgot to do No 3.
Also,
a quick nitpick. This seems a bit of a leftover or from an earlier version. Sorry, I just opened the patch in PhpStorm and it complained that this is never thrown.
For number 5, up to now, this naming convention is never presented in the UI as the label of the entity types are shown. So it wouldn't matter up to now. Now, we are presenting the options to the user as such
That is why I was thinking to change this. But anyway, if pathauto wants to use this style, it is not a blocker for me.
Comment #19
idimopoulos CreditAttribution: idimopoulos at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedComment #20
pfrenssenThanks for having another look @idimopoulos!
On the command line we need to use the machine name. This makes sense for a lot of reasons. Most importantly because the machine names are guaranteed to be unique, but the labels are not. If there would be multiple alias types with the same label we wouldn't be able to know which one is intended. Also using the labels makes it more difficult for the end user since they need to deal with the correct capitalization, and the possibility of having spaces and special characters in the labels makes scripting more difficult.
I think it's important to show the exact same arguments in the interactive menu as are used in the command. Otherwise it would be confusing for the user.
In general I think it is a good practice to resort to machine names on the CLI. After all it is intended for technical users. It is not intended to work exactly like a UI which is designed for non-technical users.
Comment #21
pfrenssenForgot to remove the unneeded string casting again.
Comment #22
idimopoulos CreditAttribution: idimopoulos at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedThanks @pfrenssen. These are all for me. I find the patch working fine :) I also tested it in my current installation which contains a few thousand nodes.
Putting this to RTBC as far as I am concerned.
Comment #23
pfrenssenThanks!
Comment #25
BerdirThanks. I'm still confused about certain things with drush9, e.g. whether or not a composer.json is required, a similar patch in troken.module adds one to explicitly register the drush commands. But it has been tested and seems to work, resolved a minor conflict on commit.
Comment #27
moshe weitzman CreditAttribution: moshe weitzman as a volunteer commentedA composer.json is recommended for modules carrying drush commands. It is not yet mandatory, even in Drush 10. It might become mandatory one day.