-
-
Save jasondavis/d39b8fee4f5a2df30041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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