Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig O'Mahony 364 posts 918 karma points
    Apr 16, 2018 @ 08:50
    Craig O'Mahony
    0

    Programmatically remove Contour Form entries

    Hi,

    I would if someone could give me some advice please...

    As part of the upcoming GDPR changes my company has imposed a data retention policy of one month meaning that we're not permitted to keep information that's greater than a month old.

    On two of the sites (a version 7 and a version 4 build) I'm running Umbraco Contour and I've been asked if a schedule could be created that deletes form entries that are greater than a month old.

    So 2 questions really does anyone have any knowledge of programmatically removing form entries and what would be the best way of creating a scheduled task to fire this programmatic solution.

    I've created a scheduled task that runs on a server that fires a web page which runs code when loaded but any sort of browser 'issue' (i.e. Internet Explorer didn't shut down properly) causes the schedule task to fail so this solution is unstable for this request really.

    Thanks in advance, C

  • Balram Narad 37 posts 89 karma points
    Apr 16, 2018 @ 09:50
    Balram Narad
    2

    I'm not sure if this will help but we run a sql script shown below that clears our form entries from the previous 14 days. The script is run daily via a schedule. You can amend it to do previous 28 days by just changing the 14 to 28 if you need to delete last calendar month then you will need to add some code work that out.

    Delete FROM [dbname].[dbo].[UFRecords] Where Created < GETDATE() -14

    Hope that helps

    Bal

  • Craig O'Mahony 364 posts 918 karma points
    Apr 17, 2018 @ 07:35
    Craig O'Mahony
    0

    Hi Balram,

    So just to confirm this deletes Contour records from the last 14 days??

    If that's the case then that's awesome work!

    Thanks, C

  • Balram Narad 37 posts 89 karma points
    Apr 17, 2018 @ 09:11
    Balram Narad
    0

    Hi Craig

    Yes this is what we are using to clear down our form entries.

    Bal

  • Craig O'Mahony 364 posts 918 karma points
    Apr 18, 2018 @ 15:38
    Craig O'Mahony
    0

    That's brilliant thanks for your time

    :)

  • Amir Khan 1287 posts 2744 karma points
    Apr 18, 2018 @ 18:36
    Amir Khan
    0

    So would this just delete all of the entries?

    Delete FROM [dbname].[dbo].[UFRecords]

  • Balram Narad 37 posts 89 karma points
    Apr 19, 2018 @ 08:50
    Balram Narad
    0

    Hi Amir

    yes it would

    Bal

  • Gavin Williams 1 post 96 karma points
    Nov 09, 2018 @ 15:51
    Gavin Williams
    4

    Sorry this is probably a bit late but I needed to do something similar and just found your thread.

    Just a heads-up, at least on the instance I've spun up anyway. There's no referential integrity in the db (MS-Sql in my case) between the UFRecords table and the various record value fields UFDataRecordString etc so to truly remove the data you'll also need to clear these tables.

    As regards programmatically handling records, you can create a class that derives from ApplicationEventHandler and add an event handler for the RecordStorage events e.g.

            using Umbraco.Core;
            using Umbraco.Forms.Core;
            using Umbraco.Forms.Data.Storage;
    
            namespace MyUmbracoSite
            {
               public class MyUmbracoApplication:ApplicationEventHandler
               {
                    protected override void ApplicationInitialized(UmbracoApplicationBase umbracoApplicationBase, ApplicationContext applicationContext)
                    {
                        RecordStorage.RecordInserting += RecordStorage_RecordInserting;
                        RecordStorage.RecordUpdating += RecordStorage_RecordUpdating;
                    }
    
                    private void RecordStorage_RecordInserting(object sender, RecordEventArgs e)
                    {
                      // do something here, record is in the RecordEventArg object
                    }
    
                    private void RecordStorage_RecordUpdating(object sender, RecordEventArgs e)
                    {
                        //do something here
                    }
    
    
               }
            }
    

    To delete a record you can spin up a new instance of the RecordStorage class like so:

        using (var storage = new RecordStorage(ApplicationContext.Current.DatabaseContext))
        {
            storage.DeleteRecord(e.Record, e.Form);
        }
    

    Just adding for completeness in case anyone else drops by :)

Please Sign in or register to post replies

Write your reply to:

Draft