Logger.error(DotWebdavHelper.class, e.getMessage(), e);
throw new IOException(e.getMessage());
}
Folder folder = folderAPI.findFolderByPath(folderName, host,user,false);
if (isResource(uri,user)) {
Identifier identifier = APILocator.getIdentifierAPI().find(host, path);
Long timeOfPublishing = fileResourceCache.get(uri + "|" + user.getUserId());
Date currentDate = new Date();
long diff = -1;
long minTimeAllowed = Config.getIntProperty("WEBDAV_MIN_TIME_AFTER_PUBLISH_TO_ALLOW_DELETING_OF_FILES", 10);
boolean canDelete= true;
if(UtilMethods.isSet(timeOfPublishing)) {
diff = (currentDate.getTime()-timeOfPublishing)/1000;
canDelete = diff >= minTimeAllowed;
}
if(identifier!=null && identifier.getAssetType().equals("contentlet")){
Contentlet fileAssetCont = APILocator.getContentletAPI()
.findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
//Webdav calls the delete method when is creating a new file. But it creates the file with 0 content length.
//No need to wait 10 seconds with files with 0 length.
if(canDelete
|| (fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD) != null
&& fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD).length() <= 0)){
try{
APILocator.getContentletAPI().archive(fileAssetCont, user, false);
}catch (Exception e) {
Logger.error(DotWebdavHelper.class, e.getMessage(), e);
throw new DotDataException(e.getMessage(), e);
}
WorkingCache.removeAssetFromCache(fileAssetCont);
LiveCache.removeAssetFromCache(fileAssetCont);
fileResourceCache.remove(uri + "|" + user.getUserId());
}
} else {
webAsset = fileAPI.getFileByURI(path, host, false, user, false);
// This line just archive the assets
// WebAssetFactory.deleteAsset(file, user.getUserId());
// This line delete the assets (no archive)
try{
WebAssetFactory.archiveAsset(webAsset, user);
}catch (Exception e) {
Logger.error(DotWebdavHelper.class, e.getMessage(), e);
throw new DotDataException(e.getMessage(), e);
}
WorkingCache.removeAssetFromCache(webAsset);
LiveCache.removeAssetFromCache(webAsset);
}
} else if (isFolder(uri,user)) {
if(!path.endsWith("/"))
path += "/";
folder = folderAPI.findFolderByPath(path, host,user,false);
if (folder.isShowOnMenu()) {
// RefreshMenus.deleteMenus();
RefreshMenus.deleteMenu(folder);
CacheLocator.getNavToolCache().removeNav(folder.getHostId(), folder.getInode());
if(!path.equals("/")) {
Identifier ii=APILocator.getIdentifierAPI().find(folder);
CacheLocator.getNavToolCache().removeNavByPath(ii.getHostId(), ii.getParentPath());
}
}
folderAPI.delete(folder, user,false);