mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-20 01:09:56 +03:00
Fixed php binary used in child commands while installkation not properly inherited
This commit is contained in:
parent
f78a7f12a9
commit
6e79b4ba7b
2 changed files with 37 additions and 15 deletions
|
@ -18,6 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Filesystem\Exception\IOException;
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
use Zend\Config\Writer\WriterInterface;
|
use Zend\Config\Writer\WriterInterface;
|
||||||
|
|
||||||
class InstallCommand extends Command
|
class InstallCommand extends Command
|
||||||
|
@ -48,6 +49,14 @@ class InstallCommand extends Command
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $isUpdate;
|
private $isUpdate;
|
||||||
|
/**
|
||||||
|
* @var PhpExecutableFinder
|
||||||
|
*/
|
||||||
|
private $phpFinder;
|
||||||
|
/**
|
||||||
|
* @var string|bool
|
||||||
|
*/
|
||||||
|
private $phpBinary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InstallCommand constructor.
|
* InstallCommand constructor.
|
||||||
|
@ -55,22 +64,25 @@ class InstallCommand extends Command
|
||||||
* @param Filesystem $filesystem
|
* @param Filesystem $filesystem
|
||||||
* @param ConfigCustomizerManagerInterface $configCustomizers
|
* @param ConfigCustomizerManagerInterface $configCustomizers
|
||||||
* @param bool $isUpdate
|
* @param bool $isUpdate
|
||||||
|
* @param PhpExecutableFinder|null $phpFinder
|
||||||
* @throws LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
WriterInterface $configWriter,
|
WriterInterface $configWriter,
|
||||||
Filesystem $filesystem,
|
Filesystem $filesystem,
|
||||||
ConfigCustomizerManagerInterface $configCustomizers,
|
ConfigCustomizerManagerInterface $configCustomizers,
|
||||||
$isUpdate = false
|
bool $isUpdate = false,
|
||||||
|
PhpExecutableFinder $phpFinder = null
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->configWriter = $configWriter;
|
$this->configWriter = $configWriter;
|
||||||
$this->isUpdate = $isUpdate;
|
$this->isUpdate = $isUpdate;
|
||||||
$this->filesystem = $filesystem;
|
$this->filesystem = $filesystem;
|
||||||
$this->configCustomizers = $configCustomizers;
|
$this->configCustomizers = $configCustomizers;
|
||||||
|
$this->phpFinder = $phpFinder ?: new PhpExecutableFinder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('shlink:install')
|
->setName('shlink:install')
|
||||||
|
@ -84,7 +96,7 @@ class InstallCommand extends Command
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$this->io = new SymfonyStyle($input, $output);
|
$this->io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
@ -133,8 +145,8 @@ class InstallCommand extends Command
|
||||||
// If current command is not update, generate database
|
// If current command is not update, generate database
|
||||||
if (! $this->isUpdate) {
|
if (! $this->isUpdate) {
|
||||||
$this->io->write('Initializing database...');
|
$this->io->write('Initializing database...');
|
||||||
if (! $this->runCommand(
|
if (! $this->runPhpCommand(
|
||||||
'php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create',
|
'vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create',
|
||||||
'Error generating database.',
|
'Error generating database.',
|
||||||
$output
|
$output
|
||||||
)) {
|
)) {
|
||||||
|
@ -144,8 +156,8 @@ class InstallCommand extends Command
|
||||||
|
|
||||||
// Run database migrations
|
// Run database migrations
|
||||||
$this->io->write('Updating database...');
|
$this->io->write('Updating database...');
|
||||||
if (! $this->runCommand(
|
if (! $this->runPhpCommand(
|
||||||
'php vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate',
|
'vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate',
|
||||||
'Error updating database.',
|
'Error updating database.',
|
||||||
$output
|
$output
|
||||||
)) {
|
)) {
|
||||||
|
@ -154,8 +166,8 @@ class InstallCommand extends Command
|
||||||
|
|
||||||
// Generate proxies
|
// Generate proxies
|
||||||
$this->io->write('Generating proxies...');
|
$this->io->write('Generating proxies...');
|
||||||
if (! $this->runCommand(
|
if (! $this->runPhpCommand(
|
||||||
'php vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies',
|
'vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies',
|
||||||
'Error generating proxies.',
|
'Error generating proxies.',
|
||||||
$output
|
$output
|
||||||
)) {
|
)) {
|
||||||
|
@ -213,23 +225,27 @@ class InstallCommand extends Command
|
||||||
* @throws LogicException
|
* @throws LogicException
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
private function runCommand($command, $errorMessage, OutputInterface $output): bool
|
private function runPhpCommand($command, $errorMessage, OutputInterface $output): bool
|
||||||
{
|
{
|
||||||
if ($this->processHelper === null) {
|
if ($this->processHelper === null) {
|
||||||
$this->processHelper = $this->getHelper('process');
|
$this->processHelper = $this->getHelper('process');
|
||||||
}
|
}
|
||||||
|
|
||||||
$process = $this->processHelper->run($output, $command);
|
if ($this->phpBinary === null) {
|
||||||
|
$this->phpBinary = $this->phpFinder->find(false) ?: 'php';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->io->writeln('Running "' . sprintf('%s %s', $this->phpBinary, $command) . '"');
|
||||||
|
$process = $this->processHelper->run($output, sprintf('%s %s', $this->phpBinary, $command));
|
||||||
if ($process->isSuccessful()) {
|
if ($process->isSuccessful()) {
|
||||||
$this->io->writeln(' <info>Success!</info>');
|
$this->io->writeln(' <info>Success!</info>');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->io->isVerbose()) {
|
if (! $this->io->isVerbose()) {
|
||||||
return false;
|
$this->io->error($errorMessage . ' Run this command with -vvv to see specific error info.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->io->error($errorMessage . ' Run this command with -vvv to see specific error info.');
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ use Symfony\Component\Console\Helper\ProcessHelper;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use Symfony\Component\Filesystem\Exception\IOException;
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Zend\Config\Writer\WriterInterface;
|
use Zend\Config\Writer\WriterInterface;
|
||||||
|
|
||||||
|
@ -55,6 +56,9 @@ class InstallCommandTest extends TestCase
|
||||||
$configCustomizers = $this->prophesize(ConfigCustomizerManagerInterface::class);
|
$configCustomizers = $this->prophesize(ConfigCustomizerManagerInterface::class);
|
||||||
$configCustomizers->get(Argument::cetera())->willReturn($configCustomizer->reveal());
|
$configCustomizers->get(Argument::cetera())->willReturn($configCustomizer->reveal());
|
||||||
|
|
||||||
|
$finder = $this->prophesize(PhpExecutableFinder::class);
|
||||||
|
$finder->find(false)->willReturn('php');
|
||||||
|
|
||||||
$app = new Application();
|
$app = new Application();
|
||||||
$helperSet = $app->getHelperSet();
|
$helperSet = $app->getHelperSet();
|
||||||
$helperSet->set($processHelper->reveal());
|
$helperSet->set($processHelper->reveal());
|
||||||
|
@ -62,7 +66,9 @@ class InstallCommandTest extends TestCase
|
||||||
$this->command = new InstallCommand(
|
$this->command = new InstallCommand(
|
||||||
$this->configWriter->reveal(),
|
$this->configWriter->reveal(),
|
||||||
$this->filesystem->reveal(),
|
$this->filesystem->reveal(),
|
||||||
$configCustomizers->reveal()
|
$configCustomizers->reveal(),
|
||||||
|
false,
|
||||||
|
$finder->reveal()
|
||||||
);
|
);
|
||||||
$app->add($this->command);
|
$app->add($this->command);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue