Skip to content

Commit 621d132

Browse files
authored
Merge pull request #57227 from lpcvoid/master
fix: allow `occ maintenance:update:htaccess` to create .htaccess file in case it doesn't exist yet
2 parents 38ce28f + bfbec60 commit 621d132

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

core/Command/Maintenance/UpdateHtaccess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
2929
$output->writeln('.htaccess has been updated');
3030
return 0;
3131
} else {
32-
$output->writeln('<error>Error updating .htaccess file, not enough permissions, not enough free space or "overwrite.cli.url" set to an invalid URL?</error>');
32+
$output->writeln('<error>Error updating (or creating) .htaccess file, not enough permissions, not enough free space or "overwrite.cli.url" set to an invalid URL?</error>');
3333
return 1;
3434
}
3535
}

lib/private/Setup.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,15 @@ public static function updateHtaccess(): bool {
580580

581581
$setupHelper = Server::get(Setup::class);
582582

583+
// Note: The .htaccess file also needs to exist, otherwise `is_writable()`
584+
// will return false, even though the file could be written.
585+
// This function writes the .htaccess file in that case.
586+
if (!file_exists($setupHelper->pathToHtaccess())) {
587+
if (!touch($setupHelper->pathToHtaccess())) {
588+
return false;
589+
}
590+
}
591+
583592
if (!is_writable($setupHelper->pathToHtaccess())) {
584593
return false;
585594
}

0 commit comments

Comments
 (0)