2019-08-05 10:08:59 +02:00
|
|
|
<?php
|
2019-10-05 17:26:10 +02:00
|
|
|
|
2019-08-05 10:08:59 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Shlinkio\Shlink\CLI\Command\Db;
|
|
|
|
|
|
|
|
|
|
use Shlinkio\Shlink\CLI\Command\Util\AbstractLockedCommand;
|
2019-11-17 09:52:45 +01:00
|
|
|
use Shlinkio\Shlink\CLI\Command\Util\LockedCommandConfig;
|
2021-02-12 22:59:40 +01:00
|
|
|
use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface;
|
2019-08-05 10:08:59 +02:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2019-11-30 17:21:36 +01:00
|
|
|
use Symfony\Component\Lock\LockFactory;
|
2019-08-05 10:08:59 +02:00
|
|
|
use Symfony\Component\Process\PhpExecutableFinder;
|
|
|
|
|
|
|
|
|
|
abstract class AbstractDatabaseCommand extends AbstractLockedCommand
|
|
|
|
|
{
|
2021-02-12 22:59:40 +01:00
|
|
|
private ProcessRunnerInterface $processRunner;
|
2019-12-29 22:27:00 +01:00
|
|
|
private string $phpBinary;
|
2019-08-05 10:08:59 +02:00
|
|
|
|
2021-02-12 22:59:40 +01:00
|
|
|
public function __construct(
|
|
|
|
|
LockFactory $locker,
|
|
|
|
|
ProcessRunnerInterface $processRunner,
|
|
|
|
|
PhpExecutableFinder $phpFinder
|
|
|
|
|
) {
|
2019-08-05 10:08:59 +02:00
|
|
|
parent::__construct($locker);
|
2021-02-12 22:59:40 +01:00
|
|
|
$this->processRunner = $processRunner;
|
2019-08-05 10:08:59 +02:00
|
|
|
$this->phpBinary = $phpFinder->find(false) ?: 'php';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function runPhpCommand(OutputInterface $output, array $command): void
|
|
|
|
|
{
|
2020-03-15 17:25:39 +01:00
|
|
|
$command = [$this->phpBinary, ...$command, '--no-interaction'];
|
2021-02-12 22:59:40 +01:00
|
|
|
$this->processRunner->run($output, $command);
|
2019-11-17 09:52:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getLockConfig(): LockedCommandConfig
|
|
|
|
|
{
|
2021-02-12 22:59:40 +01:00
|
|
|
return LockedCommandConfig::blocking($this->getName());
|
2019-08-05 10:08:59 +02:00
|
|
|
}
|
|
|
|
|
}
|