mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Installer] Tweak installation command to always create currency and locale from parameters.yml
This commit is contained in:
parent
8627fde7ee
commit
67cab371bc
2 changed files with 52 additions and 73 deletions
|
|
@ -4,21 +4,6 @@ Feature: Sylius Install Feature
|
|||
As a Developer
|
||||
I want to run an installation command
|
||||
|
||||
Scenario: Running install setup command
|
||||
When I run Sylius CLI installer
|
||||
Then I should see output "Please enter a currency code"
|
||||
And I should see output "In which currency can your customers buy goods?"
|
||||
|
||||
Scenario: Choosing default currency
|
||||
Given I do not provide a currency
|
||||
When I run Sylius CLI installer
|
||||
Then I should see output "Adding US Dollar"
|
||||
|
||||
Scenario: Choosing non-default currency
|
||||
Given I provide currency "GBP"
|
||||
When I run Sylius CLI installer
|
||||
Then I should see output "Adding British Pound Sterling"
|
||||
|
||||
Scenario: Registering administrator account
|
||||
Given I provide full administrator data
|
||||
When I run Sylius CLI installer
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
namespace Sylius\Bundle\InstallerBundle\Command;
|
||||
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Intl\Intl;
|
||||
|
|
@ -24,10 +27,15 @@ use Symfony\Component\Validator\Constraints\NotBlank;
|
|||
class SetupCommand extends AbstractInstallCommand
|
||||
{
|
||||
/**
|
||||
* @var Currency
|
||||
* @var CurrencyInterface
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* @var LocaleInterface
|
||||
*/
|
||||
private $locale;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -49,6 +57,7 @@ EOT
|
|||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->setupCurrency($input, $output);
|
||||
$this->setupLocale($input, $output);
|
||||
$this->setupChannel();
|
||||
$this->setupAdministratorUser($input, $output);
|
||||
}
|
||||
|
|
@ -111,6 +120,37 @@ EOT
|
|||
$output->writeln('Administrator account successfully registered.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*/
|
||||
protected function setupLocale(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$localeRepository = $this->get('sylius.repository.locale');
|
||||
$localeManager = $this->get('sylius.manager.locale');
|
||||
$localeFactory = $this->get('sylius.factory.locale');
|
||||
|
||||
$code = trim($this->getContainer()->getParameter('sylius.locale'));
|
||||
$name = Intl::getLanguageBundle()->getLanguageName($code);
|
||||
$output->writeln(sprintf('Adding <info>%s</info> locale.', $name));
|
||||
|
||||
if (null !== $existingLocale = $localeRepository->findOneBy(['code' => $code])) {
|
||||
$this->locale = $existingLocale;
|
||||
|
||||
$localeManager->flush();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$locale = $localeFactory->createNew();
|
||||
$locale->setCode($code);
|
||||
|
||||
$localeManager->persist($locale);
|
||||
$localeManager->flush();
|
||||
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
|
|
@ -121,22 +161,9 @@ EOT
|
|||
$currencyManager = $this->get('sylius.manager.currency');
|
||||
$currencyFactory = $this->get('sylius.factory.currency');
|
||||
|
||||
do {
|
||||
$code = $this->getCurrencyCode($input, $output);
|
||||
|
||||
$valid = true;
|
||||
|
||||
if (0 !== count($errors = $this->validate(trim($code), [new Currency()]))) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
|
||||
$this->writeErrors($output, $errors);
|
||||
} while (!$valid);
|
||||
|
||||
$code = trim($code);
|
||||
$code = trim($this->getContainer()->getParameter('sylius.currency'));
|
||||
$name = Intl::getCurrencyBundle()->getCurrencyName($code);
|
||||
$output->writeln(sprintf('Adding <info>%s</info>', $name));
|
||||
$output->writeln(sprintf('Adding <info>%s</info> currency.', $name));
|
||||
|
||||
if (null !== $existingCurrency = $currencyRepository->findOneBy(['code' => $code])) {
|
||||
$this->currency = $existingCurrency;
|
||||
|
|
@ -157,6 +184,8 @@ EOT
|
|||
|
||||
$currencyManager->persist($currency);
|
||||
$currencyManager->flush();
|
||||
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
protected function setupChannel()
|
||||
|
|
@ -165,59 +194,24 @@ EOT
|
|||
$channelManager = $this->get('sylius.manager.channel');
|
||||
$channelFactory = $this->get('sylius.factory.channel');
|
||||
|
||||
$channel = $channelRepository->findOneByCode('DEFAULT');
|
||||
$channel = $channelRepository->findOneByCode('default');
|
||||
|
||||
if (null !== $channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var ChannelInterface $channel */
|
||||
$channel = $channelFactory->createNew();
|
||||
$channel->setCode('DEFAULT');
|
||||
$channel->setName('DEFAULT');
|
||||
$channel->setDefaultCurrency($this->currency);
|
||||
$channel->setCode('default');
|
||||
$channel->setName('Default');
|
||||
|
||||
$channel->addCurrency($this->currency);
|
||||
$channel->addLocale($this->locale);
|
||||
|
||||
$channelManager->persist($channel);
|
||||
$channelManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getCurrencyCode(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
return $this->getCode(
|
||||
$input,
|
||||
$output,
|
||||
'In which currency can your customers buy goods?',
|
||||
'Please enter a currency code (For example "GBP") or press ENTER to use "USD".',
|
||||
'USD'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @param string $question
|
||||
* @param string $description
|
||||
* @param string $defaultAnswer
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getCode(InputInterface $input, OutputInterface $output, $question, $description, $defaultAnswer)
|
||||
{
|
||||
if ($input->getOption('no-interaction')) {
|
||||
return [$defaultAnswer];
|
||||
}
|
||||
|
||||
$output->writeln($description);
|
||||
$code = $this->ask($output, '<question>'.$question.'</question> ', [], $defaultAnswer);
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue