Class Not Found Error When Loading External PHP Module From Custom Service Action

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nsoftware-george
    Junior Member
    • Oct 2024
    • 16

    #1

    Class Not Found Error When Loading External PHP Module From Custom Service Action

    I cannot seem to load an external PHP module/library in a custom service action called from a workflow. Could someone review what I have done?

    EspoCRM 9.0.5
    MySQL 8.0.42

    Background: I want to periodically check two dates on sales orders and send an email. A person must manually review the automatically-generated emails before sending them, so I am using an external library to create drafts in Office365 rather than just sending them directly.

    I decided to use a Workflow that calls a Service Action to accomplish this. I was able to create and call my custom service action from within EspoCRM, which just had basic code to create a file on the system (as a "hello world" test). The external library is CloudMail (https://www.nsoftware.com/cloudmail). The PHP edition of CloudMail can be used outside of EspoCRM on the same system. Trying to call CloudMail from within my service action results in this error:

    Code:
    [2025-06-04 14:33:37] DEBUG: Workflow 683dbc71a70a556f3: Start actions.
    [2025-06-04 14:33:37] DEBUG: Workflow 683dbc71a70a556f3, runService, Start, cid 0, SalesOrder 681cd1bf723583cbe
    [2025-06-04 14:33:37] ERROR: Slim Application Error
    Type: Error
    Code: 0
    Message: [B]Class "Espo\Custom\CloudMail\CloudMail_Office365" not found[/B]
    File: /var/www/html/callback/custom/Espo/Custom/ServiceActions/RenewalReminderServiceAction.php
    Line: 72
    To get the service action to work I added or modified these files:

    <installdir>\custom\Espo\Custom\ServiceActions\Ren ewalReminderServiceAction.php
    <installdir>\custom\Espo\Custom\Resources\metadata \app\workflow.json
    <installdir>\custom\Espo\Custom\Resources\i18n\en_ US\Workflow.json

    I placed the CloudMail include directory here:

    <installdir>\custom\Espo\Custom\CloudMail

    The CloudMail .so file is installed in /usr/lib, and as a reminder can be used outside of EspoCRM.

    I have also attached RenewalReminderServiceAction.php and related files. Be aware that I have commented/modified the service action code many times trying to debug this problem.

    I read somewhere that using an autoload.json file may help, so I wrote one which was placed here:

    <installdir>\custom\Espo\Custom\autoload.json

    I think my next step will be to use the ext-template github repo, but I imagine I could face this same problem there. Any help would be appreciated. One day when I have a bit more knowledge under my belt, the plan is to contribute back to this forum. We plan to use EspoCRM for the foreseeable future.

    Attached Files
Working...