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

bin/*, extern/* - Fix leak of "$config" in global namespace #16702

Merged
merged 1 commit into from
Mar 23, 2020

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Mar 6, 2020

…th backdrop

Overview

This removes the $config variable from some pre CMS boot locations to avoid issues with backdrop comparability

Before

When using a bin/ or extern/ script, the $config variable implicitly enters the global namespace.

Rest API tests fail on current Backdrop 1.x builds because Backdrop specifies its own global $config of type array.

After

Rest API tests pass again on backdrop

Technical Details

Backdrop recently made $config a global variable and its probable that our use of $config in these files whilst not declared global maybe caused to populate when backdrop is booted

ping @totten @herbdool

@civibot
Copy link

civibot bot commented Mar 6, 2020

(Standard links)

@herbdool
Copy link
Contributor

herbdool commented Mar 6, 2020

What's the best way to test this? I assume it has to be merged before it can be tested with automated tests with Backdrop. Seems like it needs to be tested first locally.

@seamuslee001
Copy link
Contributor Author

@herbdool the simplest way to test this would be to check it out locally then from within the main CiviCRM folder run `./tools/scripts/phpunit 'E2E_Extern_RestTest' and see that the test Rest examples work. The other thing you could try is just deploying it locally and creating a test mailing or something with some images and links and check the tracked opens and etc urls work correctly

@totten
Copy link
Member

totten commented Mar 6, 2020

Overall 👍 . Adding some supporting detail:

r-tech: So I think the main concern (which Seamus had initially raised in chat) would be that other code uses$config. Or, phrased more formally... that some code - in core or downstream - relies on this precondition:

$GLOBALS['config '] instanceof CRM_Core_Config

While it's hard to perfectly rule out the existence of such code, I'm not too concerned about it. Why? Two reasons:

  1. Because such code would already be broken in normal processing. That pre-condition is manifestly not met during normal page processing. You can see this by dropping the following line into random places:
    echo '<hr><pre>'; var_dump(['global config'=>$GLOBALS['config']]);exit();
  2. Because it goes against the long-standing idiom. The idiom is for functions to access the CRM_Core_Config by copying the singleton to a local variable:
    function fooBar() {
      $config = CRM_Core_Config::singleton();
    }

I also think this patch is doing the Right Thing because it still calls CRM_Core_Config::singleton(). Regardless of whether I like or dislike the bootstrap protocol on general grounds, calling CRM_Core_Config::singleton() is an important step in the protocol used by these files, so it's good that it's still there.

@totten totten changed the title [REF] Remove variable from preboot locations to fix compataiblity wi… bin/*, extern/* - Fix leak of "$config" in global namespace Mar 6, 2020
@seamuslee001
Copy link
Contributor Author

@totten @herbdool has anyone done a r-run on this? E2E tests would cover the Rest and Soap Interfaces i think

@totten
Copy link
Member

totten commented Mar 23, 2020

The E2E suite provides coverage of some extern use-cases. That passed when CI ran on D7, and I did a couple local runs of E2E on wp-demo and bcmaster builds, and those also passed (and demonstrated the improvement in bcmaster).

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.

3 participants