diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index d64f94b..e6f844a 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -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( diff --git a/Model/Processor/ExportProcessor.php b/Model/Processor/ExportProcessor.php index 5804a30..7e9487e 100644 --- a/Model/Processor/ExportProcessor.php +++ b/Model/Processor/ExportProcessor.php @@ -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)); @@ -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 ''; + } + } } diff --git a/docs/config-export.md b/docs/config-export.md index 1fa6993..d46bf07 100644 --- a/docs/config-export.md +++ b/docs/config-export.md @@ -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") ```