Skip to main content

Logging related files

Each action is responsible for logging its own request, response and result, although AbstractRuleActionType makes this easier by providing two methods:

  • $this->getNewLog($userFormID) to get an object of type Jadu\XFormsPro\Form\Builder\UserFormActionLog. This should be used to store necessary data, as per the (custom action example)[actions.md].
  • $this->writeLog($log) to save the log to the database.

Form Builder provides the Jadu\XFormsPro\Form\Builder\UserFormActionLogRelatedFile class to help with logging any files that may be sent or received by the action. When used correctly, these files will be made available in when viewing the Received Form, under the Log tab.

The following code snippet illustrates how to add a related file to the log entry.

    // logic to communicate with other system above this point
// for brevity, assumes $log has request, response and result set correctly

// write the log to the database first
// so we have the ID to use for the related file
$this->writeLog($log);

// create a file log
$fileLog = new UserFormActionLogRelatedFile();

// set the ID of the log it relates to
$fileLog->setLogID($log->getId());

// set the path to the file on the server
$fileLog->setPath('/path/to/file');

// set the name of the file
$fileLog->setFilename('attachment1.txt');

// mark it for saving to the database
$this->entityManager->persist($fileLog);

// update the database
$this->entityManager->flush();