@SuppressWarnings({"unchecked", "deprecation"}) public boolean renameFile(File file, String newName) throws DotStateException, DotDataException, DotSecurityException { // getting old file properties String oldFileName = file.getFileName(); String ext = UtilMethods.getFileExtension(oldFileName); Folder folder = APILocator.getFolderAPI() .findParentFolder(file, APILocator.getUserAPI().getSystemUser(), false); Identifier ident = APILocator.getIdentifierAPI().find(file); String newFileName = newName; if (UtilMethods.isSet(ext)) { newFileName = newFileName + "." + ext; } if (fileNameExists(folder, newFileName) || file.isLocked()) return false; List<Versionable> versions = APILocator.getVersionableAPI().findAllVersions(ident); boolean islive = false; for (Versionable version : versions) { File f = (File) version; // sets filename for this new file f.setFileName(newFileName); HibernateUtil.saveOrUpdate(f); if (f.isLive()) islive = true; } LiveCache.removeAssetFromCache(file); WorkingCache.removeAssetFromCache(file); CacheLocator.getIdentifierCache().removeFromCacheByVersionable(file); ident.setURI(APILocator.getIdentifierAPI().find(folder).getPath() + newFileName); // HibernateUtil.saveOrUpdate(ident); APILocator.getIdentifierAPI().save(ident); if (islive) { LiveCache.removeAssetFromCache(file); LiveCache.addToLiveAssetToCache(file); } WorkingCache.removeAssetFromCache(file); WorkingCache.addToWorkingAssetToCache(file); CacheLocator.getIdentifierCache().removeFromCacheByVersionable(file); // RefreshMenus.deleteMenus(); RefreshMenus.deleteMenu(file); CacheLocator.getNavToolCache().removeNav(folder.getHostId(), folder.getInode()); return true; }
@Override public void removeLanguageKeys(String langCode, String countryCode) { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); String languageKey = getPrimaryGroup() + "_Keys_" + (countryCode != null ? langCode + "_" + countryCode : langCode); cache.remove(languageKey, getPrimaryGroup()); }
@Override public void setLanguageKeys(String langCode, String countryCode, List<LanguageKey> keys) { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); String languageKey = getPrimaryGroup() + "_Keys_" + (countryCode != null ? langCode + "_" + countryCode : langCode); cache.put(languageKey, keys, getPrimaryGroup()); }
public void deleteFromCache(File file) throws DotDataException, DotStateException, DotSecurityException { fileCache.remove(file); WorkingCache.removeAssetFromCache(file); if (file.isLive()) { LiveCache.removeAssetFromCache(file); } CacheLocator.getIdentifierCache().removeFromCacheByVersionable(file); }
public void removeLanguage(Language l) { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); long id = l.getId(); String idSt = String.valueOf(l.getId()); String languageKey = l.getLanguageCode() + "-" + l.getCountryCode(); cache.remove(getPrimaryGroup() + id, getPrimaryGroup()); cache.remove(getPrimaryGroup() + idSt, getPrimaryGroup()); cache.remove(getPrimaryGroup() + languageKey, getPrimaryGroup()); }
public boolean hasLanguage(long id) { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); Language l = null; try { l = (Language) cache.get(getPrimaryGroup() + id, getPrimaryGroup()); } catch (DotCacheException e) { Logger.debug(LanguageCacheImpl.class, "Cache Entry not found", e); } return l != null; }
public Language getLanguageById(String id) { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); Language f = null; try { f = (Language) cache.get(getPrimaryGroup() + id, getPrimaryGroup()); } catch (DotCacheException e) { Logger.debug(LanguageCacheImpl.class, "Cache Entry not found", e); } return f; }
@Override public List<LanguageKey> getLanguageKeys(String langCode, String countryCode) throws DotCacheException { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); String languageKey = getPrimaryGroup() + "_Keys_" + (countryCode != null ? langCode + "_" + countryCode : langCode); return (List<LanguageKey>) cache.get(languageKey, getPrimaryGroup()); }
public static void removePageFile(HTMLPage htmlPage, Identifier identifier, boolean EDIT_MODE) { String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator : "working" + java.io.File.separator; String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT"); if (velocityRootPath.startsWith("/WEB-INF")) { velocityRootPath = com.liferay.util.FileUtil.getRealPath(velocityRootPath); } String filePath = folderPath + identifier.getInode() + "." + Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENSION"); velocityRootPath += java.io.File.separator; java.io.File f = new java.io.File(velocityRootPath + filePath); f.delete(); DotResourceCache vc = CacheLocator.getVeloctyResourceCache(); vc.remove(ResourceManager.RESOURCE_TEMPLATE + filePath); CacheLocator.getHTMLPageCache().remove((HTMLPage) htmlPage); }
public static void deleteMenuCache() { String velocityRootPath = ConfigUtils.getDynamicVelocityPath(); File file = new File(velocityRootPath + File.separator + "menus"); if (file.isDirectory()) { FileUtil.deltree(file, false); Logger.debug(MaintenanceUtil.class, "The directory " + file.getPath() + " has been deleted"); } else { Logger.error(MaintenanceUtil.class, file.getPath() + " is not a directory"); } CacheLocator.getNavToolCache().clearCache(); }
public boolean hasLanguage(String languageCode, String countryCode) { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); String languageKey = languageCode + "-" + countryCode; Language l = null; try { l = (Language) cache.get(getPrimaryGroup() + languageKey, getPrimaryGroup()); } catch (DotCacheException e) { Logger.debug(LanguageCacheImpl.class, "Cache Entry not found", e); } return l != null; }
public static void removeContainerFile( Container container, Identifier identifier, boolean EDIT_MODE) { String folderPath = (!EDIT_MODE) ? "live" + java.io.File.separator : "working" + java.io.File.separator; String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT"); if (velocityRootPath.startsWith("/WEB-INF")) { velocityRootPath = Config.CONTEXT.getRealPath(velocityRootPath); } velocityRootPath += java.io.File.separator; String filePath = folderPath + identifier.getInode() + "." + Config.getStringProperty("VELOCITY_CONTAINER_EXTENSION"); java.io.File f = new java.io.File(velocityRootPath + filePath); f.delete(); DotResourceCache vc = CacheLocator.getVeloctyResourceCache(); vc.remove(ResourceManager.RESOURCE_TEMPLATE + filePath); }
public MenuLinkCacheImpl() { cache = CacheLocator.getCacheAdministrator(); }
public FileFactoryImpl() { fileCache = CacheLocator.getFileCache(); }
/** * This method will copy the file data from file to version if version is not null and version * inode > 0 and will replace current file data if newData passed is not null * * @param file * @param version * @param newData * @throws IOException * @throws Exception */ public void saveFileData(File file, File destination, java.io.File newDataFile) throws IOException { String fileName = file.getFileName(); // This was added for http://jira.dotmarketing.net/browse/DOTCMS-5390 // but this breaks the original intent of the // method. See the doc for the method above. Caused // http://jira.dotmarketing.net/browse/DOTCMS-5539 so commented out. // if(newDataFile ==null || newDataFile.length() ==0){ // throw new // DotStateException("Null or 0 lenght java.io.file passed in for file:" // + file.getInode()); // } String assetsPath = APILocator.getFileAPI().getRealAssetsRootPath(); new java.io.File(assetsPath).mkdir(); // creates the new file as // inode{1}/inode{2}/inode.file_extension java.io.File workingFile = getAssetIOFile(file); // http://jira.dotmarketing.net/browse/DOTCMS-1873 // To clear velocity cache DotResourceCache vc = CacheLocator.getVeloctyResourceCache(); vc.remove(ResourceManager.RESOURCE_TEMPLATE + workingFile.getPath()); // If a new version was created, we move the current data to the new // version if (destination != null && InodeUtils.isSet(destination.getInode())) { java.io.File newVersionFile = getAssetIOFile(destination); // FileUtil.copyFile(workingFile, newVersionFile); FileUtils.copyFile(workingFile, newVersionFile); // FileInputStream is = new FileInputStream(workingFile); // FileChannel channelFrom = is.getChannel(); // java.io.File newVersionFile = getAssetIOFile(destination); // FileChannel channelTo = new // FileOutputStream(newVersionFile).getChannel(); // channelFrom.transferTo(0, channelFrom.size(), channelTo); // channelTo.force(false); // channelTo.close(); // channelFrom.close(); } if (newDataFile != null) { // Saving the new working data FileUtils.copyFile(newDataFile, workingFile); file.setSize((int) newDataFile.length()); // checks if it's an image if (UtilMethods.isImage(fileName)) { InputStream in = null; try { // gets image height in = new BufferedInputStream(new FileInputStream(workingFile)); byte[] imageData = new byte[in.available()]; in.read(imageData); Image image = Toolkit.getDefaultToolkit().createImage(imageData); MediaTracker mediaTracker = new MediaTracker(new Container()); mediaTracker.addImage(image, 0); mediaTracker.waitForID(0); int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); in.close(); in = null; // gets image width file.setHeight(imageHeight); file.setWidth(imageWidth); } catch (Exception e) { Logger.error( FileFactory.class, "Unable to read image " + workingFile + " : " + e.getMessage()); throw new IOException(e); } finally { if (in != null) { try { in.close(); } catch (Exception e) { Logger.error(FileFactory.class, "Unable to close image " + e.getMessage()); } } } } // Wiping out the thumbnails and resized versions // http://jira.dotmarketing.net/browse/DOTCMS-5911 String inode = file.getInode(); if (UtilMethods.isSet(inode)) { String realAssetPath = APILocator.getFileAPI().getRealAssetPath(); java.io.File tumbnailDir = new java.io.File( realAssetPath + java.io.File.separator + "dotGenerated" + java.io.File.separator + inode.charAt(0) + java.io.File.separator + inode.charAt(1)); if (tumbnailDir != null) { java.io.File[] files = tumbnailDir.listFiles(); if (files != null) { for (java.io.File iofile : files) { try { if (iofile.getName().startsWith("dotGenerated_")) { iofile.delete(); } } catch (SecurityException e) { Logger.error( FileFactory.class, "EditFileAction._saveWorkingFileData(): " + iofile.getName() + " cannot be erased. Please check the file permissions."); } catch (Exception e) { Logger.error( FileFactory.class, "EditFileAction._saveWorkingFileData(): " + e.getMessage()); } } } } } } }
public void clearCache() { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); // clear the cache cache.flushGroup(getPrimaryGroup()); }
public void doLiveMode(HttpServletRequest request, HttpServletResponse response) throws Exception { String uri = URLDecoder.decode(request.getRequestURI(), UtilMethods.getCharsetConfiguration()); uri = UtilMethods.cleanURI(uri); Host host = hostWebAPI.getCurrentHost(request); // Map with all identifier inodes for a given uri. String idInode = APILocator.getIdentifierAPI().find(host, uri).getInode(); // Checking the path is really live using the livecache String cachedUri = LiveCache.getPathFromCache(uri, host); // if we still have nothing. if (!InodeUtils.isSet(idInode) || cachedUri == null) { throw new ResourceNotFoundException( String.format("Resource %s not found in Live mode!", uri)); } response.setContentType(CHARSET); request.setAttribute("idInode", String.valueOf(idInode)); Logger.debug(VelocityServlet.class, "VELOCITY HTML INODE=" + idInode); /* * JIRA http://jira.dotmarketing.net/browse/DOTCMS-4659 //Set long lived cookie regardless of who this is */ String _dotCMSID = UtilMethods.getCookieValue( request.getCookies(), com.dotmarketing.util.WebKeys.LONG_LIVED_DOTCMS_ID_COOKIE); if (!UtilMethods.isSet(_dotCMSID)) { // create unique generator engine Cookie idCookie = CookieUtil.createCookie(); response.addCookie(idCookie); } com.liferay.portal.model.User user = null; HttpSession session = request.getSession(false); try { if (session != null) user = (com.liferay.portal.model.User) session.getAttribute(com.dotmarketing.util.WebKeys.CMS_USER); } catch (Exception nsue) { Logger.warn(this, "Exception trying to getUser: "******"Page Permissions for URI=" + uri); HTMLPage page = null; try { // we get the page and check permissions below page = APILocator.getHTMLPageAPI() .loadLivePageById(idInode, APILocator.getUserAPI().getSystemUser(), false); } catch (Exception e) { Logger.error( HTMLPageWebAPI.class, "unable to load live version of page: " + idInode + " because " + e.getMessage()); return; } // Check if the page is visible by a CMS Anonymous role if (!permissionAPI.doesUserHavePermission(page, PERMISSION_READ, user, true)) { // this page is protected. not anonymous access /** * ***************************************************************** If we need to redirect * someone somewhere to login before seeing a page, we need to edit the /portal/401.jsp page * to sendRedirect the user to the proper login page. We are not using the REDIRECT_TO_LOGIN * variable in the config any longer. * **************************************************************** */ if (!signedIn) { // No need for the below LAST_PATH attribute on the front end // http://jira.dotmarketing.net/browse/DOTCMS-2675 // request.getSession().setAttribute(WebKeys.LAST_PATH, // new ObjectValuePair(uri, request.getParameterMap())); request.getSession().setAttribute(com.dotmarketing.util.WebKeys.REDIRECT_AFTER_LOGIN, uri); Logger.debug( VelocityServlet.class, "VELOCITY CHECKING PERMISSION: Page doesn't have anonymous access" + uri); Logger.debug(VelocityServlet.class, "401 URI = " + uri); Logger.debug(VelocityServlet.class, "Unauthorized URI = " + uri); response.sendError(401, "The requested page/file is unauthorized"); return; } else if (!permissionAPI .getReadRoles(ident) .contains(APILocator.getRoleAPI().loadLoggedinSiteRole())) { // user is logged in need to check user permissions Logger.debug(VelocityServlet.class, "VELOCITY CHECKING PERMISSION: User signed in"); // check user permissions on this asset if (!permissionAPI.doesUserHavePermission(ident, PERMISSION_READ, user, true)) { // the user doesn't have permissions to see this page // go to unauthorized page Logger.warn( VelocityServlet.class, "VELOCITY CHECKING PERMISSION: Page doesn't have any access for this user"); response.sendError(403, "The requested page/file is forbidden"); return; } } } Logger.debug(VelocityServlet.class, "Recording the ClickStream"); if (Config.getBooleanProperty("ENABLE_CLICKSTREAM_TRACKING", false)) { if (user != null) { UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI() .getUserProxy(user, APILocator.getUserAPI().getSystemUser(), false); if (!userProxy.isNoclicktracking()) { ClickstreamFactory.addRequest( (HttpServletRequest) request, ((HttpServletResponse) response), host); } } else { ClickstreamFactory.addRequest( (HttpServletRequest) request, ((HttpServletResponse) response), host); } } // Begin Page Caching boolean buildCache = false; String key = getPageCacheKey(request); if (key != null) { String cachedPage = CacheLocator.getBlockDirectiveCache().get(key, (int) page.getCacheTTL()); if (cachedPage == null || "refresh".equals(request.getParameter("dotcache")) || "refresh".equals(request.getAttribute("dotcache")) || "refresh".equals(request.getSession().getAttribute("dotcache"))) { // build cached response buildCache = true; } else { // have cached response and are not refreshing, send it response.getWriter().write(cachedPage); return; } } Writer out = (buildCache) ? new StringWriter(4096) : new VelocityFilterWriter(response.getWriter()); // get the context from the requst if possible Context context = VelocityUtil.getWebContext(request, response); request.setAttribute("velocityContext", context); Logger.debug(VelocityServlet.class, "HTMLPage Identifier:" + idInode); try { VelocityUtil.getEngine() .getTemplate("/live/" + idInode + "." + VELOCITY_HTMLPAGE_EXTENSION) .merge(context, out); } catch (ParseErrorException e) { // out.append(e.getMessage()); } context = null; if (buildCache) { String trimmedPage = out.toString().trim(); response.getWriter().write(trimmedPage); response.getWriter().close(); synchronized (key) { String x = CacheLocator.getBlockDirectiveCache().get(key, (int) page.getCacheTTL()); if (x != null) { return; } CacheLocator.getBlockDirectiveCache() .add(getPageCacheKey(request), trimmedPage, (int) page.getCacheTTL()); } } else { out.close(); } }
private PollsQuestionPool() { _cacheable = PollsQuestion.CACHEABLE; _cache = CacheLocator.getCacheAdministrator(); }
/** * <a href="PollsQuestionPool.java.html"><b><i>View Source</i></b></a> * * @author Brian Wing Shun Chan * @version $Revision: 1.48 $ */ public class PollsQuestionPool implements Cachable { public static void clear() { _getInstance()._clear(); } public static PollsQuestion get(String questionId) { return _getInstance()._get(questionId); } public static PollsQuestion put(String questionId, PollsQuestion obj) { return _getInstance()._put(questionId, obj); } public static PollsQuestion remove(String questionId) { return _getInstance()._remove(questionId); } private static PollsQuestionPool _getInstance() { if (_instance == null) { synchronized (PollsQuestionPool.class) { if (_instance == null) { _instance = new PollsQuestionPool(); } } } return _instance; } private PollsQuestionPool() { _cacheable = PollsQuestion.CACHEABLE; _cache = CacheLocator.getCacheAdministrator(); } private void _clear() { _cache.flushGroup(primaryGroup); } private PollsQuestion _get(String questionId) { if (!_cacheable) { return null; } else if (questionId == null) { return null; } else { PollsQuestion obj = null; String key = questionId.toString(); if (Validator.isNull(key)) { return null; } try { obj = (PollsQuestion) _cache.get(key, primaryGroup); } catch (DotCacheException e) { Logger.debug(this, "Cache Entry not found", e); } return obj; } } private PollsQuestion _put(String questionId, PollsQuestion obj) { if (!_cacheable) { return obj; } else if (questionId == null) { return obj; } else { String key = questionId.toString(); if (Validator.isNotNull(key)) { _cache.put(key, obj, primaryGroup); } return obj; } } private PollsQuestion _remove(String questionId) { if (!_cacheable) { return null; } else if (questionId == null) { return null; } else { PollsQuestion obj = null; String key = questionId.toString(); if (Validator.isNull(key)) { return null; } try { obj = (PollsQuestion) _cache.get(key, primaryGroup); } catch (DotCacheException e) { Logger.debug(this, "Cache Entry not found", e); } _cache.remove(key, primaryGroup); return obj; } } private static String primaryGroup = "PollsQuestionPool"; // region's name for the cache private static String[] groupNames = {primaryGroup}; public String getPrimaryGroup() { return primaryGroup; } public String[] getGroups() { return groupNames; } private DotCacheAdministrator _cache = CacheLocator.getCacheAdministrator(); private static PollsQuestionPool _instance; private boolean _cacheable; public void clearCache() { clear(); } }
/** * Moves a file into the given directory OR host * * @param file File to be moved * @param parent Destination Folder * @param host Destination Host * @return true if move success, false otherwise * @throws DotDataException * @throws DotStateException * @throws DotSecurityException */ private Boolean moveFile(File file, Folder parent, Host host) throws DotStateException, DotDataException, DotSecurityException { HostAPI hostAPI = APILocator.getHostAPI(); // Find file identifier Identifier identifier = com.dotmarketing.business.APILocator.getIdentifierAPI().find(file); // gets working container File workingWebAsset = (File) APILocator.getVersionableAPI() .findWorkingVersion(identifier, APILocator.getUserAPI().getSystemUser(), false); // gets live container File liveWebAsset = (File) APILocator.getVersionableAPI() .findLiveVersion(identifier, APILocator.getUserAPI().getSystemUser(), false); // checks if another identifer with the same name exists in the same Boolean fileNameExists; if (parent != null) { fileNameExists = fileNameExists(parent, file.getFileName()); } else { fileNameExists = fileNameExists(APILocator.getFolderAPI().findSystemFolder(), file.getFileName()); } if (fileNameExists) { return false; } // assets cache if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) { LiveCache.removeAssetFromCache(liveWebAsset); } WorkingCache.removeAssetFromCache(workingWebAsset); // gets old parent Folder oldParent = APILocator.getFolderAPI() .findParentFolder(workingWebAsset, APILocator.getUserAPI().getSystemUser(), false); /*oldParent.deleteChild(workingWebAsset); if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) { oldParent.deleteChild(liveWebAsset); } //add new Parent parent.addChild(workingWebAsset); if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) { parent.addChild(liveWebAsset); }*/ // gets identifier for this webasset and changes the uri and persists it User systemUser; try { systemUser = APILocator.getUserAPI().getSystemUser(); if (host == null) { host = hostAPI.findParentHost(parent, systemUser, false); } } catch (DotDataException e) { Logger.error(FileFactory.class, e.getMessage(), e); throw new DotRuntimeException(e.getMessage(), e); } catch (DotSecurityException e) { Logger.error(FileFactory.class, e.getMessage(), e); throw new DotRuntimeException(e.getMessage(), e); } identifier.setHostId(host.getIdentifier()); identifier.setURI(parent != null ? workingWebAsset.getURI(parent) : workingWebAsset.getURI()); // HibernateUtil.saveOrUpdate(identifier); APILocator.getIdentifierAPI().save(identifier); if (UtilMethods.isSet(liveWebAsset)) CacheLocator.getIdentifierCache().removeFromCacheByVersionable(liveWebAsset); // IdentifierCache.addAssetToIdentifierCache(liveWebAsset); // Add to Preview and Live Cache if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) { LiveCache.removeAssetFromCache(liveWebAsset); LiveCache.addToLiveAssetToCache(liveWebAsset); } WorkingCache.removeAssetFromCache(workingWebAsset); WorkingCache.addToWorkingAssetToCache(workingWebAsset); if (file.isShowOnMenu()) { // existing folder with different show on menu ... need to regenerate menu if (parent != null) { RefreshMenus.deleteMenu(oldParent, parent); CacheLocator.getNavToolCache().removeNav(parent.getHostId(), parent.getInode()); } else { RefreshMenus.deleteMenu(oldParent); } CacheLocator.getNavToolCache().removeNav(oldParent.getHostId(), oldParent.getInode()); } return true; }
public static int deleteOldAssetVersions(Date assetsOlderThan) { int counter = 0; int auxCount = 0; /* * Run the drop tasks interatively, moving forward in time * DROP_OLD_ASSET_ITERATE_BY_SECONDS controls how many seconds to * move forward in time for each iteration - default is to iterate by 30 days */ Calendar runDate = Calendar.getInstance(); runDate.setTime(assetsOlderThan); runDate.add(Calendar.YEAR, -2); try { DotConnect dc = new DotConnect(); String minIdateSQL = "select idate from inode order by idate"; dc.setSQL(minIdateSQL); dc.setMaxRows(1); List<Map<String, Object>> map = dc.loadObjectResults(); Date d = (Date) map.get(0).get("idate"); if (d != null) runDate.setTime(d); } catch (Exception e) { Logger.info(CMSMaintenanceFactory.class, "Can't get start date"); } while (runDate.getTime().before(assetsOlderThan) || runDate.getTime().equals(assetsOlderThan)) { try { HibernateUtil.startTransaction(); Logger.info( CMSMaintenanceFactory.class, "Starting deleteOldAssetVersions for date: " + UtilMethods.dateToHTMLDate(runDate.getTime(), "yyyy-MM-dd")); ContentletAPI conAPI = APILocator.getContentletAPI(); Logger.info(CMSMaintenanceFactory.class, "Removing Contentlets"); auxCount = conAPI.deleteOldContent(runDate.getTime()); counter = auxCount; Logger.info(CMSMaintenanceFactory.class, "Removed " + auxCount + " Contentlets"); Logger.info(CMSMaintenanceFactory.class, "Removing HTML Pages"); auxCount = APILocator.getHTMLPageAPI().deleteOldVersions(runDate.getTime()); counter += auxCount; Logger.info(CMSMaintenanceFactory.class, "Removed " + auxCount + " HTML Pages"); Logger.info(CMSMaintenanceFactory.class, "Removing Containers"); auxCount = APILocator.getContainerAPI().deleteOldVersions(runDate.getTime()); counter += auxCount; Logger.info(CMSMaintenanceFactory.class, "Removed " + auxCount + " Containers"); Logger.info(CMSMaintenanceFactory.class, "Removing Templates"); auxCount = APILocator.getTemplateAPI().deleteOldVersions(runDate.getTime()); counter += auxCount; Logger.info(CMSMaintenanceFactory.class, "Removed " + auxCount + " Templates"); Logger.info(CMSMaintenanceFactory.class, "Removing Links"); auxCount = APILocator.getMenuLinkAPI().deleteOldVersions(runDate.getTime()); counter += auxCount; Logger.info(CMSMaintenanceFactory.class, "Removed " + auxCount + " Links"); Logger.info(CMSMaintenanceFactory.class, "Removing File Assets"); auxCount = APILocator.getFileAPI().deleteOldVersions(runDate.getTime()); counter += auxCount; Logger.info(CMSMaintenanceFactory.class, "Removed " + auxCount + " File Assets"); Logger.info( CMSMaintenanceFactory.class, "Finished removing old asset versions, removed " + counter + " assets"); // This is the last run, break if (runDate.getTime().equals(assetsOlderThan)) { break; } runDate.add( Calendar.SECOND, Config.getIntProperty("DROP_OLD_ASSET_ITERATE_BY_SECONDS", 60 * 60 * 24 * 30)); // we should never go past the date the user entered if (runDate.getTime().after(assetsOlderThan)) { runDate.setTime(assetsOlderThan); } } catch (Exception ex) { try { HibernateUtil.rollbackTransaction(); } catch (DotHibernateException e) { Logger.error(CMSMaintenanceFactory.class, e.getMessage()); } Logger.debug( CMSMaintenanceFactory.class, "There was a problem deleting old asset versions", ex); Logger.warn( CMSMaintenanceFactory.class, "There was a problem deleting old asset versions", ex); Logger.error(ViewCMSMaintenanceAction.class, ex.toString(), ex); if (counter > 0) { CacheLocator.getCacheAdministrator().flushAll(); } return -1; } finally { try { HibernateUtil.commitTransaction(); } catch (DotHibernateException e) { Logger.error(CMSMaintenanceFactory.class, e.getMessage()); try { HibernateUtil.rollbackTransaction(); } catch (DotHibernateException ex) { Logger.error(CMSMaintenanceFactory.class, e.getMessage()); } Logger.debug( CMSMaintenanceFactory.class, "There was a problem deleting old asset versions", e); Logger.warn( CMSMaintenanceFactory.class, "There was a problem deleting old asset versions", e); Logger.error(ViewCMSMaintenanceAction.class, e.toString(), e); if (counter > 0) { CacheLocator.getCacheAdministrator().flushAll(); } return -1; } } } if (counter > 0) { CacheLocator.getCacheAdministrator().flushAll(); } return counter; }
public static void flushCache() { DotCacheAdministrator cache = CacheLocator.getCacheAdministrator(); cache.flushAll(); }