Running 'drush sql-sync dev stage' I get the following error:

$ drush sql-sync dev stage

Fatal error: Cannot redeclare domain_settings_setup_ok() (previously declared in /var/www/sites/all/modules/domain/settings.inc:38) in /var/www/sites/all/modules/domain/settings.inc on line 44

Call Stack:
    0.0013     184288   1. {main}() /usr/local/drush/drush.php:0
    0.0198    1830600   2. drush_main() /usr/local/drush/drush.php:41
    0.3684    6802912   3. drush_dispatch() /usr/local/drush/drush.php:91
    0.3687    6805600   4. call_user_func_array() /usr/local/drush/includes/drush.inc:51
    0.3687    6806216   5. drush_command() /usr/local/drush/includes/drush.inc:0
    0.3689    6807520   6. call_user_func_array() /usr/local/drush/includes/command.inc:378
    0.3689    6807760   7. drush_invoke() /usr/local/drush/includes/command.inc:0
    0.4066    7068096   8. call_user_func_array() /usr/local/drush/includes/command.inc:327
    0.4066    7068712   9. drush_sql_sync() /usr/local/drush/includes/command.inc:0
    0.4075    7069592  10. _drush_sql_sync() /usr/local/drush/commands/sql/sync.sql.inc:34
    0.4076    7069936  11. drush_sitealias_get_record() /usr/local/drush/commands/sql/sync.sql.inc:39
    0.4076    7070456  12. _drush_sitealias_get_record() /usr/local/drush/includes/sitealias.inc:77
    0.4079    7071272  13. _drush_sitealias_build_record_from_settings() /usr/local/drush/includes/sitealias.inc:167
    0.4079    7072192  14. drush_sitealias_build_record_from_settings_file() /usr/local/drush/includes/sitealias.inc:619
    0.4084    7085416  15. require('/var/www/sites/default/settings.php') /usr/local/drush/includes/sitealias.inc:635

The resolution is simple, in the settings.php file, use: include_once './sites/all/modules/domain/settings.inc'; instead of include './sites/all/modules/domain/settings.inc';

Comments

yhager’s picture

Status: Active » Needs review
agentrickard’s picture

I was trying to avoid that for performance reasons.

Personally, I think this is a drush bug. Normally, there is no reason to load settings.php twice in a single request, otherwise line 15 of your report would be require_once() instead of require().

   0.4084    7085416  15. require('/var/www/sites/default/settings.php') /usr/local/drush/includes/sitealias.inc:635

Note that conf_init() uses include_once(), so our use of it is redundant and just increases PHP memory strain.

http://api.drupal.org/api/function/conf_init

agentrickard’s picture

Project: Domain » Drush
Version: 6.x-2.1 »
Component: Documentation » Code

Moving for discussion. Please make sure this is the right queue.

yhager’s picture

Project: Drush » Domain
Version: » 6.x-2.1
Component: Code » Documentation

I agree it can affect performance - it was just an easy fix for me. Do you think this issue should be moved to drush issue queue?
Anyway, if anyone else gets hit by this issue, vote here, so we'll know I am not the only one who uses drush with domain access :)

agentrickard’s picture

Project: Domain » Drush
Version: 6.x-2.1 »
Component: Documentation » Code

Cross-post. I already moved it once.

yhager’s picture

aw, crap - I overwrote your changes. sorry.

yhager’s picture

I am attaching a patch against drush.
Forgive my rudeness, but it's a git patch - let me know if you want a reroll against CVS.

moshe weitzman’s picture

Status: Needs review » Closed (duplicate)

This is not at all easy to fix in drush. A single include_once will hardly affect performance. lets be merciful and just do that. Please. Marking as a dupe as this came up once before.

agentrickard’s picture

Status: Closed (duplicate) » Active

@moshe

I disagree. Drush is violating how core handles it, and that causes errors in contrib.

And you can't mark it a duplicate if you're going to push the fix back to the original module.

The whole include_once() issue is something I've heard Rasmus rail about more than once, and its a habit Drupal needs to start avoiding.

Either refile to DA, or reconsider, please.

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson

The solution in #0 probably works, but the patch in #7 will not work, can not work, and should not be committed in drush.

From the patch:

   if (file_exists($site_settings_file)) {
     global $databases, $db_url, $base_url;
     $base_url = null;
-    require $site_settings_file;
+    require_once $site_settings_file;
     if (isset($db_url)) {
       $alias_record['db-url'] = $db_url;
     }

The point of this bit of code is to get the 'db-url' out of the settings file and assign it to the alias record. However, if the settings file has already been included, then "require_once" will do nothing, db_url will not be set, and you will have about a 50% chance of the correct db-url being assigned to your alias record, depending on what order they were referenced before.

I can offer you a different solution, though. drush uses backend_invoke to get the db_url from remote sites, and it could use the same technique to get the db_url from local sites. This would entirely remove including / requiring the settings.php file from the site alias code, which I think would be a big improvement.

Unfortunately, I can't roll this patch until next week, but if y'all just hang tight, I'll get it fixed up right quick.

yhager’s picture

> the patch in #7 will not work, can not work, and should not be committed in drush.

Of course it is not. I am sorry to have proposed it in the first place and overlooked this obvious flaw. I was in a hurry, and learnt my lesson :)

greg.1.anderson’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB

Sorry, I didn't mean to state it quite so strongly as that.

In any rate, this issue is now almost a duplicate of #702554: Look up sitealias database settings only after a full database bootstrap, but one more minor change is needed before things will work right for this use case. The enclosed patch should do the trick.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

looks good to me. greg is welcome to commit this if he is ready. otherwise, i can easily do it.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Thanks; committed.

agentrickard’s picture

3.0 beta working fine with DA....

Status: Fixed » Closed (fixed)

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

brainajw’s picture

Status: Closed (fixed) » Needs work

I am faced with this same error. I tried making the changes and it still gets the error. This error started when I activated the multisite module, multisite search module. Only way around this is to disable these modules. Must be a conflict between the two. I'm a noob so maybe i'm doing something wrong.

multisite_api
multisite_login
multisite_search

Type cron
Date Friday, April 2, 2010 - 07:12
User JonBr84
Location http://localhost/mysite/?q=admin/reports/status/run-cron&destination=adm...
Referrer http://localhost/mysite/?q=admin/build/modules
Message Cron run exceeded the time limit and was aborted.
Severity warning
Hostname 127.0.0.1
Operations

It happens when the cron is ran, or sometimes when I'm going into the module section in drupal.

Fatal error: Cannot redeclare domain_settings_setup_ok() (previously declared in C:\wamp\www\mysite\modules\domain\settings.inc:39) in C:\wamp\www\mysite\modules\domain\settings.inc on line 44

Everything is up to date. Versions listed below:
Drupal 6.16
Includes: Block, Book, Color, Comment, Contact, Database logging, Filter, Forum, Help, Locale, Menu, Node, Poll, Profile, Search, System, Taxonomy, Tracker, Update status, Upload, User
Modules
Up to dateok
Birthdays 6.x-1.0
Includes: Birthdays
Up to dateok
Chat Room 6.x-2.9
Includes: Chat Room
Up to dateok
Contact Forms 6.x-1.12
Includes: Contact Forms
Up to dateok
Content Construction Kit (CCK) 6.x-2.6
Also available: 6.x-3.x-dev (2010-Jan-25)

* Download
* Release notes

Includes: Content, Option Widgets
Up to dateok
FileField 6.x-3.2
Includes: FileField
Up to dateok
Front Page 6.x-1.2
Includes: Front Page
Up to dateok
Image 6.x-1.0-beta5
Includes: Image, Image Attach, Image Gallery, Image Import
Up to dateok
Image FUpload 6.x-3.0-rc2
Includes: Image FUpload, Image FUpload (CCK), Image FUpload (image)
Up to dateok
ImageAPI 6.x-1.6
Includes: ImageAPI, ImageAPI ImageMagick
Up to dateok
ImageCache 6.x-2.0-beta10
Includes: ImageCache, ImageCache UI
Up to dateok
ImageField 6.x-3.2
Includes: ImageField
Up to dateok
IMCE 6.x-1.3
Also available: 6.x-2.0-beta1 (2010-Mar-17)

* Download
* Release notes

Includes: IMCE
Up to dateok
Interface 6.x-1.0
Includes: Interface, Tabbable
Up to dateok
jQuery UI 6.x-1.3
Includes: jQuery UI
Up to dateok
Lightbox2 6.x-1.9
Includes: Lightbox2
Up to dateok
Multisite API 6.x-1.0
Includes: Multisite API
Up to dateok
OpenID URL 6.x-1.5
Also available: 6.x-2.x-dev (2009-Oct-05)

* Download
* Release notes

Includes: OpenID URL
Up to dateok
User Permissions 6.x-1.0
Includes: User Permissions
Up to dateok
Views 6.x-2.8
Also available: 6.x-3.0-alpha2 (2010-Jan-25)

* Download
* Release notes

Includes: Views
Up to dateok
Webform 6.x-2.9
Also available: 6.x-3.0-beta2 (2010-Mar-01)

* Download
* Release notes

Includes: Webform
Up to dateok
Wysiwyg 6.x-2.1
Includes: Wysiwyg

greg.1.anderson’s picture

Status: Needs work » Fixed

Use drush-HEAD. Also, please report the problem you are having, do not say "the same error". That doesn't give enough information to tell if the error is actually the same or not.

Status: Fixed » Closed (fixed)

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