Skip to content

427: System configuration full and updates export. #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/code/Magento/CatalogExport/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_CatalogExport" />
<module name="Magento_CatalogExport">
<sequence>
<module name="Magento_DataExporter"/>
<module name="Magento_CatalogExportApi"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\ConfigurationDataExporter\Api;

/**
* Accumulate changed config values for export
*/
interface ConfigRegistryInterface
{
/**
* Get array of config values for export.
*
* @return array
*/
public function getValues(): array;

/**
* Add config value to registry.
*
* @param array $value
* @return void
*/
public function addValue(array $value = []): void;

/**
* Check if registry empty..
*
* @return bool
*/
public function isEmpty(): bool;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\ConfigurationDataExporter\Api;

/**
* Provider of allowed for export configuration paths
*/
interface WhitelistProviderInterface
{
/**
* Get whitelisted configuration paths to filter export.
*
* @return array
*/
public function getWhitelist(): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurationDataExporter\Console\Command;

use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\ConfigurationDataExporter\Model\Whitelist\EnvironmentProvider;
use Magento\Framework\Config\File\ConfigFilePool;

/**
* Command provides possibility to add configuration paths to whitelist in env.php
*/
class AddPathToWhitelist extends \Symfony\Component\Console\Command\Command
{
const COMMAND_NAME = 'commerce-data-export:config:add-paths-to-whitelist';
const INPUT_OPTION_PATHS = 'paths';

/**
* @var \Magento\Framework\App\DeploymentConfig
*/
private $deploymentConfig;

/**
* @var \Magento\Framework\App\DeploymentConfig\Writer
*/
private $writer;

/**
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
* @param \Magento\Framework\App\DeploymentConfig\Writer $writer
*/
public function __construct(
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
\Magento\Framework\App\DeploymentConfig\Writer $writer
) {
parent::__construct();
$this->deploymentConfig = $deploymentConfig;
$this->writer = $writer;
}

/**
* @inheritdoc
*/
protected function configure()
{
$this->addArgument(
self::INPUT_OPTION_PATHS,
InputArgument::IS_ARRAY,
'Space-separated list of configuration paths to whitelist'
);
$this->setName(self::COMMAND_NAME)
->setDescription('Add configuration paths to export whitelist');

parent::configure();
}

/**
* Add configuration paths to whitelist
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$paths = $input->getArgument(self::INPUT_OPTION_PATHS);

if (empty($paths)) {
$output->writeln('<error>No configuration path provided</error>');
return Cli::RETURN_FAILURE;
}

try {
$whitelist = $this->preparePathToSave($paths);
$this->writer->saveConfig($whitelist, true);
} catch (\Throwable $e) {
$output->writeln(sprintf('<error>No configuration path provided: %s</error>', $e->getMessage()));
return Cli::RETURN_FAILURE;
}

$output->writeln('<info>Paths successfully added to configuration whitelist</info>');
return Cli::RETURN_SUCCESS;
}

/**
* Prepare whitelist path to save in deployment config file.
*
* @param array $paths
* @return \array[][][]
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Magento\Framework\Exception\RuntimeException
*/
private function preparePathToSave(array $paths): array
{
$whitelist = $this->deploymentConfig->get(EnvironmentProvider::WHITELIST_CONFIG_KEY, []);
$paths = array_unique($paths);
$paths = array_filter($paths, function ($path) use ($whitelist) {
return !in_array($path, $whitelist);
});

return [
ConfigFilePool::APP_ENV => [
'commerce-data-export' => [
'configuration' => [
'path-whitelist' => array_merge($whitelist, $paths)
]
]
]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurationDataExporter\Console\Command;

use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command provides possibility to full export system configuration
*/
class FullSyncCommand extends \Symfony\Component\Console\Command\Command
{
const COMMAND_NAME = 'commerce-data-export:config:export';
const INPUT_OPTION_STORE_ID = 'store';

/**
* @var \Magento\ConfigurationDataExporter\Model\FullExportProcessorInterface
*/
private $exportProcessor;

/**
* @param \Magento\ConfigurationDataExporter\Model\FullExportProcessorInterface $exportProcessor
*/
public function __construct(
\Magento\ConfigurationDataExporter\Model\FullExportProcessorInterface $exportProcessor
) {
$this->exportProcessor = $exportProcessor;
parent::__construct();
}

/**
* @inheritdoc
*/
protected function configure()
{
$this->addOption(
self::INPUT_OPTION_STORE_ID,
null,
InputOption::VALUE_OPTIONAL,
'Store ID for export configuration',
'All'
);
$this->setName(self::COMMAND_NAME)
->setDescription('Export full system configuration data to queue');

parent::configure();
}

/**
* Execute full configuration export from magento to queue.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$storeId = $input->getOption(self::INPUT_OPTION_STORE_ID);

$output->writeln(
sprintf(
'<info>Exporting configuration for %s store(s)</info>',
$storeId
)
);

$storeId = is_numeric($storeId) ? (int)$storeId : null;

try {
$this->exportProcessor->process($storeId);
} catch (\Throwable $e) {
$output->writeln(
sprintf(
'<error>Exporting configuration failed: %s</error>',
$e->getMessage()
)
);

return Cli::RETURN_FAILURE;
}

return Cli::RETURN_SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurationDataExporter\Event\Data;

use Magento\ConfigurationDataExporter\Event\Data\Meta;
use Magento\ConfigurationDataExporter\Event\Data\Data;

/**
* Changed config object
*/
class ChangedConfig
{
/**
* @var Data
*/
private $data;

/**
* @var Meta
*/
private $meta;

/**
* @param \Magento\ConfigurationDataExporter\Event\Data\Meta $meta
* @param \Magento\ConfigurationDataExporter\Event\Data\Data $data
*/
public function __construct(Meta $meta, Data $data)
{
$this->meta = $meta;
$this->data = $data;
}

/**
* Get changed config metadata
*
* @return \Magento\ConfigurationDataExporter\Event\Data\Meta
*/
public function getMeta(): Meta
{
return $this->meta;
}

/**
* Get changed config data
*
* @return \Magento\ConfigurationDataExporter\Event\Data\Data
*/
public function getData(): Data
{
return $this->data;
}
}
Loading