Suggested documentation improvement for CRM_Civirules_Utils_Upgrader::insertActionsFromJson()
The CiviRules documentation here describes how new CiviRules actions can be auto-added via a JSON file in the Civix Upgrader.php install()
method. The code snippet provided relies on the CRM_Civirules_Utils_Upgrader::insertActionsFromJson()
method. So an ugly nonrecoverable error occurs if the CiviRules extension is not already installed and enabled.
To fail cleanly during the attempt to install the new extension, the documentation could be updated to the following code, which first tests if the CiviRules insertActionsFromJson()
method exists.
if (!method_exists('CRM_Civirules_Utils_Upgrader', 'insertActionsFromJson'))
throw new Exception('Method CRM_Civirules_Utils_Upgrader::insertActionsFromJson() not found. Is the CiviRules extension enabled?');
CRM_Civirules_Utils_Upgrader::insertActionsFromJson($this->extensionDir . DIRECTORY_SEPARATOR . 'civirules_actions.json');
Although this method_exists()
precaution might be obvious to experienced Civix developers, a newcomer (like myself) might benefit from the guidance on how to fail gracefully during installation.