From 0d5a3f9deeda18944ea95bfe1775364214811213 Mon Sep 17 00:00:00 2001
From: Jon goldberg - Linux laptop <jon@palantetech.coop>
Date: Tue, 23 Jul 2013 18:03:00 -0400
Subject: [PATCH] fixes CRM-13050

----------------------------------------
* CRM-13050: cli.class.php doesn't import/export custom fields with multi-select values
  http://issues.civicrm.org/jira/browse/CRM-13050
---
 bin/cli.class.php | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/bin/cli.class.php b/bin/cli.class.php
index 9b6c4eb89a..0a0bbd73eb 100644
--- a/bin/cli.class.php
+++ b/bin/cli.class.php
@@ -298,6 +298,13 @@ class civicrm_cli_csv_exporter extends civicrm_cli {
         fputcsv($out, $columns, $this->separator, '"');
         $first = false;
       }
+      //handle values returned as arrays (i.e. custom fields that allow multiple selections) by inserting a control character
+      foreach ($row as &$field) {
+        if(is_array($field)) {
+          //convert to string
+          $field = implode($field,CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
+        }
+      }
       fputcsv($out, $row, $this->separator, '"');
     }
     fclose($out);
@@ -359,6 +366,11 @@ class civicrm_cli_csv_file extends civicrm_cli {
   function convertLine($data) {
     $params = array();
     foreach ($this->header as $i => $field) {
+      //split any multiselect data, denoted with CRM_Core_DAO::VALUE_SEPARATOR 
+      if (strpos($data[$i], CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
+        $data[$i] = explode(CRM_Core_DAO::VALUE_SEPARATOR,$data[$i]);
+        $data[$i] = array_combine($data[$i], $data[$i]);
+      }
       $params[$field] = $data[$i];
     }
     $params['version'] = 3;
-- 
GitLab