Enhance admin/upgrade cli to allow it to run non-interactive

by Dan Horning ยท 11 months ago

When running php /path/to/index.php admin/upgrade it is not possible to call the command from a non-interactive shell - I'd like to be able to run this process non-interactively as part of our deployment plan from our git repo.

Comments (2)
Dan Horning 11 months ago

here's one suggested method to make this work (that I've tested successfully)
update admin_upgrade.php:136-140 from

$this->Console->output('Upgrade from ' . $this->database_version . ' to ' . $this->file_version . '? (Y/N): ');
if (strtolower(substr($this->Console->getLine(), 0, 1)) != 'y') {
$this->Console->output("Upgrade will not be performed. Goodbye.\n");
exit;
}

to: -----------------------------------

if ((function_exists('posix_isatty') && posix_isatty(STDIN)) || !function_exists('posix_isatty')) {
$this->Console->output('Upgrade from ' . $this->database_version . ' to ' . $this->file_version . '? (Y/N): ');
if (strtolower(substr($this->Console->getLine(), 0, 1)) != 'y') {
$this->Console->output("Upgrade will not be performed. Goodbye.\n");
exit;
}
} else {
$this->Console->output('Running non-interactive upgrade from ' . $this->database_version . ' to ' . $this->file_version . '. ');
}

Dan Horning 11 months ago

and finally - an untested addition that includes windows interactive mode detection

if (
(function_exists('posix_isatty') && posix_isatty(STDIN)) ||
(
!function_exists('posix_isatty') && ((function_exists('stream_isatty') && stream_isatty(STDIN)) || !function_exists('stream_isatty'))
)
) {
$this->Console->output('Upgrade from ' . $this->database_version . ' to ' . $this->file_version . '? (Y/N): ');
if (strtolower(substr($this->Console->getLine(), 0, 1)) != 'y') {
$this->Console->output("Upgrade will not be performed. Goodbye.\n");
exit;
}
} else {
$this->Console->output('Running non-interactive upgrade from ' . $this->database_version . ' to ' . $this->file_version . '. ');
}

2

2 voters

Status Under Review