1

How do I use export.php and import.php to work with multiple sites run with Aegir.

All of them share the same files (php classes) and when I specify the site with -s mysite.org I get nothing (literally the command executes without error it just doesn't output anything).

When I run without spcifying mysite

php export.php -e Contact

PHP Warning: include_once(/var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php): failed to open stream: No such file or directory in /var/aegir/platforms/beta/sites/all/modules/civicrm/civicrm.config.php on line 118 PHP Warning: include_once(): Failed opening '/var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php' for inclusion (include_path='.:/usr/share/php') in /var/aegir/platforms/beta/sites/all/modules/civicrm/civicrm.config.php on line 118

2 Answers 2

1

To execute a PHP script in the context of a selected site, use drush php-script or drush scr.

In your question you specified the site using -s example.org, and I suspect you may be looking for -l (--uri) rather than -s (--simulate) to determine which site to load. See the first section of drush help output for these flags.

If -l doesn't do it, you can also use aliases which Aegir automatically creates for each site - you should find that drush @example.org vget site_name works and returns the name of the expected site, because there will be alias files in eg /var/aegir/.drush/EXAMPLE.ORG.alias.drushrc.php for each site.

So, you probably want something like: drush -l example.org scr /path/to/export.php

  • If drush vget site_name returns the name of the expected site, you've confirmed Drush can connect to Drupal.
  • If drush cvapi Contact.get returns contacts from your site, you've confirmed that CiviCRM works when called via Drush.
  • If drush scr import.php or drush scr export.php still don't work, that sounds like those scripts don't bootstrap "normally" for CiviCRM and there may be work to do to get them to behave.

I don't actually know how import.php/export.php are expected to behave - so I might have led you astray. Looking at them, I'd expect export.php probably works via Drush, but I see import.php is looking for $_GET['file'] which Id' expect to require special treatment for Drush use (but I see this SE answer says it works using --file=blah.csv, and that you should call them via php import.php not drush).

3
  • Unfortunately I get the same error. Alias works (drush @mysite.org help works) but I still get Could not load the settings file at: /var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php. I guess it's still targeting the wrong civicrm.settings.php (the default one instead of mysite specific
    – Marko
    Commented Jan 30, 2018 at 14:26
  • Good point - drush help works whether or not you have a valid site. I've updated my answer to recommend drush vget site_name which will confirm that Drush executes and connects to the site you expect. Commented Jan 30, 2018 at 22:49
  • Yeah, drush works, and it identifies the proper site_name, but I can't execute the export script. I always get that same error.
    – Marko
    Commented Feb 6, 2018 at 11:48
1

What finally made it work was this:

First I needed to set the CIVICRM_SETTINGS env variable to the civicrm.settings.php file for my subsite

 export CIVICRM_SETTINGS=/var/aegir/platforms/example/sites/my.site.org/civicrm.settings.php

Only then could I execute the php file export.php, not with src but with php-script

drush php-script  /var/aegir/platforms/example/sites/all/civicrm/bin/csv/export.php -e Contact

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.