@@ -28,10 +38,15 @@
require([
'jquery',
'mage/template',
+ 'Magento_Ui/js/lib/validation/validator',
+ 'Magento_Ui/js/modal/alert',
'jquery/file-uploader',
'domReady!',
'mage/translate'
-], function ($, mageTemplate) {
+], function ($, mageTemplate, validator, uiAlert) {
+ var maxFileSize = = $block->escapeJs($block->getFileSizeService()->getMaxFileSize()) ?>,
+ allowedExtensions = '= $block->escapeHtml(implode(' ', $allowedExtensions)) ?>';
+
$('#= $block->getHtmlId() ?> .fileupload').fileupload({
dataType: 'json',
formData: {
@@ -40,17 +55,44 @@ require([
},
sequentialUploads: true,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
- maxFileSize: = $block->escapeJs($block->getFileSizeService()->getMaxFileSize()) ?>,
+ allowedExtensions: allowedExtensions,
+ maxFileSize: maxFileSize,
+ dropZone: $('#= $block->getHtmlId() ?>').closest('[role="dialog"]'),
add: function (e, data) {
var progressTmpl = mageTemplate('#= $block->getHtmlId() ?>-template'),
fileSize,
- tmpl;
+ tmpl,
+ validationResult;
- $.each(data.files, function (index, file) {
+ data.files = data.files.filter(function (file) {
fileSize = typeof file.size == "undefined" ?
$.mage.__('We could not detect a size.') :
byteConvert(file.size);
+ if (maxFileSize) {
+ validationResult = validator('validate-max-size', file.size, maxFileSize);
+
+ if (!validationResult.passed) {
+ uiAlert({
+ content: validationResult.message
+ });
+
+ return false;
+ }
+ }
+
+ if (allowedExtensions) {
+ validationResult = validator('validate-file-type', file.name, allowedExtensions);
+
+ if (!validationResult.passed) {
+ uiAlert({
+ content: validationResult.message
+ });
+
+ return false;
+ }
+ }
+
data.fileId = Math.random().toString(36).substr(2, 9);
tmpl = progressTmpl({
@@ -62,11 +104,15 @@ require([
});
$(tmpl).data('image', data).appendTo('#= $block->getHtmlId() ?>');
- });
- $(this).fileupload('process', data).done(function () {
- data.submit();
+ return true;
});
+
+ if (data.files.length) {
+ $(this).fileupload('process', data).done(function () {
+ data.submit();
+ });
+ }
},
done: function (e, data) {
var progressSelector = '#' + data.fileId + ' .progressbar-container .progressbar';
diff --git a/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js b/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js
index 22540ef9d0c77..6dd0b39f692c2 100644
--- a/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js
+++ b/app/code/Magento/Cms/view/adminhtml/web/js/folder-tree.js
@@ -114,7 +114,7 @@ define([
metadata: {
node: codeCopy
},
- state: 'closed'
+ state: node.state || 'closed'
};
});
}
diff --git a/app/code/Magento/CmsUrlRewrite/etc/module.xml b/app/code/Magento/CmsUrlRewrite/etc/module.xml
index bce3dce2a40e0..1e12b5b74971d 100644
--- a/app/code/Magento/CmsUrlRewrite/etc/module.xml
+++ b/app/code/Magento/CmsUrlRewrite/etc/module.xml
@@ -6,6 +6,6 @@
*/
-->
-
+
diff --git a/app/code/Magento/CmsUrlRewriteGraphQl/etc/module.xml b/app/code/Magento/CmsUrlRewriteGraphQl/etc/module.xml
index 9cdc305f2f913..d3c65b440aab7 100644
--- a/app/code/Magento/CmsUrlRewriteGraphQl/etc/module.xml
+++ b/app/code/Magento/CmsUrlRewriteGraphQl/etc/module.xml
@@ -6,5 +6,5 @@
*/
-->
-
+
diff --git a/app/code/Magento/Config/App/Config/Type/System.php b/app/code/Magento/Config/App/Config/Type/System.php
index ed645bb63febc..4f6d9c14346f0 100644
--- a/app/code/Magento/Config/App/Config/Type/System.php
+++ b/app/code/Magento/Config/App/Config/Type/System.php
@@ -141,7 +141,7 @@ public function get($path = '')
$pathParts = explode('/', $path);
if (count($pathParts) === 1 && $pathParts[0] !== 'default') {
if (!isset($this->data[$pathParts[0]])) {
- $data = $this->reader->read();
+ $data = $this->readData();
$this->data = array_replace_recursive($data, $this->data);
}
return $this->data[$pathParts[0]];
@@ -171,7 +171,7 @@ private function loadAllData()
{
$cachedData = $this->cache->load($this->configType);
if ($cachedData === false) {
- $data = $this->reader->read();
+ $data = $this->readData();
} else {
$data = $this->serializer->unserialize($cachedData);
}
@@ -188,7 +188,7 @@ private function loadDefaultScopeData($scopeType)
{
$cachedData = $this->cache->load($this->configType . '_' . $scopeType);
if ($cachedData === false) {
- $data = $this->reader->read();
+ $data = $this->readData();
$this->cacheData($data);
} else {
$data = [$scopeType => $this->serializer->unserialize($cachedData)];
@@ -216,7 +216,7 @@ private function loadScopeData($scopeType, $scopeId)
if (is_array($this->availableDataScopes) && !isset($this->availableDataScopes[$scopeType][$scopeId])) {
return [$scopeType => [$scopeId => []]];
}
- $data = $this->reader->read();
+ $data = $this->readData();
$this->cacheData($data);
} else {
$data = [$scopeType => [$scopeId => $this->serializer->unserialize($cachedData)]];
@@ -282,6 +282,21 @@ private function getDataByPathParts($data, $pathParts)
return $data;
}
+ /**
+ * The freshly read data.
+ *
+ * @return array
+ */
+ private function readData(): array
+ {
+ $this->data = $this->reader->read();
+ $this->data = $this->postProcessor->process(
+ $this->data
+ );
+
+ return $this->data;
+ }
+
/**
* Clean cache and global variables cache
*
diff --git a/app/code/Magento/Config/App/Config/Type/System/Reader.php b/app/code/Magento/Config/App/Config/Type/System/Reader.php
index d5a0f09cdd631..9916b795a53b2 100644
--- a/app/code/Magento/Config/App/Config/Type/System/Reader.php
+++ b/app/code/Magento/Config/App/Config/Type/System/Reader.php
@@ -27,17 +27,13 @@ class Reader
*/
private $preProcessor;
- /**
- * @var \Magento\Framework\App\Config\Spi\PostProcessorInterface
- */
- private $postProcessor;
-
/**
* Reader constructor.
* @param \Magento\Framework\App\Config\ConfigSourceInterface $source
* @param \Magento\Store\Model\Config\Processor\Fallback $fallback
* @param \Magento\Framework\App\Config\Spi\PreProcessorInterface $preProcessor
* @param \Magento\Framework\App\Config\Spi\PostProcessorInterface $postProcessor
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
\Magento\Framework\App\Config\ConfigSourceInterface $source,
@@ -48,7 +44,6 @@ public function __construct(
$this->source = $source;
$this->fallback = $fallback;
$this->preProcessor = $preProcessor;
- $this->postProcessor = $postProcessor;
}
/**
@@ -60,11 +55,9 @@ public function __construct(
*/
public function read()
{
- return $this->postProcessor->process(
- $this->fallback->process(
- $this->preProcessor->process(
- $this->source->get()
- )
+ return $this->fallback->process(
+ $this->preProcessor->process(
+ $this->source->get()
)
);
}
diff --git a/app/code/Magento/Config/Block/System/Config/Form.php b/app/code/Magento/Config/Block/System/Config/Form.php
index c60dbffbdc5e0..c17df229cf549 100644
--- a/app/code/Magento/Config/Block/System/Config/Form.php
+++ b/app/code/Magento/Config/Block/System/Config/Form.php
@@ -8,6 +8,7 @@
use Magento\Config\App\Config\Type\System;
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
+use Magento\Framework\App\Config\Data\ProcessorInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;
@@ -425,23 +426,21 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
if ($placeholderValue) {
$data = $placeholderValue;
}
- if ($data === null) {
- if (array_key_exists($path, $this->_configData)) {
- $data = $this->_configData[$path];
- } elseif ($field->getConfigPath() !== null) {
- $data = $this->getConfigValue($field->getConfigPath());
- } else {
- $data = $this->getConfigValue($path);
- }
+ if ($data === null) {
+ $path = $field->getConfigPath() !== null ? $field->getConfigPath() : $path;
+ $data = $this->getConfigValue($path);
if ($field->hasBackendModel()) {
$backendModel = $field->getBackendModel();
- $backendModel->setPath($path)
- ->setValue($data)
- ->setWebsite($this->getWebsiteCode())
- ->setStore($this->getStoreCode())
- ->afterLoad();
- $data = $backendModel->getValue();
+ // Backend models which implement ProcessorInterface are processed by ScopeConfigInterface
+ if (!$backendModel instanceof ProcessorInterface) {
+ $backendModel->setPath($path)
+ ->setValue($data)
+ ->setWebsite($this->getWebsiteCode())
+ ->setStore($this->getStoreCode())
+ ->afterLoad();
+ $data = $backendModel->getValue();
+ }
}
}
diff --git a/app/code/Magento/Config/Console/Command/ConfigSet/ConfigSetProcessorFactory.php b/app/code/Magento/Config/Console/Command/ConfigSet/ConfigSetProcessorFactory.php
index b884fc2d91f3b..1b287573a9285 100644
--- a/app/code/Magento/Config/Console/Command/ConfigSet/ConfigSetProcessorFactory.php
+++ b/app/code/Magento/Config/Console/Command/ConfigSet/ConfigSetProcessorFactory.php
@@ -28,7 +28,14 @@ class ConfigSetProcessorFactory
* lock - save and lock configuration
*/
const TYPE_DEFAULT = 'default';
+
+ /**
+ * @deprecated
+ * @see TYPE_LOCK_ENV or TYPE_LOCK_CONFIG
+ */
const TYPE_LOCK = 'lock';
+ const TYPE_LOCK_ENV = 'lock-env';
+ const TYPE_LOCK_CONFIG = 'lock-config';
/**#@-*/
/**#@-*/
diff --git a/app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php b/app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php
index 2f5c10037ef06..d7d513bfad423 100644
--- a/app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php
+++ b/app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php
@@ -72,7 +72,7 @@ public function process($path, $value, $scope, $scopeCode)
throw new CouldNotSaveException(
__(
'The value you set has already been locked. To change the value, use the --%1 option.',
- ConfigSetCommand::OPTION_LOCK
+ ConfigSetCommand::OPTION_LOCK_ENV
)
);
}
diff --git a/app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php b/app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php
index 0bd28f0f78d96..6fe2adde3c41e 100644
--- a/app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php
+++ b/app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php
@@ -16,7 +16,8 @@
/**
* Processes file lock flow of config:set command.
- * This processor saves the value of configuration and lock it for editing in Admin interface.
+ * This processor saves the value of configuration into app/etc/env.php
+ * and locks it for editing in Admin interface.
*
* {@inheritdoc}
*/
@@ -49,23 +50,30 @@ class LockProcessor implements ConfigSetProcessorInterface
* @var ConfigPathResolver
*/
private $configPathResolver;
+ /**
+ * @var string
+ */
+ private $target;
/**
* @param PreparedValueFactory $preparedValueFactory The factory for prepared value
* @param DeploymentConfig\Writer $writer The deployment configuration writer
* @param ArrayManager $arrayManager An array manager for different manipulations with arrays
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths according to source type
+ * @param string $target
*/
public function __construct(
PreparedValueFactory $preparedValueFactory,
DeploymentConfig\Writer $writer,
ArrayManager $arrayManager,
- ConfigPathResolver $configPathResolver
+ ConfigPathResolver $configPathResolver,
+ $target = ConfigFilePool::APP_ENV
) {
$this->preparedValueFactory = $preparedValueFactory;
$this->deploymentConfigWriter = $writer;
$this->arrayManager = $arrayManager;
$this->configPathResolver = $configPathResolver;
+ $this->target = $target;
}
/**
@@ -97,7 +105,7 @@ public function process($path, $value, $scope, $scopeCode)
* we'll write value just after all validations are triggered.
*/
$this->deploymentConfigWriter->saveConfig(
- [ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $value)],
+ [$this->target => $this->arrayManager->set($configPath, [], $value)],
false
);
}
diff --git a/app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php b/app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php
index 06a01c6686bfd..fcd7c0d5335b1 100644
--- a/app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php
+++ b/app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php
@@ -9,6 +9,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Scope\ValidatorInterface;
use Magento\Config\Model\Config\PathValidator;
+use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\ConfigurationMismatchException;
use Magento\Framework\Exception\CouldNotSaveException;
@@ -98,12 +99,35 @@ public function __construct(
* @param boolean $lock The lock flag
* @return string Processor response message
* @throws ValidatorException If some validation is wrong
- * @throws CouldNotSaveException If cannot save config value
- * @throws ConfigurationMismatchException If processor can not be instantiated
* @since 100.2.0
+ * @deprecated
+ * @see processWithLockTarget()
*/
public function process($path, $value, $scope, $scopeCode, $lock)
{
+ return $this->processWithLockTarget($path, $value, $scope, $scopeCode, $lock);
+ }
+
+ /**
+ * Processes config:set command with the option to set a target file.
+ *
+ * @param string $path The configuration path in format section/group/field_name
+ * @param string $value The configuration value
+ * @param string $scope The configuration scope (default, website, or store)
+ * @param string $scopeCode The scope code
+ * @param boolean $lock The lock flag
+ * @param string $lockTarget
+ * @return string Processor response message
+ * @throws ValidatorException If some validation is wrong
+ */
+ public function processWithLockTarget(
+ $path,
+ $value,
+ $scope,
+ $scopeCode,
+ $lock,
+ $lockTarget = ConfigFilePool::APP_ENV
+ ) {
try {
$this->scopeValidator->isValid($scope, $scopeCode);
$this->pathValidator->validate($path);
@@ -111,14 +135,24 @@ public function process($path, $value, $scope, $scopeCode, $lock)
throw new ValidatorException(__($exception->getMessage()), $exception);
}
- $processor = $lock
- ? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK)
- : $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT);
- $message = $lock
- ? 'Value was saved and locked.'
- : 'Value was saved.';
+ $processor =
+ $lock
+ ? ( $lockTarget == ConfigFilePool::APP_ENV
+ ? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_ENV)
+ : $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_CONFIG)
+ )
+ : $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT)
+ ;
+
+ $message =
+ $lock
+ ? ( $lockTarget == ConfigFilePool::APP_ENV
+ ? 'Value was saved in app/etc/env.php and locked.'
+ : 'Value was saved in app/etc/config.php and locked.'
+ )
+ : 'Value was saved.';
- // The processing flow depends on --lock option.
+ // The processing flow depends on --lock and --share options.
$processor->process($path, $value, $scope, $scopeCode);
$this->hash->regenerate(System::CONFIG_TYPE);
diff --git a/app/code/Magento/Config/Console/Command/ConfigSetCommand.php b/app/code/Magento/Config/Console/Command/ConfigSetCommand.php
index 1df1b3c4bed14..cb79daddbf5f9 100644
--- a/app/code/Magento/Config/Console/Command/ConfigSetCommand.php
+++ b/app/code/Magento/Config/Console/Command/ConfigSetCommand.php
@@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+
namespace Magento\Config\Console\Command;
use Magento\Config\App\Config\Type\System;
@@ -10,6 +11,7 @@
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\Config\ScopeConfigInterface;
+use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@@ -34,6 +36,8 @@ class ConfigSetCommand extends Command
const OPTION_SCOPE = 'scope';
const OPTION_SCOPE_CODE = 'scope-code';
const OPTION_LOCK = 'lock';
+ const OPTION_LOCK_ENV = 'lock-env';
+ const OPTION_LOCK_CONFIG = 'lock-config';
/**#@-*/
/**#@-*/
@@ -108,11 +112,24 @@ protected function configure()
InputArgument::OPTIONAL,
'Scope code (required only if scope is not \'default\')'
),
+ new InputOption(
+ static::OPTION_LOCK_ENV,
+ 'le',
+ InputOption::VALUE_NONE,
+ 'Lock value which prevents modification in the Admin (will be saved in app/etc/env.php)'
+ ),
+ new InputOption(
+ static::OPTION_LOCK_CONFIG,
+ 'lc',
+ InputOption::VALUE_NONE,
+ 'Lock and share value with other installations, prevents modification in the Admin '
+ . '(will be saved in app/etc/config.php)'
+ ),
new InputOption(
static::OPTION_LOCK,
'l',
InputOption::VALUE_NONE,
- 'Lock value which prevents modification in the Admin'
+ 'Deprecated, use the --' . static::OPTION_LOCK_ENV . ' option instead.'
),
]);
@@ -146,12 +163,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
- return $this->processorFacadeFactory->create()->process(
+
+ $lock = $input->getOption(static::OPTION_LOCK_ENV)
+ || $input->getOption(static::OPTION_LOCK_CONFIG)
+ || $input->getOption(static::OPTION_LOCK);
+
+ $lockTargetPath = ConfigFilePool::APP_ENV;
+ if ($input->getOption(static::OPTION_LOCK_CONFIG)) {
+ $lockTargetPath = ConfigFilePool::APP_CONFIG;
+ }
+
+ return $this->processorFacadeFactory->create()->processWithLockTarget(
$input->getArgument(static::ARG_PATH),
$input->getArgument(static::ARG_VALUE),
$input->getOption(static::OPTION_SCOPE),
$input->getOption(static::OPTION_SCOPE_CODE),
- $input->getOption(static::OPTION_LOCK)
+ $lock,
+ $lockTargetPath
);
});
diff --git a/app/code/Magento/Config/Setup/InstallData.php b/app/code/Magento/Config/Setup/InstallData.php
deleted file mode 100644
index 37b8c72851712..0000000000000
--- a/app/code/Magento/Config/Setup/InstallData.php
+++ /dev/null
@@ -1,38 +0,0 @@
-createMigrationSetup();
- $setup->startSetup();
-
- $installer->appendClassAliasReplace(
- 'core_config_data',
- 'value',
- Migration::ENTITY_TYPE_MODEL,
- Migration::FIELD_CONTENT_TYPE_PLAIN,
- ['config_id']
- );
- $installer->doUpdateClassAliases();
-
- $setup->endSetup();
- }
-}
diff --git a/app/code/Magento/Config/Setup/Patch/Data/UpdateClassAliases.php b/app/code/Magento/Config/Setup/Patch/Data/UpdateClassAliases.php
new file mode 100644
index 0000000000000..8986f624c1606
--- /dev/null
+++ b/app/code/Magento/Config/Setup/Patch/Data/UpdateClassAliases.php
@@ -0,0 +1,76 @@
+moduleDataSetup = $moduleDataSetup;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $installer = $this->moduleDataSetup->createMigrationSetup();
+ $this->moduleDataSetup->startSetup();
+
+ $installer->appendClassAliasReplace(
+ 'core_config_data',
+ 'value',
+ Migration::ENTITY_TYPE_MODEL,
+ Migration::FIELD_CONTENT_TYPE_PLAIN,
+ ['config_id']
+ );
+ $installer->doUpdateClassAliases();
+ $this->moduleDataSetup->endSetup();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Config/Test/Unit/App/Config/Type/System/ReaderTest.php b/app/code/Magento/Config/Test/Unit/App/Config/Type/System/ReaderTest.php
index 7fb126a00ff84..9ec2d9bb9a1f4 100644
--- a/app/code/Magento/Config/Test/Unit/App/Config/Type/System/ReaderTest.php
+++ b/app/code/Magento/Config/Test/Unit/App/Config/Type/System/ReaderTest.php
@@ -84,10 +84,6 @@ public function testGetCachedWithLoadDefaultScopeData()
->method('process')
->with($data)
->willReturn($data);
- $this->postProcessor->expects($this->once())
- ->method('process')
- ->with($data)
- ->willReturn($data);
$this->assertEquals($data, $this->model->read());
}
}
diff --git a/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php b/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php
index 74315af448226..40aa110382ede 100644
--- a/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php
+++ b/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php
@@ -170,7 +170,12 @@ public function testGetNotCached()
$this->reader->expects($this->once())
->method('read')
->willReturn($data);
+ $this->postProcessor->expects($this->once())
+ ->method('process')
+ ->with($data)
+ ->willReturn($data);
$this->assertEquals($url, $this->configType->get($path));
+ $this->assertEquals($url, $this->configType->get($path));
}
}
diff --git a/app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php b/app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php
index 8385f75a0820a..804965e41b148 100644
--- a/app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php
+++ b/app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php
@@ -546,8 +546,8 @@ public function initFieldsDataProvider()
return [
[
['section1/group1/field1' => 'some_value'],
- false,
- null,
+ 'some_value',
+ 'section1/group1/field1',
false,
'some_value',
null,
diff --git a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ConfigSetProcessorFactoryTest.php b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ConfigSetProcessorFactoryTest.php
index decb7d52a5e0c..12b97eb254ded 100644
--- a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ConfigSetProcessorFactoryTest.php
+++ b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ConfigSetProcessorFactoryTest.php
@@ -41,7 +41,7 @@ protected function setUp()
$this->model = new ConfigSetProcessorFactory(
$this->objectManagerMock,
[
- ConfigSetProcessorFactory::TYPE_LOCK => LockProcessor::class,
+ ConfigSetProcessorFactory::TYPE_LOCK_ENV => LockProcessor::class,
ConfigSetProcessorFactory::TYPE_DEFAULT => DefaultProcessor::class,
'wrongType' => \stdClass::class,
]
@@ -59,7 +59,7 @@ public function testCreate()
$this->assertInstanceOf(
ConfigSetProcessorInterface::class,
- $this->model->create(ConfigSetProcessorFactory::TYPE_LOCK)
+ $this->model->create(ConfigSetProcessorFactory::TYPE_LOCK_ENV)
);
}
diff --git a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/DefaultProcessorTest.php b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/DefaultProcessorTest.php
index 066b0fbe84b50..984e0fe842687 100644
--- a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/DefaultProcessorTest.php
+++ b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/DefaultProcessorTest.php
@@ -166,7 +166,9 @@ private function configMockForProcessTest($path, $scope, $scopeCode)
/**
* @expectedException \Magento\Framework\Exception\LocalizedException
- * @expectedExceptionMessage The value you set has already been locked. To change the value, use the --lock option.
+ * @codingStandardsIgnoreStart
+ * @expectedExceptionMessage The value you set has already been locked. To change the value, use the --lock-env option.
+ * @codingStandardsIgnoreEnd
*/
public function testProcessLockedValue()
{
diff --git a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockConfigProcessorTest.php b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockConfigProcessorTest.php
new file mode 100644
index 0000000000000..c727184efb4fc
--- /dev/null
+++ b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockConfigProcessorTest.php
@@ -0,0 +1,220 @@
+preparedValueFactory = $this->getMockBuilder(PreparedValueFactory::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->deploymentConfigWriterMock = $this->getMockBuilder(DeploymentConfig\Writer::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->configPathResolver = $this->getMockBuilder(ConfigPathResolver::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->valueMock = $this->getMockBuilder(Value::class)
+ ->setMethods(['validateBeforeSave', 'beforeSave', 'setValue', 'getValue', 'afterSave'])
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->model = new LockProcessor(
+ $this->preparedValueFactory,
+ $this->deploymentConfigWriterMock,
+ $this->arrayManagerMock,
+ $this->configPathResolver,
+ ConfigFilePool::APP_CONFIG
+ );
+ }
+
+ /**
+ * Tests process of share flow.
+ *
+ * @param string $path
+ * @param string $value
+ * @param string $scope
+ * @param string|null $scopeCode
+ * @dataProvider processDataProvider
+ */
+ public function testProcess($path, $value, $scope, $scopeCode)
+ {
+ $this->preparedValueFactory->expects($this->once())
+ ->method('create')
+ ->with($path, $value, $scope, $scopeCode)
+ ->willReturn($this->valueMock);
+ $this->configPathResolver->expects($this->once())
+ ->method('resolve')
+ ->willReturn('system/default/test/test/test');
+ $this->arrayManagerMock->expects($this->once())
+ ->method('set')
+ ->with('system/default/test/test/test', [], $value)
+ ->willReturn([
+ 'system' => [
+ 'default' => [
+ 'test' => [
+ 'test' => [
+ 'test' => $value
+ ]
+ ]
+ ]
+ ]
+ ]);
+ $this->valueMock->expects($this->once())
+ ->method('getValue')
+ ->willReturn($value);
+ $this->deploymentConfigWriterMock->expects($this->once())
+ ->method('saveConfig')
+ ->with(
+ [
+ ConfigFilePool::APP_CONFIG => [
+ 'system' => [
+ 'default' => [
+ 'test' => [
+ 'test' => [
+ 'test' => $value
+ ]
+ ]
+ ]
+ ]
+ ]
+ ],
+ false
+ );
+ $this->valueMock->expects($this->once())
+ ->method('validateBeforeSave');
+ $this->valueMock->expects($this->once())
+ ->method('beforeSave');
+ $this->valueMock->expects($this->once())
+ ->method('afterSave');
+
+ $this->model->process($path, $value, $scope, $scopeCode);
+ }
+
+ /**
+ * @return array
+ */
+ public function processDataProvider()
+ {
+ return [
+ ['test/test/test', 'value', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
+ ['test/test/test', 'value', ScopeInterface::SCOPE_WEBSITE, 'base'],
+ ['test/test/test', 'value', ScopeInterface::SCOPE_STORE, 'test'],
+ ];
+ }
+
+ /**
+ * @expectedException \Magento\Framework\Exception\LocalizedException
+ * @expectedExceptionMessage Filesystem is not writable.
+ */
+ public function testProcessNotReadableFs()
+ {
+ $path = 'test/test/test';
+ $value = 'value';
+
+ $this->preparedValueFactory->expects($this->once())
+ ->method('create')
+ ->willReturn($this->valueMock);
+ $this->valueMock->expects($this->once())
+ ->method('getValue')
+ ->willReturn($value);
+ $this->configPathResolver->expects($this->once())
+ ->method('resolve')
+ ->willReturn('system/default/test/test/test');
+ $this->arrayManagerMock->expects($this->once())
+ ->method('set')
+ ->with('system/default/test/test/test', [], $value)
+ ->willReturn(null);
+ $this->deploymentConfigWriterMock->expects($this->once())
+ ->method('saveConfig')
+ ->willThrowException(new FileSystemException(__('Filesystem is not writable.')));
+
+ $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
+ }
+
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Invalid values
+ */
+ public function testCustomException()
+ {
+ $path = 'test/test/test';
+ $value = 'value';
+
+ $this->configPathResolver->expects($this->once())
+ ->method('resolve')
+ ->willReturn('system/default/test/test/test');
+ $this->preparedValueFactory->expects($this->once())
+ ->method('create')
+ ->willReturn($this->valueMock);
+ $this->arrayManagerMock->expects($this->never())
+ ->method('set');
+ $this->valueMock->expects($this->once())
+ ->method('getValue');
+ $this->valueMock->expects($this->once())
+ ->method('afterSave')
+ ->willThrowException(new \Exception('Invalid values'));
+ $this->deploymentConfigWriterMock->expects($this->never())
+ ->method('saveConfig');
+
+ $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
+ }
+}
diff --git a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockEnvProcessorTest.php b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockEnvProcessorTest.php
new file mode 100644
index 0000000000000..4e0248f886028
--- /dev/null
+++ b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockEnvProcessorTest.php
@@ -0,0 +1,220 @@
+preparedValueFactory = $this->getMockBuilder(PreparedValueFactory::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->deploymentConfigWriterMock = $this->getMockBuilder(DeploymentConfig\Writer::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->configPathResolver = $this->getMockBuilder(ConfigPathResolver::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->valueMock = $this->getMockBuilder(Value::class)
+ ->setMethods(['validateBeforeSave', 'beforeSave', 'setValue', 'getValue', 'afterSave'])
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->model = new LockProcessor(
+ $this->preparedValueFactory,
+ $this->deploymentConfigWriterMock,
+ $this->arrayManagerMock,
+ $this->configPathResolver,
+ ConfigFilePool::APP_ENV
+ );
+ }
+
+ /**
+ * Tests process of lock flow.
+ *
+ * @param string $path
+ * @param string $value
+ * @param string $scope
+ * @param string|null $scopeCode
+ * @dataProvider processDataProvider
+ */
+ public function testProcess($path, $value, $scope, $scopeCode)
+ {
+ $this->preparedValueFactory->expects($this->once())
+ ->method('create')
+ ->with($path, $value, $scope, $scopeCode)
+ ->willReturn($this->valueMock);
+ $this->configPathResolver->expects($this->once())
+ ->method('resolve')
+ ->willReturn('system/default/test/test/test');
+ $this->arrayManagerMock->expects($this->once())
+ ->method('set')
+ ->with('system/default/test/test/test', [], $value)
+ ->willReturn([
+ 'system' => [
+ 'default' => [
+ 'test' => [
+ 'test' => [
+ 'test' => $value
+ ]
+ ]
+ ]
+ ]
+ ]);
+ $this->valueMock->expects($this->once())
+ ->method('getValue')
+ ->willReturn($value);
+ $this->deploymentConfigWriterMock->expects($this->once())
+ ->method('saveConfig')
+ ->with(
+ [
+ ConfigFilePool::APP_ENV => [
+ 'system' => [
+ 'default' => [
+ 'test' => [
+ 'test' => [
+ 'test' => $value
+ ]
+ ]
+ ]
+ ]
+ ]
+ ],
+ false
+ );
+ $this->valueMock->expects($this->once())
+ ->method('validateBeforeSave');
+ $this->valueMock->expects($this->once())
+ ->method('beforeSave');
+ $this->valueMock->expects($this->once())
+ ->method('afterSave');
+
+ $this->model->process($path, $value, $scope, $scopeCode);
+ }
+
+ /**
+ * @return array
+ */
+ public function processDataProvider()
+ {
+ return [
+ ['test/test/test', 'value', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
+ ['test/test/test', 'value', ScopeInterface::SCOPE_WEBSITE, 'base'],
+ ['test/test/test', 'value', ScopeInterface::SCOPE_STORE, 'test'],
+ ];
+ }
+
+ /**
+ * @expectedException \Magento\Framework\Exception\LocalizedException
+ * @expectedExceptionMessage Filesystem is not writable.
+ */
+ public function testProcessNotReadableFs()
+ {
+ $path = 'test/test/test';
+ $value = 'value';
+
+ $this->preparedValueFactory->expects($this->once())
+ ->method('create')
+ ->willReturn($this->valueMock);
+ $this->valueMock->expects($this->once())
+ ->method('getValue')
+ ->willReturn($value);
+ $this->configPathResolver->expects($this->once())
+ ->method('resolve')
+ ->willReturn('system/default/test/test/test');
+ $this->arrayManagerMock->expects($this->once())
+ ->method('set')
+ ->with('system/default/test/test/test', [], $value)
+ ->willReturn(null);
+ $this->deploymentConfigWriterMock->expects($this->once())
+ ->method('saveConfig')
+ ->willThrowException(new FileSystemException(__('Filesystem is not writable.')));
+
+ $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
+ }
+
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Invalid values
+ */
+ public function testCustomException()
+ {
+ $path = 'test/test/test';
+ $value = 'value';
+
+ $this->configPathResolver->expects($this->once())
+ ->method('resolve')
+ ->willReturn('system/default/test/test/test');
+ $this->preparedValueFactory->expects($this->once())
+ ->method('create')
+ ->willReturn($this->valueMock);
+ $this->arrayManagerMock->expects($this->never())
+ ->method('set');
+ $this->valueMock->expects($this->once())
+ ->method('getValue');
+ $this->valueMock->expects($this->once())
+ ->method('afterSave')
+ ->willThrowException(new \Exception('Invalid values'));
+ $this->deploymentConfigWriterMock->expects($this->never())
+ ->method('saveConfig');
+
+ $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
+ }
+}
diff --git a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockProcessorTest.php b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockProcessorTest.php
deleted file mode 100644
index 4535e9ad888c2..0000000000000
--- a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockProcessorTest.php
+++ /dev/null
@@ -1,219 +0,0 @@
-preparedValueFactory = $this->getMockBuilder(PreparedValueFactory::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->deploymentConfigWriterMock = $this->getMockBuilder(DeploymentConfig\Writer::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->configPathResolver = $this->getMockBuilder(ConfigPathResolver::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->valueMock = $this->getMockBuilder(Value::class)
- ->setMethods(['validateBeforeSave', 'beforeSave', 'setValue', 'getValue', 'afterSave'])
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->model = new LockProcessor(
- $this->preparedValueFactory,
- $this->deploymentConfigWriterMock,
- $this->arrayManagerMock,
- $this->configPathResolver
- );
- }
-
- /**
- * Tests process of lock flow.
- *
- * @param string $path
- * @param string $value
- * @param string $scope
- * @param string|null $scopeCode
- * @dataProvider processDataProvider
- */
- public function testProcess($path, $value, $scope, $scopeCode)
- {
- $this->preparedValueFactory->expects($this->once())
- ->method('create')
- ->with($path, $value, $scope, $scopeCode)
- ->willReturn($this->valueMock);
- $this->configPathResolver->expects($this->once())
- ->method('resolve')
- ->willReturn('system/default/test/test/test');
- $this->arrayManagerMock->expects($this->once())
- ->method('set')
- ->with('system/default/test/test/test', [], $value)
- ->willReturn([
- 'system' => [
- 'default' => [
- 'test' => [
- 'test' => [
- 'test' => $value
- ]
- ]
- ]
- ]
- ]);
- $this->valueMock->expects($this->once())
- ->method('getValue')
- ->willReturn($value);
- $this->deploymentConfigWriterMock->expects($this->once())
- ->method('saveConfig')
- ->with(
- [
- ConfigFilePool::APP_ENV => [
- 'system' => [
- 'default' => [
- 'test' => [
- 'test' => [
- 'test' => $value
- ]
- ]
- ]
- ]
- ]
- ],
- false
- );
- $this->valueMock->expects($this->once())
- ->method('validateBeforeSave');
- $this->valueMock->expects($this->once())
- ->method('beforeSave');
- $this->valueMock->expects($this->once())
- ->method('afterSave');
-
- $this->model->process($path, $value, $scope, $scopeCode);
- }
-
- /**
- * @return array
- */
- public function processDataProvider()
- {
- return [
- ['test/test/test', 'value', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
- ['test/test/test', 'value', ScopeInterface::SCOPE_WEBSITE, 'base'],
- ['test/test/test', 'value', ScopeInterface::SCOPE_STORE, 'test'],
- ];
- }
-
- /**
- * @expectedException \Magento\Framework\Exception\LocalizedException
- * @expectedExceptionMessage Filesystem is not writable.
- */
- public function testProcessNotReadableFs()
- {
- $path = 'test/test/test';
- $value = 'value';
-
- $this->preparedValueFactory->expects($this->once())
- ->method('create')
- ->willReturn($this->valueMock);
- $this->valueMock->expects($this->once())
- ->method('getValue')
- ->willReturn($value);
- $this->configPathResolver->expects($this->once())
- ->method('resolve')
- ->willReturn('system/default/test/test/test');
- $this->arrayManagerMock->expects($this->once())
- ->method('set')
- ->with('system/default/test/test/test', [], $value)
- ->willReturn(null);
- $this->deploymentConfigWriterMock->expects($this->once())
- ->method('saveConfig')
- ->willThrowException(new FileSystemException(__('Filesystem is not writable.')));
-
- $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
- }
-
- /**
- * @expectedException \Exception
- * @expectedExceptionMessage Invalid values
- */
- public function testCustomException()
- {
- $path = 'test/test/test';
- $value = 'value';
-
- $this->configPathResolver->expects($this->once())
- ->method('resolve')
- ->willReturn('system/default/test/test/test');
- $this->preparedValueFactory->expects($this->once())
- ->method('create')
- ->willReturn($this->valueMock);
- $this->arrayManagerMock->expects($this->never())
- ->method('set');
- $this->valueMock->expects($this->once())
- ->method('getValue');
- $this->valueMock->expects($this->once())
- ->method('afterSave')
- ->willThrowException(new \Exception('Invalid values'));
- $this->deploymentConfigWriterMock->expects($this->never())
- ->method('saveConfig');
-
- $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
- }
-}
diff --git a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ProcessorFacadeTest.php b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ProcessorFacadeTest.php
index 4e65ab3f4cc21..ac4dda2a98517 100644
--- a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ProcessorFacadeTest.php
+++ b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ProcessorFacadeTest.php
@@ -11,6 +11,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Scope\ValidatorInterface;
use Magento\Config\Model\Config\PathValidator;
+use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\ValidatorException;
use Magento\Framework\Exception\CouldNotSaveException;
@@ -122,7 +123,13 @@ public function testProcess()
$this->assertSame(
'Value was saved.',
- $this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false)
+ $this->model->processWithLockTarget(
+ 'test/test/test',
+ 'test',
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
+ null,
+ false
+ )
);
}
@@ -132,12 +139,19 @@ public function testProcess()
*/
public function testProcessWithValidatorException(LocalizedException $exception)
{
- $this->expectException(ValidatorException::class, 'Some error');
+ $this->expectException(ValidatorException::class);
+ $this->expectExceptionMessage('Some error');
$this->scopeValidatorMock->expects($this->once())
->method('isValid')
->willThrowException($exception);
- $this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false);
+ $this->model->processWithLockTarget(
+ 'test/test/test',
+ 'test',
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
+ null,
+ false
+ );
}
/**
@@ -172,7 +186,13 @@ public function testProcessWithConfigurationMismatchException()
$this->configMock->expects($this->never())
->method('clean');
- $this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false);
+ $this->model->processWithLockTarget(
+ 'test/test/test',
+ 'test',
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
+ null,
+ false
+ );
}
/**
@@ -198,17 +218,50 @@ public function testProcessWithCouldNotSaveException()
$this->configMock->expects($this->never())
->method('clean');
- $this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false);
+ $this->model->processWithLockTarget(
+ 'test/test/test',
+ 'test',
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
+ null,
+ false
+ );
+ }
+
+ public function testExecuteLockEnv()
+ {
+ $this->scopeValidatorMock->expects($this->once())
+ ->method('isValid')
+ ->willReturn(true);
+ $this->configSetProcessorFactoryMock->expects($this->once())
+ ->method('create')
+ ->with(ConfigSetProcessorFactory::TYPE_LOCK_ENV)
+ ->willReturn($this->processorMock);
+ $this->processorMock->expects($this->once())
+ ->method('process')
+ ->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
+ $this->configMock->expects($this->once())
+ ->method('clean');
+
+ $this->assertSame(
+ 'Value was saved in app/etc/env.php and locked.',
+ $this->model->processWithLockTarget(
+ 'test/test/test',
+ 'test',
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
+ null,
+ true
+ )
+ );
}
- public function testExecuteLock()
+ public function testExecuteLockConfig()
{
$this->scopeValidatorMock->expects($this->once())
->method('isValid')
->willReturn(true);
$this->configSetProcessorFactoryMock->expects($this->once())
->method('create')
- ->with(ConfigSetProcessorFactory::TYPE_LOCK)
+ ->with(ConfigSetProcessorFactory::TYPE_LOCK_CONFIG)
->willReturn($this->processorMock);
$this->processorMock->expects($this->once())
->method('process')
@@ -217,8 +270,15 @@ public function testExecuteLock()
->method('clean');
$this->assertSame(
- 'Value was saved and locked.',
- $this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, true)
+ 'Value was saved in app/etc/config.php and locked.',
+ $this->model->processWithLockTarget(
+ 'test/test/test',
+ 'test',
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
+ null,
+ true,
+ ConfigFilePool::APP_CONFIG
+ )
);
}
}
diff --git a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSetCommandTest.php b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSetCommandTest.php
index 0271de0da81f4..cb3a401e6f1d1 100644
--- a/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSetCommandTest.php
+++ b/app/code/Magento/Config/Test/Unit/Console/Command/ConfigSetCommandTest.php
@@ -95,7 +95,7 @@ public function testExecute()
->method('create')
->willReturn($this->processorFacadeMock);
$this->processorFacadeMock->expects($this->once())
- ->method('process')
+ ->method('processWithLockTarget')
->willReturn('Some message');
$this->emulatedAreProcessorMock->expects($this->once())
->method('process')
@@ -171,9 +171,7 @@ public function testExecuteWithException()
->willReturn(false);
$this->emulatedAreProcessorMock->expects($this->once())
->method('process')
- ->willThrowException(
- new ValidatorException(__('The "test/test/test" path doesn\'t exist. Verify and try again.'))
- );
+ ->willThrowException(new ValidatorException(__('The "test/test/test" path does not exists')));
$tester = new CommandTester($this->command);
$tester->execute([
@@ -182,7 +180,7 @@ public function testExecuteWithException()
]);
$this->assertContains(
- __('The "test/test/test" path doesn\'t exist. Verify and try again.')->render(),
+ __('The "test/test/test" path does not exists')->render(),
$tester->getDisplay()
);
$this->assertSame(Cli::RETURN_FAILURE, $tester->getStatusCode());
diff --git a/app/code/Magento/Config/etc/db_schema.xml b/app/code/Magento/Config/etc/db_schema.xml
index e7be05d4a8cc2..3f55d582776ce 100644
--- a/app/code/Magento/Config/etc/db_schema.xml
+++ b/app/code/Magento/Config/etc/db_schema.xml
@@ -6,7 +6,7 @@
*/
-->
+ xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
diff --git a/app/code/Magento/Config/etc/di.xml b/app/code/Magento/Config/etc/di.xml
index bcddd8ceaf27a..a5dd18097fb47 100644
--- a/app/code/Magento/Config/etc/di.xml
+++ b/app/code/Magento/Config/etc/di.xml
@@ -296,10 +296,21 @@
- Magento\Config\Console\Command\ConfigSet\DefaultProcessor
- - Magento\Config\Console\Command\ConfigSet\LockProcessor
+ - Magento\Config\Console\Command\ConfigSet\VirtualLockEnvProcessor
+ - Magento\Config\Console\Command\ConfigSet\VirtualLockConfigProcessor
+
+
+ app_env
+
+
+
+
+ app_config
+
+
diff --git a/app/code/Magento/Config/etc/module.xml b/app/code/Magento/Config/etc/module.xml
index b64cbe2b72623..2fd4255a2bc0c 100644
--- a/app/code/Magento/Config/etc/module.xml
+++ b/app/code/Magento/Config/etc/module.xml
@@ -6,5 +6,9 @@
*/
-->
-
+
+
+
+
+
diff --git a/app/code/Magento/ConfigurableImportExport/etc/module.xml b/app/code/Magento/ConfigurableImportExport/etc/module.xml
index 83a4fc4e1a793..7ff81f8d63443 100644
--- a/app/code/Magento/ConfigurableImportExport/etc/module.xml
+++ b/app/code/Magento/ConfigurableImportExport/etc/module.xml
@@ -6,6 +6,6 @@
*/
-->
-
+
diff --git a/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php b/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php
index 0a4fc20578ed9..3a9ed653305c5 100644
--- a/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php
+++ b/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php
@@ -26,6 +26,7 @@ class ConfigurableItem extends DefaultItem
* @param \Magento\Catalog\Helper\Product\ConfigurationPool $configurationPool
* @param \Magento\Checkout\Helper\Data $checkoutHelper
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
+ * @param \Magento\Framework\Escaper|null $escaper
*/
public function __construct(
\Magento\Catalog\Helper\Image $imageHelper,
@@ -33,14 +34,16 @@ public function __construct(
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Catalog\Helper\Product\ConfigurationPool $configurationPool,
\Magento\Checkout\Helper\Data $checkoutHelper,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
+ \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
+ \Magento\Framework\Escaper $escaper = null
) {
parent::__construct(
$imageHelper,
$msrpHelper,
$urlBuilder,
$configurationPool,
- $checkoutHelper
+ $checkoutHelper,
+ $escaper
);
$this->_scopeConfig = $scopeConfig;
}
diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php
index 487ab19de2063..a30ec81528dd3 100644
--- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php
+++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php
@@ -133,6 +133,10 @@ protected function _applyConfigurableOption()
['le' => $this->getTable('catalog_product_entity')],
'le.' . $linkField . ' = l.parent_id',
['parent_id' => 'entity_id']
+ )->join(
+ ['i' => $this->_getDefaultFinalPriceTable()],
+ 'le.entity_id = i.entity_id',
+ []
);
$select = $connection->select();
diff --git a/app/code/Magento/ConfigurableProduct/Setup/InstallData.php b/app/code/Magento/ConfigurableProduct/Setup/InstallData.php
deleted file mode 100644
index 7bc56569dea44..0000000000000
--- a/app/code/Magento/ConfigurableProduct/Setup/InstallData.php
+++ /dev/null
@@ -1,74 +0,0 @@
-eavSetupFactory = $eavSetupFactory;
- }
-
- /**
- * {@inheritdoc}
- */
- public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- /** @var EavSetup $eavSetup */
- $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
- $attributes = [
- 'country_of_manufacture',
- 'minimal_price',
- 'msrp',
- 'msrp_display_actual_price_type',
- 'price',
- 'special_price',
- 'special_from_date',
- 'special_to_date',
- 'tier_price',
- 'weight',
- 'color'
- ];
- foreach ($attributes as $attributeCode) {
- $relatedProductTypes = explode(
- ',',
- $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, 'apply_to')
- );
- if (!in_array(Configurable::TYPE_CODE, $relatedProductTypes)) {
- $relatedProductTypes[] = Configurable::TYPE_CODE;
- $eavSetup->updateAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- $attributeCode,
- 'apply_to',
- implode(',', $relatedProductTypes)
- );
- }
- }
- }
-}
diff --git a/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/InstallInitialConfigurableAttributes.php b/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/InstallInitialConfigurableAttributes.php
new file mode 100644
index 0000000000000..c9fea3e74d3d2
--- /dev/null
+++ b/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/InstallInitialConfigurableAttributes.php
@@ -0,0 +1,105 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->eavSetupFactory = $eavSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ /** @var EavSetup $eavSetup */
+ $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $attributes = [
+ 'country_of_manufacture',
+ 'minimal_price',
+ 'msrp',
+ 'msrp_display_actual_price_type',
+ 'price',
+ 'special_price',
+ 'special_from_date',
+ 'special_to_date',
+ 'tier_price',
+ 'weight',
+ 'color'
+ ];
+ foreach ($attributes as $attributeCode) {
+ $relatedProductTypes = explode(
+ ',',
+ $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, 'apply_to')
+ );
+ if (!in_array(Configurable::TYPE_CODE, $relatedProductTypes)) {
+ $relatedProductTypes[] = Configurable::TYPE_CODE;
+ $eavSetup->updateAttribute(
+ \Magento\Catalog\Model\Product::ENTITY,
+ $attributeCode,
+ 'apply_to',
+ implode(',', $relatedProductTypes)
+ );
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/UpdateTierPriceAttribute.php b/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/UpdateTierPriceAttribute.php
new file mode 100644
index 0000000000000..325fb447d225f
--- /dev/null
+++ b/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/UpdateTierPriceAttribute.php
@@ -0,0 +1,94 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->eavSetupFactory = $eavSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ /** @var EavSetup $eavSetup */
+ $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $relatedProductTypes = explode(
+ ',',
+ $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'tier_price', 'apply_to')
+ );
+ $key = array_search(Configurable::TYPE_CODE, $relatedProductTypes);
+ if ($key !== false) {
+ unset($relatedProductTypes[$key]);
+ $eavSetup->updateAttribute(
+ \Magento\Catalog\Model\Product::ENTITY,
+ 'tier_price',
+ 'apply_to',
+ implode(',', $relatedProductTypes)
+ );
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ InstallInitialConfigurableAttributes::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}\
+ */
+ public static function getVersion()
+ {
+ return '2.2.0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/ConfigurableProduct/Setup/UpgradeData.php b/app/code/Magento/ConfigurableProduct/Setup/UpgradeData.php
deleted file mode 100644
index 326af02fe39bb..0000000000000
--- a/app/code/Magento/ConfigurableProduct/Setup/UpgradeData.php
+++ /dev/null
@@ -1,65 +0,0 @@
-eavSetupFactory = $eavSetupFactory;
- }
-
- /**
- * {@inheritdoc}
- */
- public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- $setup->startSetup();
- if (version_compare($context->getVersion(), '2.2.0') < 0) {
- /** @var EavSetup $eavSetup */
- $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
- $relatedProductTypes = explode(
- ',',
- $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'tier_price', 'apply_to')
- );
- $key = array_search(Configurable::TYPE_CODE, $relatedProductTypes);
- if ($key !== false) {
- unset($relatedProductTypes[$key]);
- $eavSetup->updateAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'tier_price',
- 'apply_to',
- implode(',', $relatedProductTypes)
- );
- }
- }
-
- $setup->endSetup();
- }
-}
diff --git a/app/code/Magento/ConfigurableProduct/etc/db_schema.xml b/app/code/Magento/ConfigurableProduct/etc/db_schema.xml
index d45c06bea1c3e..7c6661a5f399a 100644
--- a/app/code/Magento/ConfigurableProduct/etc/db_schema.xml
+++ b/app/code/Magento/ConfigurableProduct/etc/db_schema.xml
@@ -6,7 +6,7 @@
*/
-->
+ xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
-
+
diff --git a/app/code/Magento/ConfigurableProductGraphQl/etc/module.xml b/app/code/Magento/ConfigurableProductGraphQl/etc/module.xml
index e86b1bdf604c6..98e7957d0af8e 100644
--- a/app/code/Magento/ConfigurableProductGraphQl/etc/module.xml
+++ b/app/code/Magento/ConfigurableProductGraphQl/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/ConfigurableProductSales/etc/module.xml b/app/code/Magento/ConfigurableProductSales/etc/module.xml
index 4da83c9c0269b..bf5bc4472c8b2 100644
--- a/app/code/Magento/ConfigurableProductSales/etc/module.xml
+++ b/app/code/Magento/ConfigurableProductSales/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Contact/etc/module.xml b/app/code/Magento/Contact/etc/module.xml
index ec91859ee2c8d..64ba1c1fb0f0d 100644
--- a/app/code/Magento/Contact/etc/module.xml
+++ b/app/code/Magento/Contact/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Cookie/etc/module.xml b/app/code/Magento/Cookie/etc/module.xml
index 35c5a52f42ec7..df64e8b3ebfe8 100644
--- a/app/code/Magento/Cookie/etc/module.xml
+++ b/app/code/Magento/Cookie/etc/module.xml
@@ -6,5 +6,5 @@
*/
-->
-
+
diff --git a/app/code/Magento/Cron/etc/db_schema.xml b/app/code/Magento/Cron/etc/db_schema.xml
index 9f019d108b257..deff05d3eec96 100644
--- a/app/code/Magento/Cron/etc/db_schema.xml
+++ b/app/code/Magento/Cron/etc/db_schema.xml
@@ -6,7 +6,7 @@
*/
-->
+ xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
diff --git a/app/code/Magento/Cron/etc/module.xml b/app/code/Magento/Cron/etc/module.xml
index ce31b046500f7..8112b9e8c46db 100644
--- a/app/code/Magento/Cron/etc/module.xml
+++ b/app/code/Magento/Cron/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/CurrencySymbol/Setup/Patch/Data/ConvertSerializedCustomCurrencySymbolToJson.php b/app/code/Magento/CurrencySymbol/Setup/Patch/Data/ConvertSerializedCustomCurrencySymbolToJson.php
new file mode 100644
index 0000000000000..be2f2c5147124
--- /dev/null
+++ b/app/code/Magento/CurrencySymbol/Setup/Patch/Data/ConvertSerializedCustomCurrencySymbolToJson.php
@@ -0,0 +1,100 @@
+fieldDataConverterFactory = $fieldDataConverterFactory;
+ $this->queryModifierFactory = $queryModifierFactory;
+ $this->moduleDataSetup = $moduleDataSetup;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
+ $queryModifier = $this->queryModifierFactory->create(
+ 'in',
+ [
+ 'values' => [
+ 'path' => [Currencysymbol::XML_PATH_CUSTOM_CURRENCY_SYMBOL]
+ ]
+ ]
+ );
+ $fieldDataConverter->convert(
+ $this->moduleDataSetup->getConnection(),
+ $this->moduleDataSetup->getTable('core_config_data'),
+ 'config_id',
+ 'value',
+ $queryModifier
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.1';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/CurrencySymbol/Setup/UpgradeData.php b/app/code/Magento/CurrencySymbol/Setup/UpgradeData.php
deleted file mode 100644
index 474efde78ea5b..0000000000000
--- a/app/code/Magento/CurrencySymbol/Setup/UpgradeData.php
+++ /dev/null
@@ -1,82 +0,0 @@
-fieldDataConverterFactory = $fieldDataConverterFactory;
- $this->queryModifierFactory = $queryModifierFactory;
- }
-
- /**
- * {@inheritdoc}
- */
- public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- if (version_compare($context->getVersion(), '2.0.1', '<')) {
- $this->convertSerializedCustomCurrencySymbolToJson($setup);
- }
- }
-
- /**
- * Converts custom currency symbol configuration in core_config_data table from serialized to JSON format
- *
- * @param ModuleDataSetupInterface $setup
- * @return void
- */
- private function convertSerializedCustomCurrencySymbolToJson(ModuleDataSetupInterface $setup)
- {
- $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
- $queryModifier = $this->queryModifierFactory->create(
- 'in',
- [
- 'values' => [
- 'path' => [Currencysymbol::XML_PATH_CUSTOM_CURRENCY_SYMBOL]
- ]
- ]
- );
- $fieldDataConverter->convert(
- $setup->getConnection(),
- $setup->getTable('core_config_data'),
- 'config_id',
- 'value',
- $queryModifier
- );
- }
-}
diff --git a/app/code/Magento/CurrencySymbol/etc/module.xml b/app/code/Magento/CurrencySymbol/etc/module.xml
index f638479031f4f..2af87335518d1 100644
--- a/app/code/Magento/CurrencySymbol/etc/module.xml
+++ b/app/code/Magento/CurrencySymbol/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Customer/Block/Address/Edit.php b/app/code/Magento/Customer/Block/Address/Edit.php
index 6362f28a4f96d..6a42e9670ccc6 100644
--- a/app/code/Magento/Customer/Block/Address/Edit.php
+++ b/app/code/Magento/Customer/Block/Address/Edit.php
@@ -129,7 +129,7 @@ protected function _prepareLayout()
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
$postedData['region'] = [
- 'region_id' => $postedData['region_id'],
+ 'region_id' => isset($postedData['region_id']) ? $postedData['region_id'] : null,
'region' => $postedData['region'],
];
$this->dataObjectHelper->populateWithArray(
diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php
index 711fab9e608bf..20d330354bce4 100644
--- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php
+++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php
@@ -132,30 +132,15 @@ public function __construct(
*/
public function execute()
{
- $file = null;
- $plain = false;
- if ($this->getRequest()->getParam('file')) {
- // download file
- $file = $this->urlDecoder->decode(
- $this->getRequest()->getParam('file')
- );
- } elseif ($this->getRequest()->getParam('image')) {
- // show plain image
- $file = $this->urlDecoder->decode(
- $this->getRequest()->getParam('image')
- );
- $plain = true;
- } else {
- throw new NotFoundException(__('Page not found.'));
- }
+ list($file, $plain) = $this->getFileParams();
/** @var \Magento\Framework\Filesystem $filesystem */
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
$directory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
$fileName = CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER . '/' . ltrim($file, '/');
$path = $directory->getAbsolutePath($fileName);
- if (!$directory->isFile($fileName)
- && !$this->_objectManager->get(\Magento\MediaStorage\Helper\File\Storage::class)->processStorageFile($path)
+ if (mb_strpos($path, '..') !== false || (!$directory->isFile($fileName)
+ && !$this->_objectManager->get(\Magento\MediaStorage\Helper\File\Storage::class)->processStorageFile($path))
) {
throw new NotFoundException(__('Page not found.'));
}
@@ -198,4 +183,32 @@ public function execute()
);
}
}
+
+ /**
+ * Get parameters from request.
+ *
+ * @return array
+ * @throws NotFoundException
+ */
+ private function getFileParams()
+ {
+ $file = null;
+ $plain = false;
+ if ($this->getRequest()->getParam('file')) {
+ // download file
+ $file = $this->urlDecoder->decode(
+ $this->getRequest()->getParam('file')
+ );
+ } elseif ($this->getRequest()->getParam('image')) {
+ // show plain image
+ $file = $this->urlDecoder->decode(
+ $this->getRequest()->getParam('image')
+ );
+ $plain = true;
+ } else {
+ throw new NotFoundException(__('Page not found.'));
+ }
+
+ return [$file, $plain];
+ }
}
diff --git a/app/code/Magento/Customer/Model/Account/Redirect.php b/app/code/Magento/Customer/Model/Account/Redirect.php
index 2e8d596474e96..2ccaaea45680c 100644
--- a/app/code/Magento/Customer/Model/Account/Redirect.php
+++ b/app/code/Magento/Customer/Model/Account/Redirect.php
@@ -74,6 +74,11 @@ class Redirect
*/
private $hostChecker;
+ /**
+ * @var Session
+ */
+ private $session;
+
/**
* @param RequestInterface $request
* @param Session $customerSession
@@ -206,6 +211,10 @@ protected function processLoggedCustomer()
$referer = $this->request->getParam(CustomerUrl::REFERER_QUERY_PARAM_NAME);
if ($referer) {
$referer = $this->urlDecoder->decode($referer);
+ preg_match('/logoutSuccess\//', $referer, $matches, PREG_OFFSET_CAPTURE);
+ if (!empty($matches)) {
+ $referer = str_replace('logoutSuccess/', '', $referer);
+ }
if ($this->hostChecker->isOwnOrigin($referer)) {
$this->applyRedirect($referer);
}
diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php
index cd5fef7316999..7d0b271b9b137 100644
--- a/app/code/Magento/Customer/Model/AccountManagement.php
+++ b/app/code/Magento/Customer/Model/AccountManagement.php
@@ -48,6 +48,9 @@
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface as PsrLogger;
+use Magento\Framework\Session\SessionManagerInterface;
+use Magento\Framework\Session\SaveHandlerInterface;
+use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory;
/**
* Handle various customer account actions
@@ -243,6 +246,21 @@ class AccountManagement implements AccountManagementInterface
*/
private $transportBuilder;
+ /**
+ * @var SessionManagerInterface
+ */
+ private $sessionManager;
+
+ /**
+ * @var SaveHandlerInterface
+ */
+ private $saveHandler;
+
+ /**
+ * @var CollectionFactory
+ */
+ private $visitorCollectionFactory;
+
/**
* @var DataObjectProcessor
*/
@@ -335,6 +353,9 @@ class AccountManagement implements AccountManagementInterface
* @param CredentialsValidator|null $credentialsValidator
* @param DateTimeFactory|null $dateTimeFactory
* @param AccountConfirmation|null $accountConfirmation
+ * @param SessionManagerInterface|null $sessionManager
+ * @param SaveHandlerInterface|null $saveHandler
+ * @param CollectionFactory|null $visitorCollectionFactory
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
@@ -363,7 +384,10 @@ public function __construct(
ExtensibleDataObjectConverter $extensibleDataObjectConverter,
CredentialsValidator $credentialsValidator = null,
DateTimeFactory $dateTimeFactory = null,
- AccountConfirmation $accountConfirmation = null
+ AccountConfirmation $accountConfirmation = null,
+ SessionManagerInterface $sessionManager = null,
+ SaveHandlerInterface $saveHandler = null,
+ CollectionFactory $visitorCollectionFactory = null
) {
$this->customerFactory = $customerFactory;
$this->eventManager = $eventManager;
@@ -393,6 +417,12 @@ public function __construct(
$this->dateTimeFactory = $dateTimeFactory ?: ObjectManager::getInstance()->get(DateTimeFactory::class);
$this->accountConfirmation = $accountConfirmation ?: ObjectManager::getInstance()
->get(AccountConfirmation::class);
+ $this->sessionManager = $sessionManager
+ ?: ObjectManager::getInstance()->get(SessionManagerInterface::class);
+ $this->saveHandler = $saveHandler
+ ?: ObjectManager::getInstance()->get(SaveHandlerInterface::class);
+ $this->visitorCollectionFactory = $visitorCollectionFactory
+ ?: ObjectManager::getInstance()->get(CollectionFactory::class);
}
/**
@@ -594,7 +624,10 @@ public function resetPassword($email, $resetToken, $newPassword)
$customerSecure->setRpToken(null);
$customerSecure->setRpTokenCreatedAt(null);
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
+ $this->sessionManager->destroy();
+ $this->destroyCustomerSessions($customer->getId());
$this->customerRepository->save($customer);
+
return true;
}
@@ -896,7 +929,9 @@ private function changePasswordForCustomer($customer, $currentPassword, $newPass
$customerSecure->setRpTokenCreatedAt(null);
$this->checkPasswordStrength($newPassword);
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
+ $this->destroyCustomerSessions($customer->getId());
$this->customerRepository->save($customer);
+
return true;
}
@@ -1399,4 +1434,35 @@ private function getEmailNotification()
return $this->emailNotification;
}
}
+
+ /**
+ * Destroy all active customer sessions by customer id (current session will not be destroyed).
+ * Customer sessions which should be deleted are collecting from the "customer_visitor" table considering
+ * configured session lifetime.
+ *
+ * @param string|int $customerId
+ * @return void
+ */
+ private function destroyCustomerSessions($customerId)
+ {
+ $sessionLifetime = $this->scopeConfig->getValue(
+ \Magento\Framework\Session\Config::XML_PATH_COOKIE_LIFETIME,
+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ );
+ $dateTime = $this->dateTimeFactory->create();
+ $activeSessionsTime = $dateTime->setTimestamp($dateTime->getTimestamp() - $sessionLifetime)
+ ->format(DateTime::DATETIME_PHP_FORMAT);
+ /** @var \Magento\Customer\Model\ResourceModel\Visitor\Collection $visitorCollection */
+ $visitorCollection = $this->visitorCollectionFactory->create();
+ $visitorCollection->addFieldToFilter('customer_id', $customerId);
+ $visitorCollection->addFieldToFilter('last_visit_at', ['from' => $activeSessionsTime]);
+ $visitorCollection->addFieldToFilter('session_id', ['neq' => $this->sessionManager->getSessionId()]);
+ /** @var \Magento\Customer\Model\Visitor $visitor */
+ foreach ($visitorCollection->getItems() as $visitor) {
+ $sessionId = $visitor->getSessionId();
+ $this->sessionManager->start();
+ $this->saveHandler->destroy($sessionId);
+ $this->sessionManager->writeClose();
+ }
+ }
}
diff --git a/app/code/Magento/Customer/Model/Address/AbstractAddress.php b/app/code/Magento/Customer/Model/Address/AbstractAddress.php
index aab9a811168f9..6408276630c3f 100644
--- a/app/code/Magento/Customer/Model/Address/AbstractAddress.php
+++ b/app/code/Magento/Customer/Model/Address/AbstractAddress.php
@@ -12,6 +12,7 @@
use Magento\Customer\Api\Data\RegionInterface;
use Magento\Customer\Api\Data\RegionInterfaceFactory;
use Magento\Customer\Model\Data\Address as AddressData;
+use Magento\Framework\App\ObjectManager;
use Magento\Framework\Model\AbstractExtensibleModel;
/**
@@ -118,6 +119,9 @@ class AbstractAddress extends AbstractExtensibleModel implements AddressModelInt
*/
protected $dataObjectHelper;
+ /** @var CompositeValidator */
+ private $compositeValidator;
+
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
@@ -135,6 +139,8 @@ class AbstractAddress extends AbstractExtensibleModel implements AddressModelInt
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
+ * @param CompositeValidator $compositeValidator
+ *
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
@@ -153,7 +159,8 @@ public function __construct(
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
- array $data = []
+ array $data = [],
+ CompositeValidator $compositeValidator = null
) {
$this->_directoryData = $directoryData;
$data = $this->_implodeArrayField($data);
@@ -165,6 +172,8 @@ public function __construct(
$this->addressDataFactory = $addressDataFactory;
$this->regionDataFactory = $regionDataFactory;
$this->dataObjectHelper = $dataObjectHelper;
+ $this->compositeValidator = $compositeValidator ?: ObjectManager::getInstance()
+ ->get(CompositeValidator::class);
parent::__construct(
$context,
$registry,
@@ -562,84 +571,22 @@ public function getDataModel($defaultBillingAddressId = null, $defaultShippingAd
}
/**
- * Validate address attribute values
- *
- *
+ * Validate address attribute values.
*
- * @return bool|array
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
+ * @return array|bool
*/
public function validate()
{
if ($this->getShouldIgnoreValidation()) {
return true;
}
-
- $errors = [];
- if (!\Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'firstname']);
- }
-
- if (!\Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'lastname']);
- }
-
- if (!\Zend_Validate::is($this->getStreetLine(1), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'street']);
- }
- if (!\Zend_Validate::is($this->getCity(), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'city']);
- }
-
- if ($this->isTelephoneRequired()) {
- if (!\Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'telephone']);
- }
- }
-
- if ($this->isFaxRequired()) {
- if (!\Zend_Validate::is($this->getFax(), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'fax']);
- }
- }
-
- if ($this->isCompanyRequired()) {
- if (!\Zend_Validate::is($this->getCompany(), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'company']);
- }
- }
-
- $_havingOptionalZip = $this->_directoryData->getCountriesWithOptionalZip();
- if (!in_array(
- $this->getCountryId(),
- $_havingOptionalZip
- ) && !\Zend_Validate::is(
- $this->getPostcode(),
- 'NotEmpty'
- )
- ) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'postcode']);
- }
-
- if (!\Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'countryId']);
- }
-
- if ($this->getCountryModel()->getRegionCollection()->getSize() && !\Zend_Validate::is(
- $this->getRegionId(),
- 'NotEmpty'
- ) && $this->_directoryData->isRegionRequired(
- $this->getCountryId()
- )
- ) {
- $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'regionId']);
- }
+ $errors = $this->compositeValidator->validate($this);
if (empty($errors)) {
return true;
}
+
return $errors;
}
diff --git a/app/code/Magento/Customer/Model/Address/CompositeValidator.php b/app/code/Magento/Customer/Model/Address/CompositeValidator.php
new file mode 100644
index 0000000000000..1d16a929532f5
--- /dev/null
+++ b/app/code/Magento/Customer/Model/Address/CompositeValidator.php
@@ -0,0 +1,40 @@
+validators = $validators;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function validate(AbstractAddress $address)
+ {
+ $errors = [];
+ foreach ($this->validators as $validator) {
+ $errors = array_merge($errors, $validator->validate($address));
+ }
+
+ return $errors;
+ }
+}
diff --git a/app/code/Magento/Customer/Model/Address/Validator/Country.php b/app/code/Magento/Customer/Model/Address/Validator/Country.php
new file mode 100644
index 0000000000000..0ba8a21ff8cd9
--- /dev/null
+++ b/app/code/Magento/Customer/Model/Address/Validator/Country.php
@@ -0,0 +1,100 @@
+directoryData = $directoryData;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function validate(AbstractAddress $address)
+ {
+ $errors = $this->validateCountry($address);
+ if (empty($errors)) {
+ $errors = $this->validateRegion($address);
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Validate country existence.
+ *
+ * @param AbstractAddress $address
+ * @return array
+ */
+ private function validateCountry(AbstractAddress $address)
+ {
+ $countryId = $address->getCountryId();
+ $errors = [];
+ if (!\Zend_Validate::is($countryId, 'NotEmpty')) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'countryId']);
+ } elseif (!in_array($countryId, $this->directoryData->getCountryCollection()->getAllIds(), true)) {
+ //Checking if such country exists.
+ $errors[] = __(
+ 'Invalid value of "%value" provided for the %fieldName field.',
+ ['fieldName' => 'countryId', 'value' => htmlspecialchars($countryId)]
+ );
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Validate region existence.
+ *
+ * @param AbstractAddress $address
+ * @return array
+ */
+ private function validateRegion(AbstractAddress $address)
+ {
+ $errors = [];
+ $countryId = $address->getCountryId();
+ $countryModel = $address->getCountryModel();
+ $regionCollection = $countryModel->getRegionCollection();
+ $region = $address->getRegion();
+ $regionId = (string)$address->getRegionId();
+ $allowedRegions = $regionCollection->getAllIds();
+ $isRegionRequired = $this->directoryData->isRegionRequired($countryId);
+ if ($isRegionRequired && empty($allowedRegions) && !\Zend_Validate::is($region, 'NotEmpty')) {
+ //If region is required for country and country doesn't provide regions list
+ //region must be provided.
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'region']);
+ } elseif ($allowedRegions && !\Zend_Validate::is($regionId, 'NotEmpty') && $isRegionRequired) {
+ //If country actually has regions and requires you to
+ //select one then it must be selected.
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'regionId']);
+ } elseif ($regionId && !in_array($regionId, $allowedRegions, true)) {
+ //If a region is selected then checking if it exists.
+ $errors[] = __(
+ 'Invalid value of "%value" provided for the %fieldName field.',
+ ['fieldName' => 'regionId', 'value' => htmlspecialchars($regionId)]
+ );
+ }
+
+ return $errors;
+ }
+}
diff --git a/app/code/Magento/Customer/Model/Address/Validator/General.php b/app/code/Magento/Customer/Model/Address/Validator/General.php
new file mode 100644
index 0000000000000..679f288712b4b
--- /dev/null
+++ b/app/code/Magento/Customer/Model/Address/Validator/General.php
@@ -0,0 +1,151 @@
+eavConfig = $eavConfig;
+ $this->directoryData = $directoryData;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function validate(AbstractAddress $address)
+ {
+ $errors = array_merge(
+ $this->checkRequredFields($address),
+ $this->checkOptionalFields($address)
+ );
+
+ return $errors;
+ }
+
+ /**
+ * Check fields that are generally required.
+ *
+ * @param AbstractAddress $address
+ * @return array
+ * @throws \Zend_Validate_Exception
+ */
+ private function checkRequredFields(AbstractAddress $address)
+ {
+ $errors = [];
+ if (!\Zend_Validate::is($address->getFirstname(), 'NotEmpty')) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'firstname']);
+ }
+
+ if (!\Zend_Validate::is($address->getLastname(), 'NotEmpty')) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'lastname']);
+ }
+
+ if (!\Zend_Validate::is($address->getStreetLine(1), 'NotEmpty')) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'street']);
+ }
+
+ if (!\Zend_Validate::is($address->getCity(), 'NotEmpty')) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'city']);
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Check fields that are conditionally required.
+ *
+ * @param AbstractAddress $address
+ * @return array
+ * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws \Zend_Validate_Exception
+ */
+ private function checkOptionalFields(AbstractAddress $address)
+ {
+ $errors = [];
+ if ($this->isTelephoneRequired()
+ && !\Zend_Validate::is($address->getTelephone(), 'NotEmpty')
+ ) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'telephone']);
+ }
+
+ if ($this->isFaxRequired()
+ && !\Zend_Validate::is($address->getFax(), 'NotEmpty')
+ ) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'fax']);
+ }
+
+ if ($this->isCompanyRequired()
+ && !\Zend_Validate::is($address->getCompany(), 'NotEmpty')
+ ) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'company']);
+ }
+
+ $havingOptionalZip = $this->directoryData->getCountriesWithOptionalZip();
+ if (!in_array($address->getCountryId(), $havingOptionalZip)
+ && !\Zend_Validate::is($address->getPostcode(), 'NotEmpty')
+ ) {
+ $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'postcode']);
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Check if company field required in configuration.
+ *
+ * @return bool
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ private function isCompanyRequired()
+ {
+ return $this->eavConfig->getAttribute('customer_address', 'company')->getIsRequired();
+ }
+
+ /**
+ * Check if telephone field required in configuration.
+ *
+ * @return bool
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ private function isTelephoneRequired()
+ {
+ return $this->eavConfig->getAttribute('customer_address', 'telephone')->getIsRequired();
+ }
+
+ /**
+ * Check if fax field required in configuration.
+ *
+ * @return bool
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ private function isFaxRequired()
+ {
+ return $this->eavConfig->getAttribute('customer_address', 'fax')->getIsRequired();
+ }
+}
diff --git a/app/code/Magento/Customer/Model/Address/ValidatorInterface.php b/app/code/Magento/Customer/Model/Address/ValidatorInterface.php
new file mode 100644
index 0000000000000..8468f28e70e70
--- /dev/null
+++ b/app/code/Magento/Customer/Model/Address/ValidatorInterface.php
@@ -0,0 +1,24 @@
+session = $session;
$this->notificationStorage = $notificationStorage;
$this->state = $state;
$this->customerRepository = $customerRepository;
+ $this->logger = $logger;
}
/**
@@ -63,17 +73,23 @@ public function __construct(
*/
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
{
+ $customerId = $this->session->getCustomerId();
+
if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost()
&& $this->notificationStorage->isExists(
NotificationStorage::UPDATE_CUSTOMER_SESSION,
- $this->session->getCustomerId()
+ $customerId
)
) {
- $customer = $this->customerRepository->getById($this->session->getCustomerId());
- $this->session->setCustomerData($customer);
- $this->session->setCustomerGroupId($customer->getGroupId());
- $this->session->regenerateId();
- $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
+ try {
+ $customer = $this->customerRepository->getById($customerId);
+ $this->session->setCustomerData($customer);
+ $this->session->setCustomerGroupId($customer->getGroupId());
+ $this->session->regenerateId();
+ $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
+ } catch (NoSuchEntityException $e) {
+ $this->logger->error($e);
+ }
}
}
}
diff --git a/app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php b/app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php
index 2c7b778f5f485..7f69ab3c02bcf 100644
--- a/app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php
+++ b/app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php
@@ -92,7 +92,7 @@ public function __construct(
$this->addressFactory = $addressFactory;
$this->addressRegistry = $addressRegistry;
$this->customerRegistry = $customerRegistry;
- $this->addressResource = $addressResourceModel;
+ $this->addressResourceModel = $addressResourceModel;
$this->directoryData = $directoryData;
$this->addressSearchResultsFactory = $addressSearchResultsFactory;
$this->addressCollectionFactory = $addressCollectionFactory;
@@ -236,7 +236,7 @@ public function delete(\Magento\Customer\Api\Data\AddressInterface $address)
$address = $this->addressRegistry->retrieve($addressId);
$customerModel = $this->customerRegistry->retrieve($address->getCustomerId());
$customerModel->getAddressesCollection()->clear();
- $this->addressResource->delete($address);
+ $this->addressResourceModel->delete($address);
$this->addressRegistry->remove($addressId);
return true;
}
@@ -254,7 +254,7 @@ public function deleteById($addressId)
$address = $this->addressRegistry->retrieve($addressId);
$customerModel = $this->customerRegistry->retrieve($address->getCustomerId());
$customerModel->getAddressesCollection()->removeItemByKey($addressId);
- $this->addressResource->delete($address);
+ $this->addressResourceModel->delete($address);
$this->addressRegistry->remove($addressId);
return true;
}
diff --git a/app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php b/app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php
index 1a15b55a1e7e3..91a593c347806 100644
--- a/app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php
+++ b/app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php
@@ -7,10 +7,12 @@
namespace Magento\Customer\Model\ResourceModel;
use Magento\Customer\Api\CustomerMetadataInterface;
+use Magento\Customer\Model\Customer\NotificationStorage;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Api\ImageProcessorInterface;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
+use Magento\Framework\App\ObjectManager;
/**
* Customer repository.
@@ -88,6 +90,11 @@ class CustomerRepository implements \Magento\Customer\Api\CustomerRepositoryInte
*/
private $collectionProcessor;
+ /**
+ * @var NotificationStorage
+ */
+ private $notificationStorage;
+
/**
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
* @param \Magento\Customer\Model\Data\CustomerSecureFactory $customerSecureFactory
@@ -103,6 +110,7 @@ class CustomerRepository implements \Magento\Customer\Api\CustomerRepositoryInte
* @param ImageProcessorInterface $imageProcessor
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
* @param CollectionProcessorInterface $collectionProcessor
+ * @param NotificationStorage $notificationStorage
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
@@ -119,7 +127,8 @@ public function __construct(
DataObjectHelper $dataObjectHelper,
ImageProcessorInterface $imageProcessor,
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
- CollectionProcessorInterface $collectionProcessor = null
+ CollectionProcessorInterface $collectionProcessor,
+ NotificationStorage $notificationStorage
) {
$this->customerFactory = $customerFactory;
$this->customerSecureFactory = $customerSecureFactory;
@@ -134,7 +143,8 @@ public function __construct(
$this->dataObjectHelper = $dataObjectHelper;
$this->imageProcessor = $imageProcessor;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
- $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
+ $this->collectionProcessor = $collectionProcessor;
+ $this->notificationStorage = $notificationStorage;
}
/**
@@ -345,6 +355,8 @@ public function deleteById($customerId)
$customerModel = $this->customerRegistry->retrieve($customerId);
$customerModel->delete();
$this->customerRegistry->remove($customerId);
+ $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId);
+
return true;
}
@@ -370,20 +382,4 @@ protected function addFilterGroupToCollection(
$collection->addFieldToFilter($fields);
}
}
-
- /**
- * Retrieve collection processor
- *
- * @deprecated 100.2.0
- * @return CollectionProcessorInterface
- */
- private function getCollectionProcessor()
- {
- if (!$this->collectionProcessor) {
- $this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get(
- 'Magento\Eav\Model\Api\SearchCriteria\CollectionProcessor'
- );
- }
- return $this->collectionProcessor;
- }
}
diff --git a/app/code/Magento/Customer/Model/Visitor.php b/app/code/Magento/Customer/Model/Visitor.php
index b4bad240bc825..4624dd8b6bcf5 100644
--- a/app/code/Magento/Customer/Model/Visitor.php
+++ b/app/code/Magento/Customer/Model/Visitor.php
@@ -151,6 +151,9 @@ public function initByRequest($observer)
if ($this->session->getVisitorData()) {
$this->setData($this->session->getVisitorData());
+ if ($this->getSessionId() != $this->session->getSessionId()) {
+ $this->setSessionId($this->session->getSessionId());
+ }
}
$this->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
diff --git a/app/code/Magento/Customer/Setup/CustomerSetup.php b/app/code/Magento/Customer/Setup/CustomerSetup.php
index b1f07e4872fd8..c074285765e59 100644
--- a/app/code/Magento/Customer/Setup/CustomerSetup.php
+++ b/app/code/Magento/Customer/Setup/CustomerSetup.php
@@ -489,4 +489,23 @@ public function getEavConfig()
{
return $this->eavConfig;
}
+
+ /**
+ * Update attributes for customer.
+ *
+ * @param array $entityAttributes
+ * @return void
+ */
+ public function upgradeAttributes(array $entityAttributes)
+ {
+ foreach ($entityAttributes as $entityType => $attributes) {
+ foreach ($attributes as $attributeCode => $attributeData) {
+ $attribute = $this->getEavConfig()->getAttribute($entityType, $attributeCode);
+ foreach ($attributeData as $key => $value) {
+ $attribute->setData($key, $value);
+ }
+ $attribute->save();
+ }
+ }
+ }
}
diff --git a/app/code/Magento/Customer/Setup/InstallData.php b/app/code/Magento/Customer/Setup/InstallData.php
deleted file mode 100644
index 0bc4b19db9d1c..0000000000000
--- a/app/code/Magento/Customer/Setup/InstallData.php
+++ /dev/null
@@ -1,144 +0,0 @@
-customerSetupFactory = $customerSetupFactory;
- }
-
- /**
- * {@inheritdoc}
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- /** @var CustomerSetup $customerSetup */
- $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
-
- $setup->startSetup();
-
- // insert default customer groups
- $setup->getConnection()->insertForce(
- $setup->getTable('customer_group'),
- ['customer_group_id' => 0, 'customer_group_code' => 'NOT LOGGED IN', 'tax_class_id' => 3]
- );
- $setup->getConnection()->insertForce(
- $setup->getTable('customer_group'),
- ['customer_group_id' => 1, 'customer_group_code' => 'General', 'tax_class_id' => 3]
- );
- $setup->getConnection()->insertForce(
- $setup->getTable('customer_group'),
- ['customer_group_id' => 2, 'customer_group_code' => 'Wholesale', 'tax_class_id' => 3]
- );
- $setup->getConnection()->insertForce(
- $setup->getTable('customer_group'),
- ['customer_group_id' => 3, 'customer_group_code' => 'Retailer', 'tax_class_id' => 3]
- );
-
- $customerSetup->installEntities();
-
- $customerSetup->installCustomerForms();
-
- $disableAGCAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'disable_auto_group_change');
- $disableAGCAttribute->setData('used_in_forms', ['adminhtml_customer']);
- $disableAGCAttribute->save();
-
- $attributesInfo = [
- 'vat_id' => [
- 'label' => 'VAT number',
- 'type' => 'static',
- 'input' => 'text',
- 'position' => 140,
- 'visible' => true,
- 'required' => false,
- ],
- 'vat_is_valid' => [
- 'label' => 'VAT number validity',
- 'visible' => false,
- 'required' => false,
- 'type' => 'static',
- ],
- 'vat_request_id' => [
- 'label' => 'VAT number validation request ID',
- 'type' => 'static',
- 'visible' => false,
- 'required' => false,
- ],
- 'vat_request_date' => [
- 'label' => 'VAT number validation request date',
- 'type' => 'static',
- 'visible' => false,
- 'required' => false,
- ],
- 'vat_request_success' => [
- 'label' => 'VAT number validation request success',
- 'visible' => false,
- 'required' => false,
- 'type' => 'static',
- ],
- ];
-
- foreach ($attributesInfo as $attributeCode => $attributeParams) {
- $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
- }
-
- $vatIdAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'vat_id');
- $vatIdAttribute->setData(
- 'used_in_forms',
- ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
- );
- $vatIdAttribute->save();
-
- $entities = $customerSetup->getDefaultEntities();
- foreach ($entities as $entityName => $entity) {
- $customerSetup->addEntityType($entityName, $entity);
- }
-
- $customerSetup->updateAttribute(
- 'customer_address',
- 'street',
- 'backend_model',
- \Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend::class
- );
-
- $migrationSetup = $setup->createMigrationSetup();
-
- $migrationSetup->appendClassAliasReplace(
- 'customer_eav_attribute',
- 'data_model',
- Migration::ENTITY_TYPE_MODEL,
- Migration::FIELD_CONTENT_TYPE_PLAIN,
- ['attribute_id']
- );
- $migrationSetup->doUpdateClassAliases();
-
- $setup->endSetup();
- }
-}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php b/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php
new file mode 100644
index 0000000000000..bad5735bc3e3a
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/AddCustomerUpdatedAtAttribute.php
@@ -0,0 +1,91 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $customerSetup->addAttribute(
+ Customer::ENTITY,
+ 'updated_at',
+ [
+ 'type' => 'static',
+ 'label' => 'Updated At',
+ 'input' => 'date',
+ 'required' => false,
+ 'sort_order' => 87,
+ 'visible' => false,
+ 'system' => false,
+ ]
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ UpdateIdentifierCustomerAttributesVisibility::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.4';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php b/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php
new file mode 100644
index 0000000000000..ba50f6e17dd87
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/AddNonSpecifiedGenderAttributeOption.php
@@ -0,0 +1,94 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $entityTypeId = $customerSetup->getEntityTypeId(Customer::ENTITY);
+ $attributeId = $customerSetup->getAttributeId($entityTypeId, 'gender');
+
+ $option = ['attribute_id' => $attributeId, 'values' => [3 => 'Not Specified']];
+ $customerSetup->addAttributeOption($option);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ UpdateCustomerAttributesMetadata::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.2';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php
new file mode 100644
index 0000000000000..b066d14a3c63e
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/AddSecurityTrackingAttributes.php
@@ -0,0 +1,126 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $customerSetup->addAttribute(
+ Customer::ENTITY,
+ 'failures_num',
+ [
+ 'type' => 'static',
+ 'label' => 'Failures Number',
+ 'input' => 'hidden',
+ 'required' => false,
+ 'sort_order' => 100,
+ 'visible' => false,
+ 'system' => true,
+ ]
+ );
+
+ $customerSetup->addAttribute(
+ Customer::ENTITY,
+ 'first_failure',
+ [
+ 'type' => 'static',
+ 'label' => 'First Failure Date',
+ 'input' => 'date',
+ 'required' => false,
+ 'sort_order' => 110,
+ 'visible' => false,
+ 'system' => true,
+ ]
+ );
+
+ $customerSetup->addAttribute(
+ Customer::ENTITY,
+ 'lock_expires',
+ [
+ 'type' => 'static',
+ 'label' => 'Failures Number',
+ 'input' => 'date',
+ 'required' => false,
+ 'sort_order' => 120,
+ 'visible' => false,
+ 'system' => true,
+ ]
+ );
+ $configTable = $this->moduleDataSetup->getTable('core_config_data');
+
+ $this->moduleDataSetup->getConnection()->update(
+ $configTable,
+ ['value' => new \Zend_Db_Expr('value*24')],
+ ['path = ?' => \Magento\Customer\Model\Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD]
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ RemoveCheckoutRegisterAndUpdateAttributes::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.7';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php b/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php
new file mode 100644
index 0000000000000..83c5fe7ae6d1e
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/ConvertValidationRulesFromSerializedToJson.php
@@ -0,0 +1,84 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->fieldDataConverterFactory = $fieldDataConverterFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
+ $fieldDataConverter->convert(
+ $this->moduleDataSetup->getConnection(),
+ $this->moduleDataSetup->getTable('customer_eav_attribute'),
+ 'attribute_id',
+ 'validate_rules'
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ MigrateStoresAllowedCountriesToWebsite::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.11';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php
new file mode 100644
index 0000000000000..6e61b66f3c9db
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/DefaultCustomerGroupsAndAttributes.php
@@ -0,0 +1,174 @@
+customerSetupFactory = $customerSetupFactory;
+ $this->moduleDataSetup = $moduleDataSetup;
+ }
+
+ /**
+ * {@inheritdoc}
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+ */
+ public function apply()
+ {
+ /** @var CustomerSetup $customerSetup */
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+
+ // insert default customer groups
+ $this->moduleDataSetup->getConnection()->insertForce(
+ $this->moduleDataSetup->getTable('customer_group'),
+ ['customer_group_id' => 0, 'customer_group_code' => 'NOT LOGGED IN', 'tax_class_id' => 3]
+ );
+ $this->moduleDataSetup->getConnection()->insertForce(
+ $this->moduleDataSetup->getTable('customer_group'),
+ ['customer_group_id' => 1, 'customer_group_code' => 'General', 'tax_class_id' => 3]
+ );
+ $this->moduleDataSetup->getConnection()->insertForce(
+ $this->moduleDataSetup->getTable('customer_group'),
+ ['customer_group_id' => 2, 'customer_group_code' => 'Wholesale', 'tax_class_id' => 3]
+ );
+ $this->moduleDataSetup->getConnection()->insertForce(
+ $this->moduleDataSetup->getTable('customer_group'),
+ ['customer_group_id' => 3, 'customer_group_code' => 'Retailer', 'tax_class_id' => 3]
+ );
+
+ $customerSetup->installEntities();
+
+ $customerSetup->installCustomerForms();
+
+ $disableAGCAttribute = $customerSetup->getEavConfig()->getAttribute('customer', 'disable_auto_group_change');
+ $disableAGCAttribute->setData('used_in_forms', ['adminhtml_customer']);
+ $disableAGCAttribute->save();
+
+ $attributesInfo = [
+ 'vat_id' => [
+ 'label' => 'VAT number',
+ 'type' => 'static',
+ 'input' => 'text',
+ 'position' => 140,
+ 'visible' => true,
+ 'required' => false,
+ ],
+ 'vat_is_valid' => [
+ 'label' => 'VAT number validity',
+ 'visible' => false,
+ 'required' => false,
+ 'type' => 'static',
+ ],
+ 'vat_request_id' => [
+ 'label' => 'VAT number validation request ID',
+ 'type' => 'static',
+ 'visible' => false,
+ 'required' => false,
+ ],
+ 'vat_request_date' => [
+ 'label' => 'VAT number validation request date',
+ 'type' => 'static',
+ 'visible' => false,
+ 'required' => false,
+ ],
+ 'vat_request_success' => [
+ 'label' => 'VAT number validation request success',
+ 'visible' => false,
+ 'required' => false,
+ 'type' => 'static',
+ ],
+ ];
+
+ foreach ($attributesInfo as $attributeCode => $attributeParams) {
+ $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
+ }
+
+ $vatIdAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'vat_id');
+ $vatIdAttribute->setData(
+ 'used_in_forms',
+ ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
+ );
+ $vatIdAttribute->save();
+
+ $entities = $customerSetup->getDefaultEntities();
+ foreach ($entities as $entityName => $entity) {
+ $customerSetup->addEntityType($entityName, $entity);
+ }
+
+ $customerSetup->updateAttribute(
+ 'customer_address',
+ 'street',
+ 'backend_model',
+ \Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend::class
+ );
+
+ $migrationSetup = $this->moduleDataSetup->createMigrationSetup();
+
+ $migrationSetup->appendClassAliasReplace(
+ 'customer_eav_attribute',
+ 'data_model',
+ Migration::ENTITY_TYPE_MODEL,
+ Migration::FIELD_CONTENT_TYPE_PLAIN,
+ ['attribute_id']
+ );
+ $migrationSetup->doUpdateClassAliases();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php b/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php
new file mode 100644
index 0000000000000..7488f3fd4a920
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/MigrateStoresAllowedCountriesToWebsite.php
@@ -0,0 +1,176 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->storeManager = $storeManager;
+ $this->allowedCountries = $allowedCountries;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $this->moduleDataSetup->getConnection()->beginTransaction();
+
+ try {
+ $this->migrateStoresAllowedCountriesToWebsite();
+ $this->moduleDataSetup->getConnection()->commit();
+ } catch (\Exception $e) {
+ $this->moduleDataSetup->getConnection()->rollBack();
+ throw $e;
+ }
+ }
+
+ /**
+ * Merge allowed countries from stores to websites
+ *
+ * @return void
+ */
+ private function migrateStoresAllowedCountriesToWebsite()
+ {
+ $allowedCountries = [];
+ //Process Websites
+ foreach ($this->storeManager->getStores() as $store) {
+ $allowedCountries = $this->mergeAllowedCountries(
+ $allowedCountries,
+ $this->getAllowedCountries(ScopeInterface::SCOPE_STORE, $store->getId()),
+ $store->getWebsiteId()
+ );
+ }
+ //Process stores
+ foreach ($this->storeManager->getWebsites() as $website) {
+ $allowedCountries = $this->mergeAllowedCountries(
+ $allowedCountries,
+ $this->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId()),
+ $website->getId()
+ );
+ }
+
+ $connection = $this->moduleDataSetup->getConnection();
+
+ //Remove everything from stores scope
+ $connection->delete(
+ $this->moduleDataSetup->getTable('core_config_data'),
+ [
+ 'path = ?' => AllowedCountries::ALLOWED_COUNTRIES_PATH,
+ 'scope = ?' => ScopeInterface::SCOPE_STORES
+ ]
+ );
+
+ //Update websites
+ foreach ($allowedCountries as $scopeId => $countries) {
+ $connection->update(
+ $this->moduleDataSetup->getTable('core_config_data'),
+ [
+ 'value' => implode(',', $countries)
+ ],
+ [
+ 'path = ?' => AllowedCountries::ALLOWED_COUNTRIES_PATH,
+ 'scope_id = ?' => $scopeId,
+ 'scope = ?' => ScopeInterface::SCOPE_WEBSITES
+ ]
+ );
+ }
+ }
+
+ /**
+ * Retrieve countries not depending on global scope
+ *
+ * @param string $scope
+ * @param int $scopeCode
+ * @return array
+ */
+ private function getAllowedCountries($scope, $scopeCode)
+ {
+ return $this->allowedCountries->makeCountriesUnique(
+ $this->allowedCountries->getCountriesFromConfig($scope, $scopeCode)
+ );
+ }
+
+ /**
+ * Merge allowed countries between different scopes
+ *
+ * @param array $countries
+ * @param array $newCountries
+ * @param string $identifier
+ * @return array
+ */
+ private function mergeAllowedCountries(array $countries, array $newCountries, $identifier)
+ {
+ if (!isset($countries[$identifier])) {
+ $countries[$identifier] = $newCountries;
+ } else {
+ $countries[$identifier] = array_replace($countries[$identifier], $newCountries);
+ }
+
+ return $countries;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ UpdateAutocompleteOnStorefrontConfigPath::class
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.9';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php
new file mode 100644
index 0000000000000..51f54dc4a432c
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCheckoutRegisterAndUpdateAttributes.php
@@ -0,0 +1,136 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $this->moduleDataSetup->getConnection()->delete(
+ $this->moduleDataSetup->getTable('customer_form_attribute'),
+ ['form_code = ?' => 'checkout_register']
+ );
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $customerSetup->updateEntityType(
+ \Magento\Customer\Model\Customer::ENTITY,
+ 'entity_model',
+ \Magento\Customer\Model\ResourceModel\Customer::class
+ );
+ $customerSetup->updateEntityType(
+ \Magento\Customer\Model\Customer::ENTITY,
+ 'increment_model',
+ \Magento\Eav\Model\Entity\Increment\NumericValue::class
+ );
+ $customerSetup->updateEntityType(
+ \Magento\Customer\Model\Customer::ENTITY,
+ 'entity_attribute_collection',
+ \Magento\Customer\Model\ResourceModel\Attribute\Collection::class
+ );
+ $customerSetup->updateEntityType(
+ 'customer_address',
+ 'entity_model',
+ \Magento\Customer\Model\ResourceModel\Address::class
+ );
+ $customerSetup->updateEntityType(
+ 'customer_address',
+ 'entity_attribute_collection',
+ \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection::class
+ );
+ $customerSetup->updateAttribute(
+ 'customer_address',
+ 'country_id',
+ 'source_model',
+ \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Country::class
+ );
+ $customerSetup->updateAttribute(
+ 'customer_address',
+ 'region',
+ 'backend_model',
+ \Magento\Customer\Model\ResourceModel\Address\Attribute\Backend\Region::class
+ );
+ $customerSetup->updateAttribute(
+ 'customer_address',
+ 'region_id',
+ 'source_model',
+ \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Region::class
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ UpgradePasswordHashAndAddress::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.6';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php
new file mode 100644
index 0000000000000..30435ace54d46
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateAutocompleteOnStorefrontConfigPath.php
@@ -0,0 +1,72 @@
+moduleDataSetup = $moduleDataSetup;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $this->moduleDataSetup->getConnection()->update(
+ $this->moduleDataSetup->getTable('core_config_data'),
+ ['path' => \Magento\Customer\Model\Form::XML_PATH_ENABLE_AUTOCOMPLETE],
+ ['path = ?' => 'general/restriction/autocomplete_on_storefront']
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ AddSecurityTrackingAttributes::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.8';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php
new file mode 100644
index 0000000000000..938cd3cd52e73
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributeInputFilters.php
@@ -0,0 +1,102 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $entityAttributes = [
+ 'customer_address' => [
+ 'firstname' => [
+ 'input_filter' => 'trim'
+ ],
+ 'lastname' => [
+ 'input_filter' => 'trim'
+ ],
+ 'middlename' => [
+ 'input_filter' => 'trim'
+ ],
+ ],
+ 'customer' => [
+ 'firstname' => [
+ 'input_filter' => 'trim'
+ ],
+ 'lastname' => [
+ 'input_filter' => 'trim'
+ ],
+ 'middlename' => [
+ 'input_filter' => 'trim'
+ ],
+ ],
+ ];
+ $customerSetup->upgradeAttributes($entityAttributes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ UpdateVATNumber::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.13';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributesMetadata.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributesMetadata.php
new file mode 100644
index 0000000000000..5f4d9952590ba
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateCustomerAttributesMetadata.php
@@ -0,0 +1,203 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ /** @var CustomerSetup $customerSetup */
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $this->updateCustomerAttributesMetadata($customerSetup);
+ }
+
+ /**
+ * @param CustomerSetup $customerSetup
+ * @return void
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+ */
+ private function updateCustomerAttributesMetadata($customerSetup)
+ {
+ $entityAttributes = [
+ 'customer' => [
+ 'website_id' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'created_in' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'email' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'group_id' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'dob' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'taxvat' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'confirmation' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'created_at' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'gender' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ ],
+ 'customer_address' => [
+ 'company' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'street' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'city' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'country_id' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'region' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'region_id' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'postcode' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'telephone' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => true,
+ 'is_filterable_in_grid' => true,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'fax' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ ],
+ ];
+ $customerSetup->upgradeAttributes($entityAttributes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ DefaultCustomerGroupsAndAttributes::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.1';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php
new file mode 100644
index 0000000000000..7d0cad768d6b0
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateIdentifierCustomerAttributesVisibility.php
@@ -0,0 +1,100 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $entityAttributes = [
+ 'customer_address' => [
+ 'region_id' => [
+ 'is_used_in_grid' => false,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => false,
+ ],
+ 'firstname' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ 'lastname' => [
+ 'is_used_in_grid' => true,
+ 'is_visible_in_grid' => false,
+ 'is_filterable_in_grid' => false,
+ 'is_searchable_in_grid' => true,
+ ],
+ ],
+ ];
+ $customerSetup->upgradeAttributes($entityAttributes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ AddNonSpecifiedGenderAttributeOption::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.3';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php b/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php
new file mode 100644
index 0000000000000..d31301eedf4b1
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/UpdateVATNumber.php
@@ -0,0 +1,86 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $customerSetup = $this->customerSetupFactory->create(['resourceConnection' => $this->moduleDataSetup]);
+ $customerSetup->updateAttribute('customer_address', 'vat_id', 'frontend_label', 'VAT Number');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ ConvertValidationRulesFromSerializedToJson::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.12';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php b/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php
new file mode 100644
index 0000000000000..3b8f96a037343
--- /dev/null
+++ b/app/code/Magento/Customer/Setup/Patch/Data/UpgradePasswordHashAndAddress.php
@@ -0,0 +1,120 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->customerSetupFactory = $customerSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $this->upgradeHash();
+ $entityAttributes = [
+ 'customer_address' => [
+ 'fax' => [
+ 'is_visible' => false,
+ 'is_system' => false,
+ ],
+ ],
+ ];
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ $customerSetup->upgradeAttributes($entityAttributes);
+ }
+
+ /**
+ * @return void
+ */
+ private function upgradeHash()
+ {
+ $customerEntityTable = $this->moduleDataSetup->getTable('customer_entity');
+
+ $select = $this->moduleDataSetup->getConnection()->select()->from(
+ $customerEntityTable,
+ ['entity_id', 'password_hash']
+ );
+
+ $customers = $this->moduleDataSetup->getConnection()->fetchAll($select);
+ foreach ($customers as $customer) {
+ if ($customer['password_hash'] === null) {
+ continue;
+ }
+ list($hash, $salt) = explode(Encryptor::DELIMITER, $customer['password_hash']);
+
+ $newHash = $customer['password_hash'];
+ if (strlen($hash) === 32) {
+ $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_MD5]);
+ } elseif (strlen($hash) === 64) {
+ $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_SHA256]);
+ }
+
+ $bind = ['password_hash' => $newHash];
+ $where = ['entity_id = ?' => (int)$customer['entity_id']];
+ $this->moduleDataSetup->getConnection()->update($customerEntityTable, $bind, $where);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ AddCustomerUpdatedAtAttribute::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.5';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Customer/Setup/UpgradeData.php b/app/code/Magento/Customer/Setup/UpgradeData.php
deleted file mode 100644
index 5e08759958853..0000000000000
--- a/app/code/Magento/Customer/Setup/UpgradeData.php
+++ /dev/null
@@ -1,700 +0,0 @@
-customerSetupFactory = $customerSetupFactory;
- $this->indexerRegistry = $indexerRegistry;
- $this->eavConfig = $eavConfig;
-
- $this->fieldDataConverterFactory = $fieldDataConverterFactory ?: ObjectManager::getInstance()->get(
- FieldDataConverterFactory::class
- );
- }
-
- /**
- * {@inheritdoc}
- * @SuppressWarnings(PHPMD.NPathComplexity)
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- $setup->startSetup();
- /** @var CustomerSetup $customerSetup */
- $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
-
- if (version_compare($context->getVersion(), '2.0.6', '<')) {
- $this->upgradeVersionTwoZeroSix($customerSetup);
- }
-
- if (version_compare($context->getVersion(), '2.0.1', '<')) {
- $this->upgradeVersionTwoZeroOne($customerSetup);
- }
-
- if (version_compare($context->getVersion(), '2.0.2') < 0) {
- $this->upgradeVersionTwoZeroTwo($customerSetup);
- }
-
- if (version_compare($context->getVersion(), '2.0.3', '<')) {
- $this->upgradeVersionTwoZeroThree($customerSetup);
- }
-
- if (version_compare($context->getVersion(), '2.0.4', '<')) {
- $this->upgradeVersionTwoZeroFour($customerSetup);
- }
-
- if (version_compare($context->getVersion(), '2.0.5', '<')) {
- $this->upgradeVersionTwoZeroFive($customerSetup, $setup);
- }
-
- if (version_compare($context->getVersion(), '2.0.6', '<')) {
- $setup->getConnection()->delete(
- $setup->getTable('customer_form_attribute'),
- ['form_code = ?' => 'checkout_register']
- );
- }
-
- if (version_compare($context->getVersion(), '2.0.8', '<')) {
- $setup->getConnection()->update(
- $setup->getTable('core_config_data'),
- ['path' => \Magento\Customer\Model\Form::XML_PATH_ENABLE_AUTOCOMPLETE],
- ['path = ?' => 'general/restriction/autocomplete_on_storefront']
- );
- }
-
- if (version_compare($context->getVersion(), '2.0.7', '<')) {
- $this->upgradeVersionTwoZeroSeven($customerSetup);
- $this->upgradeCustomerPasswordResetlinkExpirationPeriodConfig($setup);
- }
-
- if (version_compare($context->getVersion(), '2.0.9', '<')) {
- $setup->getConnection()->beginTransaction();
-
- try {
- $this->migrateStoresAllowedCountriesToWebsite($setup);
- $setup->getConnection()->commit();
- } catch (\Exception $e) {
- $setup->getConnection()->rollBack();
- throw $e;
- }
- }
- if (version_compare($context->getVersion(), '2.0.11', '<')) {
- $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
- $fieldDataConverter->convert(
- $setup->getConnection(),
- $setup->getTable('customer_eav_attribute'),
- 'attribute_id',
- 'validate_rules'
- );
- }
-
- if (version_compare($context->getVersion(), '2.0.12', '<')) {
- $this->upgradeVersionTwoZeroTwelve($customerSetup);
- }
-
- if (version_compare($context->getVersion(), '2.0.13', '<')) {
- $this->upgradeVersionTwoZeroThirteen($customerSetup);
- }
-
- $this->eavConfig->clear();
- $setup->endSetup();
- }
-
- /**
- * Retrieve Store Manager
- *
- * @deprecated 100.1.3
- * @return StoreManagerInterface
- */
- private function getStoreManager()
- {
- if (!$this->storeManager) {
- $this->storeManager = ObjectManager::getInstance()->get(StoreManagerInterface::class);
- }
-
- return $this->storeManager;
- }
-
- /**
- * Retrieve Allowed Countries Reader
- *
- * @deprecated 100.1.3
- * @return AllowedCountries
- */
- private function getAllowedCountriesReader()
- {
- if (!$this->allowedCountriesReader) {
- $this->allowedCountriesReader = ObjectManager::getInstance()->get(AllowedCountries::class);
- }
-
- return $this->allowedCountriesReader;
- }
-
- /**
- * Merge allowed countries between different scopes
- *
- * @param array $countries
- * @param array $newCountries
- * @param string $identifier
- * @return array
- */
- private function mergeAllowedCountries(array $countries, array $newCountries, $identifier)
- {
- if (!isset($countries[$identifier])) {
- $countries[$identifier] = $newCountries;
- } else {
- $countries[$identifier] =
- array_replace($countries[$identifier], $newCountries);
- }
-
- return $countries;
- }
-
- /**
- * Retrieve countries not depending on global scope
- *
- * @param string $scope
- * @param int $scopeCode
- * @return array
- */
- private function getAllowedCountries($scope, $scopeCode)
- {
- $reader = $this->getAllowedCountriesReader();
- return $reader->makeCountriesUnique($reader->getCountriesFromConfig($scope, $scopeCode));
- }
-
- /**
- * Merge allowed countries from stores to websites
- *
- * @param SetupInterface $setup
- * @return void
- */
- private function migrateStoresAllowedCountriesToWebsite(SetupInterface $setup)
- {
- $allowedCountries = [];
- //Process Websites
- foreach ($this->getStoreManager()->getStores() as $store) {
- $allowedCountries = $this->mergeAllowedCountries(
- $allowedCountries,
- $this->getAllowedCountries(ScopeInterface::SCOPE_STORE, $store->getId()),
- $store->getWebsiteId()
- );
- }
- //Process stores
- foreach ($this->getStoreManager()->getWebsites() as $website) {
- $allowedCountries = $this->mergeAllowedCountries(
- $allowedCountries,
- $this->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId()),
- $website->getId()
- );
- }
-
- $connection = $setup->getConnection();
-
- //Remove everything from stores scope
- $connection->delete(
- $setup->getTable('core_config_data'),
- [
- 'path = ?' => AllowedCountries::ALLOWED_COUNTRIES_PATH,
- 'scope = ?' => ScopeInterface::SCOPE_STORES
- ]
- );
-
- //Update websites
- foreach ($allowedCountries as $scopeId => $countries) {
- $connection->update(
- $setup->getTable('core_config_data'),
- [
- 'value' => implode(',', $countries)
- ],
- [
- 'path = ?' => AllowedCountries::ALLOWED_COUNTRIES_PATH,
- 'scope_id = ?' => $scopeId,
- 'scope = ?' => ScopeInterface::SCOPE_WEBSITES
- ]
- );
- }
- }
-
- /**
- * @param array $entityAttributes
- * @param CustomerSetup $customerSetup
- * @return void
- */
- protected function upgradeAttributes(array $entityAttributes, CustomerSetup $customerSetup)
- {
- foreach ($entityAttributes as $entityType => $attributes) {
- foreach ($attributes as $attributeCode => $attributeData) {
- $attribute = $customerSetup->getEavConfig()->getAttribute($entityType, $attributeCode);
- foreach ($attributeData as $key => $value) {
- $attribute->setData($key, $value);
- }
- $attribute->save();
- }
- }
- }
-
- /**
- * @param ModuleDataSetupInterface $setup
- * @return void
- */
- private function upgradeHash($setup)
- {
- $customerEntityTable = $setup->getTable('customer_entity');
-
- $select = $setup->getConnection()->select()->from(
- $customerEntityTable,
- ['entity_id', 'password_hash']
- );
-
- $customers = $setup->getConnection()->fetchAll($select);
- foreach ($customers as $customer) {
- if ($customer['password_hash'] === null) {
- continue;
- }
- list($hash, $salt) = explode(Encryptor::DELIMITER, $customer['password_hash']);
-
- $newHash = $customer['password_hash'];
- if (strlen($hash) === 32) {
- $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_MD5]);
- } elseif (strlen($hash) === 64) {
- $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_SHA256]);
- }
-
- $bind = ['password_hash' => $newHash];
- $where = ['entity_id = ?' => (int)$customer['entity_id']];
- $setup->getConnection()->update($customerEntityTable, $bind, $where);
- }
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @return void
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- private function upgradeVersionTwoZeroOne($customerSetup)
- {
- $entityAttributes = [
- 'customer' => [
- 'website_id' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- 'created_in' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- 'email' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => true,
- ],
- 'group_id' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- 'dob' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- 'taxvat' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- 'confirmation' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- 'created_at' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- 'gender' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- ],
- 'customer_address' => [
- 'company' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- 'street' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- 'city' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- 'country_id' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- 'region' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- 'region_id' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => false,
- ],
- 'postcode' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => true,
- ],
- 'telephone' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => true,
- 'is_filterable_in_grid' => true,
- 'is_searchable_in_grid' => true,
- ],
- 'fax' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- ],
- ];
- $this->upgradeAttributes($entityAttributes, $customerSetup);
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @return void
- */
- private function upgradeVersionTwoZeroTwo($customerSetup)
- {
- $entityTypeId = $customerSetup->getEntityTypeId(Customer::ENTITY);
- $attributeId = $customerSetup->getAttributeId($entityTypeId, 'gender');
-
- $option = ['attribute_id' => $attributeId, 'values' => [3 => 'Not Specified']];
- $customerSetup->addAttributeOption($option);
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @return void
- */
- private function upgradeVersionTwoZeroThree($customerSetup)
- {
- $entityAttributes = [
- 'customer_address' => [
- 'region_id' => [
- 'is_used_in_grid' => false,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => false,
- ],
- 'firstname' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- 'lastname' => [
- 'is_used_in_grid' => true,
- 'is_visible_in_grid' => false,
- 'is_filterable_in_grid' => false,
- 'is_searchable_in_grid' => true,
- ],
- ],
- ];
- $this->upgradeAttributes($entityAttributes, $customerSetup);
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @return void
- */
- private function upgradeVersionTwoZeroFour($customerSetup)
- {
- $customerSetup->addAttribute(
- Customer::ENTITY,
- 'updated_at',
- [
- 'type' => 'static',
- 'label' => 'Updated At',
- 'input' => 'date',
- 'required' => false,
- 'sort_order' => 87,
- 'visible' => false,
- 'system' => false,
- ]
- );
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @param ModuleDataSetupInterface $setup
- * @return void
- */
- private function upgradeVersionTwoZeroFive($customerSetup, $setup)
- {
- $this->upgradeHash($setup);
- $entityAttributes = [
- 'customer_address' => [
- 'fax' => [
- 'is_visible' => false,
- 'is_system' => false,
- ],
- ],
- ];
- $this->upgradeAttributes($entityAttributes, $customerSetup);
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @return void
- */
- private function upgradeVersionTwoZeroSix($customerSetup)
- {
- $customerSetup->updateEntityType(
- \Magento\Customer\Model\Customer::ENTITY,
- 'entity_model',
- \Magento\Customer\Model\ResourceModel\Customer::class
- );
- $customerSetup->updateEntityType(
- \Magento\Customer\Model\Customer::ENTITY,
- 'increment_model',
- \Magento\Eav\Model\Entity\Increment\NumericValue::class
- );
- $customerSetup->updateEntityType(
- \Magento\Customer\Model\Customer::ENTITY,
- 'entity_attribute_collection',
- \Magento\Customer\Model\ResourceModel\Attribute\Collection::class
- );
- $customerSetup->updateEntityType(
- 'customer_address',
- 'entity_model',
- \Magento\Customer\Model\ResourceModel\Address::class
- );
- $customerSetup->updateEntityType(
- 'customer_address',
- 'entity_attribute_collection',
- \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection::class
- );
- $customerSetup->updateAttribute(
- 'customer_address',
- 'country_id',
- 'source_model',
- \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Country::class
- );
- $customerSetup->updateAttribute(
- 'customer_address',
- 'region',
- 'backend_model',
- \Magento\Customer\Model\ResourceModel\Address\Attribute\Backend\Region::class
- );
- $customerSetup->updateAttribute(
- 'customer_address',
- 'region_id',
- 'source_model',
- \Magento\Customer\Model\ResourceModel\Address\Attribute\Source\Region::class
- );
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @return void
- */
- private function upgradeVersionTwoZeroSeven($customerSetup)
- {
- $customerSetup->addAttribute(
- Customer::ENTITY,
- 'failures_num',
- [
- 'type' => 'static',
- 'label' => 'Failures Number',
- 'input' => 'hidden',
- 'required' => false,
- 'sort_order' => 100,
- 'visible' => false,
- 'system' => true,
- ]
- );
-
- $customerSetup->addAttribute(
- Customer::ENTITY,
- 'first_failure',
- [
- 'type' => 'static',
- 'label' => 'First Failure Date',
- 'input' => 'date',
- 'required' => false,
- 'sort_order' => 110,
- 'visible' => false,
- 'system' => true,
- ]
- );
-
- $customerSetup->addAttribute(
- Customer::ENTITY,
- 'lock_expires',
- [
- 'type' => 'static',
- 'label' => 'Failures Number',
- 'input' => 'date',
- 'required' => false,
- 'sort_order' => 120,
- 'visible' => false,
- 'system' => true,
- ]
- );
- }
-
- /**
- * @param CustomerSetup $customerSetup
- * @return void
- */
- private function upgradeVersionTwoZeroTwelve(CustomerSetup $customerSetup)
- {
- $customerSetup->updateAttribute('customer_address', 'vat_id', 'frontend_label', 'VAT Number');
- }
-
- /**
- * @param ModuleDataSetupInterface $setup
- * @return void
- */
- private function upgradeCustomerPasswordResetlinkExpirationPeriodConfig($setup)
- {
- $configTable = $setup->getTable('core_config_data');
-
- $setup->getConnection()->update(
- $configTable,
- ['value' => new \Zend_Db_Expr('value*24')],
- ['path = ?' => \Magento\Customer\Model\Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD]
- );
- }
-
- /**
- * @param CustomerSetup $customerSetup
- */
- private function upgradeVersionTwoZeroThirteen(CustomerSetup $customerSetup)
- {
- $entityAttributes = [
- 'customer_address' => [
- 'firstname' => [
- 'input_filter' => 'trim'
- ],
- 'lastname' => [
- 'input_filter' => 'trim'
- ],
- 'middlename' => [
- 'input_filter' => 'trim'
- ],
- ],
- 'customer' => [
- 'firstname' => [
- 'input_filter' => 'trim'
- ],
- 'lastname' => [
- 'input_filter' => 'trim'
- ],
- 'middlename' => [
- 'input_filter' => 'trim'
- ],
- ],
- ];
- $this->upgradeAttributes($entityAttributes, $customerSetup);
- }
-}
diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php
index 59c940bb85297..8e1aeaa87a10e 100644
--- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php
@@ -206,4 +206,53 @@ public function testExecuteGetParamImage()
);
$this->assertSame($this->resultRawMock, $controller->execute());
}
+
+ /**
+ * @expectedException \Magento\Framework\Exception\NotFoundException
+ * @expectedExceptionMessage Page not found.
+ */
+ public function testExecuteInvalidFile()
+ {
+ $file = '../../../app/etc/env.php';
+ $decodedFile = base64_encode($file);
+ $fileName = 'customer/' . $file;
+ $path = 'path';
+
+ $this->requestMock->expects($this->atLeastOnce())->method('getParam')->with('file')->willReturn($decodedFile);
+
+ $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
+
+ $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')
+ ->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)
+ ->willReturn($this->directoryMock);
+
+ $this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(false);
+
+ $this->objectManagerMock->expects($this->any())->method('get')
+ ->willReturnMap(
+ [
+ [\Magento\Framework\Filesystem::class, $this->fileSystemMock],
+ [\Magento\MediaStorage\Helper\File\Storage::class, $this->storage],
+ ]
+ );
+
+ $this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
+ $fileFactoryMock = $this->createMock(
+ \Magento\Framework\App\Response\Http\FileFactory::class,
+ [],
+ [],
+ '',
+ false
+ );
+
+ $controller = $this->objectManager->getObject(
+ \Magento\Customer\Controller\Adminhtml\Index\Viewfile::class,
+ [
+ 'context' => $this->contextMock,
+ 'urlDecoder' => $this->urlDecoderMock,
+ 'fileFactory' => $fileFactoryMock,
+ ]
+ );
+ $controller->execute();
+ }
}
diff --git a/app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php b/app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php
index e63ce964c15b0..0138c6c709b7c 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php
@@ -11,9 +11,9 @@
use Magento\Customer\Model\Account\Redirect;
use Magento\Customer\Model\Url as CustomerUrl;
use Magento\Framework\Controller\ResultFactory;
+use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\Url\HostChecker;
use Magento\Store\Model\ScopeInterface;
-use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -147,15 +147,15 @@ protected function setUp()
$this->model = $objectManager->getObject(
\Magento\Customer\Model\Account\Redirect::class,
[
- 'request' => $this->request,
- 'customerSession' => $this->customerSession,
- 'scopeConfig' => $this->scopeConfig,
- 'storeManager' => $this->storeManager,
- 'url' => $this->url,
- 'urlDecoder' => $this->urlDecoder,
- 'customerUrl' => $this->customerUrl,
- 'resultFactory' => $this->resultFactory,
- 'hostChecker' => $this->hostChecker
+ 'request' => $this->request,
+ 'customerSession' => $this->customerSession,
+ 'scopeConfig' => $this->scopeConfig,
+ 'storeManager' => $this->storeManager,
+ 'url' => $this->url,
+ 'urlDecoder' => $this->urlDecoder,
+ 'customerUrl' => $this->customerUrl,
+ 'resultFactory' => $this->resultFactory,
+ 'hostChecker' => $this->hostChecker,
]
);
}
@@ -191,57 +191,31 @@ public function testGetRedirect(
$redirectToDashboard
) {
// Preparations for method updateLastCustomerId()
- $this->customerSession->expects($this->once())
- ->method('getLastCustomerId')
- ->willReturn($customerId);
- $this->customerSession->expects($this->any())
- ->method('isLoggedIn')
- ->willReturn($customerLoggedIn);
- $this->customerSession->expects($this->any())
- ->method('getId')
- ->willReturn($lastCustomerId);
- $this->customerSession->expects($this->any())
- ->method('unsBeforeAuthUrl')
- ->willReturnSelf();
+ $this->customerSession->expects($this->once())->method('getLastCustomerId')->willReturn($customerId);
+ $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn($customerLoggedIn);
+ $this->customerSession->expects($this->any())->method('getId')->willReturn($lastCustomerId);
+ $this->customerSession->expects($this->any())->method('unsBeforeAuthUrl')->willReturnSelf();
$this->customerSession->expects($this->any())
->method('setLastCustomerId')
->with($lastCustomerId)
->willReturnSelf();
// Preparations for method prepareRedirectUrl()
- $this->store->expects($this->once())
- ->method('getBaseUrl')
- ->willReturn($baseUrl);
+ $this->store->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
- $this->customerSession->expects($this->any())
- ->method('getBeforeAuthUrl')
- ->willReturn($beforeAuthUrl);
- $this->customerSession->expects($this->any())
- ->method('setBeforeAuthUrl')
- ->willReturnSelf();
- $this->customerSession->expects($this->any())
- ->method('getAfterAuthUrl')
- ->willReturn($afterAuthUrl);
+ $this->customerSession->expects($this->any())->method('getBeforeAuthUrl')->willReturn($beforeAuthUrl);
+ $this->customerSession->expects($this->any())->method('setBeforeAuthUrl')->willReturnSelf();
+ $this->customerSession->expects($this->any())->method('getAfterAuthUrl')->willReturn($afterAuthUrl);
$this->customerSession->expects($this->any())
->method('setAfterAuthUrl')
->with($beforeAuthUrl)
->willReturnSelf();
- $this->customerSession->expects($this->any())
- ->method('getBeforeRequestParams')
- ->willReturn(false);
-
- $this->customerUrl->expects($this->any())
- ->method('getAccountUrl')
- ->willReturn($accountUrl);
- $this->customerUrl->expects($this->any())
- ->method('getLoginUrl')
- ->willReturn($loginUrl);
- $this->customerUrl->expects($this->any())
- ->method('getLogoutUrl')
- ->willReturn($logoutUrl);
- $this->customerUrl->expects($this->any())
- ->method('getDashboardUrl')
- ->willReturn($dashboardUrl);
+ $this->customerSession->expects($this->any())->method('getBeforeRequestParams')->willReturn(false);
+
+ $this->customerUrl->expects($this->any())->method('getAccountUrl')->willReturn($accountUrl);
+ $this->customerUrl->expects($this->any())->method('getLoginUrl')->willReturn($loginUrl);
+ $this->customerUrl->expects($this->any())->method('getLogoutUrl')->willReturn($logoutUrl);
+ $this->customerUrl->expects($this->any())->method('getDashboardUrl')->willReturn($dashboardUrl);
$this->scopeConfig->expects($this->any())
->method('isSetFlag')
@@ -253,25 +227,19 @@ public function testGetRedirect(
->with(CustomerUrl::REFERER_QUERY_PARAM_NAME)
->willReturn($referer);
- $this->urlDecoder->expects($this->any())
- ->method('decode')
- ->with($referer)
- ->willReturn($referer);
+ $this->urlDecoder->expects($this->any())->method('decode')->with($referer)->willReturn($referer);
- $this->url->expects($this->any())
- ->method('isOwnOriginUrl')
- ->willReturn(true);
+ $this->url->expects($this->any())->method('isOwnOriginUrl')->willReturn(true);
- $this->resultRedirect->expects($this->once())
- ->method('setUrl')
- ->with($beforeAuthUrl)
- ->willReturnSelf();
+ $this->resultRedirect->expects($this->once())->method('setUrl')->with($beforeAuthUrl)->willReturnSelf();
$this->resultFactory->expects($this->once())
->method('create')
->with(ResultFactory::TYPE_REDIRECT)
->willReturn($this->resultRedirect);
+ $this->hostChecker->expects($this->any())->method('isOwnOrigin')->willReturn(true);
+
$this->model->getRedirect();
}
@@ -306,6 +274,21 @@ public function getRedirectDataProvider()
[1, 2, 'referer', 'base', 'logout', '', 'account', 'login', 'logout', 'dashboard', false, true],
// Default redirect
[1, 2, 'referer', 'base', 'defined', '', 'account', 'login', 'logout', 'dashboard', true, true],
+ // Logout, Without Redirect to Dashboard
+ [
+ 'customer_id' => 1,
+ 'last_customer_id' => 2,
+ 'referer' => 'http://base.com/customer/account/logoutSuccess/',
+ 'base_url' => 'http://base.com/',
+ 'before_auth_url' => 'http://base.com/',
+ 'after_auth_url' => 'http://base.com/customer/account/',
+ 'account_url' => 'account',
+ 'login_url' => 'login',
+ 'logout_url' => 'logout',
+ 'dashboard_url' => 'dashboard',
+ 'is_customer_logged_id_flag' => true,
+ 'redirect_to_dashboard_flag' => false,
+ ],
];
}
diff --git a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php
index 0ca79833e8a13..cf55928a6d30f 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php
@@ -127,6 +127,21 @@ class AccountManagementTest extends \PHPUnit\Framework\TestCase
*/
private $accountConfirmation;
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Session\SessionManagerInterface
+ */
+ private $sessionManager;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory
+ */
+ private $visitorCollectionFactory;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Session\SaveHandlerInterface
+ */
+ private $saveHandler;
+
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
@@ -179,6 +194,19 @@ protected function setUp()
$this->dateTimeFactory = $this->createMock(DateTimeFactory::class);
$this->accountConfirmation = $this->createMock(AccountConfirmation::class);
+ $this->visitorCollectionFactory = $this->getMockBuilder(
+ \Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory::class
+ )
+ ->disableOriginalConstructor()
+ ->setMethods(['create'])
+ ->getMock();
+ $this->sessionManager = $this->getMockBuilder(\Magento\Framework\Session\SessionManagerInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->saveHandler = $this->getMockBuilder(\Magento\Framework\Session\SaveHandlerInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->accountManagement = $this->objectManagerHelper->getObject(
\Magento\Customer\Model\AccountManagement::class,
@@ -207,16 +235,22 @@ protected function setUp()
'objectFactory' => $this->objectFactory,
'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter,
'dateTimeFactory' => $this->dateTimeFactory,
- 'accountConfirmation' => $this->accountConfirmation
+ 'accountConfirmation' => $this->accountConfirmation,
+ 'sessionManager' => $this->sessionManager,
+ 'saveHandler' => $this->saveHandler,
+ 'visitorCollectionFactory' => $this->visitorCollectionFactory,
]
);
- $reflection = new \ReflectionClass(get_class($this->accountManagement));
- $reflectionProperty = $reflection->getProperty('authentication');
- $reflectionProperty->setAccessible(true);
- $reflectionProperty->setValue($this->accountManagement, $this->authenticationMock);
- $reflectionProperty = $reflection->getProperty('emailNotification');
- $reflectionProperty->setAccessible(true);
- $reflectionProperty->setValue($this->accountManagement, $this->emailNotificationMock);
+ $this->objectManagerHelper->setBackwardCompatibleProperty(
+ $this->accountManagement,
+ 'authentication',
+ $this->authenticationMock
+ );
+ $this->objectManagerHelper->setBackwardCompatibleProperty(
+ $this->accountManagement,
+ 'emailNotification',
+ $this->emailNotificationMock
+ );
}
/**
@@ -672,14 +706,14 @@ public function dataProviderCheckPasswordStrength()
'testNumber' => 1,
'password' => 'qwer',
'minPasswordLength' => 5,
- 'minCharacterSetsNum' => 1
+ 'minCharacterSetsNum' => 1,
],
[
'testNumber' => 2,
'password' => 'wrfewqedf1',
'minPasswordLength' => 5,
- 'minCharacterSetsNum' => 3
- ]
+ 'minCharacterSetsNum' => 3,
+ ],
];
}
@@ -711,7 +745,8 @@ public function testCreateAccountWithPasswordInputException(
AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER,
'default',
null,
- $minCharacterSetsNum],
+ $minCharacterSetsNum,
+ ],
]
)
);
@@ -795,7 +830,8 @@ public function testCreateAccountWithPassword()
AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER,
'default',
null,
- $minCharacterSetsNum],
+ $minCharacterSetsNum,
+ ],
[
AccountManagement::XML_PATH_REGISTER_EMAIL_TEMPLATE,
ScopeInterface::SCOPE_STORE,
@@ -806,8 +842,8 @@ public function testCreateAccountWithPassword()
AccountManagement::XML_PATH_REGISTER_EMAIL_IDENTITY,
ScopeInterface::SCOPE_STORE,
1,
- $sender
- ]
+ $sender,
+ ],
]
);
$this->string->expects($this->any())
@@ -1276,27 +1312,67 @@ private function reInitModel()
{
$this->customerSecure = $this->getMockBuilder(\Magento\Customer\Model\Data\CustomerSecure::class)
->disableOriginalConstructor()
- ->setMethods(['getRpToken', 'getRpTokenCreatedAt'])
+ ->setMethods(
+ [
+ 'getRpToken',
+ 'getRpTokenCreatedAt',
+ 'getPasswordHash',
+ 'setPasswordHash',
+ 'setRpToken',
+ 'setRpTokenCreatedAt',
+ ]
+ )
->getMock();
-
- $this->customerSecure
- ->expects($this->any())
+ $this->customerSecure->expects($this->any())
->method('getRpToken')
->willReturn('newStringToken');
-
$pastDateTime = '2016-10-25 00:00:00';
-
- $this->customerSecure
- ->expects($this->any())
+ $this->customerSecure->expects($this->any())
->method('getRpTokenCreatedAt')
->willReturn($pastDateTime);
-
$this->customer = $this->getMockBuilder(\Magento\Customer\Model\Customer::class)
->disableOriginalConstructor()
->setMethods(['getResetPasswordLinkExpirationPeriod'])
->getMock();
$this->prepareDateTimeFactory();
+ $this->sessionManager = $this->getMockBuilder(\Magento\Framework\Session\SessionManagerInterface::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['destroy', 'start', 'writeClose'])
+ ->getMockForAbstractClass();
+ $this->visitorCollectionFactory = $this->getMockBuilder(
+ \Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory::class
+ )
+ ->disableOriginalConstructor()
+ ->setMethods(['create'])
+ ->getMock();
+ $this->saveHandler = $this->getMockBuilder(\Magento\Framework\Session\SaveHandlerInterface::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['destroy'])
+ ->getMockForAbstractClass();
+
+ $dateTime = '2017-10-25 18:57:08';
+ $timestamp = '1508983028';
+ $dateTimeMock = $this->getMockBuilder(\DateTime::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['format', 'getTimestamp', 'setTimestamp'])
+ ->getMock();
+
+ $dateTimeMock->expects($this->any())
+ ->method('format')
+ ->with(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)
+ ->willReturn($dateTime);
+ $dateTimeMock->expects($this->any())
+ ->method('getTimestamp')
+ ->willReturn($timestamp);
+ $dateTimeMock->expects($this->any())
+ ->method('setTimestamp')
+ ->willReturnSelf();
+ $dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['create'])
+ ->getMock();
+ $dateTimeFactory->expects($this->any())->method('create')->willReturn($dateTimeMock);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->accountManagement = $this->objectManagerHelper->getObject(
@@ -1306,13 +1382,23 @@ private function reInitModel()
'customerRegistry' => $this->customerRegistry,
'customerRepository' => $this->customerRepository,
'customerModel' => $this->customer,
- 'dateTimeFactory' => $this->dateTimeFactory,
+ 'dateTimeFactory' => $dateTimeFactory,
+ 'stringHelper' => $this->string,
+ 'scopeConfig' => $this->scopeConfig,
+ 'sessionManager' => $this->sessionManager,
+ 'visitorCollectionFactory' => $this->visitorCollectionFactory,
+ 'saveHandler' => $this->saveHandler,
+ 'encryptor' => $this->encryptor,
+ 'dataProcessor' => $this->dataObjectProcessor,
+ 'storeManager' => $this->storeManager,
+ 'transportBuilder' => $this->transportBuilder,
]
);
- $reflection = new \ReflectionClass(get_class($this->accountManagement));
- $reflectionProperty = $reflection->getProperty('authentication');
- $reflectionProperty->setAccessible(true);
- $reflectionProperty->setValue($this->accountManagement, $this->authenticationMock);
+ $this->objectManagerHelper->setBackwardCompatibleProperty(
+ $this->accountManagement,
+ 'authentication',
+ $this->authenticationMock
+ );
}
/**
@@ -1326,6 +1412,7 @@ public function testChangePassword()
$newPassword = 'abcdefg';
$passwordHash = '1a2b3f4c';
+ $this->reInitModel();
$customer = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
->getMock();
$customer->expects($this->any())
@@ -1341,24 +1428,20 @@ public function testChangePassword()
$this->authenticationMock->expects($this->once())
->method('authenticate');
- $customerSecure = $this->getMockBuilder(\Magento\Customer\Model\Data\CustomerSecure::class)
- ->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])
- ->disableOriginalConstructor()
- ->getMock();
- $customerSecure->expects($this->once())
+ $this->customerSecure->expects($this->once())
->method('setRpToken')
->with(null);
- $customerSecure->expects($this->once())
+ $this->customerSecure->expects($this->once())
->method('setRpTokenCreatedAt')
->willReturnSelf();
- $customerSecure->expects($this->any())
+ $this->customerSecure->expects($this->any())
->method('getPasswordHash')
->willReturn($passwordHash);
$this->customerRegistry->expects($this->any())
->method('retrieveSecureData')
->with($customerId)
- ->willReturn($customerSecure);
+ ->willReturn($this->customerSecure);
$this->scopeConfig->expects($this->any())
->method('getValue')
@@ -1374,7 +1457,7 @@ public function testChangePassword()
AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER,
'default',
null,
- 1
+ 1,
],
]
);
@@ -1388,9 +1471,85 @@ public function testChangePassword()
->method('save')
->with($customer);
+ $this->sessionManager->expects($this->atLeastOnce())->method('start');
+ $this->sessionManager->expects($this->atLeastOnce())->method('writeClose');
+ $this->sessionManager->expects($this->atLeastOnce())->method('getSessionId');
+
+ $visitor = $this->getMockBuilder(\Magento\Customer\Model\Visitor::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getSessionId'])
+ ->getMock();
+ $visitor->expects($this->atLeastOnce())->method('getSessionId')
+ ->willReturnOnConsecutiveCalls('session_id_1', 'session_id_2');
+ $visitorCollection = $this->getMockBuilder(
+ \Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory::class
+ )
+ ->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'getItems'])->getMock();
+ $visitorCollection->expects($this->atLeastOnce())->method('addFieldToFilter')->willReturnSelf();
+ $visitorCollection->expects($this->atLeastOnce())->method('getItems')->willReturn([$visitor, $visitor]);
+ $this->visitorCollectionFactory->expects($this->atLeastOnce())->method('create')
+ ->willReturn($visitorCollection);
+ $this->saveHandler->expects($this->atLeastOnce())->method('destroy')
+ ->withConsecutive(
+ ['session_id_1'],
+ ['session_id_2']
+ );
+
$this->assertTrue($this->accountManagement->changePassword($email, $currentPassword, $newPassword));
}
+ public function testResetPassword()
+ {
+ $customerEmail = 'customer@example.com';
+ $customerId = '1';
+ $resetToken = 'newStringToken';
+ $newPassword = 'new_password';
+
+ $this->reInitModel();
+ $customer = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)->getMock();
+ $customer->expects($this->any())->method('getId')->willReturn($customerId);
+ $this->customerRepository->expects($this->atLeastOnce())->method('get')->with($customerEmail)
+ ->willReturn($customer);
+ $this->customer->expects($this->atLeastOnce())->method('getResetPasswordLinkExpirationPeriod')
+ ->willReturn(100000);
+ $this->string->expects($this->any())->method('strlen')->willReturnCallback(
+ function ($string) {
+ return strlen($string);
+ }
+ );
+ $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')
+ ->willReturn($this->customerSecure);
+
+ $this->customerSecure->expects($this->once())->method('setRpToken')->with(null);
+ $this->customerSecure->expects($this->once())->method('setRpTokenCreatedAt')->with(null);
+ $this->customerSecure->expects($this->any())->method('setPasswordHash')->willReturn(null);
+
+ $this->sessionManager->expects($this->atLeastOnce())->method('destroy');
+ $this->sessionManager->expects($this->atLeastOnce())->method('start');
+ $this->sessionManager->expects($this->atLeastOnce())->method('writeClose');
+ $this->sessionManager->expects($this->atLeastOnce())->method('getSessionId');
+ $visitor = $this->getMockBuilder(\Magento\Customer\Model\Visitor::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getSessionId'])
+ ->getMock();
+ $visitor->expects($this->atLeastOnce())->method('getSessionId')
+ ->willReturnOnConsecutiveCalls('session_id_1', 'session_id_2');
+ $visitorCollection = $this->getMockBuilder(
+ \Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory::class
+ )
+ ->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'getItems'])->getMock();
+ $visitorCollection->expects($this->atLeastOnce())->method('addFieldToFilter')->willReturnSelf();
+ $visitorCollection->expects($this->atLeastOnce())->method('getItems')->willReturn([$visitor, $visitor]);
+ $this->visitorCollectionFactory->expects($this->atLeastOnce())->method('create')
+ ->willReturn($visitorCollection);
+ $this->saveHandler->expects($this->atLeastOnce())->method('destroy')
+ ->withConsecutive(
+ ['session_id_1'],
+ ['session_id_2']
+ );
+ $this->assertTrue($this->accountManagement->resetPassword($customerEmail, $resetToken, $newPassword));
+ }
+
/**
* @return void
*/
@@ -1466,10 +1625,10 @@ public function testAuthenticate()
->withConsecutive(
[
'customer_customer_authenticated',
- ['model' => $customerModel, 'password' => $password]
+ ['model' => $customerModel, 'password' => $password],
],
[
- 'customer_data_object_login', ['customer' => $customerData]
+ 'customer_data_object_login', ['customer' => $customerData],
]
);
diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php
index a94b7e39bc0eb..0fc3d01673c47 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php
@@ -6,6 +6,8 @@
namespace Magento\Customer\Test\Unit\Model\Address;
+use Magento\Customer\Model\Address\CompositeValidator;
+
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
@@ -41,6 +43,12 @@ class AbstractAddressTest extends \PHPUnit\Framework\TestCase
/** @var \Magento\Customer\Model\Address\AbstractAddress */
protected $model;
+ /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
+ private $objectManager;
+
+ /** @var \Magento\Customer\Model\Address\CompositeValidator|\PHPUnit_Framework_MockObject_MockObject */
+ private $compositeValidatorMock;
+
protected function setUp()
{
$this->contextMock = $this->createMock(\Magento\Framework\Model\Context::class);
@@ -69,8 +77,9 @@ protected function setUp()
$this->resourceCollectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\AbstractDb::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->model = $objectManager->getObject(
+ $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $this->compositeValidatorMock = $this->createMock(CompositeValidator::class);
+ $this->model = $this->objectManager->getObject(
\Magento\Customer\Model\Address\AbstractAddress::class,
[
'context' => $this->contextMock,
@@ -81,7 +90,8 @@ protected function setUp()
'regionFactory' => $this->regionFactoryMock,
'countryFactory' => $this->countryFactoryMock,
'resource' => $this->resourceMock,
- 'resourceCollection' => $this->resourceCollectionMock
+ 'resourceCollection' => $this->resourceCollectionMock,
+ 'compositeValidator' => $this->compositeValidatorMock,
]
);
}
@@ -275,28 +285,15 @@ public function testSetDataWithObject()
}
/**
- * @param $data
- * @param $expected
+ * @param array $data
+ * @param array|bool $expected
+ * @return void
*
* @dataProvider validateDataProvider
*/
- public function testValidate($data, $expected)
+ public function testValidate(array $data, $expected)
{
- $attributeMock = $this->createMock(\Magento\Eav\Model\Entity\Attribute::class);
- $attributeMock->expects($this->any())
- ->method('getIsRequired')
- ->willReturn(true);
-
- $this->eavConfigMock->expects($this->any())
- ->method('getAttribute')
- ->will($this->returnValue($attributeMock));
-
- $this->directoryDataMock->expects($this->once())
- ->method('getCountriesWithOptionalZip')
- ->will($this->returnValue([]));
-
- $this->directoryDataMock->expects($this->never())
- ->method('isRegionRequired');
+ $this->compositeValidatorMock->method('validate')->with($this->model)->willReturn($expected);
foreach ($data as $key => $value) {
$this->model->setData($key, $value);
@@ -349,6 +346,10 @@ public function validateDataProvider()
array_merge(array_diff_key($data, ['postcode' => '']), ['country_id' => $countryId++]),
['"postcode" is required. Enter and try again.'],
],
+ 'region_id' => [
+ array_merge($data, ['country_id' => $countryId++, 'region_id' => 2]),
+ ['Invalid value of "2" provided for the regionId field.'],
+ ],
'country_id' => [
array_diff_key($data, ['country_id' => '']),
['"countryId" is required. Enter and try again.'],
@@ -388,4 +389,13 @@ public function getStreetFullDataProvider()
['single line', 'single line'],
];
}
+
+ protected function tearDown()
+ {
+ $this->objectManager->setBackwardCompatibleProperty(
+ $this->model,
+ '_countryModels',
+ []
+ );
+ }
}
diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/Validator/CountryTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/Validator/CountryTest.php
new file mode 100644
index 0000000000000..e70f93edab12c
--- /dev/null
+++ b/app/code/Magento/Customer/Test/Unit/Model/Address/Validator/CountryTest.php
@@ -0,0 +1,160 @@
+directoryDataMock = $this->createMock(\Magento\Directory\Helper\Data::class);
+ $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $this->model = $this->objectManager->getObject(
+ \Magento\Customer\Model\Address\Validator\Country::class,
+ [
+ 'directoryData' => $this->directoryDataMock,
+ ]
+ );
+ }
+
+ /**
+ * @param array $data
+ * @param array $countryIds
+ * @param array $allowedRegions
+ * @param array $expected
+ * @return void
+ *
+ * @dataProvider validateDataProvider
+ */
+ public function testValidate(array $data, array $countryIds, array $allowedRegions, array $expected)
+ {
+ $addressMock = $this
+ ->getMockBuilder(\Magento\Customer\Model\Address\AbstractAddress::class)
+ ->disableOriginalConstructor()
+ ->setMethods(
+ [
+ 'getCountryId',
+ 'getRegion',
+ 'getRegionId',
+ 'getCountryModel',
+ ]
+ )->getMock();
+
+ $this->directoryDataMock->expects($this->any())
+ ->method('isRegionRequired')
+ ->willReturn($data['regionRequired']);
+
+ $countryCollectionMock = $this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Country\Collection::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getAllIds'])
+ ->getMock();
+
+ $this->directoryDataMock->expects($this->any())
+ ->method('getCountryCollection')
+ ->willReturn($countryCollectionMock);
+
+ $countryCollectionMock->expects($this->any())->method('getAllIds')->willReturn($countryIds);
+
+ $addressMock->method('getCountryId')->willReturn($data['country_id']);
+
+ $countryModelMock = $this->getMockBuilder(\Magento\Directory\Model\Country::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getRegionCollection'])
+ ->getMock();
+
+ $addressMock->method('getCountryModel')->willReturn($countryModelMock);
+
+ $regionCollectionMock = $this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Region\Collection::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getAllIds'])
+ ->getMock();
+ $countryModelMock
+ ->expects($this->any())
+ ->method('getRegionCollection')
+ ->willReturn($regionCollectionMock);
+ $regionCollectionMock->expects($this->any())->method('getAllIds')->willReturn($allowedRegions);
+
+ $addressMock->method('getRegionId')->willReturn($data['region_id']);
+ $addressMock->method('getRegion')->willReturn(null);
+
+ $actual = $this->model->validate($addressMock);
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @return array
+ */
+ public function validateDataProvider()
+ {
+ $countryId = 1;
+ $data = [
+ 'firstname' => 'First Name',
+ 'lastname' => 'Last Name',
+ 'street' => "Street 1\nStreet 2",
+ 'city' => 'Odessa',
+ 'telephone' => '555-55-55',
+ 'country_id' => $countryId,
+ 'postcode' => 07201,
+ 'region_id' => 1,
+ 'region' => '',
+ 'regionRequired' => false,
+ 'company' => 'Magento',
+ 'fax' => '222-22-22',
+ ];
+ $result = [
+ 'country_id1' => [
+ array_merge($data, ['country_id' => null]),
+ [],
+ [1],
+ ['"countryId" is required. Enter and try again.'],
+ ],
+ 'country_id2' => [
+ $data,
+ [],
+ [1],
+ ['Invalid value of "' . $countryId . '" provided for the countryId field.'],
+ ],
+ 'region' => [
+ array_merge($data, ['country_id' => $countryId, 'regionRequired' => true]),
+ [$countryId++],
+ [],
+ ['"region" is required. Enter and try again.'],
+ ],
+ 'region_id1' => [
+ array_merge($data, ['country_id' => $countryId, 'regionRequired' => true, 'region_id' => '']),
+ [$countryId++],
+ [1],
+ ['"regionId" is required. Enter and try again.'],
+ ],
+ 'region_id2' => [
+ array_merge($data, ['country_id' => $countryId, 'region_id' => 2]),
+ [$countryId++],
+ [1],
+ ['Invalid value of "2" provided for the regionId field.'],
+ ],
+ 'validated' => [
+ array_merge($data, ['country_id' => $countryId]),
+ [$countryId],
+ ['1'],
+ [],
+ ],
+ ];
+
+ return $result;
+ }
+}
diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/Validator/GeneralTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/Validator/GeneralTest.php
new file mode 100644
index 0000000000000..058a69e86b43a
--- /dev/null
+++ b/app/code/Magento/Customer/Test/Unit/Model/Address/Validator/GeneralTest.php
@@ -0,0 +1,140 @@
+directoryDataMock = $this->createMock(\Magento\Directory\Helper\Data::class);
+ $this->eavConfigMock = $this->createMock(\Magento\Eav\Model\Config::class);
+ $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $this->model = $this->objectManager->getObject(
+ \Magento\Customer\Model\Address\Validator\General::class,
+ [
+ 'eavConfig' => $this->eavConfigMock,
+ 'directoryData' => $this->directoryDataMock,
+ ]
+ );
+ }
+
+ /**
+ * @param array $data
+ * @param array $expected
+ * @return void
+ *
+ * @dataProvider validateDataProvider
+ */
+ public function testValidate(array $data, array $expected)
+ {
+ $addressMock = $this
+ ->getMockBuilder(\Magento\Customer\Model\Address\AbstractAddress::class)
+ ->disableOriginalConstructor()
+ ->setMethods(
+ [
+ 'getFirstname',
+ 'getLastname',
+ 'getStreetLine',
+ 'getCity',
+ 'getTelephone',
+ 'getFax',
+ 'getCompany',
+ 'getPostcode',
+ 'getCountryId',
+ ]
+ )->getMock();
+
+ $attributeMock = $this->createMock(\Magento\Eav\Model\Entity\Attribute::class);
+ $attributeMock->expects($this->any())
+ ->method('getIsRequired')
+ ->willReturn(true);
+
+ $this->eavConfigMock->expects($this->any())
+ ->method('getAttribute')
+ ->will($this->returnValue($attributeMock));
+
+ $this->directoryDataMock->expects($this->once())
+ ->method('getCountriesWithOptionalZip')
+ ->will($this->returnValue([]));
+
+ $addressMock->method('getFirstName')->willReturn($data['firstname']);
+ $addressMock->method('getLastname')->willReturn($data['lastname']);
+ $addressMock->method('getStreetLine')->with(1)->willReturn($data['street']);
+ $addressMock->method('getCity')->willReturn($data['city']);
+ $addressMock->method('getTelephone')->willReturn($data['telephone']);
+ $addressMock->method('getFax')->willReturn($data['fax']);
+ $addressMock->method('getCompany')->willReturn($data['company']);
+ $addressMock->method('getPostcode')->willReturn($data['postcode']);
+ $addressMock->method('getCountryId')->willReturn($data['country_id']);
+
+ $actual = $this->model->validate($addressMock);
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @return array
+ */
+ public function validateDataProvider()
+ {
+ $countryId = 1;
+ $data = [
+ 'firstname' => 'First Name',
+ 'lastname' => 'Last Name',
+ 'street' => "Street 1\nStreet 2",
+ 'city' => 'Odessa',
+ 'telephone' => '555-55-55',
+ 'country_id' => $countryId,
+ 'postcode' => 07201,
+ 'company' => 'Magento',
+ 'fax' => '222-22-22',
+ ];
+ $result = [
+ 'firstname' => [
+ array_merge(array_merge($data, ['firstname' => '']), ['country_id' => $countryId++]),
+ ['"firstname" is required. Enter and try again.'],
+ ],
+ 'lastname' => [
+ array_merge(array_merge($data, ['lastname' => '']), ['country_id' => $countryId++]),
+ ['"lastname" is required. Enter and try again.'],
+ ],
+ 'street' => [
+ array_merge(array_merge($data, ['street' => '']), ['country_id' => $countryId++]),
+ ['"street" is required. Enter and try again.'],
+ ],
+ 'city' => [
+ array_merge(array_merge($data, ['city' => '']), ['country_id' => $countryId++]),
+ ['"city" is required. Enter and try again.'],
+ ],
+ 'telephone' => [
+ array_merge(array_merge($data, ['telephone' => '']), ['country_id' => $countryId++]),
+ ['"telephone" is required. Enter and try again.'],
+ ],
+ 'postcode' => [
+ array_merge(array_merge($data, ['postcode' => '']), ['country_id' => $countryId++]),
+ ['"postcode" is required. Enter and try again.'],
+ ],
+ 'validated' => [array_merge($data, ['country_id' => $countryId++]), []],
+ ];
+
+ return $result;
+ }
+}
diff --git a/app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerNotificationTest.php b/app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerNotificationTest.php
index 14a95dda76f61..c3c853bca1469 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerNotificationTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerNotificationTest.php
@@ -5,82 +5,119 @@
*/
namespace Magento\Customer\Test\Unit\Model\Plugin;
+use Magento\Backend\App\AbstractAction;
+use Magento\Customer\Api\CustomerRepositoryInterface;
+use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Model\Customer\NotificationStorage;
use Magento\Customer\Model\Plugin\CustomerNotification;
+use Magento\Customer\Model\Session;
+use Magento\Framework\App\Area;
+use Magento\Framework\App\RequestInterface;
+use Magento\Framework\App\State;
+use Magento\Framework\Exception\NoSuchEntityException;
+use Psr\Log\LoggerInterface;
class CustomerNotificationTest extends \PHPUnit\Framework\TestCase
{
- /** @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject */
- protected $session;
+ /** @var Session|\PHPUnit_Framework_MockObject_MockObject */
+ private $sessionMock;
- /** @var \Magento\Customer\Model\Customer\NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
- protected $notificationStorage;
+ /** @var NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
+ private $notificationStorageMock;
- /** @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
- protected $customerRepository;
+ /** @var CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
+ private $customerRepositoryMock;
- /** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */
- protected $appState;
+ /** @var State|\PHPUnit_Framework_MockObject_MockObject */
+ private $appStateMock;
- /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
- protected $request;
+ /** @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
+ private $requestMock;
- /** @var \Magento\Backend\App\AbstractAction|\PHPUnit_Framework_MockObject_MockObject */
- protected $abstractAction;
+ /** @var AbstractAction|\PHPUnit_Framework_MockObject_MockObject */
+ private $abstractActionMock;
+
+ /** @var LoggerInterface */
+ private $loggerMock;
/** @var CustomerNotification */
- protected $plugin;
+ private $plugin;
+
+ /** @var int */
+ private static $customerId = 1;
protected function setUp()
{
- $this->session = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
+ $this->sessionMock = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
+ ->setMethods(['getCustomerId', 'setCustomerData', 'setCustomerGroupId', 'regenerateId'])
->getMock();
- $this->notificationStorage = $this->getMockBuilder(\Magento\Customer\Model\Customer\NotificationStorage::class)
+ $this->notificationStorageMock = $this->getMockBuilder(NotificationStorage::class)
->disableOriginalConstructor()
+ ->setMethods(['isExists', 'remove'])
->getMock();
- $this->customerRepository = $this->getMockBuilder(\Magento\Customer\Api\CustomerRepositoryInterface::class)
+ $this->customerRepositoryMock = $this->getMockBuilder(CustomerRepositoryInterface::class)
->getMockForAbstractClass();
- $this->abstractAction = $this->getMockBuilder(\Magento\Backend\App\AbstractAction::class)
+ $this->abstractActionMock = $this->getMockBuilder(AbstractAction::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
- $this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
+ $this->requestMock = $this->getMockBuilder(RequestInterface::class)
->setMethods(['isPost'])
->getMockForAbstractClass();
- $this->appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
- ->disableOriginalConstructor()->getMock();
+ $this->appStateMock = $this->getMockBuilder(State::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getAreaCode'])
+ ->getMock();
+
+ $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
+ $this->appStateMock->method('getAreaCode')->willReturn(Area::AREA_FRONTEND);
+ $this->requestMock->method('isPost')->willReturn(true);
+ $this->sessionMock->method('getCustomerId')->willReturn(self::$customerId);
+ $this->notificationStorageMock->expects($this->any())
+ ->method('isExists')
+ ->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, self::$customerId)
+ ->willReturn(true);
+
$this->plugin = new CustomerNotification(
- $this->session,
- $this->notificationStorage,
- $this->appState,
- $this->customerRepository
+ $this->sessionMock,
+ $this->notificationStorageMock,
+ $this->appStateMock,
+ $this->customerRepositoryMock,
+ $this->loggerMock
);
}
public function testBeforeDispatch()
{
- $customerId = 1;
$customerGroupId =1;
- $this->appState->expects($this->any())
- ->method('getAreaCode')
- ->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
- $this->request->expects($this->any())->method('isPost')->willReturn(true);
- $customerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
- ->getMockForAbstractClass();
- $customerMock->expects($this->any())->method('getGroupId')->willReturn($customerGroupId);
- $this->customerRepository->expects($this->any())
+
+ $customerMock = $this->getMockForAbstractClass(CustomerInterface::class);
+ $customerMock->method('getGroupId')->willReturn($customerGroupId);
+ $customerMock->method('getId')->willReturn(self::$customerId);
+
+ $this->customerRepositoryMock->expects($this->once())
->method('getById')
- ->with($customerId)
+ ->with(self::$customerId)
->willReturn($customerMock);
- $this->session->expects($this->any())->method('getCustomerId')->willReturn($customerId);
- $this->session->expects($this->any())->method('setCustomerData')->with($customerMock);
- $this->session->expects($this->any())->method('setCustomerGroupId')->with($customerGroupId);
- $this->session->expects($this->once())->method('regenerateId');
- $this->notificationStorage->expects($this->any())
- ->method('isExists')
- ->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId)
- ->willReturn(true);
+ $this->notificationStorageMock->expects($this->once())
+ ->method('remove')
+ ->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, self::$customerId);
+
+ $this->sessionMock->expects($this->once())->method('setCustomerData')->with($customerMock);
+ $this->sessionMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId);
+ $this->sessionMock->expects($this->once())->method('regenerateId');
+
+ $this->plugin->beforeDispatch($this->abstractActionMock, $this->requestMock);
+ }
+
+ public function testBeforeDispatchWithNoCustomerFound()
+ {
+ $this->customerRepositoryMock->method('getById')
+ ->with(self::$customerId)
+ ->willThrowException(new NoSuchEntityException());
+ $this->loggerMock->expects($this->once())
+ ->method('error');
- $this->plugin->beforeDispatch($this->abstractAction, $this->request);
+ $this->plugin->beforeDispatch($this->abstractActionMock, $this->requestMock);
}
}
diff --git a/app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php b/app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php
index a05e9e23ef94f..06133dd89d754 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php
@@ -7,6 +7,7 @@
namespace Magento\Customer\Test\Unit\Model\ResourceModel;
use Magento\Customer\Api\CustomerMetadataInterface;
+use Magento\Customer\Model\Customer\NotificationStorage;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
/**
@@ -18,82 +19,87 @@ class CustomerRepositoryTest extends \PHPUnit\Framework\TestCase
/**
* @var \Magento\Customer\Model\CustomerFactory|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $customerFactory;
+ private $customerFactory;
/**
* @var \Magento\Customer\Model\Data\CustomerSecureFactory|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $customerSecureFactory;
+ private $customerSecureFactory;
/**
* @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $customerRegistry;
+ private $customerRegistry;
/**
* @var \Magento\Customer\Model\ResourceModel\AddressRepository|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $addressRepository;
+ private $addressRepository;
/**
* @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $customerResourceModel;
+ private $customerResourceModel;
/**
* @var \Magento\Customer\Api\CustomerMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $customerMetadata;
+ private $customerMetadata;
/**
* @var \Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $searchResultsFactory;
+ private $searchResultsFactory;
/**
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $eventManager;
+ private $eventManager;
/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $storeManager;
+ private $storeManager;
/**
* @var \Magento\Framework\Api\ExtensibleDataObjectConverter|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $extensibleDataObjectConverter;
+ private $extensibleDataObjectConverter;
/**
* @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $dataObjectHelper;
+ private $dataObjectHelper;
/**
* @var \Magento\Framework\Api\ImageProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $imageProcessor;
+ private $imageProcessor;
/**
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $extensionAttributesJoinProcessor;
+ private $extensionAttributesJoinProcessor;
/**
* @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $customer;
+ private $customer;
/**
* @var CollectionProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $collectionProcessorMock;
+ /**
+ * @var NotificationStorage|\PHPUnit_Framework_MockObject_MockObject
+ */
+ private $notificationStorage;
+
/**
* @var \Magento\Customer\Model\ResourceModel\CustomerRepository
*/
- protected $model;
+ private $model;
protected function setUp()
{
@@ -158,6 +164,10 @@ protected function setUp()
);
$this->collectionProcessorMock = $this->getMockBuilder(CollectionProcessorInterface::class)
->getMock();
+ $this->notificationStorage = $this->getMockBuilder(NotificationStorage::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
$this->model = new \Magento\Customer\Model\ResourceModel\CustomerRepository(
$this->customerFactory,
$this->customerSecureFactory,
@@ -172,7 +182,8 @@ protected function setUp()
$this->dataObjectHelper,
$this->imageProcessor,
$this->extensionAttributesJoinProcessor,
- $this->collectionProcessorMock
+ $this->collectionProcessorMock,
+ $this->notificationStorage
);
}
@@ -793,6 +804,9 @@ public function testDelete()
$this->customerRegistry->expects($this->atLeastOnce())
->method('remove')
->with($customerId);
+ $this->notificationStorage->expects($this->atLeastOnce())
+ ->method('remove')
+ ->with(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customerId);
$this->assertTrue($this->model->delete($this->customer));
}
diff --git a/app/code/Magento/Customer/Test/Unit/Model/VisitorTest.php b/app/code/Magento/Customer/Test/Unit/Model/VisitorTest.php
index ca6b8708f695c..ec787b9d3c873 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/VisitorTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/VisitorTest.php
@@ -60,15 +60,15 @@ protected function setUp()
'commit',
'clean',
])->disableOriginalConstructor()->getMock();
- $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('visitor_id'));
- $this->resource->expects($this->any())->method('addCommitCallback')->will($this->returnSelf());
+ $this->resource->expects($this->any())->method('getIdFieldName')->willReturn('visitor_id');
+ $this->resource->expects($this->any())->method('addCommitCallback')->willReturnSelf();
$arguments = $this->objectManagerHelper->getConstructArguments(
\Magento\Customer\Model\Visitor::class,
[
'registry' => $this->registry,
'session' => $this->session,
- 'resource' => $this->resource
+ 'resource' => $this->resource,
]
);
@@ -77,14 +77,13 @@ protected function setUp()
public function testInitByRequest()
{
- $this->session->expects($this->once())->method('getSessionId')
- ->will($this->returnValue('asdfhasdfjhkj2198sadf8sdf897'));
- $this->visitor->initByRequest(null);
- $this->assertEquals('asdfhasdfjhkj2198sadf8sdf897', $this->visitor->getSessionId());
-
- $this->visitor->setData(['visitor_id' => 1]);
+ $oldSessionId = 'asdfhasdfjhkj2198sadf8sdf897';
+ $newSessionId = 'bsdfhasdfjhkj2198sadf8sdf897';
+ $this->session->expects($this->any())->method('getSessionId')->willReturn($newSessionId);
+ $this->session->expects($this->atLeastOnce())->method('getVisitorData')
+ ->willReturn(['session_id' => $oldSessionId]);
$this->visitor->initByRequest(null);
- $this->assertNull($this->visitor->getSessionId());
+ $this->assertEquals($newSessionId, $this->visitor->getSessionId());
}
public function testSaveByRequest()
@@ -101,7 +100,7 @@ public function testIsModuleIgnored()
'registry' => $this->registry,
'session' => $this->session,
'resource' => $this->resource,
- 'ignores' => ['test_route_name' => true]
+ 'ignores' => ['test_route_name' => true],
]
);
$request = new \Magento\Framework\DataObject(['route_name' => 'test_route_name']);
@@ -164,7 +163,7 @@ public function testBindQuoteDestroy()
public function testClean()
{
- $this->resource->expects($this->once())->method('clean')->with($this->visitor)->will($this->returnSelf());
+ $this->resource->expects($this->once())->method('clean')->with($this->visitor)->willReturnSelf();
$this->visitor->clean();
}
}
diff --git a/app/code/Magento/Customer/etc/db_schema.xml b/app/code/Magento/Customer/etc/db_schema.xml
index 490211e4307ab..368ca417432fd 100644
--- a/app/code/Magento/Customer/etc/db_schema.xml
+++ b/app/code/Magento/Customer/etc/db_schema.xml
@@ -6,7 +6,7 @@
*/
-->
+ xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
diff --git a/app/code/Magento/Customer/etc/di.xml b/app/code/Magento/Customer/etc/di.xml
index 6df04c7f89656..43c2b9cf7bb80 100644
--- a/app/code/Magento/Customer/etc/di.xml
+++ b/app/code/Magento/Customer/etc/di.xml
@@ -420,4 +420,17 @@
+
+
+ Magento\Framework\Session\SessionManagerInterface\Proxy
+
+
+
+
+
+ - Magento\Customer\Model\Address\Validator\General
+ - Magento\Customer\Model\Address\Validator\Country
+
+
+
diff --git a/app/code/Magento/Customer/etc/events.xml b/app/code/Magento/Customer/etc/events.xml
index 66c9a3813892c..d841d8faa9c38 100644
--- a/app/code/Magento/Customer/etc/events.xml
+++ b/app/code/Magento/Customer/etc/events.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/app/code/Magento/Customer/etc/module.xml b/app/code/Magento/Customer/etc/module.xml
index 2dfe561d0da8f..853157fed1f5d 100644
--- a/app/code/Magento/Customer/etc/module.xml
+++ b/app/code/Magento/Customer/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js b/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js
index 71ca63f6750bb..be2e0aedfe4bb 100644
--- a/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js
+++ b/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js
@@ -31,6 +31,8 @@ define([
this.options.cache.label = $(this.options.passwordStrengthMeterLabelSelector, this.element);
// We need to look outside the module for backward compatibility, since someone can already use the module.
+ // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the
+ // newsletter email field or any other "email" field.
this.options.cache.email = $(this.options.formSelector).find(this.options.emailSelector);
this._bind();
},
@@ -74,7 +76,9 @@ define([
'password-not-equal-to-user-name': this.options.cache.email.val()
});
- if (password.toLowerCase() === this.options.cache.email.val().toLowerCase()) {
+ // We should only perform this check in case there is an email field on screen
+ if (this.options.cache.email.length &&
+ password.toLowerCase() === this.options.cache.email.val().toLowerCase()) {
displayScore = 1;
} else {
isValid = $.validator.validateSingleElement(this.options.cache.input);
diff --git a/app/code/Magento/CustomerAnalytics/etc/module.xml b/app/code/Magento/CustomerAnalytics/etc/module.xml
index adc4f8dd849c2..a6a3380b3462e 100644
--- a/app/code/Magento/CustomerAnalytics/etc/module.xml
+++ b/app/code/Magento/CustomerAnalytics/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/CustomerGraphQl/etc/module.xml b/app/code/Magento/CustomerGraphQl/etc/module.xml
index 88f08623c717d..c3149965b0fe0 100644
--- a/app/code/Magento/CustomerGraphQl/etc/module.xml
+++ b/app/code/Magento/CustomerGraphQl/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/CustomerImportExport/etc/module.xml b/app/code/Magento/CustomerImportExport/etc/module.xml
index 865b2e991418d..2b351d06a5ffd 100644
--- a/app/code/Magento/CustomerImportExport/etc/module.xml
+++ b/app/code/Magento/CustomerImportExport/etc/module.xml
@@ -6,6 +6,6 @@
*/
-->
-
+
diff --git a/app/code/Magento/Deploy/Console/ConsoleLogger.php b/app/code/Magento/Deploy/Console/ConsoleLogger.php
index a7d3b48fde130..0ca34439c7d4f 100644
--- a/app/code/Magento/Deploy/Console/ConsoleLogger.php
+++ b/app/code/Magento/Deploy/Console/ConsoleLogger.php
@@ -82,8 +82,8 @@ class ConsoleLogger extends AbstractLogger
LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
- LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
- LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
+ LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL,
+ LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE,
LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG
];
diff --git a/app/code/Magento/Deploy/Model/Filesystem.php b/app/code/Magento/Deploy/Model/Filesystem.php
index 3dd28f4d3e820..59880d2d669b4 100644
--- a/app/code/Magento/Deploy/Model/Filesystem.php
+++ b/app/code/Magento/Deploy/Model/Filesystem.php
@@ -10,6 +10,7 @@
use Magento\Framework\App\DeploymentConfig\Writer;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\Validator\Locale;
use Magento\User\Model\ResourceModel\User\Collection as UserCollection;
/**
@@ -100,6 +101,11 @@ class Filesystem
*/
private $userCollection;
+ /**
+ * @var Locale
+ */
+ private $locale;
+
/**
* @param \Magento\Framework\App\DeploymentConfig\Writer $writer
* @param \Magento\Framework\App\DeploymentConfig\Reader $reader
@@ -109,6 +115,9 @@ class Filesystem
* @param \Magento\Framework\Filesystem\Driver\File $driverFile
* @param \Magento\Store\Model\Config\StoreView $storeView
* @param \Magento\Framework\ShellInterface $shell
+ * @param UserCollection|null $userCollection
+ * @param Locale|null $locale
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Framework\App\DeploymentConfig\Writer $writer,
@@ -118,7 +127,9 @@ public function __construct(
\Magento\Framework\App\Filesystem\DirectoryList $directoryList,
\Magento\Framework\Filesystem\Driver\File $driverFile,
\Magento\Store\Model\Config\StoreView $storeView,
- \Magento\Framework\ShellInterface $shell
+ \Magento\Framework\ShellInterface $shell,
+ UserCollection $userCollection = null,
+ Locale $locale = null
) {
$this->writer = $writer;
$this->reader = $reader;
@@ -128,6 +139,8 @@ public function __construct(
$this->driverFile = $driverFile;
$this->storeView = $storeView;
$this->shell = $shell;
+ $this->userCollection = $userCollection ?: $this->objectManager->get(UserCollection::class);
+ $this->locale = $locale ?: $this->objectManager->get(Locale::class);
$this->functionCallPath =
PHP_BINARY . ' -f ' . BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento ';
}
@@ -193,16 +206,17 @@ protected function deployStaticContent(
private function getAdminUserInterfaceLocales()
{
$locales = [];
- foreach ($this->getUserCollection() as $user) {
+ foreach ($this->userCollection as $user) {
$locales[] = $user->getInterfaceLocale();
}
return $locales;
}
/**
- * Get used store and admin user locales
+ * Get used store and admin user locales.
*
* @return array
+ * @throws \InvalidArgumentException if unknown locale is provided by the store configuration
*/
private function getUsedLocales()
{
@@ -210,25 +224,19 @@ private function getUsedLocales()
$this->storeView->retrieveLocales(),
$this->getAdminUserInterfaceLocales()
);
- return array_unique($usedLocales);
- }
- /**
- * Get user collection
- *
- * @return UserCollection
- * @deprecated 100.1.0 Added to not break backward compatibility of the constructor signature
- * by injecting the new dependency directly.
- * The method can be removed in a future major release, when constructor signature can be changed.
- */
- private function getUserCollection()
- {
- if (!($this->userCollection instanceof UserCollection)) {
- return \Magento\Framework\App\ObjectManager::getInstance()->get(
- UserCollection::class
- );
- }
- return $this->userCollection;
+ return array_map(
+ function ($locale) {
+ if (!$this->locale->isValid($locale)) {
+ throw new \InvalidArgumentException(
+ $locale . ' argument has invalid value, run info:language:list for list of available locales'
+ );
+ }
+
+ return $locale;
+ },
+ array_unique($usedLocales)
+ );
}
/**
diff --git a/app/code/Magento/Deploy/Model/Mode.php b/app/code/Magento/Deploy/Model/Mode.php
index c7ee9b6849665..d4ae72d63bce7 100644
--- a/app/code/Magento/Deploy/Model/Mode.php
+++ b/app/code/Magento/Deploy/Model/Mode.php
@@ -236,7 +236,7 @@ private function saveAppConfigs($mode)
$configs = $this->configProvider->getConfigs($this->getMode(), $mode);
foreach ($configs as $path => $item) {
$this->emulatedAreaProcessor->process(function () use ($path, $item) {
- $this->processorFacadeFactory->create()->process(
+ $this->processorFacadeFactory->create()->processWithLockTarget(
$path,
$item['value'],
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
diff --git a/app/code/Magento/Deploy/Process/Queue.php b/app/code/Magento/Deploy/Process/Queue.php
index e5e10c8f54a19..75b21b2b7fb84 100644
--- a/app/code/Magento/Deploy/Process/Queue.php
+++ b/app/code/Magento/Deploy/Process/Queue.php
@@ -161,7 +161,7 @@ public function process()
foreach ($packages as $name => $packageJob) {
$this->assertAndExecute($name, $packages, $packageJob);
}
- $this->logger->notice('.');
+ $this->logger->info('.');
sleep(3);
foreach ($this->inProgress as $name => $package) {
if ($this->isDeployed($package)) {
@@ -214,7 +214,7 @@ private function awaitForAllProcesses()
unset($this->inProgress[$name]);
}
}
- $this->logger->notice('.');
+ $this->logger->info('.');
sleep(5);
}
if ($this->isCanBeParalleled()) {
diff --git a/app/code/Magento/Deploy/Service/DeployPackage.php b/app/code/Magento/Deploy/Service/DeployPackage.php
index 2e7b10a159c3a..7a5eb09912471 100644
--- a/app/code/Magento/Deploy/Service/DeployPackage.php
+++ b/app/code/Magento/Deploy/Service/DeployPackage.php
@@ -267,7 +267,7 @@ private function register(Package $package, PackageFile $file = null, $skipLoggi
$this->deployStaticFile->writeTmpFile('info.json', $package->getPath(), json_encode($info));
if (!$skipLogging) {
- $this->logger->notice($logMessage);
+ $this->logger->info($logMessage);
}
}
}
diff --git a/app/code/Magento/Deploy/Test/Unit/Model/FilesystemTest.php b/app/code/Magento/Deploy/Test/Unit/Model/FilesystemTest.php
index 673f31c04ffd3..00f70c6527a0d 100644
--- a/app/code/Magento/Deploy/Test/Unit/Model/FilesystemTest.php
+++ b/app/code/Magento/Deploy/Test/Unit/Model/FilesystemTest.php
@@ -5,47 +5,64 @@
*/
namespace Magento\Deploy\Test\Unit\Model;
+use Magento\Deploy\Model\Filesystem as DeployFilesystem;
+use Magento\Framework\Filesystem;
+use Magento\Framework\Filesystem\Directory\WriteInterface;
+use Magento\Framework\ObjectManagerInterface;
+use Magento\Framework\ShellInterface;
+use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
+use Magento\Store\Model\Config\StoreView;
+use Magento\User\Model\ResourceModel\User\Collection;
+use Magento\User\Model\User;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
+use Symfony\Component\Console\Output\OutputInterface;
+use Magento\Framework\Validator\Locale;
+use Magento\Framework\Setup\Lists;
+
+/**
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
+ */
class FilesystemTest extends \PHPUnit\Framework\TestCase
{
/**
- * @var \Magento\Store\Model\Config\StoreView
+ * @var StoreView|MockObject
*/
- private $storeViewMock;
+ private $storeView;
/**
- * @var \Magento\Framework\ShellInterface
+ * @var ShellInterface|MockObject
*/
- private $shellMock;
+ private $shell;
/**
- * @var \Magento\User\Model\ResourceModel\User\Collection
+ * @var OutputInterface|MockObject
*/
- private $userCollectionMock;
+ private $output;
/**
- * @var \Symfony\Component\Console\Output\OutputInterface
+ * @var Filesystem|MockObject
*/
- private $outputMock;
+ private $filesystem;
/**
- * @var \Magento\Framework\Filesystem
+ * @var WriteInterface|MockObject
*/
- private $filesystemMock;
+ private $directoryWrite;
/**
- * @var \Magento\Framework\Filesystem\Directory\WriteInterface
+ * @var Collection|MockObject
*/
- private $directoryWriteMock;
+ private $userCollection;
/**
- * @var \Magento\Framework\ObjectManagerInterface
+ * @var ObjectManagerInterface|MockObject
*/
- private $objectManagerMock;
+ private $objectManager;
/**
- * @var \Magento\Deploy\Model\Filesystem
+ * @var DeployFilesystem
*/
- private $filesystem;
+ private $deployFilesystem;
/**
* @var string
@@ -54,75 +71,146 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
-
- $this->storeViewMock = $this->createMock(\Magento\Store\Model\Config\StoreView::class);
- $this->shellMock = $this->createMock(\Magento\Framework\ShellInterface::class);
- $this->userCollectionMock = $this->createMock(\Magento\User\Model\ResourceModel\User\Collection::class);
- $this->outputMock = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
- $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
- $this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
- $this->directoryWriteMock = $this->createMock(\Magento\Framework\Filesystem\Directory\WriteInterface::class);
- $this->filesystemMock->expects($this->any())
- ->method('getDirectoryWrite')
- ->willReturn($this->directoryWriteMock);
- $this->filesystem = $objectManager->getObject(
- \Magento\Deploy\Model\Filesystem::class,
+ $objectManager = new ObjectManager($this);
+
+ $this->storeView = $this->getMockBuilder(StoreView::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->shell = $this->getMockBuilder(ShellInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->output = $this->getMockBuilder(OutputInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->objectManager = $this->getMockBuilder(ObjectManagerInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->filesystem = $this->getMockBuilder(Filesystem::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->directoryWrite = $this->getMockBuilder(WriteInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->filesystem->method('getDirectoryWrite')
+ ->willReturn($this->directoryWrite);
+
+ $this->userCollection = $this->getMockBuilder(Collection::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $lists = $this->getMockBuilder(Lists::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $lists->method('getLocaleList')
+ ->willReturn([
+ 'fr_FR' => 'France',
+ 'de_DE' => 'Germany',
+ 'nl_NL' => 'Netherlands',
+ 'en_US' => 'USA',
+ ]);
+ $locale = $objectManager->getObject(Locale::class, ['lists' => $lists]);
+
+ $this->deployFilesystem = $objectManager->getObject(
+ DeployFilesystem::class,
[
- 'storeView' => $this->storeViewMock,
- 'shell' => $this->shellMock,
- 'filesystem' => $this->filesystemMock
+ 'storeView' => $this->storeView,
+ 'shell' => $this->shell,
+ 'filesystem' => $this->filesystem,
+ 'userCollection' => $this->userCollection,
+ 'locale' => $locale,
]
);
- $userCollection = new \ReflectionProperty(\Magento\Deploy\Model\Filesystem::class, 'userCollection');
- $userCollection->setAccessible(true);
- $userCollection->setValue($this->filesystem, $this->userCollectionMock);
-
$this->cmdPrefix = PHP_BINARY . ' -f ' . BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento ';
}
public function testRegenerateStatic()
{
$storeLocales = ['fr_FR', 'de_DE', 'nl_NL'];
- $adminUserInterfaceLocales = ['de_DE', 'en_US'];
- $this->storeViewMock->expects($this->once())
- ->method('retrieveLocales')
+ $this->storeView->method('retrieveLocales')
->willReturn($storeLocales);
- $userMock = $this->createMock(\Magento\User\Model\User::class);
- $userMock->expects($this->once())
- ->method('getInterfaceLocale')
- ->willReturn('en_US');
- $this->userCollectionMock->expects($this->once())
- ->method('getIterator')
- ->willReturn(new \ArrayIterator([$userMock]));
-
- $usedLocales = array_unique(
- array_merge($storeLocales, $adminUserInterfaceLocales)
- );
- $staticContentDeployCmd = $this->cmdPrefix . 'setup:static-content:deploy -f '
- . implode(' ', $usedLocales);
+
$setupDiCompileCmd = $this->cmdPrefix . 'setup:di:compile';
- $this->shellMock->expects($this->at(0))
+ $this->shell->expects(self::at(0))
->method('execute')
->with($setupDiCompileCmd);
- $this->shellMock->expects($this->at(1))
+
+ $this->initAdminLocaleMock('en_US');
+
+ $usedLocales = ['fr_FR', 'de_DE', 'nl_NL', 'en_US'];
+ $staticContentDeployCmd = $this->cmdPrefix . 'setup:static-content:deploy -f '
+ . implode(' ', $usedLocales);
+ $this->shell->expects(self::at(1))
->method('execute')
->with($staticContentDeployCmd);
- $this->outputMock->expects($this->at(0))
+ $this->output->expects(self::at(0))
->method('writeln')
->with('Starting compilation');
- $this->outputMock->expects($this->at(2))
+ $this->output->expects(self::at(2))
->method('writeln')
->with('Compilation complete');
- $this->outputMock->expects($this->at(3))
+ $this->output->expects(self::at(3))
->method('writeln')
->with('Starting deployment of static content');
- $this->outputMock->expects($this->at(5))
+ $this->output->expects(self::at(5))
->method('writeln')
->with('Deployment of static content complete');
- $this->filesystem->regenerateStatic($this->outputMock);
+ $this->deployFilesystem->regenerateStatic($this->output);
+ }
+
+ /**
+ * Checks a case when configuration contains incorrect locale code.
+ *
+ * @return void
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage ;echo argument has invalid value, run info:language:list for list of available locales
+ */
+ public function testGenerateStaticForNotAllowedStoreViewLocale()
+ {
+ $storeLocales = ['fr_FR', 'de_DE', ';echo'];
+ $this->storeView->method('retrieveLocales')
+ ->willReturn($storeLocales);
+
+ $this->initAdminLocaleMock('en_US');
+
+ $this->deployFilesystem->regenerateStatic($this->output);
+ }
+
+ /**
+ * Checks as case when admin locale is incorrect.
+ *
+ * @return void
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage ;echo argument has invalid value, run info:language:list for list of available locales
+ */
+ public function testGenerateStaticForNotAllowedAdminLocale()
+ {
+ $storeLocales = ['fr_FR', 'de_DE', 'en_US'];
+ $this->storeView->method('retrieveLocales')
+ ->willReturn($storeLocales);
+
+ $this->initAdminLocaleMock(';echo');
+
+ $this->deployFilesystem->regenerateStatic($this->output);
+ }
+
+ /**
+ * Initializes admin user locale.
+ *
+ * @param string $locale
+ * @return void
+ */
+ private function initAdminLocaleMock($locale)
+ {
+ /** @var User|MockObject $user */
+ $user = $this->getMockBuilder(User::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->method('getInterfaceLocale')
+ ->willReturn($locale);
+ $this->userCollection->method('getIterator')
+ ->willReturn(new \ArrayIterator([$user]));
}
}
diff --git a/app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php b/app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php
index 25625eaa5e267..50725a3382073 100644
--- a/app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php
+++ b/app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php
@@ -241,7 +241,7 @@ public function testEnableProductionModeMinimal()
->willReturn($this->processorFacade);
$this->processorFacade
->expects($this->once())
- ->method('process')
+ ->method('processWithLockTarget')
->with(
'dev/debug/debug_logging',
0,
diff --git a/app/code/Magento/Deploy/etc/module.xml b/app/code/Magento/Deploy/etc/module.xml
index a61f9e1546e05..d4785cd7a3112 100644
--- a/app/code/Magento/Deploy/etc/module.xml
+++ b/app/code/Magento/Deploy/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Developer/Console/Command/GeneratePatchCommand.php b/app/code/Magento/Developer/Console/Command/GeneratePatchCommand.php
new file mode 100644
index 0000000000000..7a7deba98ea4e
--- /dev/null
+++ b/app/code/Magento/Developer/Console/Command/GeneratePatchCommand.php
@@ -0,0 +1,124 @@
+componentRegistrar = $componentRegistrar;
+ parent::__construct();
+ }
+
+ /**
+ * {@inheritdoc}
+ * @throws InvalidArgumentException
+ */
+ protected function configure()
+ {
+ $this->setName(self::COMMAND_NAME)
+ ->setDescription('Generate patch and put it in specific folder.')
+ ->setDefinition([
+ new InputArgument(
+ self::MODULE_NAME,
+ InputArgument::REQUIRED,
+ 'Module name'
+ ),
+ new InputArgument(
+ self::INPUT_KEY_PATCH_NAME,
+ InputArgument::REQUIRED,
+ 'Patch name'
+ ),
+ new InputOption(
+ self::INPUT_KEY_IS_REVERTABLE,
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Check whether patch is revertable or not.',
+ false
+ ),
+ new InputOption(
+ self::INPUT_KEY_PATCH_TYPE,
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Find out what type of patch should be generated.',
+ 'data'
+ ),
+ ]);
+
+ parent::configure();
+ }
+
+ /**
+ * Patch template
+ *
+ * @return string
+ */
+ private function getPatchTemplate()
+ {
+ return file_get_contents(__DIR__ . '/patch_template.php.dist');
+ }
+
+ /**
+ * {@inheritdoc}
+ * @throws \InvalidArgumentException
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $moduleName = $input->getArgument(self::MODULE_NAME);
+ $patchName = $input->getArgument(self::INPUT_KEY_PATCH_NAME);
+ $type = $input->getOption(self::INPUT_KEY_PATCH_TYPE);
+ $modulePath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
+ $preparedModuleName = str_replace('_', '\\', $moduleName);
+ $preparedType = ucfirst($type);
+ $patchInterface = sprintf('%sPatchInterface', $preparedType);
+ $patchTemplateData = $this->getPatchTemplate();
+ $patchTemplateData = str_replace('%moduleName%', $preparedModuleName, $patchTemplateData);
+ $patchTemplateData = str_replace('%patchType%', $preparedType, $patchTemplateData);
+ $patchTemplateData = str_replace('%patchInterface%', $patchInterface, $patchTemplateData);
+ $patchTemplateData = str_replace('%class%', $patchName, $patchTemplateData);
+ $patchDir = $patchToFile = $modulePath . '/Setup/Patch/' . $preparedType;
+
+ if (!is_dir($patchDir)) {
+ mkdir($patchDir, 0777, true);
+ }
+ $patchToFile = $patchDir . '/' . $patchName . '.php';
+ file_put_contents($patchToFile, $patchTemplateData);
+ return Cli::RETURN_SUCCESS;
+ }
+}
diff --git a/app/code/Magento/Developer/Console/Command/TablesWhitelistGenerateCommand.php b/app/code/Magento/Developer/Console/Command/TablesWhitelistGenerateCommand.php
index 3313b7ef68a68..6715ecd681efe 100644
--- a/app/code/Magento/Developer/Console/Command/TablesWhitelistGenerateCommand.php
+++ b/app/code/Magento/Developer/Console/Command/TablesWhitelistGenerateCommand.php
@@ -8,8 +8,9 @@
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Config\FileResolverByModule;
use Magento\Framework\Module\Dir;
+use Magento\Framework\Setup\Declaration\Schema\Diff\Diff;
use Magento\Framework\Setup\JsonPersistor;
-use Magento\Setup\Model\Declaration\Schema\Declaration\ReaderComposite;
+use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -103,7 +104,7 @@ private function persistModule($moduleName)
. DIRECTORY_SEPARATOR
. Dir::MODULE_ETC_DIR
. DIRECTORY_SEPARATOR
- . self::GENERATED_FILE_NAME;
+ . Diff::GENERATED_WHITELIST_FILE_NAME;
//We need to load whitelist file and update it with new revision of code.
if (file_exists($whiteListFileName)) {
$content = json_decode(file_get_contents($whiteListFileName), true);
diff --git a/app/code/Magento/Developer/Console/Command/patch_template.php.dist b/app/code/Magento/Developer/Console/Command/patch_template.php.dist
new file mode 100644
index 0000000000000..c1b07246e644f
--- /dev/null
+++ b/app/code/Magento/Developer/Console/Command/patch_template.php.dist
@@ -0,0 +1,59 @@
+moduleDataSetup = $moduleDataSetup;
+ }
+
+ /**
+ * Do Upgrade
+ *
+ * @return void
+ */
+ public function apply()
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+
+ ];
+ }
+}
diff --git a/app/code/Magento/Developer/Test/Unit/Console/Command/TablesWhitelistGenerateCommandTest.php b/app/code/Magento/Developer/Test/Unit/Console/Command/TablesWhitelistGenerateCommandTest.php
index 49235e19cc07d..66fd7e3eec638 100644
--- a/app/code/Magento/Developer/Test/Unit/Console/Command/TablesWhitelistGenerateCommandTest.php
+++ b/app/code/Magento/Developer/Test/Unit/Console/Command/TablesWhitelistGenerateCommandTest.php
@@ -10,7 +10,7 @@
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Setup\JsonPersistor;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
-use Magento\Setup\Model\Declaration\Schema\Declaration\ReaderComposite;
+use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite;
use Symfony\Component\Console\Tester\CommandTester;
/**
diff --git a/app/code/Magento/Developer/Test/Unit/Console/Command/_files/test.xml b/app/code/Magento/Developer/Test/Unit/Console/Command/_files/test.xml
index ce31b046500f7..8112b9e8c46db 100644
--- a/app/code/Magento/Developer/Test/Unit/Console/Command/_files/test.xml
+++ b/app/code/Magento/Developer/Test/Unit/Console/Command/_files/test.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml
index f68d01b8339d0..2254c94a8a913 100644
--- a/app/code/Magento/Developer/etc/di.xml
+++ b/app/code/Magento/Developer/etc/di.xml
@@ -105,6 +105,7 @@
- Magento\Developer\Console\Command\TemplateHintsEnableCommand
- Magento\Developer\Console\Command\ProfilerDisableCommand
- Magento\Developer\Console\Command\ProfilerEnableCommand
+ - Magento\Developer\Console\Command\GeneratePatchCommand
diff --git a/app/code/Magento/Developer/etc/module.xml b/app/code/Magento/Developer/etc/module.xml
index 96a8828b00c4b..e3cf8132e3e92 100644
--- a/app/code/Magento/Developer/etc/module.xml
+++ b/app/code/Magento/Developer/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Dhl/Setup/InstallData.php b/app/code/Magento/Dhl/Setup/InstallData.php
deleted file mode 100644
index 48f359aa63659..0000000000000
--- a/app/code/Magento/Dhl/Setup/InstallData.php
+++ /dev/null
@@ -1,68 +0,0 @@
-localeResolver = $localeResolver;
- }
-
- /**
- * {@inheritdoc}
- */
- public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- $days = (new DataBundle())->get(
- $this->localeResolver->getLocale()
- )['calendar']['gregorian']['dayNames']['format']['abbreviated'];
-
- $select = $setup->getConnection()->select()->from(
- $setup->getTable('core_config_data'),
- ['config_id', 'value']
- )->where(
- 'path = ?',
- 'carriers/dhl/shipment_days'
- );
-
- foreach ($setup->getConnection()->fetchAll($select) as $configRow) {
- $row = [
- 'value' => implode(
- ',',
- array_intersect_key(iterator_to_array($days), array_flip(explode(',', $configRow['value'])))
- )
- ];
- $setup->getConnection()->update(
- $setup->getTable('core_config_data'),
- $row,
- ['config_id = ?' => $configRow['config_id']]
- );
- }
- }
-}
diff --git a/app/code/Magento/Dhl/Setup/Patch/Data/PrepareShipmentDays.php b/app/code/Magento/Dhl/Setup/Patch/Data/PrepareShipmentDays.php
new file mode 100644
index 0000000000000..8b91b842c36e6
--- /dev/null
+++ b/app/code/Magento/Dhl/Setup/Patch/Data/PrepareShipmentDays.php
@@ -0,0 +1,99 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->localeResolver = $localeResolver;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ $days = (new DataBundle())->get(
+ $this->localeResolver->getLocale()
+ )['calendar']['gregorian']['dayNames']['format']['abbreviated'];
+
+ $select = $this->moduleDataSetup->getConnection()->select()->from(
+ $this->moduleDataSetup->getTable('core_config_data'),
+ ['config_id', 'value']
+ )->where(
+ 'path = ?',
+ 'carriers/dhl/shipment_days'
+ );
+ foreach ($this->moduleDataSetup->getConnection()->fetchAll($select) as $configRow) {
+ $row = [
+ 'value' => implode(
+ ',',
+ array_intersect_key(iterator_to_array($days), array_flip(explode(',', $configRow['value'])))
+ )
+ ];
+ $this->moduleDataSetup->getConnection()->update(
+ $this->moduleDataSetup->getTable('core_config_data'),
+ $row,
+ ['config_id = ?' => $configRow['config_id']]
+ );
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Dhl/etc/module.xml b/app/code/Magento/Dhl/etc/module.xml
index 4723b14763a12..b1af1baf97fc2 100644
--- a/app/code/Magento/Dhl/etc/module.xml
+++ b/app/code/Magento/Dhl/etc/module.xml
@@ -6,6 +6,6 @@
*/
-->
-
+
diff --git a/app/code/Magento/Directory/Model/ResourceModel/Country.php b/app/code/Magento/Directory/Model/ResourceModel/Country.php
index c4c0a6b95dfb4..59fb2de85c8a3 100644
--- a/app/code/Magento/Directory/Model/ResourceModel/Country.php
+++ b/app/code/Magento/Directory/Model/ResourceModel/Country.php
@@ -44,7 +44,7 @@ public function loadByCode(\Magento\Directory\Model\Country $country, $code)
default:
throw new \Magento\Framework\Exception\LocalizedException(
- __('Please correct the country code: %1.', $code)
+ __('Please correct the country code: %1.', htmlspecialchars($code))
);
}
diff --git a/app/code/Magento/Directory/Setup/DataInstaller.php b/app/code/Magento/Directory/Setup/DataInstaller.php
new file mode 100644
index 0000000000000..9fccc16e1d49b
--- /dev/null
+++ b/app/code/Magento/Directory/Setup/DataInstaller.php
@@ -0,0 +1,76 @@
+data = $data;
+ $this->resourceConnection = $resourceConnection;
+ }
+
+ /**
+ * Add country-region data.
+ *
+ * @param AdapterInterface $adapter
+ * @param array $data
+ */
+ public function addCountryRegions(AdapterInterface $adapter, array $data)
+ {
+ /**
+ * Fill table directory/country_region
+ * Fill table directory/country_region_name for en_US locale
+ */
+ foreach ($data as $row) {
+ $bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
+ $adapter->insert($this->resourceConnection->getTableName('directory_country_region'), $bind);
+ $regionId = $adapter->lastInsertId($this->resourceConnection->getTableName('directory_country_region'));
+ $bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]];
+ $adapter->insert($this->resourceConnection->getTableName('directory_country_region_name'), $bind);
+ }
+ /**
+ * Upgrade core_config_data general/region/state_required field.
+ */
+ $countries = $this->data->getCountryCollection()->getCountriesWithRequiredStates();
+ $adapter->update(
+ $this->resourceConnection->getTableName('core_config_data'),
+ [
+ 'value' => implode(',', array_keys($countries))
+ ],
+ [
+ 'scope="default"',
+ 'scope_id=0',
+ 'path=?' => \Magento\Directory\Helper\Data::XML_PATH_STATES_REQUIRED
+ ]
+ );
+ }
+}
diff --git a/app/code/Magento/Directory/Setup/InstallData.php b/app/code/Magento/Directory/Setup/InstallData.php
deleted file mode 100644
index 33c3ae4558e16..0000000000000
--- a/app/code/Magento/Directory/Setup/InstallData.php
+++ /dev/null
@@ -1,857 +0,0 @@
-directoryData = $directoryData;
- }
-
- /**
- * {@inheritdoc}
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- /**
- * Fill table directory/country
- */
- $data = [
- ['AD', 'AD', 'AND'],
- ['AE', 'AE', 'ARE'],
- ['AF', 'AF', 'AFG'],
- ['AG', 'AG', 'ATG'],
- ['AI', 'AI', 'AIA'],
- ['AL', 'AL', 'ALB'],
- ['AM', 'AM', 'ARM'],
- ['AN', 'AN', 'ANT'],
- ['AO', 'AO', 'AGO'],
- ['AQ', 'AQ', 'ATA'],
- ['AR', 'AR', 'ARG'],
- ['AS', 'AS', 'ASM'],
- ['AT', 'AT', 'AUT'],
- ['AU', 'AU', 'AUS'],
- ['AW', 'AW', 'ABW'],
- ['AX', 'AX', 'ALA'],
- ['AZ', 'AZ', 'AZE'],
- ['BA', 'BA', 'BIH'],
- ['BB', 'BB', 'BRB'],
- ['BD', 'BD', 'BGD'],
- ['BE', 'BE', 'BEL'],
- ['BF', 'BF', 'BFA'],
- ['BG', 'BG', 'BGR'],
- ['BH', 'BH', 'BHR'],
- ['BI', 'BI', 'BDI'],
- ['BJ', 'BJ', 'BEN'],
- ['BL', 'BL', 'BLM'],
- ['BM', 'BM', 'BMU'],
- ['BN', 'BN', 'BRN'],
- ['BO', 'BO', 'BOL'],
- ['BR', 'BR', 'BRA'],
- ['BS', 'BS', 'BHS'],
- ['BT', 'BT', 'BTN'],
- ['BV', 'BV', 'BVT'],
- ['BW', 'BW', 'BWA'],
- ['BY', 'BY', 'BLR'],
- ['BZ', 'BZ', 'BLZ'],
- ['CA', 'CA', 'CAN'],
- ['CC', 'CC', 'CCK'],
- ['CD', 'CD', 'COD'],
- ['CF', 'CF', 'CAF'],
- ['CG', 'CG', 'COG'],
- ['CH', 'CH', 'CHE'],
- ['CI', 'CI', 'CIV'],
- ['CK', 'CK', 'COK'],
- ['CL', 'CL', 'CHL'],
- ['CM', 'CM', 'CMR'],
- ['CN', 'CN', 'CHN'],
- ['CO', 'CO', 'COL'],
- ['CR', 'CR', 'CRI'],
- ['CU', 'CU', 'CUB'],
- ['CV', 'CV', 'CPV'],
- ['CX', 'CX', 'CXR'],
- ['CY', 'CY', 'CYP'],
- ['CZ', 'CZ', 'CZE'],
- ['DE', 'DE', 'DEU'],
- ['DJ', 'DJ', 'DJI'],
- ['DK', 'DK', 'DNK'],
- ['DM', 'DM', 'DMA'],
- ['DO', 'DO', 'DOM'],
- ['DZ', 'DZ', 'DZA'],
- ['EC', 'EC', 'ECU'],
- ['EE', 'EE', 'EST'],
- ['EG', 'EG', 'EGY'],
- ['EH', 'EH', 'ESH'],
- ['ER', 'ER', 'ERI'],
- ['ES', 'ES', 'ESP'],
- ['ET', 'ET', 'ETH'],
- ['FI', 'FI', 'FIN'],
- ['FJ', 'FJ', 'FJI'],
- ['FK', 'FK', 'FLK'],
- ['FM', 'FM', 'FSM'],
- ['FO', 'FO', 'FRO'],
- ['FR', 'FR', 'FRA'],
- ['GA', 'GA', 'GAB'],
- ['GB', 'GB', 'GBR'],
- ['GD', 'GD', 'GRD'],
- ['GE', 'GE', 'GEO'],
- ['GF', 'GF', 'GUF'],
- ['GG', 'GG', 'GGY'],
- ['GH', 'GH', 'GHA'],
- ['GI', 'GI', 'GIB'],
- ['GL', 'GL', 'GRL'],
- ['GM', 'GM', 'GMB'],
- ['GN', 'GN', 'GIN'],
- ['GP', 'GP', 'GLP'],
- ['GQ', 'GQ', 'GNQ'],
- ['GR', 'GR', 'GRC'],
- ['GS', 'GS', 'SGS'],
- ['GT', 'GT', 'GTM'],
- ['GU', 'GU', 'GUM'],
- ['GW', 'GW', 'GNB'],
- ['GY', 'GY', 'GUY'],
- ['HK', 'HK', 'HKG'],
- ['HM', 'HM', 'HMD'],
- ['HN', 'HN', 'HND'],
- ['HR', 'HR', 'HRV'],
- ['HT', 'HT', 'HTI'],
- ['HU', 'HU', 'HUN'],
- ['ID', 'ID', 'IDN'],
- ['IE', 'IE', 'IRL'],
- ['IL', 'IL', 'ISR'],
- ['IM', 'IM', 'IMN'],
- ['IN', 'IN', 'IND'],
- ['IO', 'IO', 'IOT'],
- ['IQ', 'IQ', 'IRQ'],
- ['IR', 'IR', 'IRN'],
- ['IS', 'IS', 'ISL'],
- ['IT', 'IT', 'ITA'],
- ['JE', 'JE', 'JEY'],
- ['JM', 'JM', 'JAM'],
- ['JO', 'JO', 'JOR'],
- ['JP', 'JP', 'JPN'],
- ['KE', 'KE', 'KEN'],
- ['KG', 'KG', 'KGZ'],
- ['KH', 'KH', 'KHM'],
- ['KI', 'KI', 'KIR'],
- ['KM', 'KM', 'COM'],
- ['KN', 'KN', 'KNA'],
- ['KP', 'KP', 'PRK'],
- ['KR', 'KR', 'KOR'],
- ['KW', 'KW', 'KWT'],
- ['KY', 'KY', 'CYM'],
- ['KZ', 'KZ', 'KAZ'],
- ['LA', 'LA', 'LAO'],
- ['LB', 'LB', 'LBN'],
- ['LC', 'LC', 'LCA'],
- ['LI', 'LI', 'LIE'],
- ['LK', 'LK', 'LKA'],
- ['LR', 'LR', 'LBR'],
- ['LS', 'LS', 'LSO'],
- ['LT', 'LT', 'LTU'],
- ['LU', 'LU', 'LUX'],
- ['LV', 'LV', 'LVA'],
- ['LY', 'LY', 'LBY'],
- ['MA', 'MA', 'MAR'],
- ['MC', 'MC', 'MCO'],
- ['MD', 'MD', 'MDA'],
- ['ME', 'ME', 'MNE'],
- ['MF', 'MF', 'MAF'],
- ['MG', 'MG', 'MDG'],
- ['MH', 'MH', 'MHL'],
- ['MK', 'MK', 'MKD'],
- ['ML', 'ML', 'MLI'],
- ['MM', 'MM', 'MMR'],
- ['MN', 'MN', 'MNG'],
- ['MO', 'MO', 'MAC'],
- ['MP', 'MP', 'MNP'],
- ['MQ', 'MQ', 'MTQ'],
- ['MR', 'MR', 'MRT'],
- ['MS', 'MS', 'MSR'],
- ['MT', 'MT', 'MLT'],
- ['MU', 'MU', 'MUS'],
- ['MV', 'MV', 'MDV'],
- ['MW', 'MW', 'MWI'],
- ['MX', 'MX', 'MEX'],
- ['MY', 'MY', 'MYS'],
- ['MZ', 'MZ', 'MOZ'],
- ['NA', 'NA', 'NAM'],
- ['NC', 'NC', 'NCL'],
- ['NE', 'NE', 'NER'],
- ['NF', 'NF', 'NFK'],
- ['NG', 'NG', 'NGA'],
- ['NI', 'NI', 'NIC'],
- ['NL', 'NL', 'NLD'],
- ['NO', 'NO', 'NOR'],
- ['NP', 'NP', 'NPL'],
- ['NR', 'NR', 'NRU'],
- ['NU', 'NU', 'NIU'],
- ['NZ', 'NZ', 'NZL'],
- ['OM', 'OM', 'OMN'],
- ['PA', 'PA', 'PAN'],
- ['PE', 'PE', 'PER'],
- ['PF', 'PF', 'PYF'],
- ['PG', 'PG', 'PNG'],
- ['PH', 'PH', 'PHL'],
- ['PK', 'PK', 'PAK'],
- ['PL', 'PL', 'POL'],
- ['PM', 'PM', 'SPM'],
- ['PN', 'PN', 'PCN'],
- ['PS', 'PS', 'PSE'],
- ['PT', 'PT', 'PRT'],
- ['PW', 'PW', 'PLW'],
- ['PY', 'PY', 'PRY'],
- ['QA', 'QA', 'QAT'],
- ['RE', 'RE', 'REU'],
- ['RO', 'RO', 'ROU'],
- ['RS', 'RS', 'SRB'],
- ['RU', 'RU', 'RUS'],
- ['RW', 'RW', 'RWA'],
- ['SA', 'SA', 'SAU'],
- ['SB', 'SB', 'SLB'],
- ['SC', 'SC', 'SYC'],
- ['SD', 'SD', 'SDN'],
- ['SE', 'SE', 'SWE'],
- ['SG', 'SG', 'SGP'],
- ['SH', 'SH', 'SHN'],
- ['SI', 'SI', 'SVN'],
- ['SJ', 'SJ', 'SJM'],
- ['SK', 'SK', 'SVK'],
- ['SL', 'SL', 'SLE'],
- ['SM', 'SM', 'SMR'],
- ['SN', 'SN', 'SEN'],
- ['SO', 'SO', 'SOM'],
- ['SR', 'SR', 'SUR'],
- ['ST', 'ST', 'STP'],
- ['SV', 'SV', 'SLV'],
- ['SY', 'SY', 'SYR'],
- ['SZ', 'SZ', 'SWZ'],
- ['TC', 'TC', 'TCA'],
- ['TD', 'TD', 'TCD'],
- ['TF', 'TF', 'ATF'],
- ['TG', 'TG', 'TGO'],
- ['TH', 'TH', 'THA'],
- ['TJ', 'TJ', 'TJK'],
- ['TK', 'TK', 'TKL'],
- ['TL', 'TL', 'TLS'],
- ['TM', 'TM', 'TKM'],
- ['TN', 'TN', 'TUN'],
- ['TO', 'TO', 'TON'],
- ['TR', 'TR', 'TUR'],
- ['TT', 'TT', 'TTO'],
- ['TV', 'TV', 'TUV'],
- ['TW', 'TW', 'TWN'],
- ['TZ', 'TZ', 'TZA'],
- ['UA', 'UA', 'UKR'],
- ['UG', 'UG', 'UGA'],
- ['UM', 'UM', 'UMI'],
- ['US', 'US', 'USA'],
- ['UY', 'UY', 'URY'],
- ['UZ', 'UZ', 'UZB'],
- ['VA', 'VA', 'VAT'],
- ['VC', 'VC', 'VCT'],
- ['VE', 'VE', 'VEN'],
- ['VG', 'VG', 'VGB'],
- ['VI', 'VI', 'VIR'],
- ['VN', 'VN', 'VNM'],
- ['VU', 'VU', 'VUT'],
- ['WF', 'WF', 'WLF'],
- ['WS', 'WS', 'WSM'],
- ['YE', 'YE', 'YEM'],
- ['YT', 'YT', 'MYT'],
- ['ZA', 'ZA', 'ZAF'],
- ['ZM', 'ZM', 'ZMB'],
- ['ZW', 'ZW', 'ZWE'],
- ];
-
- $columns = ['country_id', 'iso2_code', 'iso3_code'];
- $setup->getConnection()->insertArray($setup->getTable('directory_country'), $columns, $data);
-
- /**
- * Fill table directory/country_region
- * Fill table directory/country_region_name for en_US locale
- */
- $data = [
- ['US', 'AL', 'Alabama'],
- ['US', 'AK', 'Alaska'],
- ['US', 'AS', 'American Samoa'],
- ['US', 'AZ', 'Arizona'],
- ['US', 'AR', 'Arkansas'],
- ['US', 'AE', 'Armed Forces Africa'],
- ['US', 'AA', 'Armed Forces Americas'],
- ['US', 'AE', 'Armed Forces Canada'],
- ['US', 'AE', 'Armed Forces Europe'],
- ['US', 'AE', 'Armed Forces Middle East'],
- ['US', 'AP', 'Armed Forces Pacific'],
- ['US', 'CA', 'California'],
- ['US', 'CO', 'Colorado'],
- ['US', 'CT', 'Connecticut'],
- ['US', 'DE', 'Delaware'],
- ['US', 'DC', 'District of Columbia'],
- ['US', 'FM', 'Federated States Of Micronesia'],
- ['US', 'FL', 'Florida'],
- ['US', 'GA', 'Georgia'],
- ['US', 'GU', 'Guam'],
- ['US', 'HI', 'Hawaii'],
- ['US', 'ID', 'Idaho'],
- ['US', 'IL', 'Illinois'],
- ['US', 'IN', 'Indiana'],
- ['US', 'IA', 'Iowa'],
- ['US', 'KS', 'Kansas'],
- ['US', 'KY', 'Kentucky'],
- ['US', 'LA', 'Louisiana'],
- ['US', 'ME', 'Maine'],
- ['US', 'MH', 'Marshall Islands'],
- ['US', 'MD', 'Maryland'],
- ['US', 'MA', 'Massachusetts'],
- ['US', 'MI', 'Michigan'],
- ['US', 'MN', 'Minnesota'],
- ['US', 'MS', 'Mississippi'],
- ['US', 'MO', 'Missouri'],
- ['US', 'MT', 'Montana'],
- ['US', 'NE', 'Nebraska'],
- ['US', 'NV', 'Nevada'],
- ['US', 'NH', 'New Hampshire'],
- ['US', 'NJ', 'New Jersey'],
- ['US', 'NM', 'New Mexico'],
- ['US', 'NY', 'New York'],
- ['US', 'NC', 'North Carolina'],
- ['US', 'ND', 'North Dakota'],
- ['US', 'MP', 'Northern Mariana Islands'],
- ['US', 'OH', 'Ohio'],
- ['US', 'OK', 'Oklahoma'],
- ['US', 'OR', 'Oregon'],
- ['US', 'PW', 'Palau'],
- ['US', 'PA', 'Pennsylvania'],
- ['US', 'PR', 'Puerto Rico'],
- ['US', 'RI', 'Rhode Island'],
- ['US', 'SC', 'South Carolina'],
- ['US', 'SD', 'South Dakota'],
- ['US', 'TN', 'Tennessee'],
- ['US', 'TX', 'Texas'],
- ['US', 'UT', 'Utah'],
- ['US', 'VT', 'Vermont'],
- ['US', 'VI', 'Virgin Islands'],
- ['US', 'VA', 'Virginia'],
- ['US', 'WA', 'Washington'],
- ['US', 'WV', 'West Virginia'],
- ['US', 'WI', 'Wisconsin'],
- ['US', 'WY', 'Wyoming'],
- ['CA', 'AB', 'Alberta'],
- ['CA', 'BC', 'British Columbia'],
- ['CA', 'MB', 'Manitoba'],
- ['CA', 'NL', 'Newfoundland and Labrador'],
- ['CA', 'NB', 'New Brunswick'],
- ['CA', 'NS', 'Nova Scotia'],
- ['CA', 'NT', 'Northwest Territories'],
- ['CA', 'NU', 'Nunavut'],
- ['CA', 'ON', 'Ontario'],
- ['CA', 'PE', 'Prince Edward Island'],
- ['CA', 'QC', 'Quebec'],
- ['CA', 'SK', 'Saskatchewan'],
- ['CA', 'YT', 'Yukon Territory'],
- ['DE', 'NDS', 'Niedersachsen'],
- ['DE', 'BAW', 'Baden-Württemberg'],
- ['DE', 'BAY', 'Bayern'],
- ['DE', 'BER', 'Berlin'],
- ['DE', 'BRG', 'Brandenburg'],
- ['DE', 'BRE', 'Bremen'],
- ['DE', 'HAM', 'Hamburg'],
- ['DE', 'HES', 'Hessen'],
- ['DE', 'MEC', 'Mecklenburg-Vorpommern'],
- ['DE', 'NRW', 'Nordrhein-Westfalen'],
- ['DE', 'RHE', 'Rheinland-Pfalz'],
- ['DE', 'SAR', 'Saarland'],
- ['DE', 'SAS', 'Sachsen'],
- ['DE', 'SAC', 'Sachsen-Anhalt'],
- ['DE', 'SCN', 'Schleswig-Holstein'],
- ['DE', 'THE', 'Thüringen'],
- ['AT', 'WI', 'Wien'],
- ['AT', 'NO', 'Niederösterreich'],
- ['AT', 'OO', 'Oberösterreich'],
- ['AT', 'SB', 'Salzburg'],
- ['AT', 'KN', 'Kärnten'],
- ['AT', 'ST', 'Steiermark'],
- ['AT', 'TI', 'Tirol'],
- ['AT', 'BL', 'Burgenland'],
- ['AT', 'VB', 'Vorarlberg'],
- ['CH', 'AG', 'Aargau'],
- ['CH', 'AI', 'Appenzell Innerrhoden'],
- ['CH', 'AR', 'Appenzell Ausserrhoden'],
- ['CH', 'BE', 'Bern'],
- ['CH', 'BL', 'Basel-Landschaft'],
- ['CH', 'BS', 'Basel-Stadt'],
- ['CH', 'FR', 'Freiburg'],
- ['CH', 'GE', 'Genf'],
- ['CH', 'GL', 'Glarus'],
- ['CH', 'GR', 'Graubünden'],
- ['CH', 'JU', 'Jura'],
- ['CH', 'LU', 'Luzern'],
- ['CH', 'NE', 'Neuenburg'],
- ['CH', 'NW', 'Nidwalden'],
- ['CH', 'OW', 'Obwalden'],
- ['CH', 'SG', 'St. Gallen'],
- ['CH', 'SH', 'Schaffhausen'],
- ['CH', 'SO', 'Solothurn'],
- ['CH', 'SZ', 'Schwyz'],
- ['CH', 'TG', 'Thurgau'],
- ['CH', 'TI', 'Tessin'],
- ['CH', 'UR', 'Uri'],
- ['CH', 'VD', 'Waadt'],
- ['CH', 'VS', 'Wallis'],
- ['CH', 'ZG', 'Zug'],
- ['CH', 'ZH', 'Zürich'],
- ['ES', 'A Coruсa', 'A Coruña'],
- ['ES', 'Alava', 'Alava'],
- ['ES', 'Albacete', 'Albacete'],
- ['ES', 'Alicante', 'Alicante'],
- ['ES', 'Almeria', 'Almeria'],
- ['ES', 'Asturias', 'Asturias'],
- ['ES', 'Avila', 'Avila'],
- ['ES', 'Badajoz', 'Badajoz'],
- ['ES', 'Baleares', 'Baleares'],
- ['ES', 'Barcelona', 'Barcelona'],
- ['ES', 'Burgos', 'Burgos'],
- ['ES', 'Caceres', 'Caceres'],
- ['ES', 'Cadiz', 'Cadiz'],
- ['ES', 'Cantabria', 'Cantabria'],
- ['ES', 'Castellon', 'Castellon'],
- ['ES', 'Ceuta', 'Ceuta'],
- ['ES', 'Ciudad Real', 'Ciudad Real'],
- ['ES', 'Cordoba', 'Cordoba'],
- ['ES', 'Cuenca', 'Cuenca'],
- ['ES', 'Girona', 'Girona'],
- ['ES', 'Granada', 'Granada'],
- ['ES', 'Guadalajara', 'Guadalajara'],
- ['ES', 'Guipuzcoa', 'Guipuzcoa'],
- ['ES', 'Huelva', 'Huelva'],
- ['ES', 'Huesca', 'Huesca'],
- ['ES', 'Jaen', 'Jaen'],
- ['ES', 'La Rioja', 'La Rioja'],
- ['ES', 'Las Palmas', 'Las Palmas'],
- ['ES', 'Leon', 'Leon'],
- ['ES', 'Lleida', 'Lleida'],
- ['ES', 'Lugo', 'Lugo'],
- ['ES', 'Madrid', 'Madrid'],
- ['ES', 'Malaga', 'Malaga'],
- ['ES', 'Melilla', 'Melilla'],
- ['ES', 'Murcia', 'Murcia'],
- ['ES', 'Navarra', 'Navarra'],
- ['ES', 'Ourense', 'Ourense'],
- ['ES', 'Palencia', 'Palencia'],
- ['ES', 'Pontevedra', 'Pontevedra'],
- ['ES', 'Salamanca', 'Salamanca'],
- ['ES', 'Santa Cruz de Tenerife', 'Santa Cruz de Tenerife'],
- ['ES', 'Segovia', 'Segovia'],
- ['ES', 'Sevilla', 'Sevilla'],
- ['ES', 'Soria', 'Soria'],
- ['ES', 'Tarragona', 'Tarragona'],
- ['ES', 'Teruel', 'Teruel'],
- ['ES', 'Toledo', 'Toledo'],
- ['ES', 'Valencia', 'Valencia'],
- ['ES', 'Valladolid', 'Valladolid'],
- ['ES', 'Vizcaya', 'Vizcaya'],
- ['ES', 'Zamora', 'Zamora'],
- ['ES', 'Zaragoza', 'Zaragoza'],
- ['FR', 1, 'Ain'],
- ['FR', 2, 'Aisne'],
- ['FR', 3, 'Allier'],
- ['FR', 4, 'Alpes-de-Haute-Provence'],
- ['FR', 5, 'Hautes-Alpes'],
- ['FR', 6, 'Alpes-Maritimes'],
- ['FR', 7, 'Ardèche'],
- ['FR', 8, 'Ardennes'],
- ['FR', 9, 'Ariège'],
- ['FR', 10, 'Aube'],
- ['FR', 11, 'Aude'],
- ['FR', 12, 'Aveyron'],
- ['FR', 13, 'Bouches-du-Rhône'],
- ['FR', 14, 'Calvados'],
- ['FR', 15, 'Cantal'],
- ['FR', 16, 'Charente'],
- ['FR', 17, 'Charente-Maritime'],
- ['FR', 18, 'Cher'],
- ['FR', 19, 'Corrèze'],
- ['FR', '2A', 'Corse-du-Sud'],
- ['FR', '2B', 'Haute-Corse'],
- ['FR', 21, 'Côte-d\'Or'],
- ['FR', 22, 'Côtes-d\'Armor'],
- ['FR', 23, 'Creuse'],
- ['FR', 24, 'Dordogne'],
- ['FR', 25, 'Doubs'],
- ['FR', 26, 'Drôme'],
- ['FR', 27, 'Eure'],
- ['FR', 28, 'Eure-et-Loir'],
- ['FR', 29, 'Finistère'],
- ['FR', 30, 'Gard'],
- ['FR', 31, 'Haute-Garonne'],
- ['FR', 32, 'Gers'],
- ['FR', 33, 'Gironde'],
- ['FR', 34, 'Hérault'],
- ['FR', 35, 'Ille-et-Vilaine'],
- ['FR', 36, 'Indre'],
- ['FR', 37, 'Indre-et-Loire'],
- ['FR', 38, 'Isère'],
- ['FR', 39, 'Jura'],
- ['FR', 40, 'Landes'],
- ['FR', 41, 'Loir-et-Cher'],
- ['FR', 42, 'Loire'],
- ['FR', 43, 'Haute-Loire'],
- ['FR', 44, 'Loire-Atlantique'],
- ['FR', 45, 'Loiret'],
- ['FR', 46, 'Lot'],
- ['FR', 47, 'Lot-et-Garonne'],
- ['FR', 48, 'Lozère'],
- ['FR', 49, 'Maine-et-Loire'],
- ['FR', 50, 'Manche'],
- ['FR', 51, 'Marne'],
- ['FR', 52, 'Haute-Marne'],
- ['FR', 53, 'Mayenne'],
- ['FR', 54, 'Meurthe-et-Moselle'],
- ['FR', 55, 'Meuse'],
- ['FR', 56, 'Morbihan'],
- ['FR', 57, 'Moselle'],
- ['FR', 58, 'Nièvre'],
- ['FR', 59, 'Nord'],
- ['FR', 60, 'Oise'],
- ['FR', 61, 'Orne'],
- ['FR', 62, 'Pas-de-Calais'],
- ['FR', 63, 'Puy-de-Dôme'],
- ['FR', 64, 'Pyrénées-Atlantiques'],
- ['FR', 65, 'Hautes-Pyrénées'],
- ['FR', 66, 'Pyrénées-Orientales'],
- ['FR', 67, 'Bas-Rhin'],
- ['FR', 68, 'Haut-Rhin'],
- ['FR', 69, 'Rhône'],
- ['FR', 70, 'Haute-Saône'],
- ['FR', 71, 'Saône-et-Loire'],
- ['FR', 72, 'Sarthe'],
- ['FR', 73, 'Savoie'],
- ['FR', 74, 'Haute-Savoie'],
- ['FR', 75, 'Paris'],
- ['FR', 76, 'Seine-Maritime'],
- ['FR', 77, 'Seine-et-Marne'],
- ['FR', 78, 'Yvelines'],
- ['FR', 79, 'Deux-Sèvres'],
- ['FR', 80, 'Somme'],
- ['FR', 81, 'Tarn'],
- ['FR', 82, 'Tarn-et-Garonne'],
- ['FR', 83, 'Var'],
- ['FR', 84, 'Vaucluse'],
- ['FR', 85, 'Vendée'],
- ['FR', 86, 'Vienne'],
- ['FR', 87, 'Haute-Vienne'],
- ['FR', 88, 'Vosges'],
- ['FR', 89, 'Yonne'],
- ['FR', 90, 'Territoire-de-Belfort'],
- ['FR', 91, 'Essonne'],
- ['FR', 92, 'Hauts-de-Seine'],
- ['FR', 93, 'Seine-Saint-Denis'],
- ['FR', 94, 'Val-de-Marne'],
- ['FR', 95, 'Val-d\'Oise'],
- ['RO', 'AB', 'Alba'],
- ['RO', 'AR', 'Arad'],
- ['RO', 'AG', 'Argeş'],
- ['RO', 'BC', 'Bacău'],
- ['RO', 'BH', 'Bihor'],
- ['RO', 'BN', 'Bistriţa-Năsăud'],
- ['RO', 'BT', 'Botoşani'],
- ['RO', 'BV', 'Braşov'],
- ['RO', 'BR', 'Brăila'],
- ['RO', 'B', 'Bucureşti'],
- ['RO', 'BZ', 'Buzău'],
- ['RO', 'CS', 'Caraş-Severin'],
- ['RO', 'CL', 'Călăraşi'],
- ['RO', 'CJ', 'Cluj'],
- ['RO', 'CT', 'Constanţa'],
- ['RO', 'CV', 'Covasna'],
- ['RO', 'DB', 'Dâmboviţa'],
- ['RO', 'DJ', 'Dolj'],
- ['RO', 'GL', 'Galaţi'],
- ['RO', 'GR', 'Giurgiu'],
- ['RO', 'GJ', 'Gorj'],
- ['RO', 'HR', 'Harghita'],
- ['RO', 'HD', 'Hunedoara'],
- ['RO', 'IL', 'Ialomiţa'],
- ['RO', 'IS', 'Iaşi'],
- ['RO', 'IF', 'Ilfov'],
- ['RO', 'MM', 'Maramureş'],
- ['RO', 'MH', 'Mehedinţi'],
- ['RO', 'MS', 'Mureş'],
- ['RO', 'NT', 'Neamţ'],
- ['RO', 'OT', 'Olt'],
- ['RO', 'PH', 'Prahova'],
- ['RO', 'SM', 'Satu-Mare'],
- ['RO', 'SJ', 'Sălaj'],
- ['RO', 'SB', 'Sibiu'],
- ['RO', 'SV', 'Suceava'],
- ['RO', 'TR', 'Teleorman'],
- ['RO', 'TM', 'Timiş'],
- ['RO', 'TL', 'Tulcea'],
- ['RO', 'VS', 'Vaslui'],
- ['RO', 'VL', 'Vâlcea'],
- ['RO', 'VN', 'Vrancea'],
- ['FI', 'Lappi', 'Lappi'],
- ['FI', 'Pohjois-Pohjanmaa', 'Pohjois-Pohjanmaa'],
- ['FI', 'Kainuu', 'Kainuu'],
- ['FI', 'Pohjois-Karjala', 'Pohjois-Karjala'],
- ['FI', 'Pohjois-Savo', 'Pohjois-Savo'],
- ['FI', 'Etelä-Savo', 'Etelä-Savo'],
- ['FI', 'Etelä-Pohjanmaa', 'Etelä-Pohjanmaa'],
- ['FI', 'Pohjanmaa', 'Pohjanmaa'],
- ['FI', 'Pirkanmaa', 'Pirkanmaa'],
- ['FI', 'Satakunta', 'Satakunta'],
- ['FI', 'Keski-Pohjanmaa', 'Keski-Pohjanmaa'],
- ['FI', 'Keski-Suomi', 'Keski-Suomi'],
- ['FI', 'Varsinais-Suomi', 'Varsinais-Suomi'],
- ['FI', 'Etelä-Karjala', 'Etelä-Karjala'],
- ['FI', 'Päijät-Häme', 'Päijät-Häme'],
- ['FI', 'Kanta-Häme', 'Kanta-Häme'],
- ['FI', 'Uusimaa', 'Uusimaa'],
- ['FI', 'Itä-Uusimaa', 'Itä-Uusimaa'],
- ['FI', 'Kymenlaakso', 'Kymenlaakso'],
- ['FI', 'Ahvenanmaa', 'Ahvenanmaa'],
- ['EE', 'EE-37', 'Harjumaa'],
- ['EE', 'EE-39', 'Hiiumaa'],
- ['EE', 'EE-44', 'Ida-Virumaa'],
- ['EE', 'EE-49', 'Jõgevamaa'],
- ['EE', 'EE-51', 'Järvamaa'],
- ['EE', 'EE-57', 'Läänemaa'],
- ['EE', 'EE-59', 'Lääne-Virumaa'],
- ['EE', 'EE-65', 'Põlvamaa'],
- ['EE', 'EE-67', 'Pärnumaa'],
- ['EE', 'EE-70', 'Raplamaa'],
- ['EE', 'EE-74', 'Saaremaa'],
- ['EE', 'EE-78', 'Tartumaa'],
- ['EE', 'EE-82', 'Valgamaa'],
- ['EE', 'EE-84', 'Viljandimaa'],
- ['EE', 'EE-86', 'Võrumaa'],
- ['LV', 'LV-DGV', 'Daugavpils'],
- ['LV', 'LV-JEL', 'Jelgava'],
- ['LV', 'Jēkabpils', 'Jēkabpils'],
- ['LV', 'LV-JUR', 'Jūrmala'],
- ['LV', 'LV-LPX', 'Liepāja'],
- ['LV', 'LV-LE', 'Liepājas novads'],
- ['LV', 'LV-REZ', 'Rēzekne'],
- ['LV', 'LV-RIX', 'Rīga'],
- ['LV', 'LV-RI', 'Rīgas novads'],
- ['LV', 'Valmiera', 'Valmiera'],
- ['LV', 'LV-VEN', 'Ventspils'],
- ['LV', 'Aglonas novads', 'Aglonas novads'],
- ['LV', 'LV-AI', 'Aizkraukles novads'],
- ['LV', 'Aizputes novads', 'Aizputes novads'],
- ['LV', 'Aknīstes novads', 'Aknīstes novads'],
- ['LV', 'Alojas novads', 'Alojas novads'],
- ['LV', 'Alsungas novads', 'Alsungas novads'],
- ['LV', 'LV-AL', 'Alūksnes novads'],
- ['LV', 'Amatas novads', 'Amatas novads'],
- ['LV', 'Apes novads', 'Apes novads'],
- ['LV', 'Auces novads', 'Auces novads'],
- ['LV', 'Babītes novads', 'Babītes novads'],
- ['LV', 'Baldones novads', 'Baldones novads'],
- ['LV', 'Baltinavas novads', 'Baltinavas novads'],
- ['LV', 'LV-BL', 'Balvu novads'],
- ['LV', 'LV-BU', 'Bauskas novads'],
- ['LV', 'Beverīnas novads', 'Beverīnas novads'],
- ['LV', 'Brocēnu novads', 'Brocēnu novads'],
- ['LV', 'Burtnieku novads', 'Burtnieku novads'],
- ['LV', 'Carnikavas novads', 'Carnikavas novads'],
- ['LV', 'Cesvaines novads', 'Cesvaines novads'],
- ['LV', 'Ciblas novads', 'Ciblas novads'],
- ['LV', 'LV-CE', 'Cēsu novads'],
- ['LV', 'Dagdas novads', 'Dagdas novads'],
- ['LV', 'LV-DA', 'Daugavpils novads'],
- ['LV', 'LV-DO', 'Dobeles novads'],
- ['LV', 'Dundagas novads', 'Dundagas novads'],
- ['LV', 'Durbes novads', 'Durbes novads'],
- ['LV', 'Engures novads', 'Engures novads'],
- ['LV', 'Garkalnes novads', 'Garkalnes novads'],
- ['LV', 'Grobiņas novads', 'Grobiņas novads'],
- ['LV', 'LV-GU', 'Gulbenes novads'],
- ['LV', 'Iecavas novads', 'Iecavas novads'],
- ['LV', 'Ikšķiles novads', 'Ikšķiles novads'],
- ['LV', 'Ilūkstes novads', 'Ilūkstes novads'],
- ['LV', 'Inčukalna novads', 'Inčukalna novads'],
- ['LV', 'Jaunjelgavas novads', 'Jaunjelgavas novads'],
- ['LV', 'Jaunpiebalgas novads', 'Jaunpiebalgas novads'],
- ['LV', 'Jaunpils novads', 'Jaunpils novads'],
- ['LV', 'LV-JL', 'Jelgavas novads'],
- ['LV', 'LV-JK', 'Jēkabpils novads'],
- ['LV', 'Kandavas novads', 'Kandavas novads'],
- ['LV', 'Kokneses novads', 'Kokneses novads'],
- ['LV', 'Krimuldas novads', 'Krimuldas novads'],
- ['LV', 'Krustpils novads', 'Krustpils novads'],
- ['LV', 'LV-KR', 'Krāslavas novads'],
- ['LV', 'LV-KU', 'Kuldīgas novads'],
- ['LV', 'Kārsavas novads', 'Kārsavas novads'],
- ['LV', 'Lielvārdes novads', 'Lielvārdes novads'],
- ['LV', 'LV-LM', 'Limbažu novads'],
- ['LV', 'Lubānas novads', 'Lubānas novads'],
- ['LV', 'LV-LU', 'Ludzas novads'],
- ['LV', 'Līgatnes novads', 'Līgatnes novads'],
- ['LV', 'Līvānu novads', 'Līvānu novads'],
- ['LV', 'LV-MA', 'Madonas novads'],
- ['LV', 'Mazsalacas novads', 'Mazsalacas novads'],
- ['LV', 'Mālpils novads', 'Mālpils novads'],
- ['LV', 'Mārupes novads', 'Mārupes novads'],
- ['LV', 'Naukšēnu novads', 'Naukšēnu novads'],
- ['LV', 'Neretas novads', 'Neretas novads'],
- ['LV', 'Nīcas novads', 'Nīcas novads'],
- ['LV', 'LV-OG', 'Ogres novads'],
- ['LV', 'Olaines novads', 'Olaines novads'],
- ['LV', 'Ozolnieku novads', 'Ozolnieku novads'],
- ['LV', 'LV-PR', 'Preiļu novads'],
- ['LV', 'Priekules novads', 'Priekules novads'],
- ['LV', 'Priekuļu novads', 'Priekuļu novads'],
- ['LV', 'Pārgaujas novads', 'Pārgaujas novads'],
- ['LV', 'Pāvilostas novads', 'Pāvilostas novads'],
- ['LV', 'Pļaviņu novads', 'Pļaviņu novads'],
- ['LV', 'Raunas novads', 'Raunas novads'],
- ['LV', 'Riebiņu novads', 'Riebiņu novads'],
- ['LV', 'Rojas novads', 'Rojas novads'],
- ['LV', 'Ropažu novads', 'Ropažu novads'],
- ['LV', 'Rucavas novads', 'Rucavas novads'],
- ['LV', 'Rugāju novads', 'Rugāju novads'],
- ['LV', 'Rundāles novads', 'Rundāles novads'],
- ['LV', 'LV-RE', 'Rēzeknes novads'],
- ['LV', 'Rūjienas novads', 'Rūjienas novads'],
- ['LV', 'Salacgrīvas novads', 'Salacgrīvas novads'],
- ['LV', 'Salas novads', 'Salas novads'],
- ['LV', 'Salaspils novads', 'Salaspils novads'],
- ['LV', 'LV-SA', 'Saldus novads'],
- ['LV', 'Saulkrastu novads', 'Saulkrastu novads'],
- ['LV', 'Siguldas novads', 'Siguldas novads'],
- ['LV', 'Skrundas novads', 'Skrundas novads'],
- ['LV', 'Skrīveru novads', 'Skrīveru novads'],
- ['LV', 'Smiltenes novads', 'Smiltenes novads'],
- ['LV', 'Stopiņu novads', 'Stopiņu novads'],
- ['LV', 'Strenču novads', 'Strenču novads'],
- ['LV', 'Sējas novads', 'Sējas novads'],
- ['LV', 'LV-TA', 'Talsu novads'],
- ['LV', 'LV-TU', 'Tukuma novads'],
- ['LV', 'Tērvetes novads', 'Tērvetes novads'],
- ['LV', 'Vaiņodes novads', 'Vaiņodes novads'],
- ['LV', 'LV-VK', 'Valkas novads'],
- ['LV', 'LV-VM', 'Valmieras novads'],
- ['LV', 'Varakļānu novads', 'Varakļānu novads'],
- ['LV', 'Vecpiebalgas novads', 'Vecpiebalgas novads'],
- ['LV', 'Vecumnieku novads', 'Vecumnieku novads'],
- ['LV', 'LV-VE', 'Ventspils novads'],
- ['LV', 'Viesītes novads', 'Viesītes novads'],
- ['LV', 'Viļakas novads', 'Viļakas novads'],
- ['LV', 'Viļānu novads', 'Viļānu novads'],
- ['LV', 'Vārkavas novads', 'Vārkavas novads'],
- ['LV', 'Zilupes novads', 'Zilupes novads'],
- ['LV', 'Ādažu novads', 'Ādažu novads'],
- ['LV', 'Ērgļu novads', 'Ērgļu novads'],
- ['LV', 'Ķeguma novads', 'Ķeguma novads'],
- ['LV', 'Ķekavas novads', 'Ķekavas novads'],
- ['LT', 'LT-AL', 'Alytaus Apskritis'],
- ['LT', 'LT-KU', 'Kauno Apskritis'],
- ['LT', 'LT-KL', 'Klaipėdos Apskritis'],
- ['LT', 'LT-MR', 'Marijampolės Apskritis'],
- ['LT', 'LT-PN', 'Panevėžio Apskritis'],
- ['LT', 'LT-SA', 'Šiaulių Apskritis'],
- ['LT', 'LT-TA', 'Tauragės Apskritis'],
- ['LT', 'LT-TE', 'Telšių Apskritis'],
- ['LT', 'LT-UT', 'Utenos Apskritis'],
- ['LT', 'LT-VL', 'Vilniaus Apskritis'],
- ['BR', 'AC', 'Acre'],
- ['BR', 'AL', 'Alagoas'],
- ['BR', 'AP', 'Amapá'],
- ['BR', 'AM', 'Amazonas'],
- ['BR', 'BA', 'Bahia'],
- ['BR', 'CE', 'Ceará'],
- ['BR', 'ES', 'Espírito Santo'],
- ['BR', 'GO', 'Goiás'],
- ['BR', 'MA', 'Maranhão'],
- ['BR', 'MT', 'Mato Grosso'],
- ['BR', 'MS', 'Mato Grosso do Sul'],
- ['BR', 'MG', 'Minas Gerais'],
- ['BR', 'PA', 'Pará'],
- ['BR', 'PB', 'Paraíba'],
- ['BR', 'PR', 'Paraná'],
- ['BR', 'PE', 'Pernambuco'],
- ['BR', 'PI', 'Piauí'],
- ['BR', 'RJ', 'Rio de Janeiro'],
- ['BR', 'RN', 'Rio Grande do Norte'],
- ['BR', 'RS', 'Rio Grande do Sul'],
- ['BR', 'RO', 'Rondônia'],
- ['BR', 'RR', 'Roraima'],
- ['BR', 'SC', 'Santa Catarina'],
- ['BR', 'SP', 'São Paulo'],
- ['BR', 'SE', 'Sergipe'],
- ['BR', 'TO', 'Tocantins'],
- ['BR', 'DF', 'Distrito Federal'],
- ];
-
- foreach ($data as $row) {
- $bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
- $setup->getConnection()->insert($setup->getTable('directory_country_region'), $bind);
- $regionId = $setup->getConnection()->lastInsertId($setup->getTable('directory_country_region'));
-
- $bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]];
- $setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind);
- }
-
- /**
- * Fill table directory/currency_rate
- */
- $data = [
- ['EUR', 'EUR', 1],
- ['EUR', 'USD', 1.415000000000],
- ['USD', 'EUR', 0.706700000000],
- ['USD', 'USD', 1],
- ];
-
- $columns = ['currency_from', 'currency_to', 'rate'];
- $setup->getConnection()->insertArray($setup->getTable('directory_currency_rate'), $columns, $data);
-
- $setup->getConnection()->insert(
- $setup->getTable('core_config_data'),
- [
- 'scope' => 'default',
- 'scope_id' => 0,
- 'path' => Data::XML_PATH_DISPLAY_ALL_STATES,
- 'value' => 1
- ]
- );
-
- $countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates();
- $setup->getConnection()->insert(
- $setup->getTable('core_config_data'),
- [
- 'scope' => 'default',
- 'scope_id' => 0,
- 'path' => Data::XML_PATH_STATES_REQUIRED,
- 'value' => implode(',', array_keys($countries))
- ]
- );
- }
-}
diff --git a/app/code/Magento/Directory/Setup/Patch/Data/AddDataForCroatia.php b/app/code/Magento/Directory/Setup/Patch/Data/AddDataForCroatia.php
new file mode 100644
index 0000000000000..eb9d4f4018b1a
--- /dev/null
+++ b/app/code/Magento/Directory/Setup/Patch/Data/AddDataForCroatia.php
@@ -0,0 +1,115 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->dataInstallerFactory = $dataInstallerFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ /** @var DataInstaller $dataInstaller */
+ $dataInstaller = $this->dataInstallerFactory->create();
+ $dataInstaller->addCountryRegions(
+ $this->moduleDataSetup->getConnection(),
+ $this->getDataForCroatia()
+ );
+ }
+
+ /**
+ * Croatian states data.
+ *
+ * @return array
+ */
+ private function getDataForCroatia()
+ {
+ return [
+ ['HR', 'HR-01', 'Zagrebačka županija'],
+ ['HR', 'HR-02', 'Krapinsko-zagorska županija'],
+ ['HR', 'HR-03', 'Sisačko-moslavačka županija'],
+ ['HR', 'HR-04', 'Karlovačka županija'],
+ ['HR', 'HR-05', 'Varaždinska županija'],
+ ['HR', 'HR-06', 'Koprivničko-križevačka županija'],
+ ['HR', 'HR-07', 'Bjelovarsko-bilogorska županija'],
+ ['HR', 'HR-08', 'Primorsko-goranska županija'],
+ ['HR', 'HR-09', 'Ličko-senjska županija'],
+ ['HR', 'HR-10', 'Virovitičko-podravska županija'],
+ ['HR', 'HR-11', 'Požeško-slavonska županija'],
+ ['HR', 'HR-12', 'Brodsko-posavska županija'],
+ ['HR', 'HR-13', 'Zadarska županija'],
+ ['HR', 'HR-14', 'Osječko-baranjska županija'],
+ ['HR', 'HR-15', 'Šibensko-kninska županija'],
+ ['HR', 'HR-16', 'Vukovarsko-srijemska županija'],
+ ['HR', 'HR-17', 'Splitsko-dalmatinska županija'],
+ ['HR', 'HR-18', 'Istarska županija'],
+ ['HR', 'HR-19', 'Dubrovačko-neretvanska županija'],
+ ['HR', 'HR-20', 'Međimurska županija'],
+ ['HR', 'HR-21', 'Grad Zagreb']
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ InitializeDirectoryData::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.1';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Directory/Setup/Patch/Data/AddDataForIndia.php b/app/code/Magento/Directory/Setup/Patch/Data/AddDataForIndia.php
new file mode 100644
index 0000000000000..69d500960d3f0
--- /dev/null
+++ b/app/code/Magento/Directory/Setup/Patch/Data/AddDataForIndia.php
@@ -0,0 +1,130 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->dataInstallerFactory = $dataInstallerFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function apply()
+ {
+ /** @var DataInstaller $dataInstaller */
+ $dataInstaller = $this->dataInstallerFactory->create();
+ $dataInstaller->addCountryRegions(
+ $this->moduleDataSetup->getConnection(),
+ $this->getDataForIndia()
+ );
+ }
+
+ /**
+ * Indian states data.
+ *
+ * @return array
+ */
+ private function getDataForIndia()
+ {
+ return [
+ ['IN', 'AN', 'Andaman and Nicobar Islands'],
+ ['IN', 'AP', 'Andhra Pradesh'],
+ ['IN', 'AR', 'Arunachal Pradesh'],
+ ['IN', 'AS', 'Assam'],
+ ['IN', 'BR', 'Bihar'],
+ ['IN', 'CH', 'Chandigarh'],
+ ['IN', 'CT', 'Chhattisgarh'],
+ ['IN', 'DN', 'Dadra and Nagar Haveli'],
+ ['IN', 'DD', 'Daman and Diu'],
+ ['IN', 'DL', 'Delhi'],
+ ['IN', 'GA', 'Goa'],
+ ['IN', 'GJ', 'Gujarat'],
+ ['IN', 'HR', 'Haryana'],
+ ['IN', 'HP', 'Himachal Pradesh'],
+ ['IN', 'JK', 'Jammu and Kashmir'],
+ ['IN', 'JH', 'Jharkhand'],
+ ['IN', 'KA', 'Karnataka'],
+ ['IN', 'KL', 'Kerala'],
+ ['IN', 'LD', 'Lakshadweep'],
+ ['IN', 'MP', 'Madhya Pradesh'],
+ ['IN', 'MH', 'Maharashtra'],
+ ['IN', 'MN', 'Manipur'],
+ ['IN', 'ML', 'Meghalaya'],
+ ['IN', 'MZ', 'Mizoram'],
+ ['IN', 'NL', 'Nagaland'],
+ ['IN', 'OR', 'Odisha'],
+ ['IN', 'PY', 'Puducherry'],
+ ['IN', 'PB', 'Punjab'],
+ ['IN', 'RJ', 'Rajasthan'],
+ ['IN', 'SK', 'Sikkim'],
+ ['IN', 'TN', 'Tamil Nadu'],
+ ['IN', 'TG', 'Telangana'],
+ ['IN', 'TR', 'Tripura'],
+ ['IN', 'UP', 'Uttar Pradesh'],
+ ['IN', 'UT', 'Uttarakhand'],
+ ['IN', 'WB', 'West Bengal']
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [
+ InitializeDirectoryData::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.2';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Directory/Setup/Patch/Data/InitializeDirectoryData.php b/app/code/Magento/Directory/Setup/Patch/Data/InitializeDirectoryData.php
new file mode 100644
index 0000000000000..79ac53d3a449f
--- /dev/null
+++ b/app/code/Magento/Directory/Setup/Patch/Data/InitializeDirectoryData.php
@@ -0,0 +1,899 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->directoryDataFactory = $directoryDataFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+ */
+ public function apply()
+ {
+ /**
+ * Fill table directory/country
+ */
+ $data = [
+ ['AD', 'AD', 'AND'],
+ ['AE', 'AE', 'ARE'],
+ ['AF', 'AF', 'AFG'],
+ ['AG', 'AG', 'ATG'],
+ ['AI', 'AI', 'AIA'],
+ ['AL', 'AL', 'ALB'],
+ ['AM', 'AM', 'ARM'],
+ ['AN', 'AN', 'ANT'],
+ ['AO', 'AO', 'AGO'],
+ ['AQ', 'AQ', 'ATA'],
+ ['AR', 'AR', 'ARG'],
+ ['AS', 'AS', 'ASM'],
+ ['AT', 'AT', 'AUT'],
+ ['AU', 'AU', 'AUS'],
+ ['AW', 'AW', 'ABW'],
+ ['AX', 'AX', 'ALA'],
+ ['AZ', 'AZ', 'AZE'],
+ ['BA', 'BA', 'BIH'],
+ ['BB', 'BB', 'BRB'],
+ ['BD', 'BD', 'BGD'],
+ ['BE', 'BE', 'BEL'],
+ ['BF', 'BF', 'BFA'],
+ ['BG', 'BG', 'BGR'],
+ ['BH', 'BH', 'BHR'],
+ ['BI', 'BI', 'BDI'],
+ ['BJ', 'BJ', 'BEN'],
+ ['BL', 'BL', 'BLM'],
+ ['BM', 'BM', 'BMU'],
+ ['BN', 'BN', 'BRN'],
+ ['BO', 'BO', 'BOL'],
+ ['BR', 'BR', 'BRA'],
+ ['BS', 'BS', 'BHS'],
+ ['BT', 'BT', 'BTN'],
+ ['BV', 'BV', 'BVT'],
+ ['BW', 'BW', 'BWA'],
+ ['BY', 'BY', 'BLR'],
+ ['BZ', 'BZ', 'BLZ'],
+ ['CA', 'CA', 'CAN'],
+ ['CC', 'CC', 'CCK'],
+ ['CD', 'CD', 'COD'],
+ ['CF', 'CF', 'CAF'],
+ ['CG', 'CG', 'COG'],
+ ['CH', 'CH', 'CHE'],
+ ['CI', 'CI', 'CIV'],
+ ['CK', 'CK', 'COK'],
+ ['CL', 'CL', 'CHL'],
+ ['CM', 'CM', 'CMR'],
+ ['CN', 'CN', 'CHN'],
+ ['CO', 'CO', 'COL'],
+ ['CR', 'CR', 'CRI'],
+ ['CU', 'CU', 'CUB'],
+ ['CV', 'CV', 'CPV'],
+ ['CX', 'CX', 'CXR'],
+ ['CY', 'CY', 'CYP'],
+ ['CZ', 'CZ', 'CZE'],
+ ['DE', 'DE', 'DEU'],
+ ['DJ', 'DJ', 'DJI'],
+ ['DK', 'DK', 'DNK'],
+ ['DM', 'DM', 'DMA'],
+ ['DO', 'DO', 'DOM'],
+ ['DZ', 'DZ', 'DZA'],
+ ['EC', 'EC', 'ECU'],
+ ['EE', 'EE', 'EST'],
+ ['EG', 'EG', 'EGY'],
+ ['EH', 'EH', 'ESH'],
+ ['ER', 'ER', 'ERI'],
+ ['ES', 'ES', 'ESP'],
+ ['ET', 'ET', 'ETH'],
+ ['FI', 'FI', 'FIN'],
+ ['FJ', 'FJ', 'FJI'],
+ ['FK', 'FK', 'FLK'],
+ ['FM', 'FM', 'FSM'],
+ ['FO', 'FO', 'FRO'],
+ ['FR', 'FR', 'FRA'],
+ ['GA', 'GA', 'GAB'],
+ ['GB', 'GB', 'GBR'],
+ ['GD', 'GD', 'GRD'],
+ ['GE', 'GE', 'GEO'],
+ ['GF', 'GF', 'GUF'],
+ ['GG', 'GG', 'GGY'],
+ ['GH', 'GH', 'GHA'],
+ ['GI', 'GI', 'GIB'],
+ ['GL', 'GL', 'GRL'],
+ ['GM', 'GM', 'GMB'],
+ ['GN', 'GN', 'GIN'],
+ ['GP', 'GP', 'GLP'],
+ ['GQ', 'GQ', 'GNQ'],
+ ['GR', 'GR', 'GRC'],
+ ['GS', 'GS', 'SGS'],
+ ['GT', 'GT', 'GTM'],
+ ['GU', 'GU', 'GUM'],
+ ['GW', 'GW', 'GNB'],
+ ['GY', 'GY', 'GUY'],
+ ['HK', 'HK', 'HKG'],
+ ['HM', 'HM', 'HMD'],
+ ['HN', 'HN', 'HND'],
+ ['HR', 'HR', 'HRV'],
+ ['HT', 'HT', 'HTI'],
+ ['HU', 'HU', 'HUN'],
+ ['ID', 'ID', 'IDN'],
+ ['IE', 'IE', 'IRL'],
+ ['IL', 'IL', 'ISR'],
+ ['IM', 'IM', 'IMN'],
+ ['IN', 'IN', 'IND'],
+ ['IO', 'IO', 'IOT'],
+ ['IQ', 'IQ', 'IRQ'],
+ ['IR', 'IR', 'IRN'],
+ ['IS', 'IS', 'ISL'],
+ ['IT', 'IT', 'ITA'],
+ ['JE', 'JE', 'JEY'],
+ ['JM', 'JM', 'JAM'],
+ ['JO', 'JO', 'JOR'],
+ ['JP', 'JP', 'JPN'],
+ ['KE', 'KE', 'KEN'],
+ ['KG', 'KG', 'KGZ'],
+ ['KH', 'KH', 'KHM'],
+ ['KI', 'KI', 'KIR'],
+ ['KM', 'KM', 'COM'],
+ ['KN', 'KN', 'KNA'],
+ ['KP', 'KP', 'PRK'],
+ ['KR', 'KR', 'KOR'],
+ ['KW', 'KW', 'KWT'],
+ ['KY', 'KY', 'CYM'],
+ ['KZ', 'KZ', 'KAZ'],
+ ['LA', 'LA', 'LAO'],
+ ['LB', 'LB', 'LBN'],
+ ['LC', 'LC', 'LCA'],
+ ['LI', 'LI', 'LIE'],
+ ['LK', 'LK', 'LKA'],
+ ['LR', 'LR', 'LBR'],
+ ['LS', 'LS', 'LSO'],
+ ['LT', 'LT', 'LTU'],
+ ['LU', 'LU', 'LUX'],
+ ['LV', 'LV', 'LVA'],
+ ['LY', 'LY', 'LBY'],
+ ['MA', 'MA', 'MAR'],
+ ['MC', 'MC', 'MCO'],
+ ['MD', 'MD', 'MDA'],
+ ['ME', 'ME', 'MNE'],
+ ['MF', 'MF', 'MAF'],
+ ['MG', 'MG', 'MDG'],
+ ['MH', 'MH', 'MHL'],
+ ['MK', 'MK', 'MKD'],
+ ['ML', 'ML', 'MLI'],
+ ['MM', 'MM', 'MMR'],
+ ['MN', 'MN', 'MNG'],
+ ['MO', 'MO', 'MAC'],
+ ['MP', 'MP', 'MNP'],
+ ['MQ', 'MQ', 'MTQ'],
+ ['MR', 'MR', 'MRT'],
+ ['MS', 'MS', 'MSR'],
+ ['MT', 'MT', 'MLT'],
+ ['MU', 'MU', 'MUS'],
+ ['MV', 'MV', 'MDV'],
+ ['MW', 'MW', 'MWI'],
+ ['MX', 'MX', 'MEX'],
+ ['MY', 'MY', 'MYS'],
+ ['MZ', 'MZ', 'MOZ'],
+ ['NA', 'NA', 'NAM'],
+ ['NC', 'NC', 'NCL'],
+ ['NE', 'NE', 'NER'],
+ ['NF', 'NF', 'NFK'],
+ ['NG', 'NG', 'NGA'],
+ ['NI', 'NI', 'NIC'],
+ ['NL', 'NL', 'NLD'],
+ ['NO', 'NO', 'NOR'],
+ ['NP', 'NP', 'NPL'],
+ ['NR', 'NR', 'NRU'],
+ ['NU', 'NU', 'NIU'],
+ ['NZ', 'NZ', 'NZL'],
+ ['OM', 'OM', 'OMN'],
+ ['PA', 'PA', 'PAN'],
+ ['PE', 'PE', 'PER'],
+ ['PF', 'PF', 'PYF'],
+ ['PG', 'PG', 'PNG'],
+ ['PH', 'PH', 'PHL'],
+ ['PK', 'PK', 'PAK'],
+ ['PL', 'PL', 'POL'],
+ ['PM', 'PM', 'SPM'],
+ ['PN', 'PN', 'PCN'],
+ ['PS', 'PS', 'PSE'],
+ ['PT', 'PT', 'PRT'],
+ ['PW', 'PW', 'PLW'],
+ ['PY', 'PY', 'PRY'],
+ ['QA', 'QA', 'QAT'],
+ ['RE', 'RE', 'REU'],
+ ['RO', 'RO', 'ROU'],
+ ['RS', 'RS', 'SRB'],
+ ['RU', 'RU', 'RUS'],
+ ['RW', 'RW', 'RWA'],
+ ['SA', 'SA', 'SAU'],
+ ['SB', 'SB', 'SLB'],
+ ['SC', 'SC', 'SYC'],
+ ['SD', 'SD', 'SDN'],
+ ['SE', 'SE', 'SWE'],
+ ['SG', 'SG', 'SGP'],
+ ['SH', 'SH', 'SHN'],
+ ['SI', 'SI', 'SVN'],
+ ['SJ', 'SJ', 'SJM'],
+ ['SK', 'SK', 'SVK'],
+ ['SL', 'SL', 'SLE'],
+ ['SM', 'SM', 'SMR'],
+ ['SN', 'SN', 'SEN'],
+ ['SO', 'SO', 'SOM'],
+ ['SR', 'SR', 'SUR'],
+ ['ST', 'ST', 'STP'],
+ ['SV', 'SV', 'SLV'],
+ ['SY', 'SY', 'SYR'],
+ ['SZ', 'SZ', 'SWZ'],
+ ['TC', 'TC', 'TCA'],
+ ['TD', 'TD', 'TCD'],
+ ['TF', 'TF', 'ATF'],
+ ['TG', 'TG', 'TGO'],
+ ['TH', 'TH', 'THA'],
+ ['TJ', 'TJ', 'TJK'],
+ ['TK', 'TK', 'TKL'],
+ ['TL', 'TL', 'TLS'],
+ ['TM', 'TM', 'TKM'],
+ ['TN', 'TN', 'TUN'],
+ ['TO', 'TO', 'TON'],
+ ['TR', 'TR', 'TUR'],
+ ['TT', 'TT', 'TTO'],
+ ['TV', 'TV', 'TUV'],
+ ['TW', 'TW', 'TWN'],
+ ['TZ', 'TZ', 'TZA'],
+ ['UA', 'UA', 'UKR'],
+ ['UG', 'UG', 'UGA'],
+ ['UM', 'UM', 'UMI'],
+ ['US', 'US', 'USA'],
+ ['UY', 'UY', 'URY'],
+ ['UZ', 'UZ', 'UZB'],
+ ['VA', 'VA', 'VAT'],
+ ['VC', 'VC', 'VCT'],
+ ['VE', 'VE', 'VEN'],
+ ['VG', 'VG', 'VGB'],
+ ['VI', 'VI', 'VIR'],
+ ['VN', 'VN', 'VNM'],
+ ['VU', 'VU', 'VUT'],
+ ['WF', 'WF', 'WLF'],
+ ['WS', 'WS', 'WSM'],
+ ['YE', 'YE', 'YEM'],
+ ['YT', 'YT', 'MYT'],
+ ['ZA', 'ZA', 'ZAF'],
+ ['ZM', 'ZM', 'ZMB'],
+ ['ZW', 'ZW', 'ZWE'],
+ ];
+
+ $columns = ['country_id', 'iso2_code', 'iso3_code'];
+ $this->moduleDataSetup->getConnection()->insertArray(
+ $this->moduleDataSetup->getTable('directory_country'),
+ $columns,
+ $data
+ );
+ /**
+ * Fill table directory/country_region
+ * Fill table directory/country_region_name for en_US locale
+ */
+ $data = [
+ ['US', 'AL', 'Alabama'],
+ ['US', 'AK', 'Alaska'],
+ ['US', 'AS', 'American Samoa'],
+ ['US', 'AZ', 'Arizona'],
+ ['US', 'AR', 'Arkansas'],
+ ['US', 'AE', 'Armed Forces Africa'],
+ ['US', 'AA', 'Armed Forces Americas'],
+ ['US', 'AE', 'Armed Forces Canada'],
+ ['US', 'AE', 'Armed Forces Europe'],
+ ['US', 'AE', 'Armed Forces Middle East'],
+ ['US', 'AP', 'Armed Forces Pacific'],
+ ['US', 'CA', 'California'],
+ ['US', 'CO', 'Colorado'],
+ ['US', 'CT', 'Connecticut'],
+ ['US', 'DE', 'Delaware'],
+ ['US', 'DC', 'District of Columbia'],
+ ['US', 'FM', 'Federated States Of Micronesia'],
+ ['US', 'FL', 'Florida'],
+ ['US', 'GA', 'Georgia'],
+ ['US', 'GU', 'Guam'],
+ ['US', 'HI', 'Hawaii'],
+ ['US', 'ID', 'Idaho'],
+ ['US', 'IL', 'Illinois'],
+ ['US', 'IN', 'Indiana'],
+ ['US', 'IA', 'Iowa'],
+ ['US', 'KS', 'Kansas'],
+ ['US', 'KY', 'Kentucky'],
+ ['US', 'LA', 'Louisiana'],
+ ['US', 'ME', 'Maine'],
+ ['US', 'MH', 'Marshall Islands'],
+ ['US', 'MD', 'Maryland'],
+ ['US', 'MA', 'Massachusetts'],
+ ['US', 'MI', 'Michigan'],
+ ['US', 'MN', 'Minnesota'],
+ ['US', 'MS', 'Mississippi'],
+ ['US', 'MO', 'Missouri'],
+ ['US', 'MT', 'Montana'],
+ ['US', 'NE', 'Nebraska'],
+ ['US', 'NV', 'Nevada'],
+ ['US', 'NH', 'New Hampshire'],
+ ['US', 'NJ', 'New Jersey'],
+ ['US', 'NM', 'New Mexico'],
+ ['US', 'NY', 'New York'],
+ ['US', 'NC', 'North Carolina'],
+ ['US', 'ND', 'North Dakota'],
+ ['US', 'MP', 'Northern Mariana Islands'],
+ ['US', 'OH', 'Ohio'],
+ ['US', 'OK', 'Oklahoma'],
+ ['US', 'OR', 'Oregon'],
+ ['US', 'PW', 'Palau'],
+ ['US', 'PA', 'Pennsylvania'],
+ ['US', 'PR', 'Puerto Rico'],
+ ['US', 'RI', 'Rhode Island'],
+ ['US', 'SC', 'South Carolina'],
+ ['US', 'SD', 'South Dakota'],
+ ['US', 'TN', 'Tennessee'],
+ ['US', 'TX', 'Texas'],
+ ['US', 'UT', 'Utah'],
+ ['US', 'VT', 'Vermont'],
+ ['US', 'VI', 'Virgin Islands'],
+ ['US', 'VA', 'Virginia'],
+ ['US', 'WA', 'Washington'],
+ ['US', 'WV', 'West Virginia'],
+ ['US', 'WI', 'Wisconsin'],
+ ['US', 'WY', 'Wyoming'],
+ ['CA', 'AB', 'Alberta'],
+ ['CA', 'BC', 'British Columbia'],
+ ['CA', 'MB', 'Manitoba'],
+ ['CA', 'NL', 'Newfoundland and Labrador'],
+ ['CA', 'NB', 'New Brunswick'],
+ ['CA', 'NS', 'Nova Scotia'],
+ ['CA', 'NT', 'Northwest Territories'],
+ ['CA', 'NU', 'Nunavut'],
+ ['CA', 'ON', 'Ontario'],
+ ['CA', 'PE', 'Prince Edward Island'],
+ ['CA', 'QC', 'Quebec'],
+ ['CA', 'SK', 'Saskatchewan'],
+ ['CA', 'YT', 'Yukon Territory'],
+ ['DE', 'NDS', 'Niedersachsen'],
+ ['DE', 'BAW', 'Baden-Württemberg'],
+ ['DE', 'BAY', 'Bayern'],
+ ['DE', 'BER', 'Berlin'],
+ ['DE', 'BRG', 'Brandenburg'],
+ ['DE', 'BRE', 'Bremen'],
+ ['DE', 'HAM', 'Hamburg'],
+ ['DE', 'HES', 'Hessen'],
+ ['DE', 'MEC', 'Mecklenburg-Vorpommern'],
+ ['DE', 'NRW', 'Nordrhein-Westfalen'],
+ ['DE', 'RHE', 'Rheinland-Pfalz'],
+ ['DE', 'SAR', 'Saarland'],
+ ['DE', 'SAS', 'Sachsen'],
+ ['DE', 'SAC', 'Sachsen-Anhalt'],
+ ['DE', 'SCN', 'Schleswig-Holstein'],
+ ['DE', 'THE', 'Thüringen'],
+ ['AT', 'WI', 'Wien'],
+ ['AT', 'NO', 'Niederösterreich'],
+ ['AT', 'OO', 'Oberösterreich'],
+ ['AT', 'SB', 'Salzburg'],
+ ['AT', 'KN', 'Kärnten'],
+ ['AT', 'ST', 'Steiermark'],
+ ['AT', 'TI', 'Tirol'],
+ ['AT', 'BL', 'Burgenland'],
+ ['AT', 'VB', 'Vorarlberg'],
+ ['CH', 'AG', 'Aargau'],
+ ['CH', 'AI', 'Appenzell Innerrhoden'],
+ ['CH', 'AR', 'Appenzell Ausserrhoden'],
+ ['CH', 'BE', 'Bern'],
+ ['CH', 'BL', 'Basel-Landschaft'],
+ ['CH', 'BS', 'Basel-Stadt'],
+ ['CH', 'FR', 'Freiburg'],
+ ['CH', 'GE', 'Genf'],
+ ['CH', 'GL', 'Glarus'],
+ ['CH', 'GR', 'Graubünden'],
+ ['CH', 'JU', 'Jura'],
+ ['CH', 'LU', 'Luzern'],
+ ['CH', 'NE', 'Neuenburg'],
+ ['CH', 'NW', 'Nidwalden'],
+ ['CH', 'OW', 'Obwalden'],
+ ['CH', 'SG', 'St. Gallen'],
+ ['CH', 'SH', 'Schaffhausen'],
+ ['CH', 'SO', 'Solothurn'],
+ ['CH', 'SZ', 'Schwyz'],
+ ['CH', 'TG', 'Thurgau'],
+ ['CH', 'TI', 'Tessin'],
+ ['CH', 'UR', 'Uri'],
+ ['CH', 'VD', 'Waadt'],
+ ['CH', 'VS', 'Wallis'],
+ ['CH', 'ZG', 'Zug'],
+ ['CH', 'ZH', 'Zürich'],
+ ['ES', 'A Coruсa', 'A Coruña'],
+ ['ES', 'Alava', 'Alava'],
+ ['ES', 'Albacete', 'Albacete'],
+ ['ES', 'Alicante', 'Alicante'],
+ ['ES', 'Almeria', 'Almeria'],
+ ['ES', 'Asturias', 'Asturias'],
+ ['ES', 'Avila', 'Avila'],
+ ['ES', 'Badajoz', 'Badajoz'],
+ ['ES', 'Baleares', 'Baleares'],
+ ['ES', 'Barcelona', 'Barcelona'],
+ ['ES', 'Burgos', 'Burgos'],
+ ['ES', 'Caceres', 'Caceres'],
+ ['ES', 'Cadiz', 'Cadiz'],
+ ['ES', 'Cantabria', 'Cantabria'],
+ ['ES', 'Castellon', 'Castellon'],
+ ['ES', 'Ceuta', 'Ceuta'],
+ ['ES', 'Ciudad Real', 'Ciudad Real'],
+ ['ES', 'Cordoba', 'Cordoba'],
+ ['ES', 'Cuenca', 'Cuenca'],
+ ['ES', 'Girona', 'Girona'],
+ ['ES', 'Granada', 'Granada'],
+ ['ES', 'Guadalajara', 'Guadalajara'],
+ ['ES', 'Guipuzcoa', 'Guipuzcoa'],
+ ['ES', 'Huelva', 'Huelva'],
+ ['ES', 'Huesca', 'Huesca'],
+ ['ES', 'Jaen', 'Jaen'],
+ ['ES', 'La Rioja', 'La Rioja'],
+ ['ES', 'Las Palmas', 'Las Palmas'],
+ ['ES', 'Leon', 'Leon'],
+ ['ES', 'Lleida', 'Lleida'],
+ ['ES', 'Lugo', 'Lugo'],
+ ['ES', 'Madrid', 'Madrid'],
+ ['ES', 'Malaga', 'Malaga'],
+ ['ES', 'Melilla', 'Melilla'],
+ ['ES', 'Murcia', 'Murcia'],
+ ['ES', 'Navarra', 'Navarra'],
+ ['ES', 'Ourense', 'Ourense'],
+ ['ES', 'Palencia', 'Palencia'],
+ ['ES', 'Pontevedra', 'Pontevedra'],
+ ['ES', 'Salamanca', 'Salamanca'],
+ ['ES', 'Santa Cruz de Tenerife', 'Santa Cruz de Tenerife'],
+ ['ES', 'Segovia', 'Segovia'],
+ ['ES', 'Sevilla', 'Sevilla'],
+ ['ES', 'Soria', 'Soria'],
+ ['ES', 'Tarragona', 'Tarragona'],
+ ['ES', 'Teruel', 'Teruel'],
+ ['ES', 'Toledo', 'Toledo'],
+ ['ES', 'Valencia', 'Valencia'],
+ ['ES', 'Valladolid', 'Valladolid'],
+ ['ES', 'Vizcaya', 'Vizcaya'],
+ ['ES', 'Zamora', 'Zamora'],
+ ['ES', 'Zaragoza', 'Zaragoza'],
+ ['FR', 1, 'Ain'],
+ ['FR', 2, 'Aisne'],
+ ['FR', 3, 'Allier'],
+ ['FR', 4, 'Alpes-de-Haute-Provence'],
+ ['FR', 5, 'Hautes-Alpes'],
+ ['FR', 6, 'Alpes-Maritimes'],
+ ['FR', 7, 'Ardèche'],
+ ['FR', 8, 'Ardennes'],
+ ['FR', 9, 'Ariège'],
+ ['FR', 10, 'Aube'],
+ ['FR', 11, 'Aude'],
+ ['FR', 12, 'Aveyron'],
+ ['FR', 13, 'Bouches-du-Rhône'],
+ ['FR', 14, 'Calvados'],
+ ['FR', 15, 'Cantal'],
+ ['FR', 16, 'Charente'],
+ ['FR', 17, 'Charente-Maritime'],
+ ['FR', 18, 'Cher'],
+ ['FR', 19, 'Corrèze'],
+ ['FR', '2A', 'Corse-du-Sud'],
+ ['FR', '2B', 'Haute-Corse'],
+ ['FR', 21, 'Côte-d\'Or'],
+ ['FR', 22, 'Côtes-d\'Armor'],
+ ['FR', 23, 'Creuse'],
+ ['FR', 24, 'Dordogne'],
+ ['FR', 25, 'Doubs'],
+ ['FR', 26, 'Drôme'],
+ ['FR', 27, 'Eure'],
+ ['FR', 28, 'Eure-et-Loir'],
+ ['FR', 29, 'Finistère'],
+ ['FR', 30, 'Gard'],
+ ['FR', 31, 'Haute-Garonne'],
+ ['FR', 32, 'Gers'],
+ ['FR', 33, 'Gironde'],
+ ['FR', 34, 'Hérault'],
+ ['FR', 35, 'Ille-et-Vilaine'],
+ ['FR', 36, 'Indre'],
+ ['FR', 37, 'Indre-et-Loire'],
+ ['FR', 38, 'Isère'],
+ ['FR', 39, 'Jura'],
+ ['FR', 40, 'Landes'],
+ ['FR', 41, 'Loir-et-Cher'],
+ ['FR', 42, 'Loire'],
+ ['FR', 43, 'Haute-Loire'],
+ ['FR', 44, 'Loire-Atlantique'],
+ ['FR', 45, 'Loiret'],
+ ['FR', 46, 'Lot'],
+ ['FR', 47, 'Lot-et-Garonne'],
+ ['FR', 48, 'Lozère'],
+ ['FR', 49, 'Maine-et-Loire'],
+ ['FR', 50, 'Manche'],
+ ['FR', 51, 'Marne'],
+ ['FR', 52, 'Haute-Marne'],
+ ['FR', 53, 'Mayenne'],
+ ['FR', 54, 'Meurthe-et-Moselle'],
+ ['FR', 55, 'Meuse'],
+ ['FR', 56, 'Morbihan'],
+ ['FR', 57, 'Moselle'],
+ ['FR', 58, 'Nièvre'],
+ ['FR', 59, 'Nord'],
+ ['FR', 60, 'Oise'],
+ ['FR', 61, 'Orne'],
+ ['FR', 62, 'Pas-de-Calais'],
+ ['FR', 63, 'Puy-de-Dôme'],
+ ['FR', 64, 'Pyrénées-Atlantiques'],
+ ['FR', 65, 'Hautes-Pyrénées'],
+ ['FR', 66, 'Pyrénées-Orientales'],
+ ['FR', 67, 'Bas-Rhin'],
+ ['FR', 68, 'Haut-Rhin'],
+ ['FR', 69, 'Rhône'],
+ ['FR', 70, 'Haute-Saône'],
+ ['FR', 71, 'Saône-et-Loire'],
+ ['FR', 72, 'Sarthe'],
+ ['FR', 73, 'Savoie'],
+ ['FR', 74, 'Haute-Savoie'],
+ ['FR', 75, 'Paris'],
+ ['FR', 76, 'Seine-Maritime'],
+ ['FR', 77, 'Seine-et-Marne'],
+ ['FR', 78, 'Yvelines'],
+ ['FR', 79, 'Deux-Sèvres'],
+ ['FR', 80, 'Somme'],
+ ['FR', 81, 'Tarn'],
+ ['FR', 82, 'Tarn-et-Garonne'],
+ ['FR', 83, 'Var'],
+ ['FR', 84, 'Vaucluse'],
+ ['FR', 85, 'Vendée'],
+ ['FR', 86, 'Vienne'],
+ ['FR', 87, 'Haute-Vienne'],
+ ['FR', 88, 'Vosges'],
+ ['FR', 89, 'Yonne'],
+ ['FR', 90, 'Territoire-de-Belfort'],
+ ['FR', 91, 'Essonne'],
+ ['FR', 92, 'Hauts-de-Seine'],
+ ['FR', 93, 'Seine-Saint-Denis'],
+ ['FR', 94, 'Val-de-Marne'],
+ ['FR', 95, 'Val-d\'Oise'],
+ ['RO', 'AB', 'Alba'],
+ ['RO', 'AR', 'Arad'],
+ ['RO', 'AG', 'Argeş'],
+ ['RO', 'BC', 'Bacău'],
+ ['RO', 'BH', 'Bihor'],
+ ['RO', 'BN', 'Bistriţa-Năsăud'],
+ ['RO', 'BT', 'Botoşani'],
+ ['RO', 'BV', 'Braşov'],
+ ['RO', 'BR', 'Brăila'],
+ ['RO', 'B', 'Bucureşti'],
+ ['RO', 'BZ', 'Buzău'],
+ ['RO', 'CS', 'Caraş-Severin'],
+ ['RO', 'CL', 'Călăraşi'],
+ ['RO', 'CJ', 'Cluj'],
+ ['RO', 'CT', 'Constanţa'],
+ ['RO', 'CV', 'Covasna'],
+ ['RO', 'DB', 'Dâmboviţa'],
+ ['RO', 'DJ', 'Dolj'],
+ ['RO', 'GL', 'Galaţi'],
+ ['RO', 'GR', 'Giurgiu'],
+ ['RO', 'GJ', 'Gorj'],
+ ['RO', 'HR', 'Harghita'],
+ ['RO', 'HD', 'Hunedoara'],
+ ['RO', 'IL', 'Ialomiţa'],
+ ['RO', 'IS', 'Iaşi'],
+ ['RO', 'IF', 'Ilfov'],
+ ['RO', 'MM', 'Maramureş'],
+ ['RO', 'MH', 'Mehedinţi'],
+ ['RO', 'MS', 'Mureş'],
+ ['RO', 'NT', 'Neamţ'],
+ ['RO', 'OT', 'Olt'],
+ ['RO', 'PH', 'Prahova'],
+ ['RO', 'SM', 'Satu-Mare'],
+ ['RO', 'SJ', 'Sălaj'],
+ ['RO', 'SB', 'Sibiu'],
+ ['RO', 'SV', 'Suceava'],
+ ['RO', 'TR', 'Teleorman'],
+ ['RO', 'TM', 'Timiş'],
+ ['RO', 'TL', 'Tulcea'],
+ ['RO', 'VS', 'Vaslui'],
+ ['RO', 'VL', 'Vâlcea'],
+ ['RO', 'VN', 'Vrancea'],
+ ['FI', 'Lappi', 'Lappi'],
+ ['FI', 'Pohjois-Pohjanmaa', 'Pohjois-Pohjanmaa'],
+ ['FI', 'Kainuu', 'Kainuu'],
+ ['FI', 'Pohjois-Karjala', 'Pohjois-Karjala'],
+ ['FI', 'Pohjois-Savo', 'Pohjois-Savo'],
+ ['FI', 'Etelä-Savo', 'Etelä-Savo'],
+ ['FI', 'Etelä-Pohjanmaa', 'Etelä-Pohjanmaa'],
+ ['FI', 'Pohjanmaa', 'Pohjanmaa'],
+ ['FI', 'Pirkanmaa', 'Pirkanmaa'],
+ ['FI', 'Satakunta', 'Satakunta'],
+ ['FI', 'Keski-Pohjanmaa', 'Keski-Pohjanmaa'],
+ ['FI', 'Keski-Suomi', 'Keski-Suomi'],
+ ['FI', 'Varsinais-Suomi', 'Varsinais-Suomi'],
+ ['FI', 'Etelä-Karjala', 'Etelä-Karjala'],
+ ['FI', 'Päijät-Häme', 'Päijät-Häme'],
+ ['FI', 'Kanta-Häme', 'Kanta-Häme'],
+ ['FI', 'Uusimaa', 'Uusimaa'],
+ ['FI', 'Itä-Uusimaa', 'Itä-Uusimaa'],
+ ['FI', 'Kymenlaakso', 'Kymenlaakso'],
+ ['FI', 'Ahvenanmaa', 'Ahvenanmaa'],
+ ['EE', 'EE-37', 'Harjumaa'],
+ ['EE', 'EE-39', 'Hiiumaa'],
+ ['EE', 'EE-44', 'Ida-Virumaa'],
+ ['EE', 'EE-49', 'Jõgevamaa'],
+ ['EE', 'EE-51', 'Järvamaa'],
+ ['EE', 'EE-57', 'Läänemaa'],
+ ['EE', 'EE-59', 'Lääne-Virumaa'],
+ ['EE', 'EE-65', 'Põlvamaa'],
+ ['EE', 'EE-67', 'Pärnumaa'],
+ ['EE', 'EE-70', 'Raplamaa'],
+ ['EE', 'EE-74', 'Saaremaa'],
+ ['EE', 'EE-78', 'Tartumaa'],
+ ['EE', 'EE-82', 'Valgamaa'],
+ ['EE', 'EE-84', 'Viljandimaa'],
+ ['EE', 'EE-86', 'Võrumaa'],
+ ['LV', 'LV-DGV', 'Daugavpils'],
+ ['LV', 'LV-JEL', 'Jelgava'],
+ ['LV', 'Jēkabpils', 'Jēkabpils'],
+ ['LV', 'LV-JUR', 'Jūrmala'],
+ ['LV', 'LV-LPX', 'Liepāja'],
+ ['LV', 'LV-LE', 'Liepājas novads'],
+ ['LV', 'LV-REZ', 'Rēzekne'],
+ ['LV', 'LV-RIX', 'Rīga'],
+ ['LV', 'LV-RI', 'Rīgas novads'],
+ ['LV', 'Valmiera', 'Valmiera'],
+ ['LV', 'LV-VEN', 'Ventspils'],
+ ['LV', 'Aglonas novads', 'Aglonas novads'],
+ ['LV', 'LV-AI', 'Aizkraukles novads'],
+ ['LV', 'Aizputes novads', 'Aizputes novads'],
+ ['LV', 'Aknīstes novads', 'Aknīstes novads'],
+ ['LV', 'Alojas novads', 'Alojas novads'],
+ ['LV', 'Alsungas novads', 'Alsungas novads'],
+ ['LV', 'LV-AL', 'Alūksnes novads'],
+ ['LV', 'Amatas novads', 'Amatas novads'],
+ ['LV', 'Apes novads', 'Apes novads'],
+ ['LV', 'Auces novads', 'Auces novads'],
+ ['LV', 'Babītes novads', 'Babītes novads'],
+ ['LV', 'Baldones novads', 'Baldones novads'],
+ ['LV', 'Baltinavas novads', 'Baltinavas novads'],
+ ['LV', 'LV-BL', 'Balvu novads'],
+ ['LV', 'LV-BU', 'Bauskas novads'],
+ ['LV', 'Beverīnas novads', 'Beverīnas novads'],
+ ['LV', 'Brocēnu novads', 'Brocēnu novads'],
+ ['LV', 'Burtnieku novads', 'Burtnieku novads'],
+ ['LV', 'Carnikavas novads', 'Carnikavas novads'],
+ ['LV', 'Cesvaines novads', 'Cesvaines novads'],
+ ['LV', 'Ciblas novads', 'Ciblas novads'],
+ ['LV', 'LV-CE', 'Cēsu novads'],
+ ['LV', 'Dagdas novads', 'Dagdas novads'],
+ ['LV', 'LV-DA', 'Daugavpils novads'],
+ ['LV', 'LV-DO', 'Dobeles novads'],
+ ['LV', 'Dundagas novads', 'Dundagas novads'],
+ ['LV', 'Durbes novads', 'Durbes novads'],
+ ['LV', 'Engures novads', 'Engures novads'],
+ ['LV', 'Garkalnes novads', 'Garkalnes novads'],
+ ['LV', 'Grobiņas novads', 'Grobiņas novads'],
+ ['LV', 'LV-GU', 'Gulbenes novads'],
+ ['LV', 'Iecavas novads', 'Iecavas novads'],
+ ['LV', 'Ikšķiles novads', 'Ikšķiles novads'],
+ ['LV', 'Ilūkstes novads', 'Ilūkstes novads'],
+ ['LV', 'Inčukalna novads', 'Inčukalna novads'],
+ ['LV', 'Jaunjelgavas novads', 'Jaunjelgavas novads'],
+ ['LV', 'Jaunpiebalgas novads', 'Jaunpiebalgas novads'],
+ ['LV', 'Jaunpils novads', 'Jaunpils novads'],
+ ['LV', 'LV-JL', 'Jelgavas novads'],
+ ['LV', 'LV-JK', 'Jēkabpils novads'],
+ ['LV', 'Kandavas novads', 'Kandavas novads'],
+ ['LV', 'Kokneses novads', 'Kokneses novads'],
+ ['LV', 'Krimuldas novads', 'Krimuldas novads'],
+ ['LV', 'Krustpils novads', 'Krustpils novads'],
+ ['LV', 'LV-KR', 'Krāslavas novads'],
+ ['LV', 'LV-KU', 'Kuldīgas novads'],
+ ['LV', 'Kārsavas novads', 'Kārsavas novads'],
+ ['LV', 'Lielvārdes novads', 'Lielvārdes novads'],
+ ['LV', 'LV-LM', 'Limbažu novads'],
+ ['LV', 'Lubānas novads', 'Lubānas novads'],
+ ['LV', 'LV-LU', 'Ludzas novads'],
+ ['LV', 'Līgatnes novads', 'Līgatnes novads'],
+ ['LV', 'Līvānu novads', 'Līvānu novads'],
+ ['LV', 'LV-MA', 'Madonas novads'],
+ ['LV', 'Mazsalacas novads', 'Mazsalacas novads'],
+ ['LV', 'Mālpils novads', 'Mālpils novads'],
+ ['LV', 'Mārupes novads', 'Mārupes novads'],
+ ['LV', 'Naukšēnu novads', 'Naukšēnu novads'],
+ ['LV', 'Neretas novads', 'Neretas novads'],
+ ['LV', 'Nīcas novads', 'Nīcas novads'],
+ ['LV', 'LV-OG', 'Ogres novads'],
+ ['LV', 'Olaines novads', 'Olaines novads'],
+ ['LV', 'Ozolnieku novads', 'Ozolnieku novads'],
+ ['LV', 'LV-PR', 'Preiļu novads'],
+ ['LV', 'Priekules novads', 'Priekules novads'],
+ ['LV', 'Priekuļu novads', 'Priekuļu novads'],
+ ['LV', 'Pārgaujas novads', 'Pārgaujas novads'],
+ ['LV', 'Pāvilostas novads', 'Pāvilostas novads'],
+ ['LV', 'Pļaviņu novads', 'Pļaviņu novads'],
+ ['LV', 'Raunas novads', 'Raunas novads'],
+ ['LV', 'Riebiņu novads', 'Riebiņu novads'],
+ ['LV', 'Rojas novads', 'Rojas novads'],
+ ['LV', 'Ropažu novads', 'Ropažu novads'],
+ ['LV', 'Rucavas novads', 'Rucavas novads'],
+ ['LV', 'Rugāju novads', 'Rugāju novads'],
+ ['LV', 'Rundāles novads', 'Rundāles novads'],
+ ['LV', 'LV-RE', 'Rēzeknes novads'],
+ ['LV', 'Rūjienas novads', 'Rūjienas novads'],
+ ['LV', 'Salacgrīvas novads', 'Salacgrīvas novads'],
+ ['LV', 'Salas novads', 'Salas novads'],
+ ['LV', 'Salaspils novads', 'Salaspils novads'],
+ ['LV', 'LV-SA', 'Saldus novads'],
+ ['LV', 'Saulkrastu novads', 'Saulkrastu novads'],
+ ['LV', 'Siguldas novads', 'Siguldas novads'],
+ ['LV', 'Skrundas novads', 'Skrundas novads'],
+ ['LV', 'Skrīveru novads', 'Skrīveru novads'],
+ ['LV', 'Smiltenes novads', 'Smiltenes novads'],
+ ['LV', 'Stopiņu novads', 'Stopiņu novads'],
+ ['LV', 'Strenču novads', 'Strenču novads'],
+ ['LV', 'Sējas novads', 'Sējas novads'],
+ ['LV', 'LV-TA', 'Talsu novads'],
+ ['LV', 'LV-TU', 'Tukuma novads'],
+ ['LV', 'Tērvetes novads', 'Tērvetes novads'],
+ ['LV', 'Vaiņodes novads', 'Vaiņodes novads'],
+ ['LV', 'LV-VK', 'Valkas novads'],
+ ['LV', 'LV-VM', 'Valmieras novads'],
+ ['LV', 'Varakļānu novads', 'Varakļānu novads'],
+ ['LV', 'Vecpiebalgas novads', 'Vecpiebalgas novads'],
+ ['LV', 'Vecumnieku novads', 'Vecumnieku novads'],
+ ['LV', 'LV-VE', 'Ventspils novads'],
+ ['LV', 'Viesītes novads', 'Viesītes novads'],
+ ['LV', 'Viļakas novads', 'Viļakas novads'],
+ ['LV', 'Viļānu novads', 'Viļānu novads'],
+ ['LV', 'Vārkavas novads', 'Vārkavas novads'],
+ ['LV', 'Zilupes novads', 'Zilupes novads'],
+ ['LV', 'Ādažu novads', 'Ādažu novads'],
+ ['LV', 'Ērgļu novads', 'Ērgļu novads'],
+ ['LV', 'Ķeguma novads', 'Ķeguma novads'],
+ ['LV', 'Ķekavas novads', 'Ķekavas novads'],
+ ['LT', 'LT-AL', 'Alytaus Apskritis'],
+ ['LT', 'LT-KU', 'Kauno Apskritis'],
+ ['LT', 'LT-KL', 'Klaipėdos Apskritis'],
+ ['LT', 'LT-MR', 'Marijampolės Apskritis'],
+ ['LT', 'LT-PN', 'Panevėžio Apskritis'],
+ ['LT', 'LT-SA', 'Šiaulių Apskritis'],
+ ['LT', 'LT-TA', 'Tauragės Apskritis'],
+ ['LT', 'LT-TE', 'Telšių Apskritis'],
+ ['LT', 'LT-UT', 'Utenos Apskritis'],
+ ['LT', 'LT-VL', 'Vilniaus Apskritis'],
+ ['BR', 'AC', 'Acre'],
+ ['BR', 'AL', 'Alagoas'],
+ ['BR', 'AP', 'Amapá'],
+ ['BR', 'AM', 'Amazonas'],
+ ['BR', 'BA', 'Bahia'],
+ ['BR', 'CE', 'Ceará'],
+ ['BR', 'ES', 'Espírito Santo'],
+ ['BR', 'GO', 'Goiás'],
+ ['BR', 'MA', 'Maranhão'],
+ ['BR', 'MT', 'Mato Grosso'],
+ ['BR', 'MS', 'Mato Grosso do Sul'],
+ ['BR', 'MG', 'Minas Gerais'],
+ ['BR', 'PA', 'Pará'],
+ ['BR', 'PB', 'Paraíba'],
+ ['BR', 'PR', 'Paraná'],
+ ['BR', 'PE', 'Pernambuco'],
+ ['BR', 'PI', 'Piauí'],
+ ['BR', 'RJ', 'Rio de Janeiro'],
+ ['BR', 'RN', 'Rio Grande do Norte'],
+ ['BR', 'RS', 'Rio Grande do Sul'],
+ ['BR', 'RO', 'Rondônia'],
+ ['BR', 'RR', 'Roraima'],
+ ['BR', 'SC', 'Santa Catarina'],
+ ['BR', 'SP', 'São Paulo'],
+ ['BR', 'SE', 'Sergipe'],
+ ['BR', 'TO', 'Tocantins'],
+ ['BR', 'DF', 'Distrito Federal'],
+ ];
+ foreach ($data as $row) {
+ $bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
+ $this->moduleDataSetup->getConnection()->insert(
+ $this->moduleDataSetup->getTable('directory_country_region'),
+ $bind
+ );
+ $regionId = $this->moduleDataSetup->getConnection()->lastInsertId(
+ $this->moduleDataSetup->getTable('directory_country_region')
+ );
+ $bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]];
+ $this->moduleDataSetup->getConnection()->insert(
+ $this->moduleDataSetup->getTable('directory_country_region_name'),
+ $bind
+ );
+ }
+ /**
+ * Fill table directory/currency_rate
+ */
+ $data = [
+ ['EUR', 'EUR', 1],
+ ['EUR', 'USD', 1.415000000000],
+ ['USD', 'EUR', 0.706700000000],
+ ['USD', 'USD', 1],
+ ];
+ $columns = ['currency_from', 'currency_to', 'rate'];
+ $this->moduleDataSetup->getConnection()->insertArray(
+ $this->moduleDataSetup->getTable('directory_currency_rate'),
+ $columns,
+ $data
+ );
+ $this->moduleDataSetup->getConnection()->insert(
+ $this->moduleDataSetup->getTable('core_config_data'),
+ [
+ 'scope' => 'default',
+ 'scope_id' => 0,
+ 'path' => Data::XML_PATH_DISPLAY_ALL_STATES,
+ 'value' => 1
+ ]
+ );
+ /** @var \Magento\Directory\Helper\Data $helper */
+ $helper = $this->directoryDataFactory->create();
+ $countries = $helper->getCountryCollection()->getCountriesWithRequiredStates();
+ $this->moduleDataSetup->getConnection()->insert(
+ $this->moduleDataSetup->getTable('core_config_data'),
+ [
+ 'scope' => 'default',
+ 'scope_id' => 0,
+ 'path' => Data::XML_PATH_STATES_REQUIRED,
+ 'value' => implode(',', array_keys($countries))
+ ]
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Directory/Setup/UpgradeData.php b/app/code/Magento/Directory/Setup/UpgradeData.php
deleted file mode 100644
index 4ee9ea33673d7..0000000000000
--- a/app/code/Magento/Directory/Setup/UpgradeData.php
+++ /dev/null
@@ -1,166 +0,0 @@
-directoryData = $directoryData;
- }
-
- /**
- * Upgrades data for Directry module.
- *
- * @param ModuleDataSetupInterface $setup
- * @param ModuleContextInterface $context
- * @return void
- */
- public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- if (version_compare($context->getVersion(), '2.0.1', '<')) {
- $this->addCountryRegions($setup, $this->getDataForCroatia());
- }
- if (version_compare($context->getVersion(), '2.0.2', '<')) {
- $this->addCountryRegions($setup, $this->getDataForIndia());
- }
- }
-
- /**
- * Croatian states data.
- *
- * @return array
- */
- private function getDataForCroatia()
- {
- return [
- ['HR', 'HR-01', 'Zagrebačka županija'],
- ['HR', 'HR-02', 'Krapinsko-zagorska županija'],
- ['HR', 'HR-03', 'Sisačko-moslavačka županija'],
- ['HR', 'HR-04', 'Karlovačka županija'],
- ['HR', 'HR-05', 'Varaždinska županija'],
- ['HR', 'HR-06', 'Koprivničko-križevačka županija'],
- ['HR', 'HR-07', 'Bjelovarsko-bilogorska županija'],
- ['HR', 'HR-08', 'Primorsko-goranska županija'],
- ['HR', 'HR-09', 'Ličko-senjska županija'],
- ['HR', 'HR-10', 'Virovitičko-podravska županija'],
- ['HR', 'HR-11', 'Požeško-slavonska županija'],
- ['HR', 'HR-12', 'Brodsko-posavska županija'],
- ['HR', 'HR-13', 'Zadarska županija'],
- ['HR', 'HR-14', 'Osječko-baranjska županija'],
- ['HR', 'HR-15', 'Šibensko-kninska županija'],
- ['HR', 'HR-16', 'Vukovarsko-srijemska županija'],
- ['HR', 'HR-17', 'Splitsko-dalmatinska županija'],
- ['HR', 'HR-18', 'Istarska županija'],
- ['HR', 'HR-19', 'Dubrovačko-neretvanska županija'],
- ['HR', 'HR-20', 'Međimurska županija'],
- ['HR', 'HR-21', 'Grad Zagreb']
- ];
- }
-
- /**
- * Indian states data.
- *
- * @return array
- */
- private function getDataForIndia()
- {
- return [
- ['IN', 'AN', 'Andaman and Nicobar Islands'],
- ['IN', 'AP', 'Andhra Pradesh'],
- ['IN', 'AR', 'Arunachal Pradesh'],
- ['IN', 'AS', 'Assam'],
- ['IN', 'BR', 'Bihar'],
- ['IN', 'CH', 'Chandigarh'],
- ['IN', 'CT', 'Chhattisgarh'],
- ['IN', 'DN', 'Dadra and Nagar Haveli'],
- ['IN', 'DD', 'Daman and Diu'],
- ['IN', 'DL', 'Delhi'],
- ['IN', 'GA', 'Goa'],
- ['IN', 'GJ', 'Gujarat'],
- ['IN', 'HR', 'Haryana'],
- ['IN', 'HP', 'Himachal Pradesh'],
- ['IN', 'JK', 'Jammu and Kashmir'],
- ['IN', 'JH', 'Jharkhand'],
- ['IN', 'KA', 'Karnataka'],
- ['IN', 'KL', 'Kerala'],
- ['IN', 'LD', 'Lakshadweep'],
- ['IN', 'MP', 'Madhya Pradesh'],
- ['IN', 'MH', 'Maharashtra'],
- ['IN', 'MN', 'Manipur'],
- ['IN', 'ML', 'Meghalaya'],
- ['IN', 'MZ', 'Mizoram'],
- ['IN', 'NL', 'Nagaland'],
- ['IN', 'OR', 'Odisha'],
- ['IN', 'PY', 'Puducherry'],
- ['IN', 'PB', 'Punjab'],
- ['IN', 'RJ', 'Rajasthan'],
- ['IN', 'SK', 'Sikkim'],
- ['IN', 'TN', 'Tamil Nadu'],
- ['IN', 'TG', 'Telangana'],
- ['IN', 'TR', 'Tripura'],
- ['IN', 'UP', 'Uttar Pradesh'],
- ['IN', 'UT', 'Uttarakhand'],
- ['IN', 'WB', 'West Bengal']
- ];
- }
-
- /**
- * Add country regions data to appropriate tables.
- *
- * @param ModuleDataSetupInterface $setup
- * @param array $data
- * @return void
- */
- private function addCountryRegions(ModuleDataSetupInterface $setup, array $data)
- {
- /**
- * Fill table directory/country_region
- * Fill table directory/country_region_name for en_US locale
- */
- foreach ($data as $row) {
- $bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
- $setup->getConnection()->insert($setup->getTable('directory_country_region'), $bind);
- $regionId = $setup->getConnection()->lastInsertId($setup->getTable('directory_country_region'));
- $bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]];
- $setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind);
- }
- /**
- * Upgrade core_config_data general/region/state_required field.
- */
- $countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates();
- $setup->getConnection()->update(
- $setup->getTable('core_config_data'),
- [
- 'value' => implode(',', array_keys($countries))
- ],
- [
- 'scope="default"',
- 'scope_id=0',
- 'path=?' => Data::XML_PATH_STATES_REQUIRED
- ]
- );
- }
-}
diff --git a/app/code/Magento/Directory/etc/db_schema.xml b/app/code/Magento/Directory/etc/db_schema.xml
index 769c253d45f11..72fd929b98a07 100644
--- a/app/code/Magento/Directory/etc/db_schema.xml
+++ b/app/code/Magento/Directory/etc/db_schema.xml
@@ -6,7 +6,7 @@
*/
-->
+ xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
diff --git a/app/code/Magento/Directory/etc/module.xml b/app/code/Magento/Directory/etc/module.xml
index a3735ca6ddde1..3a750db5e7cfd 100644
--- a/app/code/Magento/Directory/etc/module.xml
+++ b/app/code/Magento/Directory/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/Link.php b/app/code/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/Link.php
index 8ee93c37a7775..8d5f64e02be47 100644
--- a/app/code/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/Link.php
+++ b/app/code/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/Link.php
@@ -7,6 +7,7 @@
namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit;
use Magento\Downloadable\Helper\Download as DownloadHelper;
+use Magento\Framework\App\Response\Http as HttpResponse;
class Link extends \Magento\Catalog\Controller\Adminhtml\Product\Edit
{
@@ -42,7 +43,9 @@ protected function _processDownload($resource, $resourceType)
$fileName = $helper->getFilename();
$contentType = $helper->getContentType();
- $this->getResponse()->setHttpResponseCode(
+ /** @var HttpResponse $response */
+ $response = $this->getResponse();
+ $response->setHttpResponseCode(
200
)->setHeader(
'Pragma',
@@ -59,16 +62,22 @@ protected function _processDownload($resource, $resourceType)
);
if ($fileSize = $helper->getFileSize()) {
- $this->getResponse()->setHeader('Content-Length', $fileSize);
+ $response->setHeader('Content-Length', $fileSize);
}
-
- if ($contentDisposition = $helper->getContentDisposition()) {
- $this->getResponse()
- ->setHeader('Content-Disposition', $contentDisposition . '; filename=' . $fileName);
+ //Setting disposition as state in the config or forcing it for HTML.
+ /** @var string|null $contentDisposition */
+ $contentDisposition = $helper->getContentDisposition();
+ if (!$contentDisposition || $contentType === 'text/html') {
+ $contentDisposition = 'attachment';
}
-
- $this->getResponse()->clearBody();
- $this->getResponse()->sendHeaders();
+ $response->setHeader(
+ 'Content-Disposition',
+ $contentDisposition . '; filename=' . $fileName
+ );
+ //Rendering
+ $response->clearBody();
+ $response->sendHeaders();
+
$helper->output();
}
diff --git a/app/code/Magento/Downloadable/Controller/Download.php b/app/code/Magento/Downloadable/Controller/Download.php
index b2cf89c1af980..f0bef425d4b45 100644
--- a/app/code/Magento/Downloadable/Controller/Download.php
+++ b/app/code/Magento/Downloadable/Controller/Download.php
@@ -6,6 +6,7 @@
namespace Magento\Downloadable\Controller;
use Magento\Downloadable\Helper\Download as DownloadHelper;
+use Magento\Framework\App\Response\Http as HttpResponse;
/**
* Download controller
@@ -14,6 +15,13 @@
*/
abstract class Download extends \Magento\Framework\App\Action\Action
{
+ /**
+ * @var array
+ */
+ private $disallowedContentTypes = [
+ 'text/html',
+ ];
+
/**
* Prepare response to output resource contents
*
@@ -28,9 +36,12 @@ protected function _processDownload($path, $resourceType)
$helper->setResource($path, $resourceType);
$fileName = $helper->getFilename();
+
$contentType = $helper->getContentType();
- $this->getResponse()->setHttpResponseCode(
+ /** @var HttpResponse $response */
+ $response = $this->getResponse();
+ $response->setHttpResponseCode(
200
)->setHeader(
'Pragma',
@@ -47,15 +58,19 @@ protected function _processDownload($path, $resourceType)
);
if ($fileSize = $helper->getFileSize()) {
- $this->getResponse()->setHeader('Content-Length', $fileSize);
+ $response->setHeader('Content-Length', $fileSize);
}
- if ($contentDisposition = $helper->getContentDisposition()) {
- $this->getResponse()->setHeader('Content-Disposition', $contentDisposition . '; filename=' . $fileName);
+ $contentDisposition = $helper->getContentDisposition();
+ if (!$contentDisposition || in_array($contentType, $this->disallowedContentTypes)) {
+ // For security reasons we force browsers to download the file instead of opening it.
+ $contentDisposition = \Zend_Mime::DISPOSITION_ATTACHMENT;
}
- $this->getResponse()->clearBody();
- $this->getResponse()->sendHeaders();
+ $response->setHeader('Content-Disposition', $contentDisposition . '; filename=' . $fileName);
+ //Rendering
+ $response->clearBody();
+ $response->sendHeaders();
$helper->output();
}
diff --git a/app/code/Magento/Downloadable/Setup/InstallData.php b/app/code/Magento/Downloadable/Setup/InstallData.php
deleted file mode 100644
index e015f3a23c191..0000000000000
--- a/app/code/Magento/Downloadable/Setup/InstallData.php
+++ /dev/null
@@ -1,178 +0,0 @@
-eavSetupFactory = $eavSetupFactory;
- }
-
- /**
- * {@inheritdoc}
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- /** @var EavSetup $eavSetup */
- $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
- /**
- * Add attributes to the eav/attribute table
- */
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'links_purchased_separately',
- [
- 'type' => 'int',
- 'backend' => '',
- 'frontend' => '',
- 'label' => 'Links can be purchased separately',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
- 'visible' => false,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'unique' => false,
- 'apply_to' => 'downloadable',
- 'used_in_product_listing' => true
- ]
- );
-
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'samples_title',
- [
- 'type' => 'varchar',
- 'backend' => '',
- 'frontend' => '',
- 'label' => 'Samples title',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
- 'visible' => false,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'unique' => false,
- 'apply_to' => 'downloadable'
- ]
- );
-
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'links_title',
- [
- 'type' => 'varchar',
- 'backend' => '',
- 'frontend' => '',
- 'label' => 'Links title',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
- 'visible' => false,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'unique' => false,
- 'apply_to' => 'downloadable'
- ]
- );
-
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'links_exist',
- [
- 'type' => 'int',
- 'backend' => '',
- 'frontend' => '',
- 'label' => '',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => true,
- 'visible' => false,
- 'required' => false,
- 'user_defined' => false,
- 'default' => '0',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'unique' => false,
- 'apply_to' => 'downloadable',
- 'used_in_product_listing' => 1
- ]
- );
-
- $fieldList = [
- 'price',
- 'special_price',
- 'special_from_date',
- 'special_to_date',
- 'minimal_price',
- 'cost',
- 'tier_price',
- 'weight',
- ];
-
- // make these attributes applicable to downloadable products
- foreach ($fieldList as $field) {
- $applyTo = explode(
- ',',
- $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to')
- );
- if (!in_array('downloadable', $applyTo)) {
- $applyTo[] = 'downloadable';
- $eavSetup->updateAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- $field,
- 'apply_to',
- implode(',', $applyTo)
- );
- }
- }
- }
-}
diff --git a/app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php b/app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php
new file mode 100644
index 0000000000000..9c101425e49ae
--- /dev/null
+++ b/app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php
@@ -0,0 +1,206 @@
+moduleDataSetup = $moduleDataSetup;
+ $this->eavSetupFactory = $eavSetupFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+ */
+ public function apply()
+ {
+ /** @var EavSetup $eavSetup */
+ $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
+ /**
+ * Add attributes to the eav/attribute table
+ */
+ $eavSetup->addAttribute(
+ \Magento\Catalog\Model\Product::ENTITY,
+ 'links_purchased_separately',
+ [
+ 'type' => 'int',
+ 'backend' => '',
+ 'frontend' => '',
+ 'label' => 'Links can be purchased separately',
+ 'input' => '',
+ 'class' => '',
+ 'source' => '',
+ 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
+ 'visible' => false,
+ 'required' => true,
+ 'user_defined' => false,
+ 'default' => '',
+ 'searchable' => false,
+ 'filterable' => false,
+ 'comparable' => false,
+ 'visible_on_front' => false,
+ 'unique' => false,
+ 'apply_to' => 'downloadable',
+ 'used_in_product_listing' => true
+ ]
+ );
+
+ $eavSetup->addAttribute(
+ \Magento\Catalog\Model\Product::ENTITY,
+ 'samples_title',
+ [
+ 'type' => 'varchar',
+ 'backend' => '',
+ 'frontend' => '',
+ 'label' => 'Samples title',
+ 'input' => '',
+ 'class' => '',
+ 'source' => '',
+ 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
+ 'visible' => false,
+ 'required' => true,
+ 'user_defined' => false,
+ 'default' => '',
+ 'searchable' => false,
+ 'filterable' => false,
+ 'comparable' => false,
+ 'visible_on_front' => false,
+ 'unique' => false,
+ 'apply_to' => 'downloadable'
+ ]
+ );
+ $eavSetup->addAttribute(
+ \Magento\Catalog\Model\Product::ENTITY,
+ 'links_title',
+ [
+ 'type' => 'varchar',
+ 'backend' => '',
+ 'frontend' => '',
+ 'label' => 'Links title',
+ 'input' => '',
+ 'class' => '',
+ 'source' => '',
+ 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
+ 'visible' => false,
+ 'required' => true,
+ 'user_defined' => false,
+ 'default' => '',
+ 'searchable' => false,
+ 'filterable' => false,
+ 'comparable' => false,
+ 'visible_on_front' => false,
+ 'unique' => false,
+ 'apply_to' => 'downloadable'
+ ]
+ );
+ $eavSetup->addAttribute(
+ \Magento\Catalog\Model\Product::ENTITY,
+ 'links_exist',
+ [
+ 'type' => 'int',
+ 'backend' => '',
+ 'frontend' => '',
+ 'label' => '',
+ 'input' => '',
+ 'class' => '',
+ 'source' => '',
+ 'global' => true,
+ 'visible' => false,
+ 'required' => false,
+ 'user_defined' => false,
+ 'default' => '0',
+ 'searchable' => false,
+ 'filterable' => false,
+ 'comparable' => false,
+ 'visible_on_front' => false,
+ 'unique' => false,
+ 'apply_to' => 'downloadable',
+ 'used_in_product_listing' => 1
+ ]
+ );
+ $fieldList = [
+ 'price',
+ 'special_price',
+ 'special_from_date',
+ 'special_to_date',
+ 'minimal_price',
+ 'cost',
+ 'tier_price',
+ 'weight',
+ ];
+ // make these attributes applicable to downloadable products
+ foreach ($fieldList as $field) {
+ $applyTo = explode(
+ ',',
+ $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to')
+ );
+ if (!in_array('downloadable', $applyTo)) {
+ $applyTo[] = 'downloadable';
+ $eavSetup->updateAttribute(
+ \Magento\Catalog\Model\Product::ENTITY,
+ $field,
+ 'apply_to',
+ implode(',', $applyTo)
+ );
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getVersion()
+ {
+ return '2.0.0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/app/code/Magento/Downloadable/Test/Unit/Controller/Adminhtml/Downloadable/Product/Edit/LinkTest.php b/app/code/Magento/Downloadable/Test/Unit/Controller/Adminhtml/Downloadable/Product/Edit/LinkTest.php
index e125ddee9c5d8..aa8b774ab5511 100644
--- a/app/code/Magento/Downloadable/Test/Unit/Controller/Adminhtml/Downloadable/Product/Edit/LinkTest.php
+++ b/app/code/Magento/Downloadable/Test/Unit/Controller/Adminhtml/Downloadable/Product/Edit/LinkTest.php
@@ -22,7 +22,7 @@ class LinkTest extends \PHPUnit\Framework\TestCase
protected $request;
/**
- * @var \Magento\Framework\App\ResponseInterface
+ * @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $response;
@@ -109,6 +109,8 @@ protected function setUp()
*/
public function testExecuteFile($fileType)
{
+ $fileSize = 58493;
+ $fileName = 'link.jpg';
$this->request->expects($this->at(0))->method('getParam')->with('id', 0)
->will($this->returnValue(1));
$this->request->expects($this->at(1))->method('getParam')->with('type', 0)
@@ -117,7 +119,20 @@ public function testExecuteFile($fileType)
->will($this->returnSelf());
$this->response->expects($this->once())->method('clearBody')
->will($this->returnSelf());
- $this->response->expects($this->any())->method('setHeader')
+ $this->response
+ ->expects($this->any())
+ ->method('setHeader')
+ ->withConsecutive(
+ ['Pragma', 'public', true],
+ [
+ 'Cache-Control',
+ 'must-revalidate, post-check=0, pre-check=0',
+ true,
+ ],
+ ['Content-type', 'text/html'],
+ ['Content-Length', $fileSize],
+ ['Content-Disposition', 'attachment; filename=' . $fileName]
+ )
->will($this->returnSelf());
$this->response->expects($this->once())->method('sendHeaders')
->will($this->returnSelf());
@@ -132,13 +147,13 @@ public function testExecuteFile($fileType)
$this->downloadHelper->expects($this->once())->method('setResource')
->will($this->returnSelf());
$this->downloadHelper->expects($this->once())->method('getFilename')
- ->will($this->returnValue('link.jpg'));
+ ->will($this->returnValue($fileName));
$this->downloadHelper->expects($this->once())->method('getContentType')
- ->will($this->returnSelf('file'));
+ ->willReturn('text/html');
$this->downloadHelper->expects($this->once())->method('getFileSize')
- ->will($this->returnValue(null));
+ ->will($this->returnValue($fileSize));
$this->downloadHelper->expects($this->once())->method('getContentDisposition')
- ->will($this->returnValue(null));
+ ->will($this->returnValue('inline'));
$this->downloadHelper->expects($this->once())->method('output')
->will($this->returnSelf());
$this->linkModel->expects($this->once())->method('load')
diff --git a/app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkTest.php b/app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkTest.php
index 3e1255766f1f9..f2e288d75a40a 100644
--- a/app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkTest.php
+++ b/app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkTest.php
@@ -273,7 +273,13 @@ public function testGetLinkForWrongCustomer()
$this->assertEquals($this->response, $this->link->execute());
}
- public function testExceptionInUpdateLinkStatus()
+ /**
+ * @param string $mimeType
+ * @param string $disposition
+ * @dataProvider downloadTypesDataProvider
+ * @return void
+ */
+ public function testExceptionInUpdateLinkStatus($mimeType, $disposition)
{
$this->objectManager->expects($this->at(0))
->method('get')
@@ -303,7 +309,7 @@ public function testExceptionInUpdateLinkStatus()
$this->linkPurchasedItem->expects($this->once())->method('getLinkType')->willReturn('url');
$this->linkPurchasedItem->expects($this->once())->method('getLinkUrl')->willReturn('link_url');
- $this->processDownload('link_url', 'url');
+ $this->processDownload('link_url', 'url', $mimeType, $disposition);
$this->linkPurchasedItem->expects($this->any())->method('setNumberOfDownloadsUsed')->willReturnSelf();
$this->linkPurchasedItem->expects($this->any())->method('setStatus')->with('expired')->willReturnSelf();
@@ -317,8 +323,18 @@ public function testExceptionInUpdateLinkStatus()
$this->assertEquals($this->response, $this->link->execute());
}
- private function processDownload($resource, $resourceType)
+ /**
+ * @param string $resource
+ * @param string $resourceType
+ * @param string $mimeType
+ * @param string $disposition
+ * @return void
+ */
+ private function processDownload($resource, $resourceType, $mimeType, $disposition)
{
+ $fileSize = 58493;
+ $fileName = 'link.jpg';
+
$this->objectManager->expects($this->at(3))
->method('get')
->with(\Magento\Downloadable\Helper\Download::class)
@@ -327,30 +343,23 @@ private function processDownload($resource, $resourceType)
->method('setResource')
->with($resource, $resourceType)
->willReturnSelf();
- $this->downloadHelper->expects($this->once())->method('getFilename')->willReturn('file_name');
- $this->downloadHelper->expects($this->once())->method('getContentType')->willReturn('content_type');
+ $this->downloadHelper->expects($this->once())->method('getFilename')->willReturn($fileName);
+ $this->downloadHelper->expects($this->once())->method('getContentType')->willReturn($mimeType);
$this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
- $this->response->expects($this->at(1))->method('setHeader')->with('Pragma', 'public', true)->willReturnSelf();
- $this->response->expects($this->at(2))
- ->method('setHeader')
- ->with('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
- ->willReturnSelf();
- $this->response->expects($this->at(3))
+ $this->response
+ ->expects($this->any())
->method('setHeader')
- ->with('Content-type', 'content_type', true)
- ->willReturnSelf();
- $this->downloadHelper->expects($this->once())->method('getFileSize')->willReturn('file_size');
- $this->response->expects($this->at(4))
- ->method('setHeader')
- ->with('Content-Length', 'file_size')
- ->willReturnSelf();
- $this->downloadHelper->expects($this->once())
- ->method('getContentDisposition')
- ->willReturn('content_disposition');
- $this->response->expects($this->at(5))
- ->method('setHeader')
- ->with('Content-Disposition', 'content_disposition; filename=file_name')
+ ->withConsecutive(
+ ['Pragma', 'public', true],
+ ['Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true],
+ ['Content-type', $mimeType, true],
+ ['Content-Length', $fileSize],
+ ['Content-Disposition', $disposition . '; filename=' . $fileName]
+ )
->willReturnSelf();
+
+ $this->downloadHelper->expects($this->once())->method('getContentDisposition')->willReturn($disposition);
+ $this->downloadHelper->expects($this->once())->method('getFileSize')->willReturn($fileSize);
$this->response->expects($this->once())->method('clearBody')->willReturnSelf();
$this->response->expects($this->once())->method('sendHeaders')->willReturnSelf();
$this->downloadHelper->expects($this->once())->method('output');
@@ -394,6 +403,76 @@ public function testLinkNotAvailable($messageType, $status, $notice)
$this->assertEquals($this->response, $this->link->execute());
}
+ /**
+ * @param string $mimeType
+ * @param string $disposition
+ * @dataProvider downloadTypesDataProvider
+ * @return void
+ */
+ public function testContentDisposition($mimeType, $disposition)
+ {
+ $this->objectManager->expects($this->any())
+ ->method('get')
+ ->willReturnMap([
+ [
+ \Magento\Customer\Model\Session::class,
+ $this->session,
+ ],
+ [
+ \Magento\Downloadable\Helper\Data::class,
+ $this->helperData,
+ ],
+ [
+ \Magento\Downloadable\Helper\Download::class,
+ $this->downloadHelper,
+ ],
+ ]);
+
+ $this->request->expects($this->once())->method('getParam')->with('id', 0)->willReturn('some_id');
+ $this->objectManager->expects($this->at(1))
+ ->method('create')
+ ->with(\Magento\Downloadable\Model\Link\Purchased\Item::class)
+ ->willReturn($this->linkPurchasedItem);
+ $this->linkPurchasedItem->expects($this->once())
+ ->method('load')
+ ->with('some_id', 'link_hash')
+ ->willReturnSelf();
+ $this->linkPurchasedItem->expects($this->once())->method('getId')->willReturn(5);
+ $this->helperData->expects($this->once())
+ ->method('getIsShareable')
+ ->with($this->linkPurchasedItem)
+ ->willReturn(true);
+ $this->linkPurchasedItem->expects($this->any())->method('getNumberOfDownloadsBought')->willReturn(10);
+ $this->linkPurchasedItem->expects($this->any())->method('getNumberOfDownloadsUsed')->willReturn(9);
+ $this->linkPurchasedItem->expects($this->once())->method('getStatus')->willReturn('available');
+ $this->linkPurchasedItem->expects($this->once())->method('getLinkType')->willReturn('url');
+ $this->linkPurchasedItem->expects($this->once())->method('getLinkUrl')->willReturn('link_url');
+
+ $fileSize = 58493;
+ $fileName = 'link.jpg';
+
+ $this->downloadHelper->expects($this->once())
+ ->method('setResource')
+ ->with('link_url', 'url')
+ ->willReturnSelf();
+ $this->downloadHelper->expects($this->once())->method('getFilename')->willReturn($fileName);
+ $this->downloadHelper->expects($this->once())->method('getContentType')->willReturn($mimeType);
+ $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
+ $this->response
+ ->expects($this->any())
+ ->method('setHeader')
+ ->withConsecutive(
+ ['Pragma', 'public', true],
+ ['Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true],
+ ['Content-type', $mimeType, true],
+ ['Content-Length', $fileSize],
+ ['Content-Disposition', $disposition . '; filename=' . $fileName]
+ )
+ ->willReturnSelf();
+
+ $this->assertEquals($this->response, $this->link->execute());
+ }
+
/**
* @return array
*/
@@ -406,4 +485,15 @@ public function linkNotAvailableDataProvider()
['addError', 'wrong_status', 'Something went wrong while getting the requested content.']
];
}
+
+ /**
+ * @return array
+ */
+ public function downloadTypesDataProvider()
+ {
+ return [
+ ['mimeType' => 'text/html', 'disposition' => \Zend_Mime::DISPOSITION_ATTACHMENT],
+ ['mimeType' => 'image/jpeg', 'disposition' => \Zend_Mime::DISPOSITION_INLINE],
+ ];
+ }
}
diff --git a/app/code/Magento/Downloadable/etc/db_schema.xml b/app/code/Magento/Downloadable/etc/db_schema.xml
index 675c9a5c85679..ed25628bcffd9 100644
--- a/app/code/Magento/Downloadable/etc/db_schema.xml
+++ b/app/code/Magento/Downloadable/etc/db_schema.xml
@@ -6,7 +6,7 @@
*/
-->
+ xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
diff --git a/app/code/Magento/Downloadable/etc/module.xml b/app/code/Magento/Downloadable/etc/module.xml
index 4c4e165feb014..72aadff621eca 100644
--- a/app/code/Magento/Downloadable/etc/module.xml
+++ b/app/code/Magento/Downloadable/etc/module.xml
@@ -6,7 +6,7 @@
*/
-->
-
+
diff --git a/app/code/Magento/Downloadable/view/adminhtml/templates/product/edit/downloadable/links.phtml b/app/code/Magento/Downloadable/view/adminhtml/templates/product/edit/downloadable/links.phtml
index 2515e5e339366..3ec6010218fb6 100644
--- a/app/code/Magento/Downloadable/view/adminhtml/templates/product/edit/downloadable/links.phtml
+++ b/app/code/Magento/Downloadable/view/adminhtml/templates/product/edit/downloadable/links.phtml
@@ -21,7 +21,7 @@
isSingleStoreMode() ? ' data-config-scope="' . __('[STORE VIEW]') . '"' : '' ?>>