Class FindAndReplaceUpgradeOperation
java.lang.Object
org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
org.craftercms.studio.impl.v2.upgrade.operations.site.FindAndReplaceUpgradeOperation
- All Implemented Interfaces:
org.craftercms.commons.upgrade.UpgradeOperation<String>,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.web.context.ServletContextAware
Implementation of
UpgradeOperation that replaces text in the content repository.
Supported YAML properties:
- pattern: (required) the pattern to search in the files, can be a regular expression
- replacement: (required) the expression to replace in the files, can use matched groups from the regular expression in the pattern
- Author:
- joseross
-
Nested Class Summary
Nested classes/interfaces inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
AbstractContentUpgradeOperation.ListFileVisitor -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected StringThe pattern to search in the filesprotected StringThe expression to replace in the filesFields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
CONFIG_KEY_INCLUDED_PATHS, includedPathsFields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
changedFiles, commitDetails, CONFIG_KEY_COMMIT_DETAILS, deletedFiles, servletContext, studioConfigurationFields inherited from class org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation
applicationContext, currentVersion, enabled, nextVersion -
Constructor Summary
ConstructorsConstructorDescriptionFindAndReplaceUpgradeOperation(StudioConfiguration studioConfiguration, DataSource dataSource) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoInit(org.apache.commons.configuration2.HierarchicalConfiguration config) protected booleanshouldBeUpdated(StudioUpgradeContext context, Path file) Indicates if the given file should be updated by this classprotected voidupdateFile(StudioUpgradeContext context, Path path) Performs any needed updates on the content of the given fileMethods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
doExecute, filterPaths, findIncludedPaths, readFile, writeFileMethods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
commitAllChanges, doExecute, getCommitMessage, init, loadResource, setServletContext, trackChangedFiles, trackDeletedFilesMethods inherited from class org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation
execute, setApplicationContext, setEnabled
-
Field Details
-
CONFIG_KEY_PATTERN
- See Also:
-
CONFIG_KEY_REPLACEMENT
- See Also:
-
pattern
The pattern to search in the files -
replacement
The expression to replace in the files
-
-
Constructor Details
-
FindAndReplaceUpgradeOperation
public FindAndReplaceUpgradeOperation(StudioConfiguration studioConfiguration, DataSource dataSource)
-
-
Method Details
-
doInit
protected void doInit(org.apache.commons.configuration2.HierarchicalConfiguration config) - Overrides:
doInitin classAbstractContentUpgradeOperation
-
shouldBeUpdated
Description copied from class:AbstractContentUpgradeOperationIndicates if the given file should be updated by this class- Specified by:
shouldBeUpdatedin classAbstractContentUpgradeOperation- Parameters:
context- the current upgrade contextfile- the file to check- Returns:
- true if the file should be updated
-
updateFile
protected void updateFile(StudioUpgradeContext context, Path path) throws org.craftercms.commons.upgrade.exception.UpgradeException Description copied from class:AbstractContentUpgradeOperationPerforms any needed updates on the content of the given file- Specified by:
updateFilein classAbstractContentUpgradeOperation- Parameters:
context- the current upgrade contextpath- the file to update- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException- if there is any error updating the file
-