Skip to content

Commit 828fb37

Browse files
authored
Add silverstripe-6 support (#4183)
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.
1 parent 1410e88 commit 828fb37

2 files changed

Lines changed: 69 additions & 26 deletions

File tree

docs/recipe/silverstripe.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The [deploy](#deploy) task of **Silverstripe** consists of:
3838
* [deploy:shared](/docs/recipe/deploy/shared.md#deploy-shared) – Creates symlinks for shared files and dirs
3939
* [deploy:writable](/docs/recipe/deploy/writable.md#deploy-writable) – Makes writable dirs
4040
* [deploy:vendors](/docs/recipe/deploy/vendors.md#deploy-vendors) – Installs vendors
41-
* [silverstripe:buildflush](/docs/recipe/silverstripe.md#silverstripe-buildflush)Runs /dev/build?flush=all
41+
* [silverstripe:buildflush](/docs/recipe/silverstripe.md#silverstripe-buildflush)Rebuild database and cache
4242
* [deploy:publish](/docs/recipe/common.md#deploy-publish) – Publishes the release
4343
* [deploy:symlink](/docs/recipe/deploy/symlink.md#deploy-symlink) – Creates symlink to release
4444
* [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.
5252
### shared_assets
5353
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L13)
5454

55-
Silverstripe configuration
55+
Path to the assets folder.
56+
Defaults to `"public/assets"` (or `"assets"` on older installations).
5657

5758
```php title="Default value"
5859
if (test('[ -d {{release_or_current_path}}/public ]') || test('[ -d {{deploy_path}}/shared/public ]')) {
@@ -63,11 +64,11 @@ return 'assets';
6364

6465

6566
### shared_dirs
66-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L22)
67+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L21)
6768

6869
Overrides [shared_dirs](/docs/recipe/deploy/shared.md#shared_dirs) from `recipe/deploy/shared.php`.
6970

70-
Silverstripe shared dirs
71+
7172

7273
```php title="Default value"
7374
[
@@ -77,11 +78,11 @@ Silverstripe shared dirs
7778

7879

7980
### writable_dirs
80-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L27)
81+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L25)
8182

8283
Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `recipe/deploy/writable.php`.
8384

84-
Silverstripe writable dirs
85+
8586

8687
```php title="Default value"
8788
[
@@ -90,10 +91,23 @@ Silverstripe writable dirs
9091
```
9192

9293

94+
### silverstripe_sake
95+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L33)
96+
97+
Path to the `sake` binary.
98+
Defaults to `"vendor/bin/sake"`, if it exists.
99+
:::info Autogenerated
100+
The value of this configuration is autogenerated on access.
101+
:::
102+
103+
104+
105+
93106
### silverstripe_cli_script
94-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L32)
107+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L49)
95108

96-
Silverstripe cli script
109+
Deprecated option, retained for backward compatibility.
110+
For Silverstripe 6 and above, use `silverstripe_sake` instead.
97111
:::info Autogenerated
98112
The value of this configuration is autogenerated on access.
99113
:::
@@ -105,23 +119,23 @@ The value of this configuration is autogenerated on access.
105119
## Tasks
106120

107121
### silverstripe\:build {#silverstripe-build}
108-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L48)
122+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L65)
109123

110-
Runs /dev/build.
124+
Rebuild the database.
111125

112126
Helper tasks
113127

114128

115129
### silverstripe\:buildflush {#silverstripe-buildflush}
116-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L53)
130+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L76)
117131

118-
Runs /dev/build?flush=all.
132+
Rebuild database and cache.
119133

120134

121135

122136

123137
### deploy {#deploy}
124-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L61)
138+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/silverstripe.php#L90)
125139

126140
Deploys your project.
127141

recipe/silverstripe.php

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
add('recipes', ['silverstripe']);
88

99
/**
10-
* Silverstripe configuration
10+
* Path to the assets folder.
11+
* Defaults to `"public/assets"` (or `"assets"` on older installations).
1112
*/
12-
1313
set('shared_assets', function () {
1414
if (test('[ -d {{release_or_current_path}}/public ]') || test('[ -d {{deploy_path}}/shared/public ]')) {
1515
return 'public/assets';
@@ -18,40 +18,69 @@
1818
});
1919

2020

21-
// Silverstripe shared dirs
2221
set('shared_dirs', [
2322
'{{shared_assets}}',
2423
]);
2524

26-
// Silverstripe writable dirs
2725
set('writable_dirs', [
2826
'{{shared_assets}}',
2927
]);
3028

31-
// Silverstripe cli script
29+
/**
30+
* Path to the `sake` binary.
31+
* Defaults to `"vendor/bin/sake"`, if it exists.
32+
*/
33+
set('silverstripe_sake', function () {
34+
$candidates = [
35+
'vendor/bin/sake',
36+
'vendor/silverstripe/framework/bin/sake',
37+
];
38+
foreach ($candidates as $candidate) {
39+
if (test("[ -x '{{release_or_current_path}}/$candidate' ]")) {
40+
return $candidate;
41+
}
42+
}
43+
});
44+
45+
/**
46+
* Deprecated option, retained for backward compatibility.
47+
* For Silverstripe 6 and above, use `silverstripe_sake` instead.
48+
*/
3249
set('silverstripe_cli_script', function () {
33-
$paths = [
50+
$candidates = [
3451
'framework/cli-script.php',
3552
'vendor/silverstripe/framework/cli-script.php',
3653
];
37-
foreach ($paths as $path) {
38-
if (test('[ -f {{release_or_current_path}}/' . $path . ' ]')) {
39-
return $path;
54+
foreach ($candidates as $candidate) {
55+
if (test("[ -f '{{release_or_current_path}}/$candidate' ]")) {
56+
return $candidate;
4057
}
4158
}
4259
});
4360

4461
/**
4562
* Helper tasks
4663
*/
47-
desc('Runs /dev/build');
64+
desc('Rebuild the database');
4865
task('silverstripe:build', function () {
49-
run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build');
66+
if (get('silverstripe_cli_script')) {
67+
// Old behavior (Silverstripe < 6)
68+
run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build');
69+
} elseif (get('silverstripe_sake')) {
70+
// New behavior (Silverstripe >= 6)
71+
run('{{release_or_current_path}}/{{silverstripe_sake}} db:build');
72+
}
5073
});
5174

52-
desc('Runs /dev/build?flush=all');
75+
desc('Rebuild database and cache');
5376
task('silverstripe:buildflush', function () {
54-
run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build flush=all');
77+
if (get('silverstripe_cli_script')) {
78+
// Old behavior (Silverstripe < 6)
79+
run('{{bin/php}} {{release_or_current_path}}/{{silverstripe_cli_script}} /dev/build flush=all');
80+
} elseif (get('silverstripe_sake')) {
81+
// New behavior (Silverstripe >= 6)
82+
run('{{release_or_current_path}}/{{silverstripe_sake}} -f db:build');
83+
}
5584
});
5685

5786
/**

0 commit comments

Comments
 (0)