<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic autodelete folder content every night in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/autodelete-folder-content-every-night/m-p/82164#M25231</link>
    <description>&lt;P&gt;Hi, i'm on Community version 6.2 and i'm new to Alfresco at all. I just need for the simplest way for delete the content of a specific folder every night.&lt;/P&gt;&lt;P&gt;These folder is just a temporary passtrough, often users left files here which are useless...&lt;/P&gt;&lt;P&gt;Thanks in advance for any help!&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jun 2020 15:54:07 GMT</pubDate>
    <dc:creator>TheCondor</dc:creator>
    <dc:date>2020-06-01T15:54:07Z</dc:date>
    <item>
      <title>autodelete folder content every night</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/autodelete-folder-content-every-night/m-p/82164#M25231</link>
      <description>&lt;P&gt;Hi, i'm on Community version 6.2 and i'm new to Alfresco at all. I just need for the simplest way for delete the content of a specific folder every night.&lt;/P&gt;&lt;P&gt;These folder is just a temporary passtrough, often users left files here which are useless...&lt;/P&gt;&lt;P&gt;Thanks in advance for any help!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 15:54:07 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/autodelete-folder-content-every-night/m-p/82164#M25231</guid>
      <dc:creator>TheCondor</dc:creator>
      <dc:date>2020-06-01T15:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: autodelete folder content every night</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/autodelete-folder-content-every-night/m-p/82165#M25232</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/80804"&gt;@TheCondor&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;Welcome to Alfresco!&lt;/P&gt;
&lt;P&gt;You might find this &lt;A href="https://hub.alfresco.com/t5/alfresco-content-services-forum/delete-files-from-alfresco/td-p/125410" target="_self" rel="nofollow noopener noreferrer"&gt;thread&lt;/A&gt; useful. This &lt;A href="https://blyx.com/2014/08/18/understanding-alfresco-content-deletion/" target="_self" rel="nofollow noopener noreferrer"&gt;blog&lt;/A&gt; post is also worth reading. There is also this &lt;A href="https://hub.alfresco.com/t5/alfresco-content-services-forum/auto-delete-older-documents/td-p/48999" target="_self" rel="nofollow noopener noreferrer"&gt;thread&lt;/A&gt;, that suggests a scheduled action.&lt;/P&gt;
&lt;P&gt;You could also use the API to delete the folder &amp;amp; all its children - you could have a script that is run as a scheduled job &amp;amp; it would have to be run under admin user I believe. The "permanent=false" flag puts the content into the trashcan.&lt;/P&gt;
&lt;DIV class="block request_url"&gt;
&lt;PRE&gt;https://api-explorer.alfresco.com/alfresco/api/-default-/public/alfresco/versions/1/nodes/123?permanent=true&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;To delete only the children, you could use this API call:&lt;/P&gt;
&lt;DIV class="block request_url"&gt;
&lt;PRE&gt;https://api-explorer.alfresco.com/alfresco/api/-default-/public/alfresco/versions/1/nodes/q/secondary-children/q&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 01 Jun 2020 16:22:18 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/autodelete-folder-content-every-night/m-p/82165#M25232</guid>
      <dc:creator>EddieMay</dc:creator>
      <dc:date>2020-06-01T16:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: autodelete folder content every night</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/autodelete-folder-content-every-night/m-p/82166#M25233</link>
      <description>&lt;P&gt;When you say "&lt;SPAN&gt;way for delete the content of a specific folder every night&lt;/SPAN&gt;",&lt;/P&gt;
&lt;P&gt;You can write a scheduled job that will run on schedule and deletes the files in the configured folder.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Refer these docs to learn more on scheduled jobs:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.alfresco.com/6.2/references/dev-extension-points-scheduled-jobs.html" target="_blank" rel="noopener nofollow noreferrer"&gt;https://docs.alfresco.com/6.2/references/dev-extension-points-scheduled-jobs.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://hub.alfresco.com/t5/alfresco-content-services-blog/creating-scheduled-job-in-alfresco/ba-p/288466" target="_blank" rel="nofollow noopener noreferrer"&gt;https://hub.alfresco.com/t5/alfresco-content-services-blog/creating-scheduled-job-in-alfresco/ba-p/288466&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Your scheduled job could be something like:&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;public class FolderCleanupJobProcessor extends AbstractScheduledLockedJob {

	private NodeService nodeService;

	private SearchService searchService;

	private TransactionService transactionService;
	
	private String deleteNodesSearchQuery;
	
	@Override
	public void executeJob(final JobExecutionContext jobCtx)
			throws JobExecutionException {
		try {
			// Run as system user since this job is user independent hence
			// permission is required on repository
			AuthenticationUtil.setRunAsUserSystem();
			&lt;STRONG&gt;//Create a method to get the file nodes from the configured folder
			//getListOfFilesFromArchiveFolder method can execute a search query and fetch all the nodes from the configured folder for deletion.
			final List&amp;lt;NodeRef&amp;gt; toBeDeletedNodes = getListOfFilesFromArchiveFolder();&lt;/STRONG&gt;
			if (null != toBeDeletedNodes &amp;amp;&amp;amp; !toBeDeletedNodes.isEmpty()) {
				for (final NodeRef nodeRef : toBeDeletedNodes) {
					final RetryingTransactionCallback&amp;lt;Object&amp;gt; txnWork = new RetryingTransactionCallback&amp;lt;Object&amp;gt;() {
						public Object execute() throws Exception {
							// Delete the nodeRef
							&lt;STRONG&gt;if (nodeService.exists(nodeRef)) {
								nodeService.deleteNode(nodeRef);
							}&lt;/STRONG&gt;
							return null;
						}
					};
					transactionService.getRetryingTransactionHelper().doInTransaction(txnWork);	
				}
			}
			
			
		} catch (Exception excp) {
			//LOG Errors 
		}
	}
	
	//This method can execute a search query and fetch all the nodes from the configured folder for deletion.
	private List&amp;lt;NodeRef&amp;gt; getListOfFilesFromArchiveFolder() {
		List&amp;lt;NodeRef&amp;gt; nodeRefList = null;
		ResultSet results = null;
		try {
			&lt;STRONG&gt;//deleteNodesSearchQuery is for example: PATH:"/app:company_home/app:dictionary/cm:yourFolderName//*"
			//considering your folder is in /Company Home/Data Dictionary/ folder. You can adjust the search query depending on the location of your archive folder.
			//if your folder is in a site then, query could be something like: PATH:"/app:company_home/st:sites/cm:test-site/cm:documentLibrary/cm:yourFolderName//*"
			//in the above query, cm:test-site is the site short name.&lt;/STRONG&gt;
			results = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, deleteNodesSearchQuery);
			if (null != results) {
				nodeRefList = results.getNodeRefs();
			}
		} finally {
			if (results != null) {
				results.close();
			}
		}
		return nodeRefList;
	}

	public void setNodeService(final NodeService nodeService) {
		this.nodeService = nodeService;
	}

	public void setSearchService(final SearchService searchService) {
		this.searchService = searchService;
	}
	
	public void setTransactionService(final TransactionService transactionService) {
		this.transactionService = transactionService;
	}
	
	public void setDeleteNodesSearchQuery(final String deleteNodesSearchQuery) {
		this.deleteNodesSearchQuery = deleteNodesSearchQuery;
	}
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;[EDIT]:&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/76783"&gt;@EddieMay&lt;/A&gt;&amp;nbsp;already provided useful stuff. Above response is additonal.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 16:36:10 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/autodelete-folder-content-every-night/m-p/82166#M25233</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-06-01T16:36:10Z</dc:date>
    </item>
  </channel>
</rss>

