Skip to content
6 changes: 5 additions & 1 deletion Command/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ protected function configure()
'includeScope',
null,
InputOption::VALUE_OPTIONAL,
'Scope name, multiple values can be comma separated; exports only those scopes'
"Scope name, multiple values can be comma separated; exports only those scopes.\n" .
"\t\tTo export only specific scopes add there ID(s) using a colon and separate them with semicolon.\n" .
"\t\tMake sure to use quotes when specifying multiple scope IDs:\n" .
"\t\te.g. --includeScope=\"websites:2;3,stores:2;3;4;5\" will export the settings for website IDs 2 and 3 and for the\n" .
"\t\tstore view IDs 2 to 5"
);

$this->addOption(
Expand Down
54 changes: 48 additions & 6 deletions Model/Processor/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,12 @@ public function process()
}
}

// Filter collection by scope
// Filter collection by scope and ids
if (null !== $this->includeScope) {
$includeScopes = explode(',', $this->includeScope);
$orWhere = [];
foreach ($includeScopes as $singlePath) {
$singlePath = trim($singlePath);
if (!empty($singlePath)) {
$orWhere[] = $collection->getConnection()->quoteInto('`scope` like ?', $singlePath);
}
foreach ($includeScopes as $singleScope) {
$orWhere = array_merge($orWhere, $this->getScopeRestrictions($singleScope, $collection));
}
if (count($orWhere) > 0) {
$collection->getSelect()->where(implode(' OR ', $orWhere));
Expand Down Expand Up @@ -156,4 +153,49 @@ public function setExclude($exclude)
{
$this->exclude = $exclude;
}

/**
* @param string $singleScope
* @param ConfigDataCollection $collection
*
* @return array
*/
private function getScopeRestrictions(string $singleScope, ConfigDataCollection $collection): array
{

$singleScope = trim($singleScope);
$orWhere = [];
if (!empty($singleScope)) {
$parts = explode(':', $singleScope);
$singleScope = $parts[0];
$orWhere[] = $collection->getConnection()->quoteInto('`scope` like ?', $singleScope) .
(!empty($parts[1]) ? $this->getScopeIdRestrictions($parts[1], $collection) : '');
}

return $orWhere;
}

/**
* @param string $scopeIdString
* @param ConfigDataCollection $collection
*
* @return string
*/
private function getScopeIdRestrictions(string $scopeIdString, ConfigDataCollection $collection): string
{
$scopeIdString = trim($scopeIdString);
$scopeIds = explode(';', $scopeIdString);
$orWhere = [];
foreach ($scopeIds as $scopeId) {
$scopeId = (int)$scopeId;
if ($scopeId !== 0) {
$orWhere[] = $collection->getConnection()->quoteInto('`scope_id` = ?', $scopeId);
}
}
if (count($orWhere) > 0) {
return ' AND ('.implode(' OR ', $orWhere).')';
} else {
return '';
}
}
}
7 changes: 6 additions & 1 deletion docs/config-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ Options:
--filename (-f) Specifies the export file name. Defaults to "config" (when not using "--filePerNameSpace").
--filepath (-p) Specifies the export path where the export file(s) will be written. Defaults to "var/export/config/Ymd_His/".
--include (-i) Path prefix, multiple values can be comma separated; exports only those paths
--includeScope Scope name, multiple values can be comma separated; exports only those scopes
--includeScope Scope name, multiple values can be comma separated; exports only those scopes.
To export only specific scopes add there ID(s) using a colon and separate them with semicolon.
Make sure to use quotes when specifying multiple scope IDs:
e.g. --includeScope="websites:2;3,stores:2;3;4;5" will export the settings for website IDs 2 and 3 and for the
store view IDs 2 to 5

--exclude (-x) Path prefix, multiple values can be comma separated; exports everything except ...
--filePerNameSpace (-s) Export each namespace into its own file. Enable with: y (default: "n")
```