Under Review

Ability to track who deleted records in audit table

It would be great to have the ability to see in the audit table who deleted record and when, AND once it's been restored back from the soft-delete, link back the orphaned records. (related records in subpanels need to be edit/saved after restoring the deleted record in order to be displayed again)

It's been difficult not being able to blame someone in particular 

Parents
  • In a former life I used logic_hooks to track record deletions in the audit table of modules.

    Just can use the before_delete event and write an own record to the audit table.

    Here my code (adapted to version 8.x):

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class ClassLeadsVerify {

        function LeadCheck(SugarBean &$focus, $event, $arguments) {

            if ($event=="before_delete") {
                $GLOBALS['log']->info("delete Lead ID:".$focus->id);
                   global $current_user;
                $killer = $current_user->id;
                $query = "INSERT INTO leads_audit (id,parent_id,date_created,created_by,field_name,data_type,before_value_string,after_value_string) ".
                         "VALUES (uuid(),'$focus->id',now(),'$killer','deleted','bool','0','1');";
                $GLOBALS['db']->query($query);               
             }
         
        }
    }
    ?>
Comment
  • In a former life I used logic_hooks to track record deletions in the audit table of modules.

    Just can use the before_delete event and write an own record to the audit table.

    Here my code (adapted to version 8.x):

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class ClassLeadsVerify {

        function LeadCheck(SugarBean &$focus, $event, $arguments) {

            if ($event=="before_delete") {
                $GLOBALS['log']->info("delete Lead ID:".$focus->id);
                   global $current_user;
                $killer = $current_user->id;
                $query = "INSERT INTO leads_audit (id,parent_id,date_created,created_by,field_name,data_type,before_value_string,after_value_string) ".
                         "VALUES (uuid(),'$focus->id',now(),'$killer','deleted','bool','0','1');";
                $GLOBALS['db']->query($query);               
             }
         
        }
    }
    ?>
Children