44
55namespace Synolia \SyliusMaintenancePlugin \Command ;
66
7+ use Sylius \Component \Channel \Repository \ChannelRepositoryInterface ;
8+ use Sylius \Component \Core \Model \ChannelInterface ;
79use Symfony \Component \Console \Command \Command ;
810use Symfony \Component \Console \Input \InputArgument ;
911use Symfony \Component \Console \Input \InputInterface ;
1315use Synolia \SyliusMaintenancePlugin \Exporter \MaintenanceConfigurationExporter ;
1416use Synolia \SyliusMaintenancePlugin \Factory \MaintenanceConfigurationFactory ;
1517use Synolia \SyliusMaintenancePlugin \FileManager \ConfigurationFileManager ;
18+ use Synolia \SyliusMaintenancePlugin \Model \MaintenanceConfiguration ;
1619
1720final 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}
0 commit comments