Copied to clipboard

Flag this post as spam?

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


  • Manish 373 posts 932 karma points
    Jun 23, 2016 @ 11:07
    Manish
    0

    Scheduler which can delete nodes from recycle bin

    Hi

    I am looking for some code which can help me in creating a scheduler which delete some nodes at certain interval like 50 nodes per day from recycle bin(Media and content).

    Has anybody tried for such thing.

    or any link which can help in achieving such thing

    Manish

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 23, 2016 @ 11:23
    Michaël Vanbrabandt
    0

    Take a look at this package: Recycle bin manager

    /Michaël

  • Manish 373 posts 932 karma points
    Jun 23, 2016 @ 11:40
    Manish
    0

    Hi MIcheal

    I tried this one but not works for v7. it is very old written package.

    Thanks

  • Manish 373 posts 932 karma points
    Jun 24, 2016 @ 05:40
    Manish
    0

    I tried the code which was used in recycle bin manager by creating a class in app code

     using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Globalization;
    using System.Linq;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.web;
    using umbraco.DataLayer;
    using Umbraco.Web.BaseRest;
    
    
    /// <summary>
    /// Summary description for restExt
    /// </summary>
    [RestExtension("restExtRecycleBin")]
    public class restExt
    {
        [RestExtensionMethod(AllowAll = true, ReturnXml = false)]
        public static string DeleteItems(string noToDelete, string noDaysDelay)
        {
            int int32 = Convert.ToInt32(noToDelete);
            int noDaysDelay1 = Convert.ToInt32(noDaysDelay) * -1;
            int num1 = 0;
            int[] expiredIdsToDelete = restExt.GetExpiredIdsToDelete(int32, noDaysDelay1);
            Stopwatch stopwatch = Stopwatch.StartNew();
            foreach (int num2 in expiredIdsToDelete)
            {
                if (stopwatch.Elapsed > TimeSpan.FromSeconds(300.0))
                    return num1.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                try
                {
                    new Document(num2).delete(true);
                    ++num1;
                }
                catch (Exception ex)
                {
                    string str = "Message: " + ex.Message + "StackTrace: " + ex.StackTrace + "TypeName: " + ex.GetType().Name;
                    Log.Add((LogTypes)18, num2, "[restExtRecycleBin] Could not delete: " + str);
                }
            }
            return num1.ToString((IFormatProvider)CultureInfo.InvariantCulture);
        }
    
        private static int[] GetExpiredIdsToDelete(int itemsToDelete, int noDaysDelay)
        {
            DateTime dateTime = DateTime.Now.AddDays((double)noDaysDelay);
            int[] array;
            using (IRecordsReader reader = Application.SqlHelper.ExecuteReader("SELECT distinct top " + (object)itemsToDelete + " umbracoNode.id AS nodeID from umbracoNode LEFT JOIN cmsDocument ON umbracoNode.id = cmsDocument.nodeId WHERE umbracoNode.path like '-1,-20%' AND cmsDocument.updateDate < '" + dateTime.ToString("yyyy-MM-dd") + "'", new IParameter[0]))
                array = restExt.ReadAll(reader).ToArray<int>();
            return array;
        }
    
        private static IEnumerable<int> ReadAll(IRecordsReader reader)
        {
            while (reader.Read())
                yield return (int)reader.Get<int>("nodeID");
        }
    }
    

    and this can be call like

    <!--Recycle Bin parms: /base/restExtRecycleBin/DeleteItems/<<Number of Items to Delete At A
    

    Time>>/<

    Anybody who can help to make this code more robust. Suggestions are welcome.

    Manish

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies