diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java index 58e3f6c4a95d..f73585d92b48 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java @@ -15,6 +15,7 @@ import com.dotcms.contenttype.model.type.BaseContentType; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.contenttype.model.type.ContentTypeBuilder; +import com.dotcms.contenttype.model.type.UrlMapable; import com.dotcms.exception.BaseRuntimeInternationalizationException; import com.dotcms.repackage.com.google.common.base.Preconditions; import com.dotcms.repackage.com.google.common.collect.ImmutableList; @@ -294,15 +295,19 @@ public List findByType(BaseContentType type) throws DotDataExceptio } } - @Override - public List findStructureURLMapPatterns() throws DotDataException { - List res = new ArrayList(); + @Override + public List findStructureURLMapPatterns() throws DotDataException { + List res = new ArrayList<>(); + + for ( ContentType type : fac.findUrlMapped() ){ + if (type instanceof UrlMapable){ + res.add(new SimpleStructureURLMap(type.id(), type.urlMapPattern())); + } - for (ContentType type : fac.findUrlMapped()) { - res.add(new SimpleStructureURLMap(type.id(), type.urlMapPattern())); + } + + return ImmutableList.copyOf(res); } - return ImmutableList.copyOf(res); - } @Override public void moveToSystemFolder(Folder folder) throws DotDataException { diff --git a/dotCMS/src/main/java/com/dotmarketing/startup/runonce/Task04115LowercaseIdentifierUrls.java b/dotCMS/src/main/java/com/dotmarketing/startup/runonce/Task04115LowercaseIdentifierUrls.java index 2bae69ba5ba7..384079fb1745 100644 --- a/dotCMS/src/main/java/com/dotmarketing/startup/runonce/Task04115LowercaseIdentifierUrls.java +++ b/dotCMS/src/main/java/com/dotmarketing/startup/runonce/Task04115LowercaseIdentifierUrls.java @@ -26,9 +26,12 @@ *
  • The queries are created so that ONLY PATHS AND ASSET NAMES WITH MIXED * CASES ARE UPDATED. This improves performance since paths and assets that * are already lower-case will not be processed.
  • + *
  • Cases where the UPDATE throws an error will be logged as Error and they + * will have to be fixed manually.
  • * * * @author Jose Castro + * @author Oscar Arrieta * @version 4.1.0 * @since Apr 20, 2017 * @@ -49,64 +52,96 @@ public boolean forceRun() { @Override public void executeUpgrade() throws DotDataException, DotRuntimeException { - //Disable trigger. - try { - final DotConnect dotConnect = new DotConnect(); - final List statements = getDisableTriggerQuery(); - for (String statement : statements) { - dotConnect.executeStatement(statement); - } - } catch (SQLException e) { - throw new DotDataException( - String.format("Error executing Task04115LowercaseIdentifierUrls, trying to DISABLE trigger: %s", e.getMessage()), e); - } - - Connection conn = DbConnectionFactory.getConnection(); - Logger.info(this, "============= Lower-casing Identifier URLs ============="); - try (PreparedStatement selectPs = conn.prepareStatement(getSelectQuery())) { - final int BATCH_SIZE = 100; - try (ResultSet identifiers = selectPs.executeQuery();) { - PreparedStatement updatePs = conn.prepareStatement(UPDATE_QUERY_GENERIC); - for (int counter = 1; identifiers.next(); counter++) { - final String identifier = identifiers.getString(1); - final String originalParentPath = identifiers.getString(2); - final String originalAssetName = identifiers.getString(3); - // Double-check that '/System folder' must not be modified - if ("/system folder".equalsIgnoreCase(originalParentPath)) { - continue; - } - final String parentPathLowercase = originalParentPath.toLowerCase(); - final String assetNameLowercase = originalAssetName.toLowerCase(); - updatePs.setString(1, parentPathLowercase); - updatePs.setString(2, assetNameLowercase); - updatePs.setString(3, identifier); - updatePs.addBatch(); - Logger.info(this, counter + ". " + originalParentPath + originalAssetName); - if (counter % BATCH_SIZE == 0) { - // Insert records in batches - updatePs.executeBatch(); - } - } - updatePs.executeBatch(); - Logger.info(this, "========================================================"); - } - } catch (SQLException e) { - throw new DotDataException( - String.format("Error executing Task04115LowercaseIdentifierUrls: %s", e.getMessage()), e); - } finally { - //Enable trigger. - try { - final DotConnect dotConnect = new DotConnect(); - final List statements = getEnableTriggerQuery(); + try { + DbConnectionFactory.getConnection().setAutoCommit(true); + } catch (SQLException e) { + throw new DotDataException(e.getMessage(), e); + } + + //Disable trigger. + try { + final DotConnect dotConnect = new DotConnect(); + final List statements = getDisableTriggerQuery(); + for (String statement : statements) { + dotConnect.executeStatement(statement); + } + } catch (SQLException e) { + throw new DotDataException( + String.format("Error executing Task04115LowercaseIdentifierUrls, trying to DISABLE trigger: %s", + e.getMessage()), e); + } + + Connection conn = DbConnectionFactory.getConnection(); + Logger.info(this, "============= Lower-casing Identifier URLs ============="); + try (PreparedStatement selectPs = conn.prepareStatement(getSelectQuery())) { + //final int BATCH_SIZE = 100; + try (ResultSet identifiers = selectPs.executeQuery()) { + int counter = 1; + int errors = 1; + while (identifiers.next()) { + final String identifier = identifiers.getString(1); + final String originalParentPath = identifiers.getString(2); + final String originalAssetName = identifiers.getString(3); + // Double-check that '/System folder' must not be modified + if ("/system folder".equalsIgnoreCase(originalParentPath)) { + continue; + } + final String parentPathLowercase = originalParentPath.toLowerCase(); + final String assetNameLowercase = originalAssetName.toLowerCase(); + + DotConnect dotConnect = new DotConnect(); + dotConnect.setSQL(UPDATE_QUERY_GENERIC); + dotConnect.addParam(parentPathLowercase); + dotConnect.addParam(assetNameLowercase); + dotConnect.addParam(identifier); + + Logger.info(this, counter + ". " + originalParentPath + originalAssetName); + try { + dotConnect.loadResult(); + + } catch (Exception e) { + Logger.error(this, + errors + ". Error trying to UPDATE identifier with id: " + identifier + + ", parent_path: " + originalParentPath + + ", asset_name: " + originalAssetName); + errors++; + } + + counter++; + } + Logger.info(this, "========================================================"); + + } catch (Exception e) { //ResultSet identifiers = selectPs.executeQuery() + Logger + .error(this, String.format("Error executing Task04115LowercaseIdentifierUrls: %s", e.getMessage()), + e); + throw new DotDataException( + String.format("Error executing Task04115LowercaseIdentifierUrls: %s", e.getMessage()), e); + } + } catch (Exception e) { //conn.prepareStatement(getSelectQuery()) + Logger + .error(this, String.format("Error executing Task04115LowercaseIdentifierUrls: %s", e.getMessage()), + e); + throw new DotDataException( + String.format("Error executing Task04115LowercaseIdentifierUrls: %s", e.getMessage()), e); + } finally { + //Enable trigger. + try { + final DotConnect dotConnect = new DotConnect(); + final List statements = getEnableTriggerQuery(); for (String statement : statements) { dotConnect.executeStatement(statement); } - } catch (SQLException e) { - throw new DotDataException( - String.format("Error executing Task04115LowercaseIdentifierUrls, trying to ENABLE trigger: %s", e.getMessage()), e); - } - } - } + } catch (SQLException e) { + Logger.error(this, String + .format("Error executing Task04115LowercaseIdentifierUrls, trying to ENABLE trigger: %s", + e.getMessage()), e); + throw new DotDataException( + String.format("Error executing Task04115LowercaseIdentifierUrls, trying to ENABLE trigger: %s", + e.getMessage()), e); + } + } + } /** * Returns the appropriate SELECT query based on the current