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

drush cannot redeclare : it loads duplicate command files #280

Closed
j0natan opened this issue Nov 22, 2013 · 12 comments
Closed

drush cannot redeclare : it loads duplicate command files #280

j0natan opened this issue Nov 22, 2013 · 12 comments

Comments

@j0natan
Copy link

j0natan commented Nov 22, 2013

Hi,

My original issue "drush cannot redeclare" (https://drupal.org/node/2141985) seems like "drush loads duplicate command files" (https://drupal.org/node/644126).

drush version 5.10.0

Sites cannot migrate between platform and show an error like:

Drush command terminated abnormally due to an unrecoverable error. Error: Cannot redeclare l10n_update_drush_command() (previously declared in /srv/aegir/platforms/drupal-6-2013.11.21-prod/sites/all/modules/contrib/l10n_update/l10n_update.drush.inc:12) in /srv/aegir/platforms/drupal-6-2013.11.21-prod/profiles/openatrium/modules/l10n/l10n_update/l10n_update.drush.inc, line 30
@weitzman
Copy link
Member

weitzman commented Nov 22, 2013

Please use Drupal Answers for Support

@j0natan
Copy link
Author

j0natan commented Nov 22, 2013

I've found http://drupal.stackexchange.com/questions/83959/cannot-redeclare-libraries-drush-command

Is it a support request or an issue with drush ?

I think modules could be duplicated in /profiles/ and /sites/all/modules/ as in /sites/example.org/modules/. And drush should take care of that.

@anarcat
Copy link
Contributor

anarcat commented Nov 22, 2013

Agreed. Note that this was also a problem with modules originally, but I fixed that some time ago, see #644126.

@j0natan
Copy link
Author

j0natan commented Dec 6, 2013

Another use case that is blocked by this is when I want to import a site into an aegir platform that contains one or more same modules as in the site directory.

Drush command terminated abnormally due to an unrecoverable error. Error: Cannot redeclare geocoder_drush_command() (previously declared in /srv/aegir/platforms/drupal-7-2013.12.06-maj/sites/all/modules/contrib/geocoder/geocoder.drush.inc:7) in /srv/aegir/platforms/drupal-7-2013.12.06-maj/sites/example.org/modules/contrib/geocoder/geocoder.drush.inc, line 16

Please reconsider opening this issue.

@anarcat
Copy link
Contributor

anarcat commented Feb 4, 2014

@weitzman this is not a support question, it's a bug, a regression even, at least from what I can tell. I thought I fixed this 3 years ago, can we at least keep this issue opened so we can talk about this?

@anarcat
Copy link
Contributor

anarcat commented Feb 4, 2014

I think the problem is with the cache. The new code checks for duplicates before setting the cache, but if a module is detected after loading the cache, it will hit a dupe.

@anarcat
Copy link
Contributor

anarcat commented Feb 4, 2014

Here's a working patch for 5.10:

root@smd:/home/anarcat# diff -u /usr/share/php/drush/includes/command.inc.orig /usr/share/php/drush/includes/command.inc ot@smd:/home/anarcat# diff -u /usr/share/php/drush/includes/command.inc.orig /usr/share/php/drush/includes/command.inc--- /usr/share/php/drush/includes/command.inc.orig      2014-02-04 18:08:22.281071240 -0500
+++ /usr/share/php/drush/includes/command.inc   2014-02-04 18:12:08.013085574 -0500
@@ -1375,6 +1375,7 @@
 function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) {
   static $evaluated = array();
   static $deferred = array();
+  static $loaded = array();

   $cache =& drush_get_context('DRUSH_COMMAND_FILES', array());

@@ -1445,8 +1446,15 @@
         // command file cache may not be available anymore, in which case
         // we rebuild the cache for this phase.
         if ($filepath = realpath($filename)) {
-          require_once $filepath;
-          unset($deferred[$module]);
+          $module = basename($filename);
+          $module = str_replace(array('.drush.inc', ".drush$dmv.inc"), '', $module);
+          // Only try to bootstrap modules that we have never seen before, or that we
+          // have tried to load but did not due to an unmet _drush_load() requirement.
+          if (!array_key_exists($module, $loaded)) {
+            $loaded[$module] = TRUE;
+            require_once $filepath;
+            unset($deferred[$module]);
+          }
         }
         elseif (!$reset) {
           _drush_add_commandfiles($searchpath, $phase, TRUE);

I'll figure out a pull request, but I am not sure I can test it because we still use drush 5 everywhere.

@ergonlogic
Copy link
Member

ergonlogic commented Feb 5, 2014

Could this be related to #79 (comment) ? It seems to indicate that flaky cache rebuilds are at the root of that bug too.

@mvc1095
Copy link

mvc1095 commented Feb 7, 2014

fwiw the above patch works for me in drush 5.10 using aegir 6.x-2.0.

@BWPanda
Copy link

BWPanda commented Feb 20, 2014

Above patch works for me too (I'm able to install a site in Aegir without errors), but I do get the following warning (multiple times):

Undefined variable: dmv command.inc:1450

@gboudrias
Copy link

gboudrias commented Apr 18, 2014

Works for us too, drush 5.10 / aegir 6.x-2.0. No errors or warnings that I can tell.

@shaneonabike
Copy link

shaneonabike commented Jul 24, 2014

I can confirm this works for me on drush 5.10 and Aegir 6.x-2.1 also :)

It would be great to get this rolled into drush 5.10 since it blocks development on Aegir

props to anarcat 👍

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

Successfully merging a pull request may close this issue.

8 participants