Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Important change in hook replace-command #214

Open
jurgenhaas opened this issue Nov 25, 2020 · 0 comments
Open

Important change in hook replace-command #214

jurgenhaas opened this issue Nov 25, 2020 · 0 comments

Comments

@jurgenhaas
Copy link

We ran into an issue with the replace-command hook. As an example, our command class looks like this:

<?php

namespace Drupal\example\Commands;

use Drush\Commands\DrushCommands;

/**
 * A Drush commandfile to overwrite some of the drush commands.
 */
class ExampleCommands extends DrushCommands {

  /**
   * @hook replace-command default-content-access:import-module
   */
  public function contentImportModule($module, $options = ['update-existing' => FALSE]): void {
    print 'Disabled on this site!';
  }

  /**
   * @hook replace-command locale:import
   */
  public function import($langcode, $file, $options = ['type' => self::OPT, 'override' => self::OPT]) {
    print 'Disabled on this site!';
  }

}

This worked just fine for several years now but started to fail yesterday. TBH, I don't know which component has changed to make this fail but the error message is

In InputDefinition.php line 232:
  [Symfony\Component\Console\Exception\LogicException]  
  An option named "type" already exists.                

The stack trace is

  at /var/www/html/vendor/symfony/console/Input/InputDefinition.php:232
 Symfony\Component\Console\Input\InputDefinition->addOption() at /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:206
 Consolidation\AnnotatedCommand\AnnotatedCommand->addOptions() at /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:263
 Consolidation\AnnotatedCommand\AnnotatedCommand->optionsHookForHookAnnotations() at /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/OptionsHookDispatcher.php:31
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\OptionsHookDispatcher->getOptions() at /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php:154
 Consolidation\AnnotatedCommand\CommandProcessor->optionsHook() at /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:255
 Consolidation\AnnotatedCommand\AnnotatedCommand->optionsHook() at /var/www/html/vendor/consolidation/annotated-command/src/Options/AlterOptionsCommandEvent.php:81
 Consolidation\AnnotatedCommand\Options\AlterOptionsCommandEvent->findAndAddHookOptions() at /var/www/html/vendor/consolidation/annotated-command/src/Options/AlterOptionsCommandEvent.php:72
 Consolidation\AnnotatedCommand\Options\AlterOptionsCommandEvent->alterCommandOptions() at /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:214
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:44
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/CommandEventHookDispatcher.php:30
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\CommandEventHookDispatcher->callCommandEventHooks() at /var/www/html/vendor/consolidation/annotated-command/src/Hooks/HookManager.php:424
 Consolidation\AnnotatedCommand\Hooks\HookManager->callCommandEventHooks() at /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:214
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:44
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /var/www/html/vendor/symfony/console/Application.php:1007
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:255
 Symfony\Component\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:148
 Symfony\Component\Console\Application->run() at /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php:118
 Drush\Runtime\Runtime->doRun() at /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php:49
 Drush\Runtime\Runtime->run() at /var/www/html/vendor/drush/drush/drush.php:72
 require() at /var/www/html/vendor/drush/drush/includes/preflight.inc:18
 drush_main() at phar:///usr/local/bin/drush/bin/drush.php:141
 require() at /usr/local/bin/drush:10

When removing the options parameter from our overwrite function, then it works just fine. But that contradicts the documentation: Parameters must match original command method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant