Copied to clipboard

Flag this post as spam?

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


  • Dipa 88 posts 370 karma points
    Jun 09, 2016 @ 09:16
    Dipa
    0

    Prevent deletion if node is lookuped to another node.

    Hello,

    I have one node in Content node, called 'Audience Types'. As children of this node, I have multiple audience types like admin, developer, manager, etc.

    Have another node called 'Article Types'. As its children I have multiple articles. In that child document type, I have one property called 'Audience Type', Its a 'multi node tree picker' That is get selected from that 'Audience Type' node.

    This is my structure. Now query is, if I delete any of audience from audience list, Can I know that whether it is selected in article? If yes I want to prevent deletion and if no then it can be deleted.

    In short, while deleting any audience, it should not get delete if it is referenced in any article.

    Please guide me how to do this. Thanks in advance.

    Dipa

  • MarcC 49 posts 356 karma points
    Jun 09, 2016 @ 10:12
    MarcC
    0

    Hi Dipa,

    You could achieve this by creating a method that uses the Content Service and add a check during the Trashing call to see if the node is used.

    I can only see this working by doing a linq check on each article, check the multi node tree picker property values against the node you are deleting.

    If it exists, cancel the trash otherwise let it run. I am not sure on the performance implications.

    I wrote a similar package that uses this technique to prevent ndoes being deleted by accident and the code is open and could be amended to suit your need (install the package and look in your App_code/).

    Or alternatively the package itself would work for you if you remember to enable the 'umbracoDsableDelete' on any audience item you add to your articles. Works on 7.4 but I am unsure what version if 7 you are running.

    https://our.umbraco.org/projects/website-utilities/disable-delete-74/

    May not be the best option but its one that springs to mind

    M

  • Dipa 88 posts 370 karma points
    Jun 09, 2016 @ 11:35
    Dipa
    0

    Hi MarcC,

    That package is not useful to me. User can delete the audience but if it is used then not. So your second suggestion is not helpful to me.

    Regarding first suggestion, Can you tell me where can I set that linq check method? As delete functionality is default of Umbraco. Till now I haven't use this type of method in Umbraco.

    Please provide me any guideline or article, using which I can set this kind of method.

    Thanks, Dipa

  • MarcC 49 posts 356 karma points
    Jun 09, 2016 @ 12:43
    MarcC
    0

    Hi Dipla,

    You can create a class that interhits ApplicationEventHandler and then add a method onto the ContentService.Trashing queue to do this check, when you delete a node it runs through Trashing as it is moving the node to the recycling bin.

    My source code is available in the package I mentioned which does something similar, except looking for a property with the alias "umbracoDisableDelete". You could examine it to give you an idea of how it operates and modify it?

    This could be a good starting base for you perhaps?

    namespace YourNameSpace.EventHandlers
    {
        public class UmbracoDisableDelete : ApplicationEventHandler
        {
    
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                ContentService.Trashing += YourMethod;
            }
    
            void YourMethod(IContentService sender, MoveEventArgs<IContent> e)
            {
                //do your checks here for your condition and if true cancel the delete of the node.
                        if (true)
                        {
                            e.Cancel = true;
                        }
            }
    
        }
    }
    

    I have built this in my App_Code folder in its own cs class

    Good luck!

  • Dipa 88 posts 370 karma points
    Jun 10, 2016 @ 06:19
    Dipa
    0

    Hi MarcC,

    I got my solution, But now have one query. I have many fields like this(lookup). Then how it can be distinguished it?

    As it is working on Id of node, I have to work with document type comparison as per requirement.

    Can you guide me bit for how can I set these multiple type of delete?

    Thanks, Dipa

  • MarcC 49 posts 356 karma points
    Jun 10, 2016 @ 07:40
    MarcC
    0

    Hi Dipa,

    Not exactly sure what you mean, can you post some code snippets?

  • Dipa 88 posts 370 karma points
    Jun 10, 2016 @ 08:39
    Dipa
    0

    Hi MarcC,

    My question is like below :

    I have 'Article Type' node and below it articles as children. In that I have one property called 'Audience Type' which is lookup from Another node called 'Audience Type'.

    Like that I have another property called 'Topic Type' which is lookup from another node called 'Topic Type'. And topic type is also lookup with audience. Means 'Topic Type' is lookup with Article and Audience both. So how can set conditions while deleting any of these child node?

    feel free to ask if any doubt.

    Thanks, Dipa

  • MarcC 49 posts 356 karma points
    Jun 10, 2016 @ 11:26
    MarcC
    0

    Hi Dipa,

    Here is some code I am about to convert to an umbraco package, it works with 7.4.x and it will prevent a node being deleted if it is used within a content picker or multi node tree picker else where.

    The code hasnt been checked so please let me know if it works well for you and it does read the umbraco database, shouldnt cause any damage but please be careful

    EDIT: package created to facilitate this need

    https://our.umbraco.org/projects/backoffice-extensions/pund-prevent-used-node-deletion/

  • Dipa 88 posts 370 karma points
    Jun 11, 2016 @ 05:16
    Dipa
    0

    Hi MarcC,

    In 'NodeInUseCheck' method, you have define 'List' of 'propertyIds'.

    So my question is : 'List' is any customer class you have define? If yes then please let me know it's properties. Because it is giving me error.

    Thanks, Dipa

  • MarcC 49 posts 356 karma points
    Jun 13, 2016 @ 07:31
    MarcC
    100

    Hi Dipla,

    I've updated the code and created a package with the source in it for you.

    https://our.umbraco.org/projects/backoffice-extensions/pund-prevent-used-node-deletion/

    I will be doing an update to the pack soon to allow it to also check for items stored in RJP.MultiUrls

    Hope this helps!

Please Sign in or register to post replies

Write your reply to:

Draft