Skip to content

Commit e204b84

Browse files
author
Bohdan Korablov
committed
MAGETWO-64602: Sync config file with DB: Validation
1 parent 7489c13 commit e204b84

File tree

5 files changed

+46
-91
lines changed

5 files changed

+46
-91
lines changed

app/code/Magento/Deploy/Console/Command/App/ApplicationDumpCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\Console\Command\Command;
1313
use Symfony\Component\Console\Input\InputInterface;
1414
use Symfony\Component\Console\Output\OutputInterface;
15-
use Magento\Deploy\Model\DeploymentConfig\HashUpdater;
15+
use Magento\Deploy\Model\DeploymentConfig\Hash;
1616
use Magento\Framework\App\ObjectManager;
1717

1818
/**
@@ -31,26 +31,26 @@ class ApplicationDumpCommand extends Command
3131
private $sources;
3232

3333
/**
34-
* @var HashUpdater
34+
* @var Hash
3535
*/
36-
private $configHashUpdater;
36+
private $configHash;
3737

3838
/**
3939
* ApplicationDumpCommand constructor.
4040
*
4141
* @param Writer $writer
4242
* @param array $sources
43-
* @param HashUpdater $configHashUpdater
43+
* @param Hash $configHash
4444
*/
4545
public function __construct(
4646
Writer $writer,
4747
array $sources,
48-
HashUpdater $configHashUpdater = null
48+
Hash $configHash = null
4949
) {
5050
parent::__construct();
5151
$this->writer = $writer;
5252
$this->sources = $sources;
53-
$this->configHashUpdater = $configHashUpdater ?: ObjectManager::getInstance()->get(HashUpdater::class);
53+
$this->configHash = $configHash ?: ObjectManager::getInstance()->get(Hash::class);
5454
}
5555

5656
/**
@@ -98,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9898
}
9999

100100
// Generate and save new hash of deployment configuration.
101-
$this->configHashUpdater->update();
101+
$this->configHash->regenerate();
102102

103103
$output->writeln('<info>Done.</info>');
104104
return Cli::RETURN_SUCCESS;

app/code/Magento/Deploy/Model/DeploymentConfig/Hash.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,51 @@ class Hash
3535
*/
3636
private $writer;
3737

38+
/**
39+
* Hash generator.
40+
*
41+
* @var Hash\Generator
42+
*/
43+
private $configHashGenerator;
44+
45+
/**
46+
* Config data collector.
47+
*
48+
* @var DataCollector
49+
*/
50+
private $dataConfigCollector;
51+
3852
/**
3953
* @param DeploymentConfig $deploymentConfig the application deployment configuration
4054
* @param Writer $writer the configuration writer that writes to files
55+
* @param Hash\Generator $configHashGenerator the hash generator
56+
* @param DataCollector $dataConfigCollector the config data collector
4157
*/
4258
public function __construct(
4359
DeploymentConfig $deploymentConfig,
44-
Writer $writer
60+
Writer $writer,
61+
Hash\Generator $configHashGenerator,
62+
DataCollector $dataConfigCollector
4563
) {
4664
$this->deploymentConfig = $deploymentConfig;
4765
$this->writer = $writer;
66+
$this->configHashGenerator = $configHashGenerator;
67+
$this->dataConfigCollector = $dataConfigCollector;
4868
}
4969

5070
/**
51-
* Saves a deployment configuration hash to storage.
71+
* Updates hash in the storage.
5272
*
53-
* @param array|string $hash the deployment configuration data from files
5473
* @return void
5574
* @throws LocalizedException
5675
*/
57-
public function save($hash)
76+
public function regenerate()
5877
{
5978
try {
79+
$config = $this->dataConfigCollector->getConfig();
80+
$hash = $this->configHashGenerator->generate($config);
6081
$this->writer->saveConfig([ConfigFilePool::APP_ENV => [self::CONFIG_KEY => $hash]]);
61-
} catch (FileSystemException $exception) {
82+
} catch (LocalizedException $exception) {
6283
throw new LocalizedException(__('Hash has not been saved'), $exception);
6384
}
6485
}

app/code/Magento/Deploy/Model/DeploymentConfig/HashUpdater.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

app/code/Magento/Deploy/Model/DeploymentConfig/Importer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class Importer
3939
/**
4040
* Hash updater of config data.
4141
*
42-
* @var HashUpdater
42+
* @var Hash
4343
*/
44-
private $configHashUpdater;
44+
private $configHash;
4545

4646
/**
4747
* Logger.
@@ -54,20 +54,20 @@ class Importer
5454
* @param Validator $configValidator the manager of deployment configuration hash
5555
* @param ImporterPool $configImporterPool the pool of all deployment configuration importers
5656
* @param DeploymentConfig $deploymentConfig the application deployment configuration
57-
* @param HashUpdater $configHashUpdater the hash updater of config data
57+
* @param Hash $configHash the hash updater of config data
5858
* @param Logger $logger the logger
5959
*/
6060
public function __construct(
6161
Validator $configValidator,
6262
ImporterPool $configImporterPool,
6363
DeploymentConfig $deploymentConfig,
64-
HashUpdater $configHashUpdater,
64+
Hash $configHash,
6565
Logger $logger
6666
) {
6767
$this->configValidator = $configValidator;
6868
$this->configImporterPool = $configImporterPool;
6969
$this->deploymentConfig = $deploymentConfig;
70-
$this->configHashUpdater = $configHashUpdater;
70+
$this->configHash = $configHash;
7171
$this->logger = $logger;
7272
}
7373

@@ -98,7 +98,7 @@ public function import()
9898
);
9999
}
100100

101-
$this->configHashUpdater->update();
101+
$this->configHash->regenerate();
102102
}
103103
} catch (LocalizedException $exception) {
104104
$this->logger->error($exception);

app/code/Magento/Deploy/Test/Unit/Console/Command/ApplicationDumpCommandTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\Console\Cli;
1313
use Symfony\Component\Console\Input\InputInterface;
1414
use Symfony\Component\Console\Output\OutputInterface;
15-
use Magento\Deploy\Model\DeploymentConfig\HashUpdater;
15+
use Magento\Deploy\Model\DeploymentConfig\Hash;
1616

1717
/**
1818
* Test command for dump application state
@@ -40,9 +40,9 @@ class ApplicationDumpCommandTest extends \PHPUnit_Framework_TestCase
4040
private $source;
4141

4242
/**
43-
* @var HashUpdater|\PHPUnit_Framework_MockObject_MockObject
43+
* @var Hash|\PHPUnit_Framework_MockObject_MockObject
4444
*/
45-
private $configHashUpdaterMock;
45+
private $configHashMock;
4646

4747
/**
4848
* @var ApplicationDumpCommand
@@ -51,7 +51,7 @@ class ApplicationDumpCommandTest extends \PHPUnit_Framework_TestCase
5151

5252
public function setUp()
5353
{
54-
$this->configHashUpdaterMock = $this->getMockBuilder(HashUpdater::class)
54+
$this->configHashMock = $this->getMockBuilder(Hash::class)
5555
->disableOriginalConstructor()
5656
->getMock();
5757
$this->input = $this->getMockBuilder(InputInterface::class)
@@ -68,7 +68,7 @@ public function setUp()
6868
$this->command = new ApplicationDumpCommand(
6969
$this->writer,
7070
[['namespace' => 'system', 'source' => $this->source]],
71-
$this->configHashUpdaterMock
71+
$this->configHashMock
7272
);
7373
}
7474

@@ -78,8 +78,8 @@ public function testExport()
7878
'system' => ['systemDATA']
7979
];
8080
$data = [ConfigFilePool::APP_CONFIG => $dump];
81-
$this->configHashUpdaterMock->expects($this->once())
82-
->method('update');
81+
$this->configHashMock->expects($this->once())
82+
->method('regenerate');
8383
$this->source
8484
->expects($this->once())
8585
->method('get')

0 commit comments

Comments
 (0)