New tools to automate the configuration and staging/production migration

2011-04-15 04:22
Written by
Filed under


Joseph (not verified)
2011-10-20 - 14:19

We've done a lot of refactoring with 4.2 that changes the behavior of the import/export scripts (and fixes some bugs that prevented it from working in earlier releases).


It's now better integrated with the re-designed cli.php.


Here are the new usage directions for 4.2:


* Usage:
 * php bin/csv/import.php -e <entity> --file /path/to/csv/file [ -s ]
 * e.g.: php bin/csv/import.php -e Contact --file /tmp/import.csv


* Usage:
 * php bin/csv/export.php -e <entity> [ --field=value --field=value ] [ -s ]
 * e.g.: php bin/csv/export.php -e Contact -s

The export doesn't export all the fields in Version 4.2.2

With a standard install I first exported the Custom Group Table:

php export.php -e CustomField Tag > custom_field.csv

I then re-imported it:

php import.php -e CustomGroup --file C:\Exports\custom_group.csv

When checking the before / after copies of the Custom Group Table (and the export file) I noticed that the following fields had not been included in the export (and hence, the values in these fields could not be re-imported, and so were lost):





With 4.2, there's a change in how parameters are passed using these tools.  You need to add columns to the CSV itself.  The parameter name goes in the header, and the value in the record.

Here's a snippet I used to remove all the contacts from a database while keeping the settings, custom fields, etc. intact.  it adds a column called "skip_undelete" with a vaue of "1" for each record:

drush civicrm-sql-query "SELECT id from civicrm_contact WHERE id > 1;" > test.csv
sed -i '1 s/.*/&,skip_undelete/' test.csv
sed -i '2,$ s/.*/&,1/' test.csv
php /var/www/<mysite>/sites/all/modules/contrib/civicrm/bin/csv/delete.php -e Contact -u civi.admin -p <mypass> --file=<mypath>/test.csv


I'm using an older version of CiviCRM (4.6) with Drupal 7 on Linux and until now I've not really used the command line stuff for CiviCRM, only for Drupal.

But I now need to do exports & imports of contacts etc to & from CiviCRM and so I've installed Drush & got it working. I've tried doing an export with the export.php script with Drush and can manipulate the search results to some degree. But for some reason if only exports the first 26 rows ... is the a parameter that I should be using to get the full rowcount?

Also, where is the best place to get a more detailed list of examples, list of possible parameters etc?