Has anyone used the API to "clean-up" content? I have a couple of folders that I want content to disappear from once it has passed its unpublish date.
I know there's a delete method that will move a node to the trash, and that's good enough for me.
Before I develop something from scratch, I wanted to see if anyone had already developed something like this that they would share. This is a small part of a bigger project and I don't want to spend too much time on it.
An option that would automate the process entirely would be to create a small .net control that uses the umbraco api to find and delete (put in the trash) pages that meet your specific requirements. This will be a pretty small bit of code.
Then, put the dll in the /bin folder of your umbraco site and the .ascx in the /usercontrols folder; create a new macro in umbraco and select your usercontrol.
Now that you've got a macro, add it to a page on your site. Be sure to hide the page from navigation (with the umbracoNaviHide property) or place it outside your site's content hierarchy. Just be sure website visitors won't find the page as if it were a regular content page (though even if they did it wouldn't hurt anything, it just doesn't display anything useful for website visitors).
Then, set a scheduled task in the /config/umbracoSettings.config file to call your page periodically. When the page is run the macro fires and any expired content will be deleted. Run it once a week, once a day, or every hour depending on how precisely you want the content to be moved to trash.
<scheduledTasks> <!-- add tasks that should be called with an interval (seconds) --> <!-- <task log="true" alias="test60" interval="60" url="http://localhost/umbraco/test.aspx"/>--> </scheduledTasks>
I was looking for a way to keep everything "inside" Umbraco without relying on windows task scheduler or creating a service. Your solution looks to be self contained and portable.
Oh and thank Petr for your suggestion. I may not be able to use the dashboard control for my project, but the code-behind will give me some insight on how to mass-manipulate content using the API.
Auto-delete content
Has anyone used the API to "clean-up" content? I have a couple of folders that I want content to disappear from once it has passed its unpublish date.
I know there's a delete method that will move a node to the trash, and that's good enough for me.
Before I develop something from scratch, I wanted to see if anyone had already developed something like this that they would share. This is a small part of a bigger project and I don't want to spend too much time on it.
Thanks,
Ben
Maybe you can try use http://our.umbraco.org/projects/content-maintenance-dashboard-package and delete unpublished nodes.
An option that would automate the process entirely would be to create a small .net control that uses the umbraco api to find and delete (put in the trash) pages that meet your specific requirements. This will be a pretty small bit of code.
Then, put the dll in the /bin folder of your umbraco site and the .ascx in the /usercontrols folder; create a new macro in umbraco and select your usercontrol.
Now that you've got a macro, add it to a page on your site. Be sure to hide the page from navigation (with the umbracoNaviHide property) or place it outside your site's content hierarchy. Just be sure website visitors won't find the page as if it were a regular content page (though even if they did it wouldn't hurt anything, it just doesn't display anything useful for website visitors).
Then, set a scheduled task in the /config/umbracoSettings.config file to call your page periodically. When the page is run the macro fires and any expired content will be deleted. Run it once a week, once a day, or every hour depending on how precisely you want the content to be moved to trash.
cheers,
doug.
Thanks Doug!
I was looking for a way to keep everything "inside" Umbraco without relying on windows task scheduler or creating a service. Your solution looks to be self contained and portable.
Regards,
Ben
Oh and thank Petr for your suggestion. I may not be able to use the dashboard control for my project, but the code-behind will give me some insight on how to mass-manipulate content using the API.
Here's what I came up with for my user control. I think it's rather database intensive, but shouldn't be bad if I run it once a day. :
I'm passing in the nodeID value from my macro as a parameter. I want all children underneath the specified node to be deleted once they've expired.
This looks great. Any idea if this code will still work on Umbraco 6.x?
is working on a reply...