Skip to content

Instantly share code, notes, and snippets.

@jmertic
Last active February 9, 2018 20:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jmertic/6272437 to your computer and use it in GitHub Desktop.
Save jmertic/6272437 to your computer and use it in GitHub Desktop.
<?php
class FieldChangeHook
{
protected static $fetchedRow = array();
/**
* Called as before_save logic hook to grab the fetched_row values
*/
public function saveFetchedRow($bean, $event, $arguments)
{
if ( !empty($bean->id) ) {
self::$fetchedRow[$bean->id] = $bean->fetched_row;
}
}
/**
* Called as a after_save logic hook to execute the actual business process
*/
public function executeBusinessProcess($bean, $event, $arguments)
{
// call on changed records only
if ( isset(self::$fetchedRow[$bean->id]) && $this->fieldname != self::$fetchedRow[$bean->id]['fieldname'] ) {
//
// execute changed record business process
//
}
// call on new records only
if ( !isset(self::$fetchedRow[$bean->id]) ) {
//
// execute new record business process
//
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment