Copied to clipboard

Flag this post as spam?

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


  • Bean 8 posts 78 karma points
    Sep 20, 2016 @ 08:25
    Bean
    0

    DeleteVersion inside ContentService does not work

    Hi all,

    I am using umbraco 7.3.1, i want to customize to delete all old versions of a doctype when publish new one, just tried to use DeleteVersion inside ContentService but after ran, there was no revision get delete.

    I tried with both true|false for param "deletePriorVersions".

    Is there any body can help?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Sep 20, 2016 @ 08:27
    Michaël Vanbrabandt
    0

    Hi Bean,

    can you show us the full code you used?

    /Michaël

  • Bean 8 posts 78 karma points
    Sep 20, 2016 @ 08:42
    Bean
    0

    Hi Michael,

    This is a function that i created to update the weather information in our system

    public bool UpdateWeatherInfo(int citySettingsId, string temperature, string weatherIcon, string cloudyGusts, string humidity, string wind) { var node = Services.ContentService.GetById(citySettingsId); node.SetValue("temperature", temperature); node.SetValue("weatherIconId", weatherIcon); node.SetValue("cloudyGusts", cloudyGusts); node.SetValue("humidity", humidity); node.SetValue("wind", wind); var currentVersion = node.Version; try { ContentService.SaveAndPublishWithStatus(node); Umbraco.ContentImport.Utils.LoggingHelper.LogInfor("Current version is " + currentVersion.ToString()); ContentService.DeleteVersion(citySettingsId, currentVersion, true); return true; } catch { }; return false; }

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Sep 20, 2016 @ 08:54
    Michaël Vanbrabandt
    0

    Hi Bean,

    if you want to delete all older version maybe you could use the function .DeleteVersions(int id, DateTime versionDate, [int userId = 0])

    Then for the date you take the current date when adding a new version.

    This will remove all version to till current date.

    Hope this helps

    /Michaël

  • Bean 8 posts 78 karma points
    Sep 21, 2016 @ 02:53
    Bean
    0

    Hi Michael,

    I also tried with ContentService.DeleteVersions(1234, DateTime.Now.AddDays(-100)); but it runs forever although it only has 12000 versions

    What's wrong here?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Sep 21, 2016 @ 07:11
    Michaël Vanbrabandt
    0

    Hi Bean,

    you have 12000 versions that needs to be deleted? WOW!

    So if you run this function it keeps running untill you get an error or did you manually stop it after a period of time?

    Can you check the log under App_Data/logs to see if anything is logged there?

    /Michaël

  • Remko 118 posts 283 karma points
    Mar 21, 2018 @ 15:01
    Remko
    0

    Hi,

    I bit of an old topic I guess, but this still doesn't seem to work...

    We've made an importfunction to update a lot of nodes each day. Because we don't want the database to grow larger and larger, we decided to throw away the versions of the node in each import.

    Just by executing this line: cs.DeleteVersions(nodeId, removeOlderVersionsFromDate.Value, userId);

    Where removeOlderVersionsFromDate.Value is DateTime (DateTime.Now.AddDays(-1))

    This doesn't seem to do anything at all... Is there another way to get rid of the audit trail for a node?

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Mar 21, 2018 @ 15:25
    Nicholas Westby
    0

    Is there another way to get rid of the audit trail for a node?

    It would be a hack, but you could always directly delete from the database tables. I would also recommend writing up an issue here so you can get rid of the hack at some point: http://issues.umbraco.org/issues

  • Hynek Kvapil 2 posts 93 karma points
    Jul 17, 2019 @ 03:44
    Hynek Kvapil
    0

    Hello,

    version 8.0.2

    on content save to prevent saving huge amount of version in time I do call

    sender.DeleteVersions(node.Id, DateTime.Now.AddDays(-ProjectConstant.MaxDaysBackAllowForVersions));
    

    getting

    Server error: Contact administrator, see log for full details. The DELETE statement conflicted with the REFERENCE constraint "FK_umbracoDocumentVersion_umbracoContentVersion_id". The conflict occurred in database "DBNAME", table "dbo.umbracoDocumentVersion", column 'id'. The statement has been terminated.
    
Please Sign in or register to post replies

Write your reply to:

Draft