wp-cli sometimes fails to find cms path
Initially reported as https://github.com/veda-consulting/uk.co.vedaconsulting.mosaico/issues/293 but on further investigation the url issue only occurs when mailings are invoked by wp-cli.
wp-cli is called with the
--path option but the current working directory is not within the CMS tree,
CRM_Utils_System_WordPress::cmsRootPath() is unable to determine the CMS path resulting in the
realpath($cmsPath) call in
CRM_Utils_System_WordPress::getCiviSourceStorage() returning the current working directory and hence a bad value for the
$config->userFrameworkBaseURL which is used when replacing trackable URL's in
A workaround is to hardcode in
$civicrm_setting['URL Preferences']['userFrameworkResourceURL'] = 'https://domain.tld/wp-content/plugins/civicrm/civicrm';
The fix is to save the
--path setting so that
CRM_Utils_System_WordPress::cmsRootPath() returns the right information.