Skip to content

Commit 73c4266

Browse files
authored
Merge pull request #34 from timmess/SYLIUS-274-maintenance-channels
Sylius maintenance channels
2 parents ac5681a + b947caa commit 73c4266

File tree

4 files changed

+88
-12
lines changed

4 files changed

+88
-12
lines changed

.github/workflows/analysis.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
php:
19-
- 8.0
19+
- 8.1
2020
- 8.2
2121
symfony:
2222
- '5.4.*'
23-
- '6.2.*'
23+
- '6.3.*'
2424
env:
2525
APP_ENV: test
2626
steps:

.github/workflows/sylius.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
php:
19-
- 8.0
19+
- 8.1
2020
- 8.2
2121
sylius:
2222
- 1.10.0
2323
- 1.12.0
2424
symfony:
2525
- 5.4
26-
- 6.2
26+
- 6.3
2727
node:
2828
- 14.x
2929
exclude:
3030
-
3131
sylius: 1.10.0
32-
symfony: 6.2
33-
-
34-
php: '8.0'
35-
symfony: 6.2
32+
symfony: 6.3
3633
env:
3734
APP_ENV: test
3835
package-name: synolia/sylius-maintenance-plugin

src/Command/EnableMaintenanceCommand.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Synolia\SyliusMaintenancePlugin\Command;
66

7+
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
8+
use Sylius\Component\Core\Model\ChannelInterface;
79
use Symfony\Component\Console\Command\Command;
810
use Symfony\Component\Console\Input\InputArgument;
911
use Symfony\Component\Console\Input\InputInterface;
@@ -13,6 +15,7 @@
1315
use Synolia\SyliusMaintenancePlugin\Exporter\MaintenanceConfigurationExporter;
1416
use Synolia\SyliusMaintenancePlugin\Factory\MaintenanceConfigurationFactory;
1517
use Synolia\SyliusMaintenancePlugin\FileManager\ConfigurationFileManager;
18+
use Synolia\SyliusMaintenancePlugin\Model\MaintenanceConfiguration;
1619

1720
final class EnableMaintenanceCommand extends Command
1821
{
@@ -23,6 +26,7 @@ public function __construct(
2326
private MaintenanceConfigurationExporter $maintenanceExporter,
2427
private MaintenanceConfigurationFactory $configurationFactory,
2528
private CacheInterface $synoliaMaintenanceCache,
29+
private ChannelRepositoryInterface $channelRepository,
2630
) {
2731
parent::__construct();
2832
}
@@ -37,18 +41,40 @@ protected function configure(): void
3741
}
3842

3943
protected function execute(InputInterface $input, OutputInterface $output): int
44+
{
45+
$maintenanceConfiguration = $this->getMaintenanceConfiguration($input);
46+
$this->maintenanceExporter->export($maintenanceConfiguration);
47+
$this->synoliaMaintenanceCache->delete(ConfigurationFileManager::MAINTENANCE_CACHE_KEY);
48+
$output->writeln($this->translator->trans('maintenance.ui.message_enabled'));
49+
50+
return 0;
51+
}
52+
53+
private function getChannels(): array
54+
{
55+
$channels = $this->channelRepository->findAll();
56+
$channelToExport = [];
57+
58+
/** @var ChannelInterface $channel */
59+
foreach ($channels as $channel) {
60+
$channelToExport[] = $channel->getCode();
61+
}
62+
63+
return $channelToExport;
64+
}
65+
66+
private function getMaintenanceConfiguration(InputInterface $input): MaintenanceConfiguration
4067
{
4168
$maintenanceConfiguration = $this->configurationFactory->get();
69+
$maintenanceConfiguration->setChannels($this->getChannels());
4270
$maintenanceConfiguration->setEnabled(true);
71+
4372
/** @var array $ipsAddress */
4473
$ipsAddress = $input->getArgument('ips_address');
4574
if ([] !== $ipsAddress) {
4675
$maintenanceConfiguration->setIpAddresses(implode(',', $ipsAddress));
4776
}
48-
$this->maintenanceExporter->export($maintenanceConfiguration);
49-
$this->synoliaMaintenanceCache->delete(ConfigurationFileManager::MAINTENANCE_CACHE_KEY);
50-
$output->writeln($this->translator->trans('maintenance.ui.message_enabled'));
5177

52-
return 0;
78+
return $maintenanceConfiguration;
5379
}
5480
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Synolia\SyliusMaintenancePlugin\PHPUnit;
6+
7+
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
8+
use Sylius\Component\Core\Model\ChannelInterface;
9+
use Sylius\Component\Core\Test\Services\DefaultChannelFactory;
10+
use Symfony\Component\Yaml\Yaml;
11+
12+
final class MulitChannelMaintenanceTest extends AbstractWebTestCase
13+
{
14+
protected function setUp(): void
15+
{
16+
parent::setUp();
17+
18+
/** @var ChannelRepositoryInterface $channelRepository */
19+
$channelRepository = $this->manager->getRepository(ChannelInterface::class);
20+
/** @var DefaultChannelFactory $channelFactory */
21+
$channelFactory = self::$kernel->getContainer()->get('sylius.behat.factory.default_channel');
22+
23+
// set hostname for actuel channel
24+
$channel = $channelRepository->findOneByCode('FASHION_WEB');
25+
$channel->setHostname('fashion.localhost');
26+
27+
// create a new channel for maintenance
28+
$maintenanceChannel = $channelFactory->create('test', 'Test channel')['channel'];
29+
$maintenanceChannel->setHostname('test.localhost');
30+
$this->manager->persist($maintenanceChannel);
31+
32+
$this->manager->flush();
33+
}
34+
35+
public function testMaintenanceIsNotEnabledWhenFileIsNotEnabled(): void
36+
{
37+
\file_put_contents(
38+
$this->file,
39+
Yaml::dump([
40+
'channels' => [
41+
'FASHION_WEB',
42+
'test',
43+
],
44+
'enabled' => true,
45+
]),
46+
);
47+
self::$client->request('GET', 'http://fashion.localhost/en_US/');
48+
$this->assertSiteIsInMaintenance();
49+
50+
self::$client->request('GET', 'http://test.localhost/en_US/');
51+
$this->assertSiteIsInMaintenance();
52+
}
53+
}

0 commit comments

Comments
 (0)