Results 1 to 2 of 2

Thread: How to add delete and merged records to Tracker

  1. #1
    thowden is offline Sugar Community Member
    Join Date
    Jul 2007
    Posts
    19

    Default How to add delete and merged records to Tracker

    Tracker module does not track deleted accounts and as a result MergeRecords module does not track all entries when merging as it only tracks the Save on the parent account.

    Platform is SugarCRM CE 5.2.0d on Windows and MS-SQL.

    The changes required for this are all in the file /data/sugarbean.php starting at line 4264 or there-abouts:
    Code:
    4264 $query = "UPDATE $this->table_name set deleted=1 , date_modified = '$date_modified' where id='$id'";
    4265 $this->db->query($query, true,"Error marking record deleted: ");
    4266 $this->mark_relationships_deleted($id);
    4267
    4268 // Take the item off the recently viewed lists</span>
    Changing the code to include both a log entry for deletions and the tracker entry.
    Code:
    4264 $query = "UPDATE $this->table_name set deleted=1 , date_modified = '$date_modified' where id='$id'";
    4265 # thowden 20090518: Added for logging of deletions
    4266 $GLOBALS['log']->info('Deletion ' . $id . ' query : ' . $query);
    4267 # end thowden
    4268 $this->db->query($query, true,"Error marking record deleted: ");
    4269 $this->mark_relationships_deleted($id);
    4270 # thowden 20090518 added to tracker for deletions
    4271 $this->track_view($current_user->id, $this->module_dir, 'deleted');
    4272 # end thowden
    4273 // Take the item off the recently viewed lists</span>
    The log entry could be changed to only debug, error, or warning level, but I figure that 'delete' will be one of those things we will constantly be chasing for our beloved end-users.

    Hand-in-hand with deletion is the concept of restoration and for good measure this can also be tracked.

    Further down the file: noting that line numbers shown here vary as they are already changed compared to the original file due to the inclusion of the code above.
    Code:
    4289 $query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='$id'";
    4290 $this->db->query($query, true,"Error marking record undeleted: ");
    4291
    4292 // call the custom business logic
    Changes to:
    Code:
    4295 # thowden 20090518: Added for logging of restorations
    4296 $GLOBALS['log']->info('Restoring ' . $name . ' ' . $value . ' query : ' . $query);
    4297 # end thowden
    4298 $this->db->query($query, true,"Error marking record undeleted: ");
    4299 # thowden 20090518 added to tracker for restores
    4300 $this->track_view($current_user->id, $this->module_dir, 'restored');
    4301 # end thowden
    Now you can review in both the sugarcrm.log or whatever you call your log file and in the Tracker table in your SugarCRM database. I would note that in both the delete and restore processes I have not allowed for the error of being unable to delete/restore. It would be more robust with some error-handling and detailed log/track messages. But for the moment I'll assume each transactions suceeds.

    For the merge process details to be really useful we wanted to add a trigger in the database to run some scripts. In order for the trigger to function it needs to have a unique record that it 'knows' means that the merge transactions have completed.

    So I added a new entry to the Tracker database. File to modify is
    modules\MergeRecords\SaveMerge.php
    Find line 118 in the file:
    Code:
    118 $GLOBALS['log']->debug("Merged record with id of ".$return_id);</span>
    ... and add the following
    Code:
    118 $GLOBALS['log']->debug("Merged record with id of ".$return_id);
    119 # thowden 20090518 added to tracker for mergecomplete
    120 $mergesource->track_view($current_user->id, 'MergeRecords', 'mergecomplete');
    121 # end thowden
    This completes a merged accounts transaction set for any number of merged accounts with a mergecomplete transaction. The database trigger is linked to that entry and recognises all the transactions by the monitor_id column value which is unique for a transaction set.

    To query the Tracker table try using something like the following and modify the date value to something more appropriate.
    Code:
    select * from tracker where convert(char(10),date_modified,112)>='20090520'
    Next I need to tackle the process for merging Contacts.
    Last edited by thowden; 2009-05-21 at 11:12 PM.

  2. #2
    mlange is offline Junior Member
    Join Date
    Nov 2011
    Posts
    5

    Default Re: How to add delete and merged records to Tracker

    I'm trying to implement this in 6.4.3. (Professional)
    The code-lines don't appear in the same manner so i filled in the code from thowden between the lines i found.

    Unfortunately, the deletions don't appear in the .log files nor in the tracker-reports.

    Any sugesstions?


    Thanks a lot.


    Best regards
    Matthias Lange

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem trying to delete a campaign url tracker
    By acoronasz72 in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2008-11-17, 09:26 PM
  2. delete main & sub records
    By mikesolomon in forum Help
    Replies: 2
    Last Post: 2008-04-09, 12:48 PM
  3. How to delete records with the Sugar SOAP API?
    By sugarmichael in forum Developer Help
    Replies: 1
    Last Post: 2008-03-12, 09:55 PM
  4. Inserting records into the tracker table
    By stevec in forum Developer Help
    Replies: 1
    Last Post: 2006-07-20, 10:29 PM
  5. Delete Records
    By cexar in forum Help
    Replies: 0
    Last Post: 2006-04-26, 07:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •