Problem/Motivation

Drush 12 changes the way it injects services. In #3078507, some refactoring was done to make the Drush commands available in the main module (purge). To make my custom code work (calling \Drupal::service('purge_drush.queue_commands');), I did this naive change of copying all service definitions from drush.services.yml to services.yml and all Drush commands under `src/Drush/Commands`. I also updated the class namespaces in drush.services.yml

Steps to reproduce

Install Drush 12. Notice that the services defined in `drush.services.yml` in the module suddenly don't work.

Proposed resolution

Make Drush commands compatible with Drush 12.

Remaining tasks

None.

User interface changes

None.

API changes

The services in (current) drush.services.yml in the module will be available globally in Drupal.

Data model changes

None.

Issue fork purge-3440974

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kekkis created an issue. See original summary.

kekkis’s picture

Version: 8.x-3.5 » 8.x-3.x-dev

Fixing Version info.

kekkis’s picture

Assigned: kekkis » Unassigned
Status: Active » Needs review

An open and honest question in addition to the one in the IS: would we want to opt for auto-wiring instead of adding the create methods? It's the new in, hip and pop thing available in Drush 12.5. At least using create methods gives us a little more backwards compatibility.

sokru’s picture

Status: Needs review » Needs work

Thanks for this! Requested few changes. I suggest we keep compatibility for drush v11.

japerry’s picture

To get included in the 8.x-3.x version of purge, it will need to NOT use the autowiring functionality. It appears we will need to roll a new major version of purge to accommodate many issues that have been accumulating over the past few months, but won't happen until after Drupal 11.

kekkis’s picture

Status: Needs work » Needs review

@japerry, I have pushed changes in the MR now. Please review again. As you can see in the comments, I also manually tested with the two combos that IMO make some kind of sense: Drupal 10.1+Drush 11 and Drupal 10.2+Drush 12. But as I wrote this note, I thought of yet another combo that is sensible in some cases: Drupal 10.1 + Drush 12. Here's the output for that test, which also indicates that the combination works ok with the branch:

$ ddev drush -vvv p:diagnostics
 [preflight] Config paths: /var/www/html/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /var/www/html/web/drush/sites,/var/www/html/drush/sites
 [preflight] Commandfile search paths: /var/www/html/vendor/drush/drush/src
 [debug] Bootstrap further to find p:diagnostics [0.32 sec, 2.63 MB]
 [debug] Trying to bootstrap as far as we can [0.32 sec, 2.63 MB]
 [info] Drush bootstrap phase: bootstrapDrupalRoot() [0.32 sec, 2.64 MB]
 [info] Change working directory to /var/www/html/web [0.32 sec, 2.64 MB]
 [info] Initialized Drupal 10.1.8 root directory at /var/www/html/web [0.32 sec, 2.64 MB]
 [info] Drush bootstrap phase: bootstrapDrupalSite() [0.32 sec, 2.77 MB]
 [debug] Could not find a Drush config file at sites/default/drush.yml. [0.32 sec, 2.84 MB]
 [info] Initialized Drupal site purge-test-10-1-drush-12.ddev.site at sites/default [0.32 sec, 2.84 MB]
 [info] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.32 sec, 2.84 MB]
 [info] Drush bootstrap phase: bootstrapDrupalDatabase() [0.33 sec, 3.03 MB]
 [info] Successfully connected to the Drupal database. [0.33 sec, 3.02 MB]
 [info] Drush bootstrap phase: bootstrapDrupalFull() [0.33 sec, 3.03 MB]
 [debug] Start bootstrap of the Drupal Kernel. [0.33 sec, 3.02 MB]
 [debug] Finished bootstrap of the Drupal Kernel. [0.35 sec, 3.7 MB]
 [debug] Loading drupal module drush commands & etc. [0.35 sec, 3.7 MB]
 [debug] Found drush.services.yml for purge Drush commands [0.35 sec, 3.71 MB]
 [debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeCommands [0.37 sec, 4.52 MB]
 [debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeCommentsCommands [0.37 sec, 4.52 MB]
 [debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeSessionsCommands [0.37 sec, 4.52 MB]
 [debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeUserFieldsCommands [0.37 sec, 4.53 MB]
 [debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeUserTableCommands [0.37 sec, 4.54 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\DebugCommands [0.37 sec, 4.54 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\DiagnosticsCommand [0.37 sec, 4.55 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\InvalidateCommand [0.37 sec, 4.55 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\ProcessorCommands [0.37 sec, 4.56 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\PurgerCommands [0.37 sec, 4.58 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\QueueCommands [0.37 sec, 4.61 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\QueuerCommands [0.37 sec, 4.64 MB]
 [debug] Add a commandfile class: Drupal\purge\Drush\Commands\TypesCommand [0.37 sec, 4.65 MB]
 [debug] Done with bootstrap max in Application::bootstrapAndFind(): trying to find p:diagnostics again. [0.42 sec, 6.97 MB]
 [info] Starting bootstrap to none [0.43 sec, 7.09 MB]
 [info] Drush bootstrap phase 0 [0.43 sec, 7.09 MB]
 [info] Try to validate bootstrap phase 0 [0.43 sec, 7.09 MB]
 [error]  diagnostics: ERROR: Purgers: There is no purger loaded which means that you need a module enabled to provide a purger plugin to clear your external cache or CDN. [0.44 sec, 7.45 MB]
 -------------------- ------------------------------------------------------------------------- ---------------------------------------- ----------
  Title                Recommendation                                                            Value                                    Severity
 -------------------- ------------------------------------------------------------------------- ---------------------------------------- ----------
  Queuers              Queuer for the 'drush p:queue-add' command.                               Drush p:queue-add                        OK
  Page cache max age   Your site instructs external caching systems not to cache anything. Not   no caching                               WARNING
                       only does this make cache invalidation futile, it is also a great
                       danger to your website as any form of traffic can bring it down
                       quickly!
  Capacity             There is no purging capacity available.                                   0                                        WARNING
  Queue size           Your queue is empty!                                                      0                                        OK
  Purgers              There is no purger loaded which means that you need a module enabled to                                            ERROR
                       provide a purger plugin to clear your external cache or CDN.
  Processors           You have multiple processors working the queue.                           Drush p:queue-work, Drush p:invalidate   OK
 -------------------- ------------------------------------------------------------------------- ---------------------------------------- ----------
kekkis’s picture

Issue summary: View changes

Updated issue summary.

  • japerry committed 9bdb01d5 on 8.x-3.x authored by kekkis
    Issue #3440974 by kekkis, japerry, sokru: Drush 12 compatibility
    
japerry’s picture

Status: Needs review » Fixed

Looks good! Tested against D9, 10, and 11 with Drush 10, 11, and 13. I presume 12 should work inbetween ;)

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.