Applying a patch to the Shopware 6 Core

Viewed 143

My current version of Shopware has a small problem, for which I'd like to implement the following patch: https://gitlab.com/mh2017/shopware6-patches/-/raw/master/core/variant-listing-updater.patch

To implement this patch I am using the cweagans/composer-patches plug-in. When running composer update the Shopware Core is attempted to be removed and re-installed:

Gathering patches for root package.
Removing package shopware/core so that it can be re-installed and re-patched.
  - Removing shopware/core (6.4.7.0)

However the removal of the Core fails, as the update command fails:

> [ ! -f vendor/autoload.php ] || $PHP_BINARY bin/console system:update:prepare
ErrorException {#7
  #message: "Warning: include(/var/www/html/vendor/composer/../shopware/core/Framework/Plugin/KernelPluginLoader/StaticKernelPluginLoader.php): failed to open stream: No such file or directory"
  #code: 0
  #file: "./vendor/symfony/error-handler/DebugClassLoader.php"
  #line: 349
  #severity: E_WARNING
  trace: {
    ./vendor/symfony/error-handler/DebugClassLoader.php:349 { …}
    ./bin/console:49 {
      › 
      › $pluginLoader = new StaticKernelPluginLoader($classLoader, null);
      › 
    }
  }
}
Script [ ! -f vendor/autoload.php ] || $PHP_BINARY bin/console system:update:prepare handling the pre-update-cmd event returned with error code 255

This seems to be due to the fact that the core isn't there when attempting to run this command. When attempting to run this with the --no-scripts command, the command does run but also does not patch the Shopware version (as it is also a script).

What would be the best way to apply patches to the Shopware core that also ensures that composer runs smoothly?

1 Answers

Write simple bash script like this and add it to composer script or run manually. I'm using this commands in my gitlab pipelines.

# apply commit
  curl -o /tmp/NEXT-21468.patch https://github.com/shopware/platform/commit/285c5d4b6bf9f93f7ebfbbcb3354e95fb5adb6ee.patch
  git apply -p3 --directory='vendor/shopware/core' < /tmp/NEXT-21468.patch
# use sed to replace case sensitive path
  curl -o /tmp/NEXT-20216.patch  https://github.com/shopware/platform/commit/bec6ac21a78ab84c7181dac2347e3e670f92033c.patch
  sed -i 's|/src/Core/|/src/core/|g' /tmp/NEXT-20216.patch
  sed -i 's|/src/Storefront/|/src/storefront/|g' /tmp/NEXT-20216.patch
  git apply -p2 --directory='vendor/shopware' < /tmp/NEXT-20216.patch
# apply pull request
 curl -o /tmp/NEXT-21994.patch https://patch-diff.githubusercontent.com/raw/shopware/platform/pull/2536.patch
 git apply -p3 --directory='vendor/shopware/core' < /tmp/NEXT-21994.patch
Related