drd:pi:sync Drush command not working anymore

Created on 10 October 2024, 2 months ago

Problem/Motivation

I noticed, that the Drush command drd:pi:sync is not registered anymore, since the transition from drush.services.yml to autoloading was done.

I debugged the issue and figured that it has to do with the Drush Command discovery. Drush only takes commands into account that are direct subclasses of the DrushCommands class

In DrdPiCommands we extend DrdCommands and that makes the following drush condition not matching.

$reflectionClass->isSubclassOf(DrushCommands::class)

See https://www.php.net/manual/en/reflectionclass.issubclassof.php . It is only true if it is a direct subclass. So it behaves differently to instanceof which would take the whole class tree into account.

Steps to reproduce

Proposed resolution

I'm not sure if that problem actually should be filed as a Drush issue. For DRD there are currently two different approaches possible.

  1. Add a drush.services.yml as long as it is supported by Drush (< Drush 14)
  2. Make DrdPiCommands extend DrushCommands and copy&paste some of the pieces from DrdCommands that are required for it to run

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

4.1

Component

Code

Created by

🇩🇪Germany szeidler Berlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @szeidler
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Great analysis, thanks @szeidler

    I really wonder why Drush uses isSubclassOf instead of instanceof, so it may be worth asking the question. However, we may not see any short term resolution and may have to resolve it ourselves.

    How about subsclassing DrushCommands as you suggested, but instead of copy & paste of some code, we could move those parts, that should be common to multiple classes into a trait.

    Do you want to give that a try in an MR?

  • 🇩🇪Germany szeidler Berlin

    It's mainly the prepare() and execute() method and a lot of shared properties + constructor + create. For me it felt wrong to move the constructor and create function into the trait. It would lead to typehint issues.

    That's why I splitted up all the common properties and moved them into the trait as well. The class DrdPiCommands uses a reduced set of properties. class DrdCommands declares all properties that are not shared by via the trait.

    What do you think?

  • Pipeline finished with Failed
    2 months ago
    Total: 253s
    #307470
  • Pipeline finished with Success
    2 months ago
    Total: 173s
    #307474
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is looking great. I reviewed the code and would be RTBC, except I can't test it as we don't have PI accounts.

    @szeidler if you could confirm, that it also works in your scenario, please feel free to set to RTBC and I'll merge that right away.

  • 🇩🇪Germany szeidler Berlin

    Yes, the platform synchronization is working fine with the patch. I also checked most of the DRD Drush commands, but only that they are throwing no errors/warnings.

  • Pipeline finished with Skipped
    2 months ago
    #309105
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Excellent, thank you so much for your contribution.

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

Production build 0.71.5 2024