/** * @param \Civi\Core\Event\UnhandledExceptionEvent $event * @throws Exception */ public static function handleException($event) { $e = $event->exception; if ($e instanceof CRM_Core_Exception) { $params = $e->getErrorData(); $message = $e->getMessage(); $session = CRM_Core_Session::singleton(); $session->setStatus($message, CRM_Utils_Array::value('message_title', $params), CRM_Utils_Array::value('message_type', $params, 'error')); // @todo remove this code - legacy redirect path is an interim measure for moving redirects out of BAO // to somewhere slightly more acceptable. they should not be part of the exception class & should // be managed @ the form level - if you find a form that is triggering this piece of code // you should log a ticket for it to be removed with details about the form you were on. if (!empty($params['legacy_redirect_path'])) { if (CRM_Utils_System::isDevelopment()) { // here we could set a message telling devs to log it per above } CRM_Utils_System::redirect($params['legacy_redirect_path'], $params['legacy_redirect_query']); } } }
protected static function _invoke($args) { if ($args[0] !== 'civicrm') { return; } // CRM-15901: Turn off PHP errors display for all ajax calls if (CRM_Utils_Array::value(1, $args) == 'ajax' || CRM_Utils_Array::value('snippet', $_REQUEST)) { ini_set('display_errors', 0); } if (!defined('CIVICRM_SYMFONY_PATH')) { try { // Traditional Civi invocation path self::hackMenuRebuild($args); // may exit self::init($args); self::hackStandalone($args); $item = self::getItem($args); return self::runItem($item); } catch (CRM_Core_EXCEPTION $e) { $params = $e->getErrorData(); $message = $e->getMessage(); if (isset($params['legacy_status_bounce'])) { //@todo remove this- see comments on //https://github.com/eileenmcnaughton/civicrm-core/commit/ae686b09e2c987091612bb25ba0a58e520a203e7 CRM_Core_Error::statusBounce($params['message']); } else { $session = CRM_Core_Session::singleton(); $session->setStatus($message, CRM_Utils_Array::value('message_title', $params), CRM_Utils_Array::value('message_type', $params, 'error')); // @todo remove this code - legacy redirect path is an interim measure for moving redirects out of BAO // to somewhere slightly more acceptable. they should not be part of the exception class & should // be managed @ the form level - if you find a form that is triggering this piece of code // you should log a ticket for it to be removed with details about the form you were on. if (!empty($params['legacy_redirect_path'])) { if (CRM_Utils_System::isDevelopment()) { // here we could set a message telling devs to log it per above } CRM_Utils_System::redirect($params['legacy_redirect_path'], $params['legacy_redirect_query']); } } } catch (Exception $e) { // Recall: CRM_Core_Config is initialized before calling CRM_Core_Invoke $config = CRM_Core_Config::singleton(); return CRM_Core_Error::handleUnhandledException($e); /* if ($config->backtrace) { return CRM_Core_Error::formatHtmlException($e); } else { // TODO }*/ } } else { // Symfony-based invocation path require_once CIVICRM_SYMFONY_PATH . '/app/bootstrap.php.cache'; require_once CIVICRM_SYMFONY_PATH . '/app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $response = $kernel->handle(Symfony\Component\HttpFoundation\Request::createFromGlobals()); // $response->send(); return $response->getContent(); } }
/** * System.Get API. * * @param array $params * * @return array */ function civicrm_api3_system_get($params) { $config = CRM_Core_Config::singleton(); $returnValues = array(array('version' => CRM_Utils_System::version(), 'uf' => CIVICRM_UF, 'php' => array('version' => phpversion(), 'tz' => date_default_timezone_get(), 'extensions' => get_loaded_extensions(), 'ini' => _civicrm_api3_system_get_redacted_ini()), 'mysql' => array('version' => CRM_Core_DAO::singleValueQuery('SELECT @@version')), 'cms' => array('type' => CIVICRM_UF, 'modules' => CRM_Core_Module::collectStatuses($config->userSystem->getModules())), 'civi' => array('version' => CRM_Utils_System::version(), 'dev' => (bool) CRM_Utils_System::isDevelopment(), 'components' => array_keys(CRM_Core_Component::getEnabledComponents()), 'extensions' => preg_grep('/^uninstalled$/', CRM_Extension_System::singleton()->getManager()->getStatuses(), PREG_GREP_INVERT), 'exampleUrl' => CRM_Utils_System::url('civicrm/example', NULL, TRUE, NULL, FALSE)))); return civicrm_api3_create_success($returnValues, $params, 'System', 'get'); }
/** * @param $dsn * @param string $fileName * @param null $prefix * @param bool $isQueryString * @param bool $dieOnErrors */ public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE) { require_once 'DB.php'; $db = DB::connect($dsn); if (PEAR::isError($db)) { die("Cannot open {$dsn}: " . $db->getMessage()); } if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) { $db->query('SET SESSION sql_mode = STRICT_TRANS_TABLES'); } if (!$isQueryString) { $string = $prefix . file_get_contents($fileName); } else { // use filename as query string $string = $prefix . $fileName; } // get rid of comments starting with # and -- $string = preg_replace("/^#[^\n]*\$/m", "\n", $string); $string = preg_replace("/^(--[^-]).*/m", "\n", $string); $queries = preg_split('/;\\s*$/m', $string); foreach ($queries as $query) { $query = trim($query); if (!empty($query)) { CRM_Core_Error::debug_query($query); $res =& $db->query($query); if (PEAR::isError($res)) { if ($dieOnErrors) { die("Cannot execute {$query}: " . $res->getMessage()); } else { echo "Cannot execute {$query}: " . $res->getMessage() . "<p>"; } } } } }
/** * Initialize the DAO object. * * @param string $dsn * The database connection string. */ public static function init($dsn) { Civi::$statics[__CLASS__]['init'] = 1; $options =& PEAR::getStaticProperty('DB_DataObject', 'options'); $options['database'] = $dsn; if (defined('CIVICRM_DAO_DEBUG')) { self::DebugLevel(CIVICRM_DAO_DEBUG); } CRM_Core_DAO::setFactory(new CRM_Contact_DAO_Factory()); if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) { CRM_Core_DAO::executeQuery('SET SESSION sql_mode = STRICT_TRANS_TABLES'); } CRM_Core_DAO::executeQuery('SET NAMES utf8'); }
/** * System.Get API. * * @param array $params * * @return array */ function civicrm_api3_system_get($params) { $config = CRM_Core_Config::singleton(); $returnValues = array(array('version' => CRM_Utils_System::version(), 'uf' => CIVICRM_UF, 'php' => array('version' => phpversion(), 'time' => time(), 'tz' => date_default_timezone_get(), 'sapi' => php_sapi_name(), 'extensions' => get_loaded_extensions(), 'ini' => _civicrm_api3_system_get_redacted_ini()), 'mysql' => array('version' => CRM_Core_DAO::singleValueQuery('SELECT @@version'), 'time' => CRM_Core_DAO::singleValueQuery('SELECT unix_timestamp()'), 'vars' => _civicrm_api3_system_get_redacted_mysql()), 'cms' => array('version' => $config->userSystem->getVersion(), 'type' => CIVICRM_UF, 'modules' => CRM_Core_Module::collectStatuses($config->userSystem->getModules())), 'civi' => array('version' => CRM_Utils_System::version(), 'dev' => (bool) CRM_Utils_System::isDevelopment(), 'components' => array_keys(CRM_Core_Component::getEnabledComponents()), 'extensions' => preg_grep('/^uninstalled$/', CRM_Extension_System::singleton()->getManager()->getStatuses(), PREG_GREP_INVERT), 'multidomain' => CRM_Core_DAO::singleValueQuery('SELECT count(*) FROM civicrm_domain') > 1, 'settings' => _civicrm_api3_system_get_redacted_settings(), 'exampleUrl' => CRM_Utils_System::url('civicrm/example', NULL, TRUE, NULL, FALSE)), 'http' => array('software' => CRM_Utils_Array::value('SERVER_SOFTWARE', $_SERVER), 'forwarded' => !empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['X_FORWARDED_PROTO']), 'port' => empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? 'Standard' : 'Nonstandard'), 'os' => array('type' => php_uname('s'), 'release' => php_uname('r'), 'version' => php_uname('v'), 'machine' => php_uname('m')))); return civicrm_api3_create_success($returnValues, $params, 'System', 'get'); }
/** * Initialize the DataObject framework. * * @return void */ private function _initDAO() { CRM_Core_DAO::init($this->dsn); $factoryClass = $this->DAOFactoryClass; require_once str_replace('_', DIRECTORY_SEPARATOR, $factoryClass) . '.php'; CRM_Core_DAO::setFactory(new $factoryClass()); if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) { CRM_Core_DAO::executeQuery('SET SESSION sql_mode = STRICT_TRANS_TABLES'); } }