private function bootstrap($cmsRoot, $civicrm_config_path) { define('CIVICRM_CMSDIR', $cmsRoot); require_once $civicrm_config_path; // so the configuration works with php-cli $_SERVER['PHP_SELF'] = "/index.php"; $_SERVER['HTTP_HOST'] = 'localhost'; // $this->_site; $_SERVER['REMOTE_ADDR'] = "127.0.0.1"; $_SERVER['SERVER_SOFTWARE'] = NULL; $_SERVER['REQUEST_METHOD'] = 'GET'; // SCRIPT_FILENAME needed by CRM_Utils_System::cmsRootPath $_SERVER['SCRIPT_FILENAME'] = __FILE__; // CRM-8917 - check if script name starts with /, if not - prepend it. if (ord($_SERVER['SCRIPT_NAME']) != 47) { $_SERVER['SCRIPT_NAME'] = '/' . $_SERVER['SCRIPT_NAME']; } $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', $config->userFrameworkBaseURL); } global $civicrm_root; if (!\CRM_Utils_System::loadBootstrap(array(), FALSE, FALSE, $civicrm_root)) { throw new \Exception("Failed to bootstrap CMS"); // return FALSE; } return TRUE; }
/** * @return bool */ private function _bootstrap() { // so the configuration works with php-cli $_SERVER['PHP_SELF'] = "/index.php"; $_SERVER['HTTP_HOST'] = $this->_site; $_SERVER['REMOTE_ADDR'] = "127.0.0.1"; $_SERVER['SERVER_SOFTWARE'] = NULL; $_SERVER['REQUEST_METHOD'] = 'GET'; // SCRIPT_FILENAME needed by CRM_Utils_System::cmsRootPath $_SERVER['SCRIPT_FILENAME'] = __FILE__; // CRM-8917 - check if script name starts with /, if not - prepend it. if (ord($_SERVER['SCRIPT_NAME']) != 47) { $_SERVER['SCRIPT_NAME'] = '/' . $_SERVER['SCRIPT_NAME']; } $civicrm_root = dirname(__DIR__); chdir($civicrm_root); require_once 'civicrm.config.php'; // autoload 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; $cms = new $class(); if (!CRM_Utils_System::loadBootstrap(array(), FALSE, FALSE, $civicrm_root)) { $this->_log(ts("Failed to bootstrap CMS")); return FALSE; } if (strtolower($this->_entity) == 'job') { if (!$this->_user) { $this->_log(ts("Jobs called from cli.php require valid user as parameter")); return FALSE; } } if (!empty($this->_user)) { if (!CRM_Utils_System::authenticateScript(TRUE, $this->_user, $this->_password, TRUE, FALSE, FALSE)) { $this->_log(ts("Failed to login as %1. Wrong username or password.", array('1' => $this->_user))); return FALSE; } if (!$cms->loadUser($this->_user)) { $this->_log(ts("Failed to login as %1", array('1' => $this->_user))); return FALSE; } } return TRUE; }
private function _bootstrap() { // so the configuration works with php-cli $_SERVER['PHP_SELF'] = "/index.php"; $_SERVER['HTTP_HOST'] = $this->_site; $_SERVER['REMOTE_ADDR'] = "127.0.0.1"; // SCRIPT_FILENAME needed by CRM_Utils_System::cmsRootPath $_SERVER['SCRIPT_FILENAME'] = __FILE__; // CRM-8917 - check if script name starts with /, if not - prepend it. if (ord($_SERVER['SCRIPT_NAME']) != 47) { $_SERVER['SCRIPT_NAME'] = '/' . $_SERVER['SCRIPT_NAME']; } $civicrm_root = dirname(__DIR__); chdir($civicrm_root); require_once 'civicrm.config.php'; // autoload require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; CRM_Core_ClassLoader::singleton()->register(); require_once 'CRM/Core/Config.php'; $this->_config = CRM_Core_Config::singleton(); require_once 'CRM/Utils/System.php'; $class = 'CRM_Utils_System_' . $this->_config->userFramework; $cms = new $class(); if (!CRM_Utils_System::loadBootstrap(array(), FALSE, FALSE, $civicrm_root)) { $this->_log(ts("Failed to bootstrap CMS")); return FALSE; } if (strtolower($this->_entity) == 'job') { if (!$this->_user) { $this->_log(ts("Jobs called from cli.php require valid user as parameter")); return FALSE; } } if (!empty($this->_user)) { if (!$cms->loadUser($this->_user)) { $this->_log(ts("Failed to login as %1", array('1' => $this->_user))); return FALSE; } } return TRUE; }