CRM-19813 - Only dispatch through EventDispatcher after booting
authorTim Otten <totten@civicrm.org>
Tue, 11 Apr 2017 08:00:32 +0000 (01:00 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 11 Apr 2017 08:15:56 +0000 (01:15 -0700)
commit4d8e83b6770f500adb949524f1e90d0f4b4e58f6
tree7f63904bf4614a6fb2c96b2c2c0e5e2431aa6957
parent66390ef5e9086fe441da1e85368f5305bdf23d42
CRM-19813 - Only dispatch through EventDispatcher after booting

After merging #9949, some screens (like the contact-result list or "View
Contact") reported warnings like:

```
Notice: Undefined index: in CRM_Core_BAO_Country::countryLimit() (line 90 of /home/foo/buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/BAO/Country.php).
Notice: Undefined index: in CRM_Core_BAO_Country::provinceLimit() (line 62 of /home/foo/buildkit/build/dmaster/sites/all/modules/civicrm/CRM/Core/BAO/Country.php).
```

Bisecting the git history revealed that it stemmed from switching
`hook_civicrm_entityTypes` to go through EventDispatcher.

https://github.com/civicrm/civicrm-core/pull/9949/commits/fb1d9ad2f5116245ba3488a26f8e0b065f328006#diff-8869a8f3c6318eb0580ce2aa04b713bfL1835

This hook is apparently similar to `hook_civicrm_container` in that both
fires pre-boot.  If we attempt to dispatch it through the container in a
pre-boot environment, something initializes incorrectly.

This change proposes a general rule:
 * If you fire a hook before the container or EventDispatcher is available...
 * Then don't try to use the container or EventDispatcher.
CRM/Utils/Hook.php
Civi/Core/Container.php