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

Fix loading with alternate packages path (system-level) #16407

Merged
merged 5 commits into from
Jan 30, 2020

Conversation

totten
Copy link
Member

@totten totten commented Jan 28, 2020

Overview

The configuration option $civicrm_paths['civicrm.packages'] allows one to specify the local path and remote URL of the packages folder. This is not done often, but it is helpful for the composer/D8/git deployment styles. Alas, there are still sundry hard-coded references to the packages folder.

This fixes some (but not all) references to packages. It generally focuses on classes that are used in universal/system-level processes (such as the class-loader).

Before

CRM_Core_Resources, CRM_Core_Smarty, CRM_Core_IDS, CRM_Core_ClassLoader, and CRM_Utils_String have path references which assume that civicrm-packages.git lives directly under [civicrm.root]/packages.

After

Each of these references has been updated to relax that expectation.

Comments

Generally, it's preferable to either:

  • Remove any explicit reference to packages and just rely on the include-path (for *.php files)
  • Construct references to packages using the "paths" subsystem (e.g. Civi::paths()->getPath('[civicrm.packages]/foobar').

However, some files have peculiar issues which make that problematic -- so several of these items required alternative solutions.

This PR is an extracted subset of #16328, which was an exploratory branch aimed at supporting deployment of Civi git repos in D8 via composer. The changes are extracted to make the size of the review more manageable. It's probably best to use this smaller PR to consider topics like regression-risk and general code convention rather than trying to assess the fuller aims of #16328.

@civibot
Copy link

civibot bot commented Jan 28, 2020

(Standard links)

@civibot civibot bot added the master label Jan 28, 2020
@totten totten changed the title Fix loading with alternate packages path Fix loading with alternate packages path (system-level) Jan 28, 2020
@totten
Copy link
Member Author

totten commented Jan 29, 2020

jenkins, test this please

@@ -124,7 +124,13 @@ public function register($prepend = FALSE) {
$this->initHtmlPurifier($prepend);

$this->_registered = TRUE;
$packages_path = implode(DIRECTORY_SEPARATOR, [$civicrm_base_path, 'packages']);
// The ClassLoader runs before the classes are available. Approximate Civi::paths()->get('[civicrm.packages]').
if (isset($GLOBALS['civicrm_paths']['civicrm.packages']['path'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adds an IF - no change for normal cases

@@ -177,7 +183,12 @@ private function getHtmlPurifierPath() {
// we do this to prevent a autoloader errors with joomla / 3rd party packages
// Use absolute path, since we don't know the content of include_path yet.
// CRM-11304
$file = dirname(__FILE__) . '/../../packages/IDS/vendors/htmlpurifier/HTMLPurifier/Bootstrap.php';
if (isset($GLOBALS['civicrm_paths']['civicrm.packages']['path'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -433,7 +433,7 @@ public static function strtoboolstr($str) {
* the converted string
*/
public static function htmlToText($html) {
require_once 'packages/html2text/rcube_html2text.php';
require_once 'html2text/rcube_html2text.php';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have tests on this I believe

@@ -818,6 +818,19 @@ public function coreResourceList($region) {
// Allow hooks to modify this list
CRM_Utils_Hook::coreResourceList($items, $region);

// Oof, existing listeners would expect $items to typically begin with 'bower_components/' or 'packages/'
// (using an implicit base of `[civicrm.root]`). We preserve the hook contract and cleanup $items post-hook.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most complex part of this PR but my take on it is it would fail very broadly if it were going to. I'm pretty sure the new mailing screen would not load if this were broken (it does load)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite right - if these things didn't work, then everything would be wrong in... pretty much every screen. It'd be missing jQuery, etc. A problem would be pretty obvious.

@eileenmcnaughton
Copy link
Contributor

Code makes sense - I did a basic click around on the test site - feels low risk. Merging

@eileenmcnaughton eileenmcnaughton merged commit 25d2bad into civicrm:master Jan 30, 2020
@totten totten deleted the master-altpkgs-basic branch February 12, 2020 06:03
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