Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: HELP - Leads module data corrupted by mass update

  1. #1
    danheff is offline Senior Member
    Join Date
    Aug 2008
    Posts
    90

    Default HELP - Leads module data corrupted by mass update

    HELP! I've seen this mentioned before and I'm hoping for a quick fix for someone who doesn't know MySQL. I selected 13 records under Leads to mass update, changing an "assigned to" from one name to another. Suddenly, about 90% of ALL Leads were updated with this new name. I have told everyone to stop using sugar and I have nightly backups of the SQL. My consultant is on vacation for the week and I want to get us back up and running, but have no idea what steps to take to restore the leads data. Can anyone help?

  2. #2
    eNick is offline Sugar Community Member
    Join Date
    Apr 2008
    Location
    UK
    Posts
    282

    Default Re: HELP - Leads module data corrupted by mass update

    You should be able to undo this change by querying against the audit trail data.


    Do you have access to the database? For example, do you know how to get into phpMyAdmin and view the database?
    T H E S U G A R R E F I N E R Y
    : : : SugarCrm Customisation and Integration Services : : :

    SugarCRM Systems Integration Partner
    Trusted with SugarCRM
    http://www.theSugarRefinery.com ::: sales@{removethis}theSugarRefinery.com

  3. #3
    danheff is offline Senior Member
    Join Date
    Aug 2008
    Posts
    90

    Default Re: HELP - Leads module data corrupted by mass update

    thanks for the swift response!
    We are hosting Sugar in Linux on VMWare on our server. I have access to all the files, but am not sure how to view the database.
    Sorry to be such a rookie here. If worse comes to worse, we can restore the entire virtual machine overnight, but I'm hoping I can learn just enough to be able to do this restore...is that totally unrealistic?

  4. #4
    eNick is offline Sugar Community Member
    Join Date
    Apr 2008
    Location
    UK
    Posts
    282

    Default Re: HELP - Leads module data corrupted by mass update

    Ok, so no DB access but you have access to the files. Do you have write access to the folders on the server? If so, I can wrap the SQL up in a PHP script, you can place them on your server and run the code via Sugar.

    Can you email me?

    nick.holt@{removethis}theSugarRefinery.com

    and we'll take it from there
    Last edited by eNick; 2008-08-20 at 08:30 PM.
    T H E S U G A R R E F I N E R Y
    : : : SugarCrm Customisation and Integration Services : : :

    SugarCRM Systems Integration Partner
    Trusted with SugarCRM
    http://www.theSugarRefinery.com ::: sales@{removethis}theSugarRefinery.com

  5. #5
    danheff is offline Senior Member
    Join Date
    Aug 2008
    Posts
    90

    Default Re: HELP - Leads module data corrupted by mass update

    That would be great!!!! I do have write access to all files...

  6. #6
    eNick is offline Sugar Community Member
    Join Date
    Apr 2008
    Location
    UK
    Posts
    282

    Default Re: HELP - Leads module data corrupted by mass update

    Ok, email me - we'll see what we can do
    T H E S U G A R R E F I N E R Y
    : : : SugarCrm Customisation and Integration Services : : :

    SugarCRM Systems Integration Partner
    Trusted with SugarCRM
    http://www.theSugarRefinery.com ::: sales@{removethis}theSugarRefinery.com

  7. #7
    eNick is offline Sugar Community Member
    Join Date
    Apr 2008
    Location
    UK
    Posts
    282

    Default Re: HELP - Leads module data corrupted by mass update

    Ok Dan, I've emailed you everything you need but it's getting late in the UK and I may need to leave this with you.


    Here's my two step method.

    1) First of all, query the leads_audit table to find out when your update started.
    2) Once you got that, you can undo the changes.

    This would be really easy if you could access the database thru phpMyAdmin, but as you can't the easiest thing is to knock up a quick bit of code to do it.

    So, you're going to need to create files in the <sugar root>/modules/Leads folder. The first one is called temp_dump_leads.php

    And it contains this:
    Code:
    <?php
    	 //Connect using default database settings
    	 $this->db = & PearDatabase::getInstance();
    	 $this->dbManager = DBManagerFactory::getInstance();
     
    	//Dump what's in the lead_audit table for today to find out the time this happened
    	 $result=$this->dbManager->query(" 
    SELECT * 
    FROM `leads_audit` 
    WHERE date_created > '2008-08-20'
    ORDER BY date_created desc
    ;");
    	 while ($row = $result->fetch_row()) {
    	 foreach($row as $field){
    		 echo $field.", ";
    	 }
    	 echo '<br>';
    	 }
    ?>
    To run that code, load Sugar and then change the url to read index.php?module=Leads&action=temp_dump_leads

    It will print on the screen a few thousand records showing the before and after values and dates changed. Scroll down till you find the start of your update and note the date time (it's in yyyy-mm-dd hh:mm format).

    Ok, now step 2 the update....

    Create a second file called temp_restore_leads.php which looks like this:

    Code:
    <?php
    		//Connect using default database settings
    	 $this->db = & PearDatabase::getInstance();
    	 $this->dbManager = DBManagerFactory::getInstance();
     
    	 //Restore the data	 $result=$this->dbManager->query(" 
    	 update leads, leads_audit 
    		set leads.assigned_user_id = leads_audit.before_value_string 
    		where leads_audit.date_created > '2008-08-20 19:13' 
    		and leads.id=leads_audit.parent_id
    ;");
     
    		echo "DONE! DATA RESTORED";
    		echo '<br>';
    ?>
    But change the line where leads_audit.date_created > '2008-08-20 19:13' to match the date and time you noted in step 1.

    Run the code in the same way as before - change the url to read index.php?module=Leads&action=temp_restore_leads

    That will undo your change.

    Now delete those two temp files.

    I've tested this on my system. I've got to hit the sack but hopefully if you're having problems finding your Sugar root directory or creating the files, someone else can guide you now.


    Good luck

    Nick
    Last edited by eNick; 2008-08-20 at 09:27 PM.
    T H E S U G A R R E F I N E R Y
    : : : SugarCrm Customisation and Integration Services : : :

    SugarCRM Systems Integration Partner
    Trusted with SugarCRM
    http://www.theSugarRefinery.com ::: sales@{removethis}theSugarRefinery.com

  8. #8
    danheff is offline Senior Member
    Join Date
    Aug 2008
    Posts
    90

    Default Re: HELP - Leads module data corrupted by mass update

    If there's anyone else available, I am really struggling with this. I can't get any results to display with the first temp_dump_leads.php file. Saved file into sugar/modules/Leads. typed in web address as indicated. HELP!!

  9. #9
    jjwdesign's Avatar
    jjwdesign is offline Sugar Community Member
    Join Date
    Dec 2006
    Location
    Orlando, FL
    Posts
    503

    Default Re: HELP - Leads module data corrupted by mass update

    I've seen this exact same problem twice. I believe it's a bug, but could never reproduce it. We were lucky enough to have nightly backups, so in our case we compared the current data with the past days data to revert to the previous data. However you do the comparison, it will require some programming and SQL knowledge.

    Setup nightly backups using something like phpMyBackupPro or some other utility. It's a must.

    I believe this is a bug.
    SugarForge Projects:
    JJWDesign Google Maps
    JJWDesign Tools and Reports

    Follow my blog postings at JJW Design.

  10. #10
    danheff is offline Senior Member
    Join Date
    Aug 2008
    Posts
    90

    Default Re: HELP - Leads module data corrupted by mass update

    ITS DONE!!! Everything worked. Turned out my internal Sugar clock is off, so I had to adjust first .php file accordingly, 2nd php file had a line that should have been two lines...

    //Restore the data $result=$this->dbManager->query("

    should be

    //Restore the data
    $result=$this->dbManager->query("

    but it worked!!! Thanks!!!! NO MORE MASS UPDATES FOR THIS SUGAR ADMIN...
    cheers.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 2008-03-24, 11:44 PM
  2. Replies: 2
    Last Post: 2007-06-19, 08:33 PM
  3. Replies: 0
    Last Post: 2007-06-16, 02:20 PM
  4. Replies: 1
    Last Post: 2006-09-11, 03:38 PM
  5. Replies: 0
    Last Post: 2005-05-10, 08:33 AM

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
  •