Class AbstractContentUpgradeOperation
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
- All Implemented Interfaces:
org.craftercms.commons.upgrade.UpgradeOperation<String>
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.web.context.ServletContextAware
- Direct Known Subclasses:
AbstractContentTypeUpgradeOperation
,ConfigEncryptionUpgradeOperation
,FindAndReplaceUpgradeOperation
,MultiFindAndReplaceUpgradeOperation
Base implementation of
UpgradeOperation
for all site content upgrades
Supported YAML properties:
- includedPaths: (required) list of patterns to check for files in the repository
- Author:
- joseross
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Implementation ofFileVisitor
that collects files matching any of the given patterns -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
List of patterns to check for files in the repositoryFields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
changedFiles, commitDetails, CONFIG_KEY_COMMIT_DETAILS, deletedFiles, servletContext, studioConfiguration
Fields inherited from class org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation
applicationContext, currentVersion, enabled, nextVersion
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
doExecute
(StudioUpgradeContext context) protected void
doInit
(org.apache.commons.configuration2.HierarchicalConfiguration config) filterPaths
(StudioUpgradeContext context, List<Path> matchedPaths) Filters the given list checking if the files match the update conditionsfindIncludedPaths
(StudioUpgradeContext context) Finds all files in the given site that match any of the given patternsprotected String
Performs a read operation from the file systemprotected abstract boolean
shouldBeUpdated
(StudioUpgradeContext context, Path file) Indicates if the given file should be updated by this classprotected abstract void
updateFile
(StudioUpgradeContext context, Path path) Performs any needed updates on the content of the given fileprotected void
Performs a write operation in the file system without committing any changes in the repositoryMethods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
commitAllChanges, doExecute, getCommitMessage, init, loadResource, setServletContext, trackChangedFiles, trackDeletedFiles
Methods inherited from class org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation
execute, setApplicationContext, setEnabled
-
Field Details
-
CONFIG_KEY_INCLUDED_PATHS
- See Also:
-
includedPaths
List of patterns to check for files in the repository
-
-
Constructor Details
-
AbstractContentUpgradeOperation
-
-
Method Details
-
doInit
protected void doInit(org.apache.commons.configuration2.HierarchicalConfiguration config) - Overrides:
doInit
in classorg.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
-
doExecute
public void doExecute(StudioUpgradeContext context) throws org.craftercms.commons.upgrade.exception.UpgradeException - Specified by:
doExecute
in classAbstractUpgradeOperation
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
-
findIncludedPaths
Finds all files in the given site that match any of the given patterns- Parameters:
context
- the current upgrade context- Returns:
- the list of matching files
- Throws:
IOException
- if there is any error finding the files
-
filterPaths
protected List<Path> filterPaths(StudioUpgradeContext context, List<Path> matchedPaths) throws org.craftercms.commons.upgrade.exception.UpgradeException Filters the given list checking if the files match the update conditions- Parameters:
context
- the current upgrade contextmatchedPaths
- the list of files to filter- Returns:
- the filtered list of files
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error filtering the files
-
shouldBeUpdated
protected abstract boolean shouldBeUpdated(StudioUpgradeContext context, Path file) throws org.craftercms.commons.upgrade.exception.UpgradeException Indicates if the given file should be updated by this class- Parameters:
context
- the current upgrade contextfile
- the file to check- Returns:
- true if the file should be updated
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error checking the file
-
updateFile
protected abstract void updateFile(StudioUpgradeContext context, Path path) throws org.craftercms.commons.upgrade.exception.UpgradeException Performs any needed updates on the content of the given file- 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
-
readFile
protected String readFile(Path path) throws org.craftercms.commons.upgrade.exception.UpgradeException Performs a read operation from the file system- Parameters:
path
- the file to read- Returns:
- the content of the file
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error reading the file
-
writeFile
protected void writeFile(Path path, String content) throws org.craftercms.commons.upgrade.exception.UpgradeException Performs a write operation in the file system without committing any changes in the repository- Parameters:
path
- the file to writecontent
- the content to write- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- is there is any error writing the content
-