Skip to content

Commit 873f2a4

Browse files
feat: Take care of more files and folders in migration
1 parent 457e488 commit 873f2a4

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/CLI/Commands/Migrate/To/PublicFolder.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function command(CLI $cli): void
3939
protected static function confirmMigration(CLI $cli): void
4040
{
4141
$cli->br();
42-
$cli->confirmToContinue('💡 Migrating your folder setup can lead to a broken site. Make sure to backup your current installation. If you have modified your index.php you might need to adjust the new index.php after the migration. Do you want to continue?');
42+
$cli->confirmToContinue("💡 Migrating your folder setup can lead to a broken site.\n\nMake sure to backup your current installation. If you have modified your index.php you might need to adjust the new index.php after the migration.\n\nDo you want to continue?");
4343
$cli->br();
4444
}
4545

@@ -55,8 +55,8 @@ protected static function makeIndexPHP(CLI $cli, string $publicDir)
5555
protected static function makePublicDir(CLI $cli, string $publicDir): void
5656
{
5757
if (is_dir($publicDir) === true) {
58-
$cli->confirmToContinue('The public folder exists. Do you still want to continue?');
59-
return;
58+
$cli->confirmToContinue('⚠️ The public folder exists. Do you still want to continue?');
59+
$cli->br();
6060
}
6161

6262
Dir::make($publicDir);
@@ -67,6 +67,7 @@ protected static function makePublicDir(CLI $cli, string $publicDir): void
6767
protected static function movableDirs(string $dir): array
6868
{
6969
return [
70+
$dir . '/.well-known',
7071
$dir . '/assets',
7172
$dir . '/media',
7273
];
@@ -76,6 +77,11 @@ protected static function movableFiles(string $dir): array
7677
{
7778
return [
7879
$dir . '/.htaccess',
80+
$dir . '/favicon.ico',
81+
$dir . '/favicon.png',
82+
$dir . '/favicon.svg',
83+
$dir . '/favicon.gif',
84+
$dir . '/robots.txt',
7985
];
8086
}
8187

@@ -87,8 +93,21 @@ protected static function moveDirs(CLI $cli, string $destination, array $dirs):
8793
}
8894

8995
$dirname = basename($dir);
96+
$target = $destination . '/' . $dirname;
97+
98+
// avoid overwriting directories that should not be overwritten
99+
if (is_dir($target) === true) {
100+
$input = $cli->confirm('⚠️ The directory ' . $dirname . ' exists. Do you want to overwrite it?');
101+
$cli->br();
102+
103+
if ($input->confirmed() === false) {
104+
continue;
105+
}
106+
}
107+
108+
Dir::remove($target);
90109

91-
if (Dir::move($dir, $destination . '/' . $dirname) === true) {
110+
if (Dir::move($dir, $target) === true) {
92111
$cli->out('✅ The ' . $dirname . ' directory has been moved');
93112
} else {
94113
$cli->out('🚨 The ' . $dirname . ' directory could not be moved');
@@ -104,6 +123,19 @@ protected static function moveFiles(CLI $cli, string $destination, array $files)
104123
}
105124

106125
$filename = basename($file);
126+
$target = $destination . '/' . $filename;
127+
128+
// avoid overwriting directories that should not be overwritten
129+
if (is_dir($target) === true) {
130+
$input = $cli->confirm('⚠️ The file ' . $filename . ' exists. Do you want to overwrite it?');
131+
$cli->br();
132+
133+
if ($input->confirmed() === false) {
134+
continue;
135+
}
136+
}
137+
138+
F::remove($target);
107139

108140
if (F::move($file, $destination . '/' . $filename) === true) {
109141
$cli->out('✅ The ' . $filename . ' file has been moved');

src/CLI/Commands/Migrate/To/RootFolder.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Kirby\CLI\CLI;
88
use Kirby\Filesystem\Dir;
9+
use Kirby\Filesystem\F;
910

1011
class RootFolder extends PublicFolder
1112
{
@@ -28,8 +29,11 @@ public static function command(CLI $cli): void
2829
return;
2930
}
3031

31-
static::moveDirs($cli, $dir, static::movableDirs($publicDir));
32-
static::moveFiles($cli, $dir, static::movableFiles($publicDir));
32+
$dirs = Dir::dirs($publicDir, null, true);
33+
$files = Dir::files($publicDir, ['index.php'], true);
34+
35+
static::moveDirs($cli, $dir, $dirs);
36+
static::moveFiles($cli, $dir, $files);
3337

3438
static::makeIndexPHP($cli, $dir);
3539
static::removePublicDir($cli, $publicDir);
@@ -44,11 +48,19 @@ protected static function makeIndexPHP(CLI $cli, string $dir)
4448

4549
$cli->make($dir . '/index.php', $template);
4650

47-
$cli->out('✅ The index.php has been created');
51+
$cli->out('✅ The new index.php has been created');
52+
53+
// remove the old index.php
54+
F::remove($dir . '/public/index.php');
4855
}
4956

5057
protected static function removePublicDir(CLI $cli, string $publicDir): void
5158
{
59+
if (Dir::isEmpty($publicDir) === false) {
60+
$cli->out('🚨 The public directory is not empty yet. Please make sure to move remaining files and directories yourself.');
61+
return;
62+
}
63+
5264
if (Dir::remove($publicDir) === true) {
5365
$cli->out('✅ The public directory has been removed');
5466
} else {

0 commit comments

Comments
 (0)