Skip to content

Commit

Permalink
Civi::paths() - Decouple settings from paths. Allow path vars.
Browse files Browse the repository at this point in the history
There has been a policy underwhich paths and URLs are assumed to be relative
to different points (urls => webroot; paths => sites/*/files/civicrm).  For
some settings, this is fairly confusing.  The policy had been encoded in
`SettingsBag::getPath` and `SettingsBag::getUrl`.  It's particularly
confusing because (sometimes) the default value of a specific property isn't
really aligned with the policy.

This revision attempts to cleanup in two ways:

 1. It removes policy from `SettingsBag` and puts it in `Civi\Core\Paths`.
 2. It makes the policy less important by allowing variables in the paths.
   * `[civicrm.files]/upload` might evaluate to `/var/www/sites/default/files/civicrm/upload`
   * `[cms.root]/myuploads` might evaluate to `/var/www/myuploads`

The revision also updates MagicMerge to store various path and URL policies
in `getPropertyMap()` rather than adhoc callbacks.
  • Loading branch information
totten committed Sep 17, 2015
1 parent 90777b7 commit e3d28c7
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 419 deletions.
117 changes: 0 additions & 117 deletions CRM/Core/Config/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,126 +42,9 @@
*/
class CRM_Core_Config_Defaults {

/**
* Set the default values.
* in an empty db, also called when setting component using GUI
*
* @param array $defaults
* Associated array of form elements.
* @param bool $formMode
* this variable is set true for GUI
* mode (eg: Global setting >> Components)
*
*/
public static function setValues(&$defaults, $formMode = FALSE) {
}

public static function getCustomCssUrl($k = NULL) {
return Civi::settings()->getUrl('customCSSURL', 'absolute');
}

public static function getCustomFileUploadDir($k = NULL) {
$settings = Civi::settings();
$value = $settings->getPath('customFileUploadDir');
if (empty($value)) {
$defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
$value = $settings->filterPath($defaultFileStorage['path'] . "custom/");
}
$value = CRM_Utils_File::addTrailingSlash($value);
CRM_Utils_File::createDir($value);
CRM_Utils_File::restrictAccess($value);
return $value;
}


public static function getCustomPhpPathDir($k = NULL) {
return Civi::settings()->getPath('customPHPPathDir');
}

public static function getCustomTemplateDir($k = NULL) {
return Civi::settings()->getPath('customTemplateDir');
}

public static function getExtensionsUrl($k = NULL) {
return Civi::settings()->getUrl('extensionsURL', 'absolute');
}

public static function getExtensionsDir($k = NULL) {
return Civi::settings()->getPath('extensionsDir');
}

public static function getImageUploadDir($k = NULL) {
$settings = Civi::settings();
$value = $settings->getPath('imageUploadDir');
if (empty($value)) {
$defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
$value = $settings->filterPath($defaultFileStorage['path'] . "persist/contribute/");
}
$value = CRM_Utils_File::addTrailingSlash($value);
CRM_Utils_File::createDir($value);
return $value;
}

public static function getImageUploadUrl($k = NULL) {
$settings = Civi::settings();
$imageUploadURL = $settings->getUrl('imageUploadURL', 'absolute');
if (empty($imageUploadURL)) {
$defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
$imageUploadURL = $settings->filterUrl($defaultFileStorage['url'] . 'persist/contribute/', 'absolute');
}
return $imageUploadURL;
}

public static function getUploadDir($k = NULL) {
$settings = Civi::settings();
$value = $settings->getPath('uploadDir');
if (empty($value)) {
$defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
$value = $settings->filterPath($defaultFileStorage['path'] . "upload/");
}
$value = CRM_Utils_File::addTrailingSlash($value);
CRM_Utils_File::createDir($value);
CRM_Utils_File::restrictAccess($value);
return $value;
}

public static function getUserFrameworkResourceUrl($k = NULL) {
$settings = Civi::settings();
$url = $settings->getUrl('userFrameworkResourceURL', 'absolute');
if (empty($url)) {
$config = CRM_Core_Config::singleton();
$civiSource = $config->userSystem->getCiviSourceStorage();
$url = $settings->filterUrl($civiSource['url'], 'absolute');
}
return $url;
}

public static function getResourceBase($k = NULL) {
$settings = Civi::settings();
$url = $settings->getUrl('userFrameworkResourceURL', 'relative');
if (empty($url)) {
$config = CRM_Core_Config::singleton();
$civiSource = $config->userSystem->getCiviSourceStorage();
$url = $settings->filterUrl($civiSource['url'], 'relative');
}
return $url;
}

public static function getDefaultCurrencySymbol($k = NULL) {
$config = CRM_Core_Config::singleton();
return $config->defaultCurrencySymbol(Civi::settings()->get('defaultCurrency'));
}

public static function setPath($key, $value) {
Civi::settings()->setPath($key, $value);
}

public static function setUrl($key, $value) {
Civi::settings()->setPath($key, $value);
}

public static function revert($key) {
Civi::settings()->revert($key);
}

}
Loading

0 comments on commit e3d28c7

Please sign in to comment.