Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dev/cloud-native#3) CRM_Utils_File - Deprecate baseFilePath() et al #14778

Merged
merged 3 commits into from
Jul 10, 2019

Conversation

totten
Copy link
Member

@totten totten commented Jul 10, 2019

Overview

This deprecates a function which was enabling/complicit in problematic file-construction logic.

Before

  • In CRM_Utils_File, the functions baseFilePath(), relativeDirectory($directory), and absoluteDirectory($directory, $basePath = NULL) exist. They are not deprecated.

After

  • In CRM_Utils_File, the functions baseFilePath() and relativeDirectory($directory) exist. They are deprecated, but they behave the same as before.
  • In CRM_Utils_File, the function absoluteDirectory($directory, $basePath) now requires the second parameter. This parameter is actually provided by all callers in the known universe.

Technical Details

The function baseFilePath() represents a hack: the configuration in civicrm.settings.php did not provide a genuine way to figure out the path to the civicrm data folder (e.g. /var/www/sites/default/files/civicrm), but it did provide CIVICRM_TEMPLATE_COMPILEDIR (e.g. /var/www/sites/default/files/civicrm/templates_c). In absence of a proper reference to the data-folder, various bits of code used baseFilePath() to guess it.

This hack means that paths are brittle: if one changes CIVICRM_TEMPLATE_COMPILEDIR, it could have confusing repercussions on other folders which have nothing to do with template compilation.

Since Civi 4.7, there has been a way to identify /var/www/sites/default/files/civicrm specifically (and even customize/override it) using Civi::paths().

However, this only deprecates baseFilePath(). The function is useful in providing backward-compatibility with existing deployments/civicrm.settings.php-content.

https://lab.civicrm.org/dev/cloud-native/issues/3

totten added 3 commits July 9, 2019 23:30
The rationale is provided in the docblock.
Previous versions interpreted `$basePath=NULL` to mean "default to `self::baseFilePath()`".
However, no code in the known `universe` relies on this interpretation, and
the `baseFilePath()` function is problematic/deprecated.

We could almost deprecate the entire function `absoluteDirectory()`;
however, it's fine to keep around: the semantics are reasonable if one
provides `$basePath`, and there is one active use-case in which
`Civi\Core\Paths` calls `absoluteDirectory()` with a suitable `$basePath`.
Computation of a relative path requires some base.  This implementation is
problematic because it relies on an implicit base which was constructed
problematically.  Moreover, the function is not used anywhere in the known
`universe`.
@civibot
Copy link

civibot bot commented Jul 10, 2019

(Standard links)

@eileenmcnaughton
Copy link
Contributor

This seems safe & sensible - I am a fan of more aggressive deprecation (throwing up the warnings) but this is quite early in your process I guess

@eileenmcnaughton eileenmcnaughton merged commit 4df07b6 into civicrm:master Jul 10, 2019
@totten totten deleted the master-basefilepath branch July 10, 2019 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants