Skip to content

Commit 2594691

Browse files
committed
New upgrade command
1 parent f480d13 commit 2594691

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ This should print the Kirby CLI version and a list of available commands
6161
- kirby remove:command
6262
- kirby roots
6363
- kirby unzip
64+
- kirby upgrade
6465
- kirby uuid:generate
6566
- kirby uuid:populate
6667
- kirby uuid:remove

commands/upgrade.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
use Kirby\CLI\CLI;
6+
7+
return [
8+
'description' => 'Upgrades a Kirby core',
9+
'args' => [
10+
'version' => [
11+
'description' => 'The version corresponding with the tag name in the kirby repo',
12+
'defaultValue' => 'latest'
13+
]
14+
],
15+
'command' => static function (CLI $cli): void {
16+
$version = $cli->arg('version');
17+
$kirby = $cli->kirby();
18+
$kirbyRoot = $kirby->root('kirby');
19+
$folder = 'kirby.' . $version;
20+
21+
// if entered version is `latest`
22+
// get exact version to compare current kirby version
23+
if ($version === 'latest') {
24+
$release = json_decode(file_get_contents('https://getkirby.com/security.json'));
25+
$version = $release->latest;
26+
}
27+
28+
if (version_compare($version, $kirby->version(), '<=') === true) {
29+
throw new Exception('Current Kirby version is the same or higher than the version you are trying to upgrade to');
30+
}
31+
32+
if (is_dir($cli->dir() . '/' . $folder) === true) {
33+
throw new Exception('The ' . $folder . ' directory exists');
34+
}
35+
36+
$cli->out('Upgrading Kirby from ' . $kirby->version() . ' to ' . $version . '');
37+
$cli->run('install:repo', 'getkirby/kirby', $folder, $version);
38+
39+
// move current kirby to temp directory as backup
40+
rename($kirbyRoot, $kirbyRoot . '.old');
41+
42+
// move new kirby to current root
43+
rename($cli->dir() . '/' . $folder, $kirbyRoot);
44+
45+
// delete old kirby
46+
$cli->rmdir($kirbyRoot . '.old');
47+
48+
// delete temp panel directory
49+
$cli->rmdir($kirby->root('media') . '/panel');
50+
51+
$cli->success('The Kirby has been upgraded to ' . $version);
52+
}
53+
];

0 commit comments

Comments
 (0)