protected void _loadStructures( RenderRequest req, User user, String countWebKey, String viewWebKey, String queryWebKey) throws Exception { com.liferay.portlet.RenderRequestImpl reqImpl = (com.liferay.portlet.RenderRequestImpl) req; HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); // gets the session object for the messages HttpSession session = httpReq.getSession(); Integer structureType = (Integer) session.getAttribute(com.dotmarketing.util.WebKeys.Structure.STRUCTURE_EDIT_TYPE); if (req.getParameter("structureType") != null) structureType = Integer.parseInt(req.getParameter("structureType")); if (structureType != null) session.setAttribute( com.dotmarketing.util.WebKeys.Structure.STRUCTURE_EDIT_TYPE, structureType); String query = req.getParameter("query"); String resetQuery = req.getParameter("resetQuery"); List<Structure> structures = new java.util.ArrayList<Structure>(); try { String orderby = req.getParameter("orderBy"); if (!UtilMethods.isSet(orderby)) { orderby = "upper(name)"; } String direction = req.getParameter("direction"); if (!UtilMethods.isSet(direction)) { direction = "asc"; } int pageNumber = 1; if (UtilMethods.isSet(req.getParameter("pageNumber"))) { pageNumber = Integer.parseInt(req.getParameter("pageNumber")); } int limit = com.dotmarketing.util.Config.getIntProperty("PER_PAGE"); int offset = (pageNumber - 1) * limit; if ((query == null) && (resetQuery == null)) { query = (String) session.getAttribute(queryWebKey); } session.setAttribute(queryWebKey, query); int count = 0; String queryCondition = ""; if (((query != null) && (query.length() != 0)) || (structureType != null)) { if (query == null) query = ""; query = query.trim(); if (UtilMethods.isSet(query)) { queryCondition += "(lower(name) " + "like '%" + query.toLowerCase().replace("\'", "\\\'") + "%' or inode='" + query + "')"; } } else { Logger.debug(this, "Getting all Forms Structures"); } if (UtilMethods.isSet(queryCondition)) { queryCondition += " and structuretype=" + Structure.STRUCTURE_TYPE_FORM; } else { queryCondition += " structuretype=" + Structure.STRUCTURE_TYPE_FORM; } structures = StructureFactory.getStructuresByUser( user, queryCondition, orderby, limit, offset, direction); count = (int) ((PaginatedArrayList<Structure>) structures).getTotalResults(); req.setAttribute(countWebKey, new Integer(count)); req.setAttribute(viewWebKey, structures); } catch (Exception e) { req.setAttribute(viewWebKey, structures); Logger.error(this, "Exception e =" + e.getMessage(), e); throw new Exception(e.getMessage()); } }
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; }