CRM-14856 - CRM_Profile_Form_Edit - Reimplement cancelURL
[civicrm-core.git] / bin / cli.class.php
index cad7f6ce3c68f05858130008bee1494c96404c99..de72c475b41673eb7f3297a250fd035059de530d 100644 (file)
@@ -51,6 +51,7 @@ class civicrm_cli {
   // optional arguments
   var $_site = 'localhost';
   var $_user = NULL;
+  var $_password = NULL;
 
   // all other arguments populate the parameters
   // array that is passed to civicrm_api
@@ -200,10 +201,21 @@ class civicrm_cli {
     chdir($civicrm_root);
     require_once ('civicrm.config.php');
     // autoload
-    require_once $civicrm_root . '/CRM/Core/ClassLoader.php';
+    if ( !class_exists('CRM_Core_ClassLoader') ) {
+      require_once $civicrm_root . '/CRM/Core/ClassLoader.php';
+    }
     CRM_Core_ClassLoader::singleton()->register();
 
     $this->_config = CRM_Core_Config::singleton();
+    
+    // HTTP_HOST will be 'localhost' unless overwritten with the -s argument.
+    // Now we have a Config object, we can set it from the Base URL.
+    if ($_SERVER['HTTP_HOST'] == 'localhost') {
+        $_SERVER['HTTP_HOST'] = preg_replace(
+                '!^https?://([^/]+)/$!i', 
+                '$1',
+                $this->_config->userFrameworkBaseURL);
+    }
 
     $class = 'CRM_Utils_System_' . $this->_config->userFramework;
 
@@ -366,7 +378,7 @@ 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 
+      //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]);