Self-reapplying recipes 😈

Created on 22 January 2025, 6 months ago

Problem/Motivation

A need has arisen for recipes to be able to be reapplied automatically under certain conditions. The canonical example is Drupal CMS's SEO Tools recipe -- it attaches a bunch of useful SEO stuff to extant content types, but if you then create a new content type, it won't have any of the SEO things unless you specifically go and reapply the recipe.

Wouldn't it be neat to do that automatically? I think we can do it with ECA, as long as there are a couple of things in place.

Proposed resolution

Here's what we need, in order:

  1. ECA must be able to react when a recipe is applied. An issue for this already exists: Add support for event RecipeAppliedEvent Active
  2. ECA needs to expose an action plugin that can apply a recipe. It should accept one argument (for now), which is the recipe's Composer package name (e.g. drupal/drupal_cms_seo_tools), and use \Composer\InstalledVersions::getInstallPath() to find out where the recipe is installed. Applying a recipe programmatically is quite easy:
    $recipe = Recipe::createFromDirectory('/path/to/recipe/dir');
    RecipeRunner::processRecipe($recipe);
    

With these two features in place, a recipe could supply (or dynamically create) an ECA model to reapply itself any time a particular condition, or set of conditions, is fulfilled.

Feature request
Status

Active

Version

2.1

Component

Code

Created by

🇺🇸United States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @phenaproxima
  • 🇺🇸United States phenaproxima Massachusetts
  • 🇺🇸United States phenaproxima Massachusetts
    • jurgenhaas committed 0dbaca91 on 2.1.x
      Issue #3501480 by phenaproxima, jurgenhaas: Create an action that can...
  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Merge request !463Allow Composer package name resolution → (Merged) created by phenaproxima
  • 🇺🇸United States phenaproxima Massachusetts

    We are going to need to be able to pass a package name to this action, because we cannot rely on any particular path. Even though Drupal CMS provides a default path of recipes/FOO, that can be overridden by developers and vary by recipe.

    Having Composer resolve the package path using its runtime API, which is completely safe to rely on, should solve this problem. Here's some more info about that: https://getcomposer.org/doc/07-runtime.md#knowing-the-path-in-which-a-pa...

    A little bit about InstalledVersions: https://getcomposer.org/doc/07-runtime.md#knowing-the-path-in-which-a-pa.... Specifically, it is completely safe to rely on as long as we have the autoloader, which we very definitely do, or Drupal wouldn't boot up in the first place. Quoth Composer's docs:

    composer-runtime-api 2.0 introduced a new Composer\InstalledVersions class which offers a few static methods to inspect which versions are currently installed. This is automatically available to your code as long as you include the Composer autoloader.

    (composer-runtime-api is not a real package; it's just a symbol used by Composer to ensure compatibility.)

  • Pipeline finished with Failed
    6 months ago
    Total: 463s
    #403070
  • Pipeline finished with Canceled
    6 months ago
    Total: 191s
    #403093
  • Pipeline finished with Success
    6 months ago
    #403097
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thank you @phenaproxima for that improvement in the MR. I've moved this forward and changed the action config such that it only accepts the package name, and not the optional path directly, as that wouldn't really make sense.

    Will merge this, if test remain green. I think that's really exciting.

  • Pipeline finished with Success
    6 months ago
    Total: 473s
    #403478
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Tests are green and I've also tested this locally, it works as expected.

  • Pipeline finished with Skipped
    5 months ago
    #407810
  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Pipeline finished with Success
    5 months ago
    Total: 306s
    #426797
  • Status changed to Fixed 3 months ago
  • 🇮🇹Italy kopeboy Milan

    a recipe could supply (or dynamically create) an ECA model to reapply itself any time a particular condition, or set of conditions, is fulfilled

    🤯 🙌🏻

  • Pipeline finished with Canceled
    2 days ago
    Total: 328s
    #540910
  • Pipeline finished with Failed
    2 days ago
    Total: 615s
    #540916
  • Pipeline finished with Success
    2 days ago
    Total: 570s
    #540939
  • Pipeline finished with Skipped
    2 days ago
    #540959
Production build 0.71.5 2024