mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created empoty locked command to create shlink database
This commit is contained in:
parent
7ed85e8916
commit
7fa1f1c63c
@ -28,6 +28,8 @@ return [
|
|||||||
Command\Tag\CreateTagCommand::NAME => Command\Tag\CreateTagCommand::class,
|
Command\Tag\CreateTagCommand::NAME => Command\Tag\CreateTagCommand::class,
|
||||||
Command\Tag\RenameTagCommand::NAME => Command\Tag\RenameTagCommand::class,
|
Command\Tag\RenameTagCommand::NAME => Command\Tag\RenameTagCommand::class,
|
||||||
Command\Tag\DeleteTagsCommand::NAME => Command\Tag\DeleteTagsCommand::class,
|
Command\Tag\DeleteTagsCommand::NAME => Command\Tag\DeleteTagsCommand::class,
|
||||||
|
|
||||||
|
Command\Db\CreateDatabaseCommand::NAME => Command\Db\CreateDatabaseCommand::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@ use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface;
|
|||||||
use Shlinkio\Shlink\Common\Service\PreviewGenerator;
|
use Shlinkio\Shlink\Common\Service\PreviewGenerator;
|
||||||
use Shlinkio\Shlink\Core\Service;
|
use Shlinkio\Shlink\Core\Service;
|
||||||
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
|
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console as SymfonyCli;
|
||||||
use Symfony\Component\Lock;
|
use Symfony\Component\Lock\Factory as Locker;
|
||||||
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||||
use Zend\ServiceManager\Factory\InvokableFactory;
|
use Zend\ServiceManager\Factory\InvokableFactory;
|
||||||
|
|
||||||
@ -19,7 +20,9 @@ return [
|
|||||||
|
|
||||||
'dependencies' => [
|
'dependencies' => [
|
||||||
'factories' => [
|
'factories' => [
|
||||||
Application::class => Factory\ApplicationFactory::class,
|
SymfonyCli\Application::class => Factory\ApplicationFactory::class,
|
||||||
|
SymfonyCli\Helper\ProcessHelper::class => Factory\ProcessHelperFactory::class,
|
||||||
|
PhpExecutableFinder::class => InvokableFactory::class,
|
||||||
|
|
||||||
GeolocationDbUpdater::class => ConfigAbstractFactory::class,
|
GeolocationDbUpdater::class => ConfigAbstractFactory::class,
|
||||||
|
|
||||||
@ -44,11 +47,13 @@ return [
|
|||||||
Command\Tag\CreateTagCommand::class => ConfigAbstractFactory::class,
|
Command\Tag\CreateTagCommand::class => ConfigAbstractFactory::class,
|
||||||
Command\Tag\RenameTagCommand::class => ConfigAbstractFactory::class,
|
Command\Tag\RenameTagCommand::class => ConfigAbstractFactory::class,
|
||||||
Command\Tag\DeleteTagsCommand::class => ConfigAbstractFactory::class,
|
Command\Tag\DeleteTagsCommand::class => ConfigAbstractFactory::class,
|
||||||
|
|
||||||
|
Command\Db\CreateDatabaseCommand::class => ConfigAbstractFactory::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
ConfigAbstractFactory::class => [
|
ConfigAbstractFactory::class => [
|
||||||
GeolocationDbUpdater::class => [DbUpdater::class, Reader::class, Lock\Factory::class],
|
GeolocationDbUpdater::class => [DbUpdater::class, Reader::class, Locker::class],
|
||||||
|
|
||||||
Command\ShortUrl\GenerateShortUrlCommand::class => [Service\UrlShortener::class, 'config.url_shortener.domain'],
|
Command\ShortUrl\GenerateShortUrlCommand::class => [Service\UrlShortener::class, 'config.url_shortener.domain'],
|
||||||
Command\ShortUrl\ResolveUrlCommand::class => [Service\UrlShortener::class],
|
Command\ShortUrl\ResolveUrlCommand::class => [Service\UrlShortener::class],
|
||||||
@ -60,7 +65,7 @@ return [
|
|||||||
Command\Visit\LocateVisitsCommand::class => [
|
Command\Visit\LocateVisitsCommand::class => [
|
||||||
Service\VisitService::class,
|
Service\VisitService::class,
|
||||||
IpLocationResolverInterface::class,
|
IpLocationResolverInterface::class,
|
||||||
Lock\Factory::class,
|
Locker::class,
|
||||||
GeolocationDbUpdater::class,
|
GeolocationDbUpdater::class,
|
||||||
],
|
],
|
||||||
Command\Visit\UpdateDbCommand::class => [DbUpdater::class],
|
Command\Visit\UpdateDbCommand::class => [DbUpdater::class],
|
||||||
@ -73,6 +78,12 @@ return [
|
|||||||
Command\Tag\CreateTagCommand::class => [Service\Tag\TagService::class],
|
Command\Tag\CreateTagCommand::class => [Service\Tag\TagService::class],
|
||||||
Command\Tag\RenameTagCommand::class => [Service\Tag\TagService::class],
|
Command\Tag\RenameTagCommand::class => [Service\Tag\TagService::class],
|
||||||
Command\Tag\DeleteTagsCommand::class => [Service\Tag\TagService::class],
|
Command\Tag\DeleteTagsCommand::class => [Service\Tag\TagService::class],
|
||||||
|
|
||||||
|
Command\Db\CreateDatabaseCommand::class => [
|
||||||
|
Locker::class,
|
||||||
|
SymfonyCli\Helper\ProcessHelper::class,
|
||||||
|
PhpExecutableFinder::class,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
61
module/CLI/src/Command/Db/CreateDatabaseCommand.php
Normal file
61
module/CLI/src/Command/Db/CreateDatabaseCommand.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\CLI\Command\Db;
|
||||||
|
|
||||||
|
use Shlinkio\Shlink\CLI\Command\Util\AbstractLockedCommand;
|
||||||
|
use Shlinkio\Shlink\CLI\Command\Util\LockedCommandConfig;
|
||||||
|
use Shlinkio\Shlink\CLI\Util\ExitCodes;
|
||||||
|
use Symfony\Component\Console\Helper\ProcessHelper;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Lock\Factory as Locker;
|
||||||
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
|
|
||||||
|
class CreateDatabaseCommand extends AbstractLockedCommand
|
||||||
|
{
|
||||||
|
public const NAME = 'db:create';
|
||||||
|
private const DOCTRINE_HELPER_SCRIPT = 'vendor/doctrine/orm/bin/doctrine.php';
|
||||||
|
private const DOCTRINE_HELPER_COMMAND = 'orm:schema-tool:create';
|
||||||
|
|
||||||
|
/** @var ProcessHelper */
|
||||||
|
private $processHelper;
|
||||||
|
/** @var string */
|
||||||
|
private $phpBinary;
|
||||||
|
|
||||||
|
public function __construct(Locker $locker, ProcessHelper $processHelper, PhpExecutableFinder $phpFinder)
|
||||||
|
{
|
||||||
|
parent::__construct($locker);
|
||||||
|
$this->processHelper = $processHelper;
|
||||||
|
$this->phpBinary = $phpFinder->find(false) ?: 'php';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName(self::NAME)
|
||||||
|
->setDescription(
|
||||||
|
'Creates the database needed for shlink to work. It will do nothing if the database already exists'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function lockedExecute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$this->checkDbExists();
|
||||||
|
|
||||||
|
$command = [$this->phpBinary, self::DOCTRINE_HELPER_SCRIPT, self::DOCTRINE_HELPER_COMMAND];
|
||||||
|
$this->processHelper->run($output, $command);
|
||||||
|
|
||||||
|
return ExitCodes::EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function checkDbExists(): void
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getLockConfig(): LockedCommandConfig
|
||||||
|
{
|
||||||
|
return new LockedCommandConfig($this->getName(), true);
|
||||||
|
}
|
||||||
|
}
|
20
module/CLI/src/Factory/ProcessHelperFactory.php
Normal file
20
module/CLI/src/Factory/ProcessHelperFactory.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\CLI\Factory;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
|
class ProcessHelperFactory
|
||||||
|
{
|
||||||
|
public function __invoke(): Helper\ProcessHelper
|
||||||
|
{
|
||||||
|
$processHelper = new Helper\ProcessHelper();
|
||||||
|
$processHelper->setHelperSet(new Helper\HelperSet([
|
||||||
|
new Helper\FormatterHelper(),
|
||||||
|
new Helper\DebugFormatterHelper(),
|
||||||
|
]));
|
||||||
|
|
||||||
|
return $processHelper;
|
||||||
|
}
|
||||||
|
}
|
29
module/CLI/test/Factory/ProcessHelperFactoryTest.php
Normal file
29
module/CLI/test/Factory/ProcessHelperFactoryTest.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkioTest\Shlink\CLI\Factory;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Shlinkio\Shlink\Installer\Factory\ProcessHelperFactory;
|
||||||
|
|
||||||
|
class ProcessHelperFactoryTest extends TestCase
|
||||||
|
{
|
||||||
|
/** @var ProcessHelperFactory */
|
||||||
|
private $factory;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->factory = new ProcessHelperFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function createsTheServiceWithTheProperSetOfHelpers(): void
|
||||||
|
{
|
||||||
|
$processHelper = ($this->factory)();
|
||||||
|
$helperSet = $processHelper->getHelperSet();
|
||||||
|
|
||||||
|
$this->assertCount(2, $helperSet);
|
||||||
|
$this->assertTrue($helperSet->has('formatter'));
|
||||||
|
$this->assertTrue($helperSet->has('debug_formatter'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user