From 386f4a7160322e86530d6867a6c27635499135c7 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Mon, 9 Mar 2026 16:23:18 +0100 Subject: [PATCH] Add silverstripe-6 support silverstripe/framework#11353 (merged in Silverstripe 6) refactored the CLI interaction, dropping `cli-script.php` and changing how arguments are handled. Update the recipe while trying to retain backward compatibility with previous Silverstripe versions. --- docs/recipe/silverstripe.md | 40 ++++++++++++++++++--------- recipe/silverstripe.php | 55 ++++++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 26 deletions(-) diff --git a/docs/recipe/silverstripe.md b/docs/recipe/silverstripe.md index 4266a0b40..ce4167a0f 100644 --- a/docs/recipe/silverstripe.md +++ b/docs/recipe/silverstripe.md @@ -38,7 +38,7 @@ The [deploy](#deploy) task of **Silverstripe** consists of: * [deploy:shared](/docs/recipe/deploy/shared.md#deploy-shared) – Creates symlinks for shared files and dirs * [deploy:writable](/docs/recipe/deploy/writable.md#deploy-writable) – Makes writable dirs * [deploy:vendors](/docs/recipe/deploy/vendors.md#deploy-vendors) – Installs vendors -* [silverstripe:buildflush](/docs/recipe/silverstripe.md#silverstripe-buildflush) – Runs /dev/build?flush=all +* [silverstripe:buildflush](/docs/recipe/silverstripe.md#silverstripe-buildflush) – Rebuild database and cache * [deploy:publish](/docs/recipe/common.md#deploy-publish) – Publishes the release * [deploy:symlink](/docs/recipe/deploy/symlink.md#deploy-symlink) – Creates symlink to release * [deploy:unlock](/docs/recipe/deploy/lock.md#deploy-unlock) – Unlocks deploy @@ -52,7 +52,8 @@ The silverstripe recipe is based on the [common](/docs/recipe/common.md) recipe. ### shared_assets [Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L13) -Silverstripe configuration +Path to the assets folder. +Defaults to `"public/assets"` (or `"assets"` on older installations). ```php title="Default value" if (test('[ -d {{release_or_current_path}}/public ]') || test('[ -d {{deploy_path}}/shared/public ]')) { @@ -63,11 +64,11 @@ return 'assets'; ### shared_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L22) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L21) Overrides [shared_dirs](/docs/recipe/deploy/shared.md#shared_dirs) from `recipe/deploy/shared.php`. -Silverstripe shared dirs + ```php title="Default value" [ @@ -77,11 +78,11 @@ Silverstripe shared dirs ### writable_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L27) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L25) Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `recipe/deploy/writable.php`. -Silverstripe writable dirs + ```php title="Default value" [ @@ -90,10 +91,23 @@ Silverstripe writable dirs ``` +### silverstripe_sake +[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L33) + +Path to the `sake` binary. +Defaults to `"vendor/bin/sake"`, if it exists. +:::info Autogenerated +The value of this configuration is autogenerated on access. +::: + + + + ### silverstripe_cli_script -[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L32) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L49) -Silverstripe cli script +Deprecated option, retained for backward compatibility. +For Silverstripe 6 and above, use `silverstripe_sake` instead. :::info Autogenerated The value of this configuration is autogenerated on access. ::: @@ -105,23 +119,23 @@ The value of this configuration is autogenerated on access. ## Tasks ### silverstripe\:build {#silverstripe-build} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L48) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L65) -Runs /dev/build. +Rebuild the database. Helper tasks ### silverstripe\:buildflush {#silverstripe-buildflush} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L53) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L76) -Runs /dev/build?flush=all. +Rebuild database and cache. ### deploy {#deploy} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L61) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L90) Deploys your project. diff --git a/recipe/silverstripe.php b/recipe/silverstripe.php index d32549344..810f8fe61 100644 --- a/recipe/silverstripe.php +++ b/recipe/silverstripe.php @@ -7,9 +7,9 @@ add('recipes', ['silverstripe']); /** - * Silverstripe configuration + * Path to the assets folder. + * Defaults to `"public/assets"` (or `"assets"` on older installations). */ - set('shared_assets', function () { if (test('[ -d {{release_or_current_path}}/public ]') || test('[ -d {{deploy_path}}/shared/public ]')) { return 'public/assets'; @@ -18,25 +18,42 @@ }); -// Silverstripe shared dirs set('shared_dirs', [ '{{shared_assets}}', ]); -// Silverstripe writable dirs set('writable_dirs', [ '{{shared_assets}}', ]); -// Silverstripe cli script +/** + * Path to the `sake` binary. + * Defaults to `"vendor/bin/sake"`, if it exists. + */ +set('silverstripe_sake', function () { + $candidates = [ + 'vendor/bin/sake', + 'vendor/silverstripe/framework/bin/sake', + ]; + foreach ($candidates as $candidate) { + if (test("[ -x '{{release_or_current_path}}/$candidate' ]")) { + return $candidate; + } + } +}); + +/** + * Deprecated option, retained for backward compatibility. + * For Silverstripe 6 and above, use `silverstripe_sake` instead. + */ set('silverstripe_cli_script', function () { - $paths = [ + $candidates = [ 'framework/cli-script.php', 'vendor/silverstripe/framework/cli-script.php', ]; - foreach ($paths as $path) { - if (test('[ -f {{release_or_current_path}}/' . $path . ' ]')) { - return $path; + foreach ($candidates as $candidate) { + if (test("[ -f '{{release_or_current_path}}/$candidate' ]")) { + return $candidate; } } }); @@ -44,14 +61,26 @@ /** * Helper tasks */ -desc('Runs /dev/build'); +desc('Rebuild the database'); task('silverstripe:build', function () { - run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build'); + if (get('silverstripe_cli_script')) { + // Old behavior (Silverstripe < 6) + run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build'); + } elseif (get('silverstripe_sake')) { + // New behavior (Silverstripe >= 6) + run('{{release_or_current_path}}/{{silverstripe_sake}} db:build'); + } }); -desc('Runs /dev/build?flush=all'); +desc('Rebuild database and cache'); task('silverstripe:buildflush', function () { - run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build flush=all'); + if (get('silverstripe_cli_script')) { + // Old behavior (Silverstripe < 6) + run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build flush=all'); + } elseif (get('silverstripe_sake')) { + // New behavior (Silverstripe >= 6) + run('{{release_or_current_path}}/{{silverstripe_sake}} -f db:build'); + } }); /**