Created
January 15, 2014 21:22
-
-
Save stovak/8444958 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function nebula_audit_entity_update($entity, $type) { | |
$orig_wrapper = entity_metadata_wrapper($type, $entity->original); | |
$new_wrapper = entity_metadata_wrapper($type, $entity); | |
$properties = $orig_wrapper->getPropertyInfo(); | |
$diffs = array(); | |
foreach ($properties as $key => $property) { | |
$old = $orig_wrapper->$key->value(); | |
$new = $new_wrapper->$key->value(); | |
if ($old !== $new) { | |
if (is_array($old)) { | |
$diff = $property['label']." changed:<ul>"; | |
$added = array_diff($old, $new); | |
foreach ($added as $item) { | |
$diff .= "<li>".(string)$item." added</li>"; | |
} | |
$subtracted = array_diff($new, $old); | |
foreach($subtracted as $item) { | |
$diff .= "<li>".(string)$item." removed</li>"; | |
} | |
$diff .="</ul>"; | |
} else { | |
$diff = $property['label']." changed from '{$old}' to '${new}'"; | |
} | |
} | |
if (!empty($diff)) { | |
$diffs[] = $diff; | |
unset($diff); | |
} | |
} | |
$diffs = "<ul><li>" . implode("</li><li>", $diffs) . "</li><ul><br><br>"; | |
watchdog("nebula_audit", "Entity {$type}://{$entity} updated by {$GLOBALS['user']->mail}: {$diffs}", array(), WATCHDOG_INFO ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment