Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueprints: Add ifAlreadyInstalled to installPlugin and installTheme steps #1244

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Apr 15, 2024

Changes

Adds an ifAlreadyInstalled?: 'overwrite' | 'skip' | 'error' option to installPlugin and installTheme steps. It defaults to overwrite.

Consider the following Blueprint:

{
    "preferredVersions": {
        "php": "latest",
        "wp": "6.4"
    },
    "steps": [
        {
            "step": "installTheme",
            "themeZipFile": {
                "resource": "wordpress.org/themes",
                "slug": "twentytwentyfour"
            }
        }
    ]
}

Before this PR, it would result in an error. After this PR, the installation just works. If the Blueprint author explicitly wants the installation to fail, they can specify the ifAlreadyInstalled option:

{
    "steps": [
        {
            "step": "installTheme",
            "themeZipFile": {
                "resource": "wordpress.org/themes",
                "slug": "twentytwentyfour"
            },
            "ifAlreadyInstalled": "skip" // or "error"
        }
    ]
}

Motivation

Installing a plugin or theme over a currently installed one is a common gotcha. Currently it results in an error and blocks the Blueprint execution. This behavior is, however, often undesirable as it prevents having a single Blueprint that installs a twentytwentyfour theme on different versions of WordPress.

An addition of the ifAlreadyInstalled option puts the Blueprint author in control and provides a sensible default behavior where the installation will "just work" by replacing the already installed version of the plugin or theme.

Closes #1157
Related to WordPress/blueprints#19

Testing instructions

Confirm the unit tests pass

cc @bgrgicak @brandonpayton

…steps

Adds an `ifAlreadyInstalled?: 'overwrite' | 'skip' | 'error'` option to
installPlugin and installTheme steps. It defaults to `overwrite`.

Installing a plugin or theme over a currently installed one is a common
gotcha. Currently it results in an error and blocks the Blueprint
execution. This behavior is, however, often undesirable as it prevents
having a single Blueprint that installs a twentytwentyfour theme on
different versions of WordPress.

An addition of the `ifAlreadyInstalled` option puts the Blueprint author
in control and provides a sensible default behavior where the
installation will "just work" by replacing the already installed version
of the plugin or theme.

 ## Testing instructions

Confirm the unit tests pass
Comment on lines +90 to +92
throw new Error(
`Cannot install asset ${assetFolderName} to ${assetFolderPath} because a file with the same name already exists. Note it's a file, not a directory! Is this by mistake?`
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugins can be a file, for example, Hello Dolly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that's not a big deal in this case because we always assume a folder name when unzipping a plugin. If the zip contains just a hello-dolly.php file, we'll make up a folder name. It's not perfect, but that's how it works today and changing it is outside of scope of this PR. I'm happy to find a better solution in Blueprints v2.

@bgrgicak
Copy link
Collaborator

This is great, and overwrite seems like the right default choice.

@adamziel adamziel merged commit 6e93da9 into trunk Apr 16, 2024
5 checks passed
@adamziel adamziel deleted the add-ifAlreadyInstalled-option branch April 16, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when blueprint includes themeInstall step for latest WordPress default theme
2 participants