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.
When 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 CRM_Mailing_BAO_TrackableURL::getTrackerURL()
A workaround is to hardcode in civicrm.settings.php
:
$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.