Merge pull request #10439 from jitendrapurohit/CRM-20657
[civicrm-core.git] / bin / cli.class.php
index 1a2b8cab6c7829e508e3b40c7eed4608b9f7cdc1..195792554074fd8994f34c275613579a1ecc05c0 100644 (file)
@@ -46,6 +46,7 @@ class civicrm_cli {
   var $_action = NULL;
   var $_output = FALSE;
   var $_joblog = FALSE;
+  var $_semicolon = FALSE;
   var $_config;
 
   // optional arguments
@@ -185,6 +186,9 @@ class civicrm_cli {
       elseif ($arg == '-j' || $arg == '--joblog') {
         $this->_joblog = TRUE;
       }
+      elseif ($arg == '-sem' || $arg == '--semicolon') {
+        $this->_semicolon = TRUE;
+      }
       else {
         foreach ($this->_additional_arguments as $short => $long) {
           if ($arg == '-' . $short || $arg == '--' . $long) {
@@ -265,7 +269,7 @@ class civicrm_cli {
         $this->_log(ts("Failed to login as %1. Wrong username or password.", array('1' => $this->_user)));
         return FALSE;
       }
-      if (!$cms->loadUser($this->_user)) {
+      if (($this->_config->userFramework == 'Joomla' && !$cms->loadUser($this->_user, $this->_password)) || !$cms->loadUser($this->_user)) {
         $this->_log(ts("Failed to login as %1", array('1' => $this->_user)));
         return FALSE;
       }
@@ -342,7 +346,14 @@ class civicrm_cli_csv_exporter extends civicrm_cli {
     parent::initialize();
   }
 
+  /**
+   * Run the script.
+   */
   public function run() {
+    if ($this->_semicolon) {
+      $this->separator = ';';
+    }
+
     $out = fopen("php://output", 'w');
     fputcsv($out, $this->columns, $this->separator, '"');
 
@@ -407,9 +418,6 @@ class civicrm_cli_csv_file extends civicrm_cli {
       $this->separator = ";";
       rewind($handle);
       $header = fgetcsv($handle, 0, $this->separator);
-      if (count($header) == 1) {
-        die("Invalid file format for " . $this->_file . ". It must be a valid csv with separator ',' or ';'\n");
-      }
     }
 
     $this->header = $header;
@@ -419,6 +427,10 @@ class civicrm_cli_csv_file extends civicrm_cli {
         continue;
       }
       $this->row++;
+      if ($this->row % 1000 == 0) {
+        // Reset PEAR_DB_DATAOBJECT cache to prevent memory leak
+        CRM_Core_DAO::freeResult();
+      }
       $params = $this->convertLine($data);
       $this->processLine($params);
     }