From beb6f6f3839480733368ae9cdb7110e8344d2056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=A9ndez?= Date: Fri, 10 Jan 2025 08:57:29 -0600 Subject: [PATCH] Fix search indexing processor to expand the changeset inside of doMainProcess method execution (#483) --- .../AbstractSearchIndexingProcessor.java | 97 +++++++++---------- .../notification/NotificationProcessor.java | 2 +- 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/craftercms/deployer/impl/processors/AbstractSearchIndexingProcessor.java b/src/main/java/org/craftercms/deployer/impl/processors/AbstractSearchIndexingProcessor.java index b1623c05..942827e4 100644 --- a/src/main/java/org/craftercms/deployer/impl/processors/AbstractSearchIndexingProcessor.java +++ b/src/main/java/org/craftercms/deployer/impl/processors/AbstractSearchIndexingProcessor.java @@ -199,69 +199,66 @@ public boolean supportsMode(Deployment.Mode mode) { protected abstract void doCreateIndexIfMissing(); /** - * Override to add pages/components that need to be updated because a component that they include was updated. + * Expand changeSet by adding pages/components that need to be updated because a component that they include was updated. * * @param changeSet original change set * @return filtered change set */ - @Override - protected ChangeSet getFilteredChangeSet(ChangeSet changeSet) { + protected ChangeSet expandChangeSet(ChangeSet changeSet) { if (createIndexIfMissing) { logger.info("Ensuring that index {} exists", indexId); doCreateIndexIfMissing(); } boolean isReprocessAll = BooleanUtils.toBoolean(getDeploymentParam(REPROCESS_ALL_FILES_PARAM_NAME)); - changeSet = super.getFilteredChangeSet(changeSet); - if (changeSet != null && !changeSet.isEmpty() && xmlFlatteningEnabled && !isReprocessAll) { - List createdFiles = changeSet.getCreatedFiles(); - List updatedFiles = changeSet.getUpdatedFiles(); - List deletedFiles = changeSet.getDeletedFiles(); - List newUpdatedFiles = new ArrayList<>(updatedFiles); - - if (CollectionUtils.isNotEmpty(createdFiles)) { - for (String path : createdFiles) { - if (isDescriptor(path)) { - addItemsThatInheritFromDescriptorToUpdatedFiles(path, createdFiles, newUpdatedFiles, - deletedFiles); - } - if (reindexItemsOnComponentUpdates && isComponent(path)) { - addItemsThatIncludeComponentToUpdatedFiles(path, createdFiles, newUpdatedFiles, deletedFiles); - } + if (changeSet == null || changeSet.isEmpty() || !xmlFlatteningEnabled || isReprocessAll) { + return changeSet; + } + List createdFiles = changeSet.getCreatedFiles(); + List updatedFiles = changeSet.getUpdatedFiles(); + List deletedFiles = changeSet.getDeletedFiles(); + List newUpdatedFiles = new ArrayList<>(updatedFiles); + + if (CollectionUtils.isNotEmpty(createdFiles)) { + for (String path : createdFiles) { + if (isDescriptor(path)) { + addItemsThatInheritFromDescriptorToUpdatedFiles(path, createdFiles, newUpdatedFiles, + deletedFiles); + } + if (reindexItemsOnComponentUpdates && isComponent(path)) { + addItemsThatIncludeComponentToUpdatedFiles(path, createdFiles, newUpdatedFiles, deletedFiles); } } + } - if (CollectionUtils.isNotEmpty(updatedFiles)) { - for (String path : updatedFiles) { - if (isDescriptor(path)) { - addItemsThatInheritFromDescriptorToUpdatedFiles(path, createdFiles, newUpdatedFiles, - deletedFiles); - } - if (reindexItemsOnComponentUpdates && isComponent(path)) { - addItemsThatIncludeComponentToUpdatedFiles(path, createdFiles, newUpdatedFiles, deletedFiles); - } + if (CollectionUtils.isNotEmpty(updatedFiles)) { + for (String path : updatedFiles) { + if (isDescriptor(path)) { + addItemsThatInheritFromDescriptorToUpdatedFiles(path, createdFiles, newUpdatedFiles, + deletedFiles); + } + if (reindexItemsOnComponentUpdates && isComponent(path)) { + addItemsThatIncludeComponentToUpdatedFiles(path, createdFiles, newUpdatedFiles, deletedFiles); } } + } - if (CollectionUtils.isNotEmpty(deletedFiles)) { - for (String path : deletedFiles) { - if (isDescriptor(path)) { - addItemsThatInheritFromDescriptorToUpdatedFiles(path, createdFiles, newUpdatedFiles, - deletedFiles); - } - if (reindexItemsOnComponentUpdates && isComponent(path)) { - addItemsThatIncludeComponentToUpdatedFiles(path, createdFiles, newUpdatedFiles, deletedFiles); - } + if (CollectionUtils.isNotEmpty(deletedFiles)) { + for (String path : deletedFiles) { + if (isDescriptor(path)) { + addItemsThatInheritFromDescriptorToUpdatedFiles(path, createdFiles, newUpdatedFiles, + deletedFiles); + } + if (reindexItemsOnComponentUpdates && isComponent(path)) { + addItemsThatIncludeComponentToUpdatedFiles(path, createdFiles, newUpdatedFiles, deletedFiles); } } - - ChangeSet filteredChangeSet = new ChangeSet(createdFiles, newUpdatedFiles, deletedFiles); - filteredChangeSet.setUpdateDetails(changeSet.getUpdateDetails()); - filteredChangeSet.setUpdateLog(changeSet.getUpdateLog()); - return filteredChangeSet; - } else { - return changeSet; } + + ChangeSet filteredChangeSet = new ChangeSet(createdFiles, newUpdatedFiles, deletedFiles); + filteredChangeSet.setUpdateDetails(changeSet.getUpdateDetails()); + filteredChangeSet.setUpdateLog(changeSet.getUpdateLog()); + return filteredChangeSet; } @Override @@ -269,12 +266,14 @@ protected ChangeSet doMainProcess(Deployment deployment, ProcessorExecution exec ChangeSet filteredChangeSet, ChangeSet originalChangeSet) throws DeployerException { logger.info("Performing search indexing..."); - List createdFiles = emptyIfNull(filteredChangeSet.getCreatedFiles()); - List updatedFiles = emptyIfNull(filteredChangeSet.getUpdatedFiles()); - List deletedFiles = emptyIfNull(filteredChangeSet.getDeletedFiles()); + ChangeSet expandedChangeSet = expandChangeSet(filteredChangeSet); + + List createdFiles = emptyIfNull(expandedChangeSet.getCreatedFiles()); + List updatedFiles = emptyIfNull(expandedChangeSet.getUpdatedFiles()); + List deletedFiles = emptyIfNull(expandedChangeSet.getDeletedFiles()); UpdateSet updateSet = new UpdateSet(ListUtils.union(createdFiles, updatedFiles), deletedFiles); - updateSet.setUpdateDetails(filteredChangeSet.getUpdateDetails()); - updateSet.setUpdateLog(filteredChangeSet.getUpdateLog()); + updateSet.setUpdateDetails(expandedChangeSet.getUpdateDetails()); + updateSet.setUpdateLog(expandedChangeSet.getUpdateLog()); UpdateStatus updateStatus = new UpdateStatus(); execution.setStatusDetails(updateStatus); diff --git a/src/main/java/org/craftercms/deployer/impl/processors/notification/NotificationProcessor.java b/src/main/java/org/craftercms/deployer/impl/processors/notification/NotificationProcessor.java index 07e19447..f0ac8b64 100644 --- a/src/main/java/org/craftercms/deployer/impl/processors/notification/NotificationProcessor.java +++ b/src/main/java/org/craftercms/deployer/impl/processors/notification/NotificationProcessor.java @@ -141,7 +141,7 @@ private boolean matchesStatusCondition(Deployment deployment) { return switch (statusCondition) { case SUCCESS -> status == Deployment.Status.SUCCESS; case ON_ANY_STATUS -> true; - case ON_ANY_FAILURE -> hasExecutionsFailures(deployment); + case ON_ANY_FAILURE -> status == Deployment.Status.FAILURE || hasExecutionsFailures(deployment); case ON_TOTAL_FAILURE -> status == Deployment.Status.FAILURE; }; }