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

public abstract class AbstractContentUpgradeOperation extends AbstractUpgradeOperation
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
  • Field Details

    • CONFIG_KEY_INCLUDED_PATHS

      public static final String CONFIG_KEY_INCLUDED_PATHS
      See Also:
    • includedPaths

      protected List<String> includedPaths
      List of patterns to check for files in the repository
  • Constructor Details

    • AbstractContentUpgradeOperation

      public AbstractContentUpgradeOperation(StudioConfiguration studioConfiguration)
  • Method Details

    • doInit

      protected void doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
      Overrides:
      doInit in class org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
    • doExecute

      public void doExecute(StudioUpgradeContext context) throws org.craftercms.commons.upgrade.exception.UpgradeException
      Specified by:
      doExecute in class AbstractUpgradeOperation
      Throws:
      org.craftercms.commons.upgrade.exception.UpgradeException
    • findIncludedPaths

      protected List<Path> findIncludedPaths(StudioUpgradeContext context) throws IOException
      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 context
      matchedPaths - 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 context
      file - 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 context
      path - 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 write
      content - the content to write
      Throws:
      org.craftercms.commons.upgrade.exception.UpgradeException - is there is any error writing the content