Commit 635f0b86 authored by totten's avatar totten

CRM-16373 - CRM_Core_Config - Simplify initialization, esp `templateCompileDir`

Generally, this commit removes some silly 1-line functions, misplaed
functions, duplicated steps, obvious comments, and expired comments.

There is a change in `templateCompileDir`.

The `templateCompileDir` had two different intialization blocks (in
different places), which likely arose from variations in the code-paths used
for memcache systems.  Both routines append a locale and create the dir.

This is redundant, and it unnecessarily forces us to resolve the locale
early during initialization.  But honestly we don't need to append the
locale until much later (when/if Smarty is first used).

There are a few oddballs who use `$config->templateCompileDir` and they may
see a slight change (working with the real templateCompileDir rather than
the locale subdir):

 * The cleanup. If this code causes a change, it will be an improvement:
   instead of cleaning the Smarty cache for one locale, it'll clean the
   entire Smarty cache for all locales.
 * Random temp files. The temp files seem to be transactional in nature
   (tied to the specific invocatoin) and not to the locale.
parent 348754d5
This diff is collapsed.
......@@ -42,15 +42,6 @@
*/
class CRM_Core_Config_Defaults {
public function setCoreVariables() {
global $civicrm_root;
$this->templateDir = array(
$civicrm_root . DIRECTORY_SEPARATOR .
'templates' . DIRECTORY_SEPARATOR,
);
}
/**
* Set the default values.
* in an empty db, also called when setting component using GUI
......@@ -79,9 +70,7 @@ class CRM_Core_Config_Defaults {
}
$baseCMSURL = CRM_Utils_System::baseCMSURL();
if ($config->templateCompileDir) {
$path = CRM_Utils_File::baseFilePath($config->templateCompileDir);
}
$path = CRM_Utils_File::baseFilePath();
if (!isset($defaults['enableSSL'])) {
$defaults['enableSSL'] = 0;
}
......@@ -106,9 +95,7 @@ class CRM_Core_Config_Defaults {
);
if (strpos($civicrm_root,
DIRECTORY_SEPARATOR . 'sites' .
DIRECTORY_SEPARATOR . 'all' .
DIRECTORY_SEPARATOR . 'modules'
DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules'
) === FALSE
) {
$startPos = strpos($civicrm_root,
......@@ -150,14 +137,14 @@ class CRM_Core_Config_Defaults {
}
}
if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) {
if (!isset($defaults['imageUploadDir']) && is_dir($path)) {
$imgDir = $path . "persist/contribute/";
CRM_Utils_File::createDir($imgDir);
$defaults['imageUploadDir'] = $imgDir;
}
if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) {
if (!isset($defaults['uploadDir']) && is_dir($path)) {
$uploadDir = $path . "upload/";
CRM_Utils_File::createDir($uploadDir);
......@@ -165,7 +152,7 @@ class CRM_Core_Config_Defaults {
$defaults['uploadDir'] = $uploadDir;
}
if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) {
if (!isset($defaults['customFileUploadDir']) && is_dir($path)) {
$customDir = $path . "custom/";
CRM_Utils_File::createDir($customDir);
......
......@@ -104,6 +104,10 @@ class CRM_Core_DAO extends DB_DataObject {
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');
}
}
/**
......
......@@ -97,7 +97,9 @@ class CRM_Core_Smarty extends Smarty {
else {
$this->template_dir = $config->templateDir;
}
$this->compile_dir = $config->templateCompileDir;
$this->compile_dir = CRM_Utils_File::addTrailingSlash(CRM_Utils_File::addTrailingSlash($config->templateCompileDir) . $this->getLocale());
CRM_Utils_File::createDir($this->compile_dir);
CRM_Utils_File::restrictAccess($this->compile_dir);
// check and ensure it is writable
// else we sometime suppress errors quietly and this results
......@@ -315,4 +317,18 @@ class CRM_Core_Smarty extends Smarty {
return $this;
}
private function getLocale() {
global $tsLocale;
if (!empty($tsLocale)) {
return $tsLocale;
}
$config = CRM_Core_Config::singleton();
if (!empty($config->lcMessages)) {
return $config->lcMessages;
}
return 'en_US';
}
}
......@@ -123,7 +123,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form {
$this->locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
$smarty = CRM_Core_Smarty::singleton();
$smarty->compile_dir = $this->_config->templateCompileDir;
//$smarty->compile_dir = $this->_config->templateCompileDir;
$smarty->assign('multilingual', $this->multilingual);
$smarty->assign('locales', $this->locales);
......
......@@ -496,13 +496,14 @@ HTACCESS;
* Create the base file path from which all our internal directories are
* offset. This is derived from the template compile directory set
*/
public static function baseFilePath($templateCompileDir = NULL) {
public static function baseFilePath() {
static $_path = NULL;
if (!$_path) {
if ($templateCompileDir == NULL) {
$config = CRM_Core_Config::singleton();
$templateCompileDir = $config->templateCompileDir;
// Note: Don't rely on $config; that creates a dependency loop.
if (!defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
throw new RuntimeException("Undefined constant: CIVICRM_TEMPLATE_COMPILEDIR");
}
$templateCompileDir = CIVICRM_TEMPLATE_COMPILEDIR;
$path = dirname($templateCompileDir);
......
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Class CRM_Utils_Geocode
*/
class CRM_Utils_Geocode {
/**
* @return string|''
* Class name, or empty.
*/
public static function getProviderClass() {
$config = CRM_Core_Config::singleton();
if ($config->geoProvider) {
return 'CRM_Utils_Geocode_' . $config->geoProvider;
}
elseif ($config->mapProvider) {
return 'CRM_Utils_Geocode_' . $config->mapProvider;
}
else {
return '';
}
}
}
......@@ -499,21 +499,6 @@ class CRM_Utils_System {
return $config->userSystem->postURL($action);
}
/**
* Rewrite various system URLs to https.
*/
public static function mapConfigToSSL() {
$config = CRM_Core_Config::singleton();
$config->userFrameworkResourceURL = str_replace('http://', 'https://', $config->userFrameworkResourceURL);
$config->resourceBase = $config->userFrameworkResourceURL;
if (!empty($config->extensionsURL)) {
$config->extensionsURL = str_replace('http://', 'https://', $config->extensionsURL);
}
return $config->userSystem->mapConfigToSSL();
}
/**
* Get the base URL of the system.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment