Unable to disable any hooks

Created on 6 September 2024, 7 months ago

Not sure if I am missing something, but I have had to do some jiggery-pokery to get this module to work. These are the steps I have taken to get a result (i.e. skipping the sos_mailchimp_ENTITY_TYPE_update() hook):

  1. Added the config to settings.php:
    $config['migrate_boost.settings'] = [
      'modules' => [
        'sos_mailchimp',
      ],
      'hooks' => [
        'sos_subscription_update' => [
          'sos_mailchimp',
        ],
      ],
    ];

    I realise these settings overlap - I added 'hooks' when nothing was happening so I wanted to try both methods.

  2. Commented out the initial if/return test on static::$alterActive in MigrateBoost.php/alter() as it is always set to NULL, preventing the function from ever running.
  3. Run the migration via drush:
    ddev drush migrate:boost:reset
    ddev drush migrate:import sos_subscription --limit=1

The 2nd drush command gives me an output of:

DISABLED: sos_mailchimp_sos_subscription_presave
DISABLED: sos_mailchimp_sos_subscription_update
 [notice] Processed 1 item (0 created, 1 updated, 0 failed, 0 ignored) - done with 'sos_subscription'

and whilst there are other hooks in sos_mailchimp.module, those are the only 2 that would have been invoked from this particular migration scenario, so that seems good.

Any ideas why I needed to comment that line of code out? Of course, I have to uncomment it to ensure it doesn't run on other drush commands.

Drupal 10.3.3
PHP 8.3.10
nginx/1.26.1

πŸ’¬ Support request
Status

Active

Version

1.0

Component

Documentation

Created by

πŸ‡«πŸ‡·France paulbeaney

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

Merge Requests

Comments & Activities

  • Issue created by @paulbeaney
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    What version of Drush are you using?

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Quick disclaimer, I'm not the original author so any other advice would be greatly appreciated. I think this is generally a side effect of drush updates.

    We want to keep that alter check cause I think that keeps recursion from happening.

    So the hook implements alter alters how the implementations are called.
    Drush is supposed to boot the migrate boost.

    I tried to make it more backwards compatible with this, but something is missing.

    public static function bootDrush($command) {
        // Check if $command is an instance of ArgvInput.
        if ($command instanceof ArgvInput) {
          $command_name = $command->getFirstArgument();
        }
        else {
          // Assuming it's an array for backward compatibility.
          $command_name = $command['command'];
        }
    
        if (in_array($command_name, static::getConfig('commands'))) {
          static::enable();
        }
        else {
          static::disable();
        }
      }
    

    So for some reason the enable command is not being called which means either the command name is not picked up or the commands config is failing.

    Can you share your Drush version?

  • πŸ‡«πŸ‡·France paulbeaney

    Thanks for getting back to me and sorry for omitting that rather important bit of info! I am using drush 12.5.3.0.

    I'm not familiar with the inner workings of drush so I haven't been able to dig too deep yet, but initial debugging seems to indicate that functions such as initCommand(), boosterEnable() and bootDrush() only get called when running either of the Migrate Boost module's own commands (i.e. enable or reset). The rest of the time, the first thing that gets called seems to be MigrateBoost::alter().

    I'll keep digging and feedback anything I find and if you have any ideas of where to look, I am all ears!

  • πŸ‡«πŸ‡·France paulbeaney

    I have made what I think is some good progress on this - at least, it works, and it doesn't seem to interfere with drush commands other than the two this module is targetting. I have implemented 2 annotated hooks in MigrateBoostCommands which run before migrate:import and migrate:rollback (one callback to target each command) and simply call MigrateBoost::enable().

    I have created a fork and updated the file on GitHub, but this is my first foray into non-patch contribution, so if I need to do anything else to make it visible or otherwise complete the process, please let me know!

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Oh that looks good, I'll try to test it in a bit!

  • πŸ‡¬πŸ‡·Greece dwb17

    dwb17 β†’ changed the visibility of the branch 3472566-unable-to-disable to hidden.

  • πŸ‡¬πŸ‡·Greece dwb17

    dwb17 β†’ changed the visibility of the branch 3472566-unable-to-disable to active.

  • Merge request !7Update MigrateBoostCommands.php β†’ (Merged) created by nicxvan
  • Status changed to Fixed 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I've merged this in, I left it in .dev so it can be tested a bit.

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

  • Status changed to Fixed about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡¨πŸ‡¦Canada ptaff

    Running the official 1.0.1 version.

    I hit the same problem as the original poster, where hooks aren't disabled, and only become disabled when commenting the if clause in alter(). It appears though the disabling only happens for the first item in a migration β€” alas, hooks run for all the other items.

    Hence I would gladly test the 1.0.x-dev version that seems to fix the issue.

    But real life means I'm stuck with drush version 12. Customer hosting currently will not upgrade post PHP-8.2 β€” drush version 13 requires PHP-8.3.

    I'm quite glazed-eye when looking at the code, could you please tell me what part of the patch requires drush version 13, so that I can find a workaround, and perhaps submit a patch to make migrate_boost compatible for crusty old environments such as the one I have to deal with?

    Thank you,

  • πŸ‡«πŸ‡·France paulbeaney

    Hi ptaff,

    I am also on drush 12, so having installed the dev version of Migrate Boost manually to get round Composer's refusal to add it, I think I have found what needs changing to the dev version of this module to allow it to work with both Drush 12 and 13:

    Move the file to

    I have tested this with both Drush 12 and Drush 13 so I am pretty confident that it is a universal solution. The only other required change would be setting the composer.json dependency to drush 12.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    If you're still on drush 12 you must be on drupal 10 right? The initial alpha 1 version should still work for you.

  • πŸ‡«πŸ‡·France paulbeaney

    Yup, D10.4.4 to be precise. Until ptaff posted here I was just using my tweaked version from the MR via a composer-applied patch file on the current release. The possibility of going back to an official version intrigued me, hence my renewed dabbling :)

    Given that my suggestion doesn't compromise the Drush 13 functionality (that I can see - I am very happy to be corrected), is there any reason not to have a more widely compatible codebase?

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Can you put that on an MR so I can test it? Drush changed how commands are registered between 12 and 13 as far as I know.

  • πŸ‡«πŸ‡·France paulbeaney

    Certainly. I had already considered it but I'm not sure how to since this issue already has an MR. Can you enlighten me?

    As for the correct folders for Drush, that confused me as well. Whilst it is true that Drush 12 requires commandfiles to be in src/Drush/Commands, we are actually using pre-command hooks here which I guess may work differently. Whilst I can't find a single example or indication of where the pre-commands should be placed, I can only confirm empirically that Drush 13 definitely doesn't find them in src/Commands.

    This is the only reference I have found: https://www.drush.org/13.x/commands/

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    nicxvan β†’ changed the visibility of the branch 3472566-unable-to-disable to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    nicxvan β†’ changed the visibility of the branch 1.0.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I created a new branch for you to use, please use the issue instructions to pull down the drush12 branch and push there.
    You can create an MR from that once you're ready and set it to needs review.

  • Pipeline finished with Failed
    14 days ago
    Total: 131s
    #452328
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Any chance you can solve those failures?

  • Pipeline finished with Failed
    13 days ago
    Total: 549s
    #453137
  • Pipeline finished with Canceled
    13 days ago
    Total: 80s
    #453156
  • Pipeline finished with Success
    13 days ago
    Total: 133s
    #453160
  • πŸ‡«πŸ‡·France paulbeaney

    Any chance you can solve those failures?

    It would appear the answer is "yes"! That was my first real foray into GitLab...

Production build 0.71.5 2024