Define the Terminals in the Custom Process Script

You define terminals for custom process logging in PHP scripts that you import to the process designer.

Custom process logging uses this PHP syntax:

use \RightNow\Connect\v1_3 as versioned_namespace;
versioned_namespace\Terminal::logger(terminal_name, log_level, log_message);

For example:

use \RightNow\Connect\v1_3 as RNCPHPV3;
RNCPHPV3\Terminal::logger(terminal1, 'Fatal', 'This is a fatal error.');
Create a PHP file, like you would for any custom process script, that defines the terminals you wish to use for logging.

The following example shows a PHP script for logging events associated with custom processes for Organization objects.


<?

/**
 * CPMObjectEventHandler: OrgTest
 * Package: RN
 * Objects: Organization
 * Actions: Create, Update, Destroy
 * Version: 1.2
 **/

/**
define("Fatal","1");
define("Alert","2");
define("Critical","3");
define("Error","4");
define("Warning","5");
define("Trace","6");
define("Info","7");
define("Debug","8");
**/

// This object procedure binds to v1_2 of Connect PHP.
use \RightNow\Connect\v1_2 as RNCPHP;

// This object procedure binds to the v1 interface of SPM.
use \RightNow\CPM\v1 as RNCPM;
use \RightNow\Connect\v1_3 as RNCPHPV3;

class OrgTest implements RNCPM\ObjectEventHandler
	{
	public static function apply( $run_mode, $action, $obj, $n_cycles )
		{
		$terminalObj = new RNCPHPV3\Terminal();
		$terminalObj::logger("terminal1", 1, "This is a fatal error.");
		$terminalObj::logger("terminal1", 'Fatal', "This is a fatal error.");
		$terminalObj::logger("terminal1", 'Debug', "This is a debug message.");
		$terminalObj::logger("terminal1", 'Info', "This is an info message.");
		$terminalObj::logger("terminal2", 'Critical', "This is a critical error.");
		$terminalObj::logger("terminal2", 'Info', "This is an info message.");
		$terminalObj::logger("terminal3", 'Alert', "This is an alert.");
		$terminalObj::logger("terminal4", 4, "This is an error.");
		$terminalObj::logger("terminal6", 'Debug', "This is a debug message.");
		$terminalObj::logger("terminal6", 'Warning',"This is a warning.");

		// For testing

		if (is_null($obj->Notes))
		{
			$obj->Notes = new RNCPHP\NoteArray;
		}
		$note = new RNCPHP\Note;
		$note->Text = date( 'r' ) . "\n";

		switch ( $action )
		{
		case RNCPM\ActionCreate:
			$note->Text .= "Created";
			break;

		case RNCPM\ActionUpdate:
			$note->Text .= "Updated";
			break;

		case RNCPM\ActionDestroy:
			$note->Text .= "Destroyed";
			break;

		default:
			assert( !'
				!!! Unknown action !!!
			  ' ) || die( -1 );
		}
		
		$note->Text .= " by " . __CLASS__ . "\n";
		$obj->Notes[] = $note;

		if (RNCPM\RunModeLive != $run_mode)
		{
			echo( "\nHello from OrgTest, run_mode= $run_mode, action= $action, id= {$obj->ID} n_cycles= $n_cycles\n" ); // */
			echo( "Note= " . $note->Text );
			return;
		}

		// End testing
		
		return;
	}
}


class OrgTest_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
{
	public static function setup()
	{
		// Nothing special to set up.
		return;
	}

	public static function fetchObject( $action, $object_type )
	{
		$org = new RNCPHP\Organization;
		switch ( $action )
		{
		case RNCPM\ActionCreate:
			$org->Name = 'A new Org';
			break;

		case RNCPM\ActionUpdate:
			$org->Name = 'An updated Org';
			break;

		case RNCPM\ActionDestroy:
			$org->Name = 'A destroyed Org';
			break;
		}

		$org->save();
		return( $org );
	}

	public static function validate( $action, $object )
	{
		assert("
			1 === ".count( $object->Notes )."
		  " ) || die(-1);
		return( true ); // It's false.
	}

	public static function cleanup()
	{
		// Nothing special to clean up.
		return;
	}
}