Skip to content
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

Adding the ability to specify a store or website code instead of an identifier #12

Open
wants to merge 2 commits into
base: v2.4
Choose a base branch
from
Open
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
27 changes: 25 additions & 2 deletions Console/Command/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Mygento\Configsync\Console\Command;

use Magento\Store\Model\StoreManagerInterface;

class Sync extends \Symfony\Component\Console\Command\Command
{
private const DELETE = '%DELETE%';
Expand All @@ -27,17 +29,24 @@ class Sync extends \Symfony\Component\Console\Command\Command
*/
private $output;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param \Magento\Framework\App\Config\ConfigResource\ConfigInterface $configInterface
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
StoreManagerInterface $storeManager,
\Magento\Framework\App\Config\ConfigResource\ConfigInterface $configInterface,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
parent::__construct();
$this->configInterface = $configInterface;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
}

/**
Expand Down Expand Up @@ -85,7 +94,7 @@ protected function execute(
$importedValues = 0;

foreach ($envData as $scopeKey => $data) {
if (!preg_match('/^(default|(websites|stores)-\d+)$/', $scopeKey)) {
if (!preg_match('/^(default|(websites|stores)-\w+)$/', $scopeKey)) {
$this->diag('<error>Skipped scope: ' . $scopeKey . '</error>');
continue;
}
Expand All @@ -94,6 +103,21 @@ protected function execute(
$scope = $scopeKeyExtracted['scope'];
$scopeId = $scopeKeyExtracted['scopeId'];

try {
if (is_string($scopeId)) {
Copy link
Contributor

@luckyraul luckyraul Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not always string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ($scope === 'websites') {
$scopeId = $this->storeManager->getWebsite($scopeId)->getId();
}
if ($scope === 'stores') {
$scopeId = $this->storeManager->getStore($scopeId)->getId();
}
}
} catch (\Exception $e) {
$this->diag('<info>' . $e->getMessage() . '</info>');
continue;
}


$this->diag('<bg=yellow>Scope: ' . $scope . '</>');
$this->diag('<bg=yellow>Scope Id: ' . $scopeId . '</>');
$this->diag('');
Expand All @@ -105,7 +129,6 @@ protected function execute(
$this->diag('<info>' . $e->getMessage() . '</info>');
continue;
}

$this->diag('Path: <comment>' . $path . '</comment>');
$this->diag('Current value: <comment>' . $currentValue . '</comment>');
$this->diag('New value: <comment>' . $newValue . '</comment>');
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ For example:
web/secure/use_in_frontend: 1
stores-1:
web/secure/use_in_frontend: 0
websites-us:
web/secure/use_in_frontend: 1
stores-us:
web/secure/use_in_frontend: 0

Valid scope keys are:

- default
- stores-`$id`
- websites-`$id`
or
* stores-`$code`
* websites-`$code`

Use `%DELETE%` to delete config path

Expand Down
Loading