001
014
015 package com.liferay.portal.verify;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018 import com.liferay.portal.kernel.util.StringBundler;
019 import com.liferay.portal.util.PortalUtil;
020 import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
021 import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
022 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
023 import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
024 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
025
026 import java.sql.Connection;
027 import java.sql.PreparedStatement;
028 import java.sql.ResultSet;
029
030
033 public class VerifyAsset extends VerifyProcess {
034
035 protected void deleteOrphanedAssetEntries() throws Exception {
036 Connection con = null;
037 PreparedStatement ps = null;
038 ResultSet rs = null;
039
040 try {
041 long classNameId = PortalUtil.getClassNameId(
042 DLFileEntryConstants.getClassName());
043
044 con = DataAccess.getUpgradeOptimizedConnection();
045
046 StringBundler sb = new StringBundler(5);
047
048 sb.append("select classPK, entryId from AssetEntry where ");
049 sb.append("classNameId = ");
050 sb.append(classNameId);
051 sb.append(" and classPK not in (select fileVersionId from ");
052 sb.append("DLFileVersion)");
053
054 ps = con.prepareStatement(sb.toString());
055
056 rs = ps.executeQuery();
057
058 while (rs.next()) {
059 long classPK = rs.getLong("classPK");
060 long entryId = rs.getLong("entryId");
061
062 DLFileEntry dlFileEntry =
063 DLFileEntryLocalServiceUtil.fetchDLFileEntry(classPK);
064
065 if (dlFileEntry == null) {
066 AssetEntryLocalServiceUtil.deleteAssetEntry(entryId);
067 }
068 }
069 }
070 finally {
071 DataAccess.cleanUp(con, ps, rs);
072 }
073 }
074
075 @Override
076 protected void doVerify() throws Exception {
077 deleteOrphanedAssetEntries();
078 rebuildTree();
079 }
080
081 protected void rebuildTree() throws Exception {
082 Connection con = null;
083 PreparedStatement ps = null;
084 ResultSet rs = null;
085
086 try {
087 con = DataAccess.getUpgradeOptimizedConnection();
088
089 ps = con.prepareStatement(
090 "select distinct groupId from AssetCategory where " +
091 "(leftCategoryId is null) or (rightCategoryId is null)");
092
093 rs = ps.executeQuery();
094
095 while (rs.next()) {
096 long groupId = rs.getLong("groupId");
097
098 AssetCategoryLocalServiceUtil.rebuildTree(groupId, true);
099 }
100 }
101 finally {
102 DataAccess.cleanUp(con, ps, rs);
103 }
104 }
105
106 }