{{trans "Welcome to %store_name." store_name=$store.getFrontendName()}}
+
+ {{trans
+ 'To sign in to our site, use these credentials during checkout or on the My Account page:'
+
+ customer_url=$this.getUrl($store,'customer/account/',[_nosid:1])
+ |raw}}
+
+
+
{{trans "Email:"}} {{var customer.email}}
+
{{trans "Password:"}}{{trans "Password you set when creating account"}}
+
+
+ {{trans
+ 'Forgot your account password? Click here to reset it.'
+
+ reset_url="$this.getUrl($store,'customer/account/createPassword/',[_query:[id:$customer.id,token:$customer.rp_token],_nosid:1])"
+ |raw}}
+
+
{{trans "When you sign in to your account, you will be able to:"}}
+
+
{{trans "Proceed through checkout faster"}}
+
{{trans "Check the status of orders"}}
+
{{trans "View past orders"}}
+
{{trans "Store alternative addresses (for shipping to multiple family members and friends)"}}
{{trans "Welcome to %store_name." store_name=$store.getFrontendName()}}
+
+ {{trans
+ 'To sign in to our site, use these credentials during checkout or on the My Account page:'
+
+ customer_url=$this.getUrl($store,'customer/account/',[_nosid:1])
+ |raw}}
+
+
+
{{trans "Email:"}} {{var customer.email}}
+
{{trans "Password:"}}{{trans "Password you set when creating account"}}
+
+
+ {{trans
+ 'Forgot your account password? Click here to reset it.'
+
+ reset_url="$this.getUrl($store,'customer/account/createPassword/',[_query:[id:$customer.id,token:$customer.rp_token],_nosid:1])"
+ |raw}}
+
+
{{trans "When you sign in to your account, you will be able to:"}}
+
+
{{trans "Proceed through checkout faster"}}
+
{{trans "Check the status of orders"}}
+
{{trans "View past orders"}}
+
{{trans "Store alternative addresses (for shipping to multiple family members and friends)"}}
+
diff --git a/dev/tests/integration/testsuite/Magento/GroupedProduct/Pricing/Price/FinalPriceTest.php b/dev/tests/integration/testsuite/Magento/GroupedProduct/Pricing/Price/FinalPriceTest.php
new file mode 100644
index 0000000000000..2b40b621c7180
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/GroupedProduct/Pricing/Price/FinalPriceTest.php
@@ -0,0 +1,72 @@
+get('\Magento\Catalog\Api\ProductRepositoryInterface');
+ /** @var $product \Magento\Catalog\Model\Product */
+ $product = $productRepository->get('grouped-product');
+
+ $this->assertEquals(10, $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue());
+ }
+
+ /**
+ * @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
+ * @magentoAppIsolation enabled
+ */
+ public function testFinalPriceWithTearPrice()
+ {
+ $productRepository = Bootstrap::getObjectManager()
+ ->get('\Magento\Catalog\Api\ProductRepositoryInterface');
+ /** @var ProductTierPriceInterface $tierPrice */
+ $tierPrice = Bootstrap::getObjectManager()->create(ProductTierPriceInterface::class);
+ $tierPrice->setQty(1);
+ $tierPrice->setCustomerGroupId(\Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL);
+ $tierPrice->setValue(5);
+
+ /** @var $simpleProduct \Magento\Catalog\Api\Data\ProductInterface */
+ $simpleProduct = $productRepository->get('simple');
+ $simpleProduct->setTierPrices([
+ $tierPrice
+ ]);
+ $productRepository->save($simpleProduct);
+
+ /** @var $product \Magento\Catalog\Model\Product */
+ $product = $productRepository->get('grouped-product');
+ $this->assertEquals(5, $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue());
+ }
+
+ /**
+ * @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
+ * @magentoAppIsolation enabled
+ */
+ public function testFinalPriceWithSpecialPrice()
+ {
+ $productRepository = Bootstrap::getObjectManager()
+ ->get('\Magento\Catalog\Api\ProductRepositoryInterface');
+
+ /** @var $simpleProduct \Magento\Catalog\Api\Data\ProductInterface */
+ $simpleProduct = $productRepository->get('simple');
+ $simpleProduct->setCustomAttribute('special_price', 6);
+ $productRepository->save($simpleProduct);
+
+ /** @var $product \Magento\Catalog\Model\Product */
+ $product = $productRepository->get('grouped-product');
+ $this->assertEquals(6, $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue());
+ }
+}
diff --git a/dev/tests/integration/testsuite/Magento/Theme/Model/Config/ValidatorTest.php b/dev/tests/integration/testsuite/Magento/Theme/Model/Config/ValidatorTest.php
new file mode 100644
index 0000000000000..669671bf0c7c5
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Theme/Model/Config/ValidatorTest.php
@@ -0,0 +1,107 @@
+get('Magento\Framework\App\AreaList')
+ ->getArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE)
+ ->load(\Magento\Framework\App\Area::PART_CONFIG);
+ $objectManager->get('Magento\Framework\App\State')
+ ->setAreaCode(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
+
+ $this->model = $objectManager->get('Magento\Theme\Model\Design\Config\Validator');
+ }
+
+ /**
+ * @magentoDataFixture Magento/Email/Model/_files/email_template.php
+ * @expectedException \Magento\Framework\Exception\LocalizedException
+ * @expectedExceptionMessage Incorrect configuration for email_header_template. Template body has a reference to
+ */
+ public function testValidateHasRecursiveReference()
+ {
+ $fieldConfig = [
+ 'path' => 'design/email/header_template',
+ 'fieldset' => 'other_settings/email',
+ 'field' => 'email_header_template'
+ ];
+
+ $designConfigMock = $this->getMockBuilder('Magento\Theme\Api\Data\DesignConfigInterface')
+ ->disableOriginalConstructor()
+ ->setMethods([])
+ ->getMock();
+ $designConfigExtensionMock = $this->getMockBuilder('Magento\Theme\Api\Data\DesignConfigExtensionInterface')
+ ->disableOriginalConstructor()
+ ->setMethods([])
+ ->getMock();
+ $designElementMock = $this->getMockBuilder('Magento\Theme\Model\Data\Design\Config\Data')
+ ->disableOriginalConstructor()
+ ->setMethods([])
+ ->getMock();
+
+ $designConfigMock->expects($this->once())
+ ->method('getExtensionAttributes')
+ ->willReturn($designConfigExtensionMock);
+ $designConfigExtensionMock->expects($this->once())
+ ->method('getDesignConfigData')
+ ->willReturn([$designElementMock]);
+ $designElementMock->expects($this->any())->method('getFieldConfig')->willReturn($fieldConfig);
+ $designElementMock->expects($this->once())->method('getPath')->willReturn($fieldConfig['path']);
+ $designElementMock->expects($this->once())->method('getValue')->willReturn(1);
+
+ $this->model->validate($designConfigMock);
+ }
+
+ /**
+ * @magentoDataFixture Magento/Email/Model/_files/email_template.php
+ */
+ public function testValidateNoRecursiveReference()
+ {
+ $fieldConfig = [
+ 'path' => 'design/email/footer_template',
+ 'fieldset' => 'other_settings/email',
+ 'field' => 'email_footer_template'
+ ];
+
+ $designConfigMock = $this->getMockBuilder('Magento\Theme\Api\Data\DesignConfigInterface')
+ ->disableOriginalConstructor()
+ ->setMethods([])
+ ->getMock();
+ $designConfigExtensionMock = $this->getMockBuilder('Magento\Theme\Api\Data\DesignConfigExtensionInterface')
+ ->disableOriginalConstructor()
+ ->setMethods([])
+ ->getMock();
+ $designElementMock = $this->getMockBuilder('Magento\Theme\Model\Data\Design\Config\Data')
+ ->disableOriginalConstructor()
+ ->setMethods([])
+ ->getMock();
+
+ $designConfigMock->expects($this->once())
+ ->method('getExtensionAttributes')
+ ->willReturn($designConfigExtensionMock);
+ $designConfigExtensionMock->expects($this->once())
+ ->method('getDesignConfigData')
+ ->willReturn([$designElementMock]);
+ $designElementMock->expects($this->any())->method('getFieldConfig')->willReturn($fieldConfig);
+ $designElementMock->expects($this->once())->method('getPath')->willReturn($fieldConfig['path']);
+ $designElementMock->expects($this->once())->method('getValue')->willReturn(1);
+
+ $this->model->validate($designConfigMock);
+ }
+}
diff --git a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php
index 1b84ed9bb008b..ddff84be4a177 100644
--- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php
+++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php
@@ -111,7 +111,7 @@ public function create(array $arguments)
{
$writeFactory = new \Magento\Framework\Filesystem\Directory\WriteFactory($this->driverPool);
$generatedFiles = new GeneratedFiles($this->directoryList, $writeFactory);
- $generatedFiles->regenerate();
+ $generatedFiles->cleanGeneratedFiles();
$deploymentConfig = $this->createDeploymentConfig($this->directoryList, $this->configFilePool, $arguments);
$arguments = array_merge($deploymentConfig->get(), $arguments);
diff --git a/lib/internal/Magento/Framework/Code/GeneratedFiles.php b/lib/internal/Magento/Framework/Code/GeneratedFiles.php
index ec6e43b8c67f1..75d5ff4b4b73b 100644
--- a/lib/internal/Magento/Framework/Code/GeneratedFiles.php
+++ b/lib/internal/Magento/Framework/Code/GeneratedFiles.php
@@ -5,7 +5,6 @@
*/
namespace Magento\Framework\Code;
-use Magento\Framework\Config\Data\ConfigData;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Filesystem\Directory\WriteFactory;
@@ -48,67 +47,127 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
* Clean generated code and DI configuration
*
* @return void
+ *
+ * @deprecated
+ * @see \Magento\Framework\Code\GeneratedFiles::cleanGeneratedFiles
*/
public function regenerate()
+ {
+ $this->cleanGeneratedFiles();
+ }
+
+ /**
+ * Clean var/generation, var/di and var/cache
+ *
+ * @return void
+ */
+ public function cleanGeneratedFiles()
{
if ($this->write->isExist(self::REGENERATE_FLAG)) {
+
+ $enabledCacheTypes = [];
+
//TODO: to be removed in scope of MAGETWO-53476
- //clean cache
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
$configPool = new ConfigFilePool();
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
- $this->saveCacheStatus($envPath);
+ $enabledCacheTypes = $this->getEnabledCacheTypes();
+ $this->disableAllCacheTypes();
}
//TODO: Till here
+
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));
+ // Clean var/generation dir
if ($this->write->isDirectory($generationPath)) {
$this->write->delete($generationPath);
}
+
+ // Clean var/di
if ($this->write->isDirectory($diPath)) {
$this->write->delete($diPath);
}
+
+ // Clean var/cache
if ($this->write->isDirectory($cachePath)) {
$this->write->delete($cachePath);
}
- //add to queue
-
$this->write->delete(self::REGENERATE_FLAG);
+ $this->enableCacheTypes($enabledCacheTypes);
}
}
/**
- * Read Cache types from env.php and write to a json file.
+ * Create flag for cleaning up var/generation, var/di and var/cache directories for subsequent
+ * regeneration of this content
*
- * @param string $envPath
* @return void
*/
- private function saveCacheStatus($envPath)
+ public function requestRegeneration()
+ {
+ $this->write->touch(self::REGENERATE_FLAG);
+ }
+
+ /**
+ * Reads Cache configuration from env.php and returns indexed array containing all the enabled cache types.
+ *
+ * @return string[]
+ */
+ private function getEnabledCacheTypes()
{
- $cacheData = include $envPath;
-
- if (isset($cacheData['cache_types'])) {
- $enabledCacheTypes = $cacheData['cache_types'];
- $enabledCacheTypes = array_filter($enabledCacheTypes, function ($value) {
- return $value;
- });
- if (!empty($enabledCacheTypes)) {
- $varDir = $this->directoryList->getPath(DirectoryList::VAR_DIR);
- $this->write->writeFile(
- $this->write->getRelativePath($varDir) . '/.cachestates.json',
- json_encode($enabledCacheTypes)
- );
- $cacheTypes = array_keys($cacheData['cache_types']);
+ $enabledCacheTypes = [];
+ $envPath = $this->getEnvPath();
+ if ($this->write->isReadable($this->write->getRelativePath($envPath))) {
+ $envData = include $envPath;
+ if (isset($envData['cache_types'])) {
+ $cacheStatus = $envData['cache_types'];
+ $enabledCacheTypes = array_filter($cacheStatus, function ($value) {
+ return $value;
+ });
+ $enabledCacheTypes = array_keys($enabledCacheTypes);
+ }
+ }
+ return $enabledCacheTypes;
+ }
+
+
+ /**
+ * Returns path to env.php file
+ *
+ * @return string
+ * @throws \Exception
+ */
+ private function getEnvPath()
+ {
+ $deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
+ $configPool = new ConfigFilePool();
+ $envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
+ return $envPath;
+ }
+
+ /**
+ * Disables all cache types by updating env.php.
+ *
+ * @return void
+ */
+ private function disableAllCacheTypes()
+ {
+ $envPath = $this->getEnvPath();
+ if ($this->write->isWritable($this->write->getRelativePath($envPath))) {
+ $envData = include $envPath;
+
+ if (isset($envData['cache_types'])) {
+ $cacheTypes = array_keys($envData['cache_types']);
foreach ($cacheTypes as $cacheType) {
- $cacheData['cache_types'][$cacheType] = 0;
+ $envData['cache_types'][$cacheType] = 0;
}
$formatter = new PhpFormatter();
- $contents = $formatter->format($cacheData);
+ $contents = $formatter->format($envData);
$this->write->writeFile($this->write->getRelativePath($envPath), $contents);
if (function_exists('opcache_invalidate')) {
@@ -121,12 +180,34 @@ private function saveCacheStatus($envPath)
}
/**
- * Create flag for regeneration of code and di
+ * Enables apppropriate cache types in app/etc/env.php based on the passed in $cacheTypes array
+ * TODO: to be removed in scope of MAGETWO-53476
+ *
+ * @param string[]
*
* @return void
*/
- public function requestRegeneration()
+ private function enableCacheTypes($cacheTypes)
{
- $this->write->touch(self::REGENERATE_FLAG);
+ if (empty($cacheTypes)) {
+ return;
+ }
+ $envPath = $this->getEnvPath();
+ if ($this->write->isReadable($this->write->getRelativePath($envPath))) {
+ $envData = include $envPath;
+ foreach ($cacheTypes as $cacheType) {
+ if (isset($envData['cache_types'][$cacheType])) {
+ $envData['cache_types'][$cacheType] = 1;
+ }
+ }
+
+ $formatter = new PhpFormatter();
+ $contents = $formatter->format($envData);
+
+ $this->write->writeFile($this->write->getRelativePath($envPath), $contents);
+ if (function_exists('opcache_invalidate')) {
+ opcache_invalidate($this->write->getAbsolutePath($envPath));
+ }
+ }
}
}
diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/GeneratedFilesTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/GeneratedFilesTest.php
index 4fef046786871..5d5f7178ed909 100644
--- a/lib/internal/Magento/Framework/Code/Test/Unit/GeneratedFilesTest.php
+++ b/lib/internal/Magento/Framework/Code/Test/Unit/GeneratedFilesTest.php
@@ -45,9 +45,9 @@ protected function setUp()
* @param array $getPathMap
* @param array $isDirectoryMap
* @param array $deleteMap
- * @dataProvider regenerateDataProvider
+ * @dataProvider cleanGeneratedFilesDataProvider
*/
- public function testRegenerate($getPathMap, $isDirectoryMap, $deleteMap)
+ public function testCleanGeneratedFiles($getPathMap, $isDirectoryMap, $deleteMap)
{
$this->writeInterface
@@ -62,20 +62,21 @@ public function testRegenerate($getPathMap, $isDirectoryMap, $deleteMap)
$this->writeInterface->expects($this->any())->method('getRelativePath')->willReturnMap($getPathMap);
$this->writeInterface->expects($this->any())->method('isDirectory')->willReturnMap($isDirectoryMap);
$this->writeInterface->expects($this->exactly(1))->method('delete')->willReturnMap($deleteMap);
- $this->model->regenerate();
+ $this->model->cleanGeneratedFiles();
}
/**
* @return array
*/
- public function regenerateDataProvider()
+ public function cleanGeneratedFilesDataProvider()
{
$pathToGeneration = 'path/to/generation';
$pathToDi = 'path/to/di';
$pathToCache = 'path/to/di';
$pathToConfig = 'path/to/config';
- $getPathMap = [[DirectoryList::GENERATION, $pathToGeneration],
+ $getPathMap = [
+ [DirectoryList::GENERATION, $pathToGeneration],
[DirectoryList::DI, $pathToDi],
[DirectoryList::CACHE, $pathToCache],
[DirectoryList::CONFIG, $pathToConfig],
@@ -98,7 +99,7 @@ public function regenerateDataProvider()
];
}
- public function testRegenerateWithNoFlag()
+ public function testCleanGeneratedFilesWithNoFlag()
{
$this->writeInterface
->expects($this->once())
@@ -108,7 +109,7 @@ public function testRegenerateWithNoFlag()
$this->directoryList->expects($this->never())->method('getPath');
$this->writeInterface->expects($this->never())->method('getPath');
$this->writeInterface->expects($this->never())->method('delete');
- $this->model->regenerate();
+ $this->model->cleanGeneratedFiles();
}
public function testRequestRegeneration()
diff --git a/setup/config/di.config.php b/setup/config/di.config.php
index 9c73aae475358..81ddbde7adb1e 100644
--- a/setup/config/di.config.php
+++ b/setup/config/di.config.php
@@ -21,6 +21,7 @@
'Magento\Setup\Controller\Environment',
'Magento\Setup\Controller\DependencyCheck',
'Magento\Setup\Controller\DatabaseCheck',
+ 'Magento\Setup\Controller\ValidateAdminCredentials',
'Magento\Setup\Controller\AddDatabase',
'Magento\Setup\Controller\WebConfiguration',
'Magento\Setup\Controller\CustomizeYourStore',
diff --git a/setup/pub/magento/setup/create-admin-account.js b/setup/pub/magento/setup/create-admin-account.js
index ec9fdf9c6b248..dd8357dd9a568 100644
--- a/setup/pub/magento/setup/create-admin-account.js
+++ b/setup/pub/magento/setup/create-admin-account.js
@@ -5,14 +5,14 @@
'use strict';
angular.module('create-admin-account', ['ngStorage'])
- .controller('createAdminAccountController', ['$scope', '$state', '$localStorage', function ($scope, $state, $localStorage) {
+ .controller('createAdminAccountController', ['$scope', '$state', '$localStorage', '$http', function ($scope, $state, $localStorage, $http) {
$scope.admin = {
'passwordStatus': {
class: 'none',
label: 'None'
}
};
-
+
$scope.passwordStatusChange = function () {
if (angular.isUndefined($scope.admin.password)) {
return;
@@ -41,6 +41,25 @@ angular.module('create-admin-account', ['ngStorage'])
$scope.admin = $localStorage.admin;
}
+ $scope.validateCredentials = function () {
+ var data = {
+ 'db': $localStorage.db,
+ 'admin': $localStorage.admin,
+ 'store': $localStorage.store,
+ 'config': $localStorage.config
+ };
+ $http.post('index.php/validate-admin-credentials', data)
+ .success(function (data) {
+ $scope.validateCredentials.result = data;
+ if ($scope.validateCredentials.result.success) {
+ $scope.nextState();
+ }
+ })
+ .error(function (data) {
+ $scope.validateCredentials.failed = data;
+ });
+ };
+
$scope.$on('nextState', function () {
$localStorage.admin = $scope.admin;
});
diff --git a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
index 17d86ef9bad58..577e787bdd5f2 100644
--- a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
@@ -5,13 +5,9 @@
*/
namespace Magento\Setup\Console\Command;
-use Magento\Framework\App\Filesystem\DirectoryList;
-use Magento\Backend\Console\Command\AbstractCacheManageCommand;
-use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Setup\ConsoleLogger;
use Magento\Setup\Model\InstallerFactory;
use Magento\Setup\Model\ObjectManagerProvider;
-use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -34,9 +30,7 @@ class UpgradeCommand extends AbstractSetupCommand
private $installerFactory;
/**
- * Object Manager
- *
- * @var ObjectManagerProvider
+ * @var \Magento\Setup\Model\ObjectManagerProvider;
*/
private $objectManagerProvider;
@@ -79,9 +73,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $areaCode = 'setup';
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
$objectManager = $this->objectManagerProvider->get();
- $areaCode = 'setup';
/** @var \Magento\Framework\App\State $appState */
$appState = $objectManager->get('Magento\Framework\App\State');
$appState->setAreaCode($areaCode);
@@ -98,40 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('Please re-run Magento compile command');
}
- return $this->enableCaches($objectManager, $output);
- }
-
- /**
- * Enables cache if cachestates exists
- * TODO: to be removed in scope of MAGETWO-53476
- *
- * @param \Magento\Framework\ObjectManagerInterface $objectManager
- * @param \Symfony\Component\Console\Output\OutputInterface $output
- * @return int
- */
- private function enableCaches($objectManager, $output)
- {
- $writeFactory = $objectManager->get('Magento\Framework\Filesystem\Directory\WriteFactory');
- $write = $writeFactory->create(BP);
- /** @var \Magento\Framework\App\Filesystem\DirectoryList $dirList */
- $dirList = $objectManager->get('Magento\Framework\App\Filesystem\DirectoryList');
-
- $pathToCacheStatus = $write->getRelativePath($dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json');
-
- if ($write->isExist($pathToCacheStatus)) {
- $params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
- $command = $this->getApplication()->find('cache:enable');
-
- $arguments = ['command' => 'cache:enable', AbstractCacheManageCommand::INPUT_KEY_TYPES => $params ];
- $returnCode = $command->run(new ArrayInput($arguments), $output);
-
- $write->delete($pathToCacheStatus);
- if (isset($returnCode) && $returnCode > 0) {
- $message = ' Error occured during upgrade. Error code: ' . $returnCode . '';
- $output->writeln($message);
- return \Magento\Framework\Console\Cli::RETURN_FAILURE;
- }
- }
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
}
}
diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php
index 647ba4e59f7d0..5b3507911ef4e 100644
--- a/setup/src/Magento/Setup/Controller/Install.php
+++ b/setup/src/Magento/Setup/Controller/Install.php
@@ -6,21 +6,18 @@
namespace Magento\Setup\Controller;
-use Magento\Setup\Model\AdminAccount;
+use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\ConfigOptionsListConstants as SetupConfigOptionsList;
-use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList;
+use Magento\SampleData;
use Magento\Setup\Model\Installer;
use Magento\Setup\Model\Installer\ProgressFactory;
use Magento\Setup\Model\InstallerFactory;
-use Magento\Setup\Model\StoreConfigurationDataMapper as UserConfig;
+use Magento\Setup\Model\RequestDataConverter;
use Magento\Setup\Model\WebLogger;
use Zend\Json\Json;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
-use Magento\Setup\Console\Command\InstallCommand;
-use Magento\SampleData;
-use Magento\Framework\App\DeploymentConfig;
/**
* Install controller
@@ -54,6 +51,11 @@ class Install extends AbstractActionController
*/
private $deploymentConfig;
+ /**
+ * @var RequestDataConverter
+ */
+ private $requestDataConverter;
+
/**
* Default Constructor
*
@@ -62,19 +64,22 @@ class Install extends AbstractActionController
* @param ProgressFactory $progressFactory
* @param \Magento\Framework\Setup\SampleData\State $sampleDataState
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
+ * @param RequestDataConverter $requestDataConverter
*/
public function __construct(
WebLogger $logger,
InstallerFactory $installerFactory,
ProgressFactory $progressFactory,
\Magento\Framework\Setup\SampleData\State $sampleDataState,
- DeploymentConfig $deploymentConfig
+ DeploymentConfig $deploymentConfig,
+ RequestDataConverter $requestDataConverter
) {
$this->log = $logger;
$this->installer = $installerFactory->create($logger);
$this->progressFactory = $progressFactory;
$this->sampleDataState = $sampleDataState;
$this->deploymentConfig = $deploymentConfig;
+ $this->requestDataConverter = $requestDataConverter;
}
/**
@@ -91,7 +96,6 @@ public function indexAction()
* Index Action
*
* @return JsonModel
- * @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function startAction()
{
@@ -99,11 +103,9 @@ public function startAction()
$json = new JsonModel;
try {
$this->checkForPriorInstall();
- $data = array_merge(
- $this->importDeploymentConfigForm(),
- $this->importUserConfigForm(),
- $this->importAdminUserForm()
- );
+ $content = $this->getRequest()->getContent();
+ $source = $content ? $source = Json::decode($content, Json::TYPE_ARRAY) : [];
+ $data = $this->requestDataConverter->convert($source);
$this->installer->install($data);
$json->setVariable(
'key',
@@ -168,102 +170,4 @@ private function checkForPriorInstall()
throw new \Magento\Setup\Exception('Magento application is already installed.');
}
}
-
- /**
- * Maps data from request to format of deployment config model
- *
- * @return array
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- private function importDeploymentConfigForm()
- {
- $content = $this->getRequest()->getContent();
- $source = [];
- if ($content) {
- $source = Json::decode($content, Json::TYPE_ARRAY);
- }
-
- $result = [];
- $result[SetupConfigOptionsList::INPUT_KEY_DB_HOST] = isset($source['db']['host']) ? $source['db']['host'] : '';
- $result[SetupConfigOptionsList::INPUT_KEY_DB_NAME] = isset($source['db']['name']) ? $source['db']['name'] : '';
- $result[SetupConfigOptionsList::INPUT_KEY_DB_USER] = isset($source['db']['user']) ? $source['db']['user'] :'';
- $result[SetupConfigOptionsList::INPUT_KEY_DB_PASSWORD] =
- isset($source['db']['password']) ? $source['db']['password'] : '';
- $result[SetupConfigOptionsList::INPUT_KEY_DB_PREFIX] =
- isset($source['db']['tablePrefix']) ? $source['db']['tablePrefix'] : '';
- $result[BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME] = isset($source['config']['address']['admin'])
- ? $source['config']['address']['admin'] : '';
- $result[SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key'])
- ? $source['config']['encrypt']['key'] : null;
- $result[SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE] = isset($source['config']['sessionSave']['type'])
- ? $source['config']['sessionSave']['type'] : SetupConfigOptionsList::SESSION_SAVE_FILES;
- $result[Installer::ENABLE_MODULES] = isset($source['store']['selectedModules'])
- ? implode(',', $source['store']['selectedModules']) : '';
- $result[Installer::DISABLE_MODULES] = isset($source['store']['allModules'])
- ? implode(',', array_diff($source['store']['allModules'], $source['store']['selectedModules'])) : '';
- return $result;
- }
-
- /**
- * Maps data from request to format of user config model
- *
- * @return array
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- private function importUserConfigForm()
- {
- $result = [];
- $source = [];
- $content = $this->getRequest()->getContent();
- if ($content) {
- $source = Json::decode($content, Json::TYPE_ARRAY);
- }
- if (isset($source['config']['address']['base_url']) && !empty($source['config']['address']['base_url'])) {
- $result[UserConfig::KEY_BASE_URL] = $source['config']['address']['base_url'];
- }
- $result[UserConfig::KEY_USE_SEF_URL] = isset($source['config']['rewrites']['allowed'])
- ? $source['config']['rewrites']['allowed'] : '';
- $result[UserConfig::KEY_IS_SECURE] = isset($source['config']['https']['front'])
- ? $source['config']['https']['front'] : '';
- $result[UserConfig::KEY_IS_SECURE_ADMIN] = isset($source['config']['https']['admin'])
- ? $source['config']['https']['admin'] : '';
- $result[UserConfig::KEY_BASE_URL_SECURE] = (isset($source['config']['https']['front'])
- || isset($source['config']['https']['admin']))
- ? $source['config']['https']['text'] : '';
- $result[UserConfig::KEY_LANGUAGE] = isset($source['store']['language'])
- ? $source['store']['language'] : '';
- $result[UserConfig::KEY_TIMEZONE] = isset($source['store']['timezone'])
- ? $source['store']['timezone'] : '';
- $result[UserConfig::KEY_CURRENCY] = isset($source['store']['currency'])
- ? $source['store']['currency'] : '';
- $result[InstallCommand::INPUT_KEY_USE_SAMPLE_DATA] = isset($source['store']['useSampleData'])
- ? $source['store']['useSampleData'] : '';
- $result[InstallCommand::INPUT_KEY_CLEANUP_DB] = isset($source['store']['cleanUpDatabase'])
- ? $source['store']['cleanUpDatabase'] : '';
- return $result;
- }
-
- /**
- * Maps data from request to format of admin account model
- *
- * @return array
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- private function importAdminUserForm()
- {
- $result = [];
- $source = [];
- $content = $this->getRequest()->getContent();
- if ($content) {
- $source = Json::decode($content, Json::TYPE_ARRAY);
- }
- $result[AdminAccount::KEY_USER] = isset($source['admin']['username']) ? $source['admin']['username'] : '';
- $result[AdminAccount::KEY_PASSWORD] = isset($source['admin']['password']) ? $source['admin']['password'] : '';
- $result[AdminAccount::KEY_EMAIL] = isset($source['admin']['email']) ? $source['admin']['email'] : '';
- $result[AdminAccount::KEY_FIRST_NAME] = $result[AdminAccount::KEY_USER];
- $result[AdminAccount::KEY_LAST_NAME] = $result[AdminAccount::KEY_USER];
- return $result;
- }
}
diff --git a/setup/src/Magento/Setup/Controller/ValidateAdminCredentials.php b/setup/src/Magento/Setup/Controller/ValidateAdminCredentials.php
new file mode 100644
index 0000000000000..6833c1fba0c11
--- /dev/null
+++ b/setup/src/Magento/Setup/Controller/ValidateAdminCredentials.php
@@ -0,0 +1,61 @@
+adminCredentialsValidator = $adminCredentialsValidator;
+ $this->requestDataConverter = $requestDataConverter;
+ }
+
+ /**
+ * Validate admin credentials.
+ *
+ * @return JsonModel
+ */
+ public function indexAction()
+ {
+ try {
+ $content = $this->getRequest()->getContent();
+ $source = $content ? $source = Json::decode($content, Json::TYPE_ARRAY) : [];
+ $data = $this->requestDataConverter->convert($source);
+ $this->adminCredentialsValidator->validate($data);
+ return new JsonModel(['success' => true]);
+ } catch (\Exception $e) {
+ return new JsonModel(['success' => false, 'error' => $e->getMessage()]);
+ }
+ }
+}
diff --git a/setup/src/Magento/Setup/Model/AdminAccount.php b/setup/src/Magento/Setup/Model/AdminAccount.php
index cd9362f8a0d47..6605052cede1e 100644
--- a/setup/src/Magento/Setup/Model/AdminAccount.php
+++ b/setup/src/Magento/Setup/Model/AdminAccount.php
@@ -137,22 +137,22 @@ private function saveAdminUser()
* @return void
* @throws \Exception If the username and email do not both match data provided to install
*/
- private function validateUserMatches($username, $email)
+ public function validateUserMatches($username, $email)
{
if ((strcasecmp($email, $this->data[self::KEY_EMAIL]) == 0) &&
(strcasecmp($username, $this->data[self::KEY_USER]) != 0)) {
// email matched but username did not
throw new \Exception(
- 'An existing user has the given email but different username. ' . self::KEY_USER .
- ' and ' . self::KEY_EMAIL . ' both need to match an existing user or both be new.'
+ 'An existing user has the given email but different username. '
+ . 'Username and email both need to match an existing user or both be new.'
);
}
if ((strcasecmp($username, $this->data[self::KEY_USER]) == 0) &&
(strcasecmp($email, $this->data[self::KEY_EMAIL]) != 0)) {
// username matched but email did not
throw new \Exception(
- 'An existing user has the given username but different email. ' . self::KEY_USER .
- ' and ' . self::KEY_EMAIL . ' both need to match an existing user or both be new.'
+ 'An existing user has the given username but different email. '
+ . 'Username and email both need to match an existing user or both be new.'
);
}
}
diff --git a/setup/src/Magento/Setup/Model/RequestDataConverter.php b/setup/src/Magento/Setup/Model/RequestDataConverter.php
new file mode 100644
index 0000000000000..bd924c16f3da0
--- /dev/null
+++ b/setup/src/Magento/Setup/Model/RequestDataConverter.php
@@ -0,0 +1,117 @@
+convertDeploymentConfigForm($source),
+ $this->convertUserConfigForm($source),
+ $this->convertAdminUserForm($source)
+ );
+ return $result;
+ }
+
+ /**
+ * Convert data from request to format of deployment config model
+ *
+ * @param array $source
+ * @return array
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ * @SuppressWarnings(PHPMD.NPathComplexity)
+ */
+ private function convertDeploymentConfigForm(array $source)
+ {
+ $result = [];
+ $result[SetupConfigOptionsList::INPUT_KEY_DB_HOST] = isset($source['db']['host']) ? $source['db']['host'] : '';
+ $result[SetupConfigOptionsList::INPUT_KEY_DB_NAME] = isset($source['db']['name']) ? $source['db']['name'] : '';
+ $result[SetupConfigOptionsList::INPUT_KEY_DB_USER] = isset($source['db']['user']) ? $source['db']['user'] : '';
+ $result[SetupConfigOptionsList::INPUT_KEY_DB_PASSWORD] =
+ isset($source['db']['password']) ? $source['db']['password'] : '';
+ $result[SetupConfigOptionsList::INPUT_KEY_DB_PREFIX] =
+ isset($source['db']['tablePrefix']) ? $source['db']['tablePrefix'] : '';
+ $result[BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME] = isset($source['config']['address']['admin'])
+ ? $source['config']['address']['admin'] : '';
+ $result[SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key'])
+ ? $source['config']['encrypt']['key'] : null;
+ $result[SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE] = isset($source['config']['sessionSave']['type'])
+ ? $source['config']['sessionSave']['type'] : SetupConfigOptionsList::SESSION_SAVE_FILES;
+ $result[Installer::ENABLE_MODULES] = isset($source['store']['selectedModules'])
+ ? implode(',', $source['store']['selectedModules']) : '';
+ $result[Installer::DISABLE_MODULES] = isset($source['store']['allModules'])
+ ? implode(',', array_diff($source['store']['allModules'], $source['store']['selectedModules'])) : '';
+ return $result;
+ }
+
+ /**
+ * Convert data from request to format of user config model
+ *
+ * @param array $source
+ * @return array
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ * @SuppressWarnings(PHPMD.NPathComplexity)
+ */
+ private function convertUserConfigForm(array $source)
+ {
+ $result = [];
+ if (isset($source['config']['address']['base_url']) && !empty($source['config']['address']['base_url'])) {
+ $result[UserConfig::KEY_BASE_URL] = $source['config']['address']['base_url'];
+ }
+ $result[UserConfig::KEY_USE_SEF_URL] = isset($source['config']['rewrites']['allowed'])
+ ? $source['config']['rewrites']['allowed'] : '';
+ $result[UserConfig::KEY_IS_SECURE] = isset($source['config']['https']['front'])
+ ? $source['config']['https']['front'] : '';
+ $result[UserConfig::KEY_IS_SECURE_ADMIN] = isset($source['config']['https']['admin'])
+ ? $source['config']['https']['admin'] : '';
+ $result[UserConfig::KEY_BASE_URL_SECURE] = (isset($source['config']['https']['front'])
+ || isset($source['config']['https']['admin']))
+ ? $source['config']['https']['text'] : '';
+ $result[UserConfig::KEY_LANGUAGE] = isset($source['store']['language'])
+ ? $source['store']['language'] : '';
+ $result[UserConfig::KEY_TIMEZONE] = isset($source['store']['timezone'])
+ ? $source['store']['timezone'] : '';
+ $result[UserConfig::KEY_CURRENCY] = isset($source['store']['currency'])
+ ? $source['store']['currency'] : '';
+ $result[InstallCommand::INPUT_KEY_USE_SAMPLE_DATA] = isset($source['store']['useSampleData'])
+ ? $source['store']['useSampleData'] : '';
+ $result[InstallCommand::INPUT_KEY_CLEANUP_DB] = isset($source['store']['cleanUpDatabase'])
+ ? $source['store']['cleanUpDatabase'] : '';
+ return $result;
+ }
+
+ /**
+ * Convert data from request to format of admin account model
+ *
+ * @param array $source
+ * @return array
+ */
+ private function convertAdminUserForm(array $source)
+ {
+ $result = [];
+ $result[AdminAccount::KEY_USER] = isset($source['admin']['username']) ? $source['admin']['username'] : '';
+ $result[AdminAccount::KEY_PASSWORD] = isset($source['admin']['password']) ? $source['admin']['password'] : '';
+ $result[AdminAccount::KEY_EMAIL] = isset($source['admin']['email']) ? $source['admin']['email'] : '';
+ $result[AdminAccount::KEY_FIRST_NAME] = $result[AdminAccount::KEY_USER];
+ $result[AdminAccount::KEY_LAST_NAME] = $result[AdminAccount::KEY_USER];
+ return $result;
+ }
+}
diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php
index 9066201ace7b3..17d78718e4bf4 100644
--- a/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php
@@ -28,21 +28,11 @@ public function testExecute()
$installer->expects($this->at(2))->method('installDataFixtures');
$installerFactory->expects($this->once())->method('create')->willReturn($installer);
- $pathToCacheStatus = '/path/to/cachefile';
- $writeFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteFactory', [], [], '', false);
- $write = $this->getMock('\Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
- $write->expects($this->once())->method('isExist')->with('/path/to/cachefile')->willReturn(false);
- $write->expects($this->once())->method('getRelativePath')->willReturn($pathToCacheStatus);
-
- $writeFactory->expects($this->once())->method('create')->willReturn($write);
- $directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
- $objectManager->expects($this->exactly(4))
+ $objectManager->expects($this->exactly(2))
->method('get')
->will($this->returnValueMap([
['Magento\Framework\App\State', $state],
- ['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader],
- ['Magento\Framework\Filesystem\Directory\WriteFactory', $writeFactory],
- ['Magento\Framework\App\Filesystem\DirectoryList', $directoryList],
+ ['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader]
]));
$commandTester = new CommandTester(new UpgradeCommand($installerFactory, $objectManagerProvider));
diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php
index 121621075a138..55666ffef059c 100644
--- a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php
@@ -7,6 +7,7 @@
namespace Magento\Setup\Test\Unit\Controller;
use \Magento\Setup\Controller\Install;
+use Magento\Setup\Model\RequestDataConverter;
class InstallTest extends \PHPUnit_Framework_TestCase
{
@@ -25,6 +26,11 @@ class InstallTest extends \PHPUnit_Framework_TestCase
*/
private $progressFactory;
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject|RequestDataConverter
+ */
+ private $requestDataConverter;
+
/**
* @var Install
*/
@@ -48,6 +54,7 @@ public function setUp()
$this->progressFactory = $this->getMock('\Magento\Setup\Model\Installer\ProgressFactory', [], [], '', false);
$this->sampleDataState = $this->getMock('\Magento\Framework\Setup\SampleData\State', [], [], '', false);
$this->deploymentConfig = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
+ $this->requestDataConverter = $this->getMock(RequestDataConverter::class, [], [], '', false);
$installerFactory->expects($this->once())->method('create')->with($this->webLogger)
->willReturn($this->installer);
@@ -56,7 +63,8 @@ public function setUp()
$installerFactory,
$this->progressFactory,
$this->sampleDataState,
- $this->deploymentConfig
+ $this->deploymentConfig,
+ $this->requestDataConverter
);
}
diff --git a/setup/src/Magento/Setup/Validator/AdminCredentialsValidator.php b/setup/src/Magento/Setup/Validator/AdminCredentialsValidator.php
new file mode 100644
index 0000000000000..b487e11a63fe1
--- /dev/null
+++ b/setup/src/Magento/Setup/Validator/AdminCredentialsValidator.php
@@ -0,0 +1,87 @@
+connectionFactory = $connectionFactory;
+ $this->adminAccountFactory = $adminAccountFactory;
+ $this->setupFactory = $setupFactory;
+ }
+
+ /**
+ * Validate admin user name and email.
+ *
+ * @param array $data
+ * @return void
+ * @throws \Exception
+ */
+ public function validate(array $data)
+ {
+ try {
+ $dbConnection = $this->connectionFactory->create([
+ ConfigOption::KEY_NAME => $data[ConfigOption::INPUT_KEY_DB_NAME],
+ ConfigOption::KEY_HOST => $data[ConfigOption::INPUT_KEY_DB_HOST],
+ ConfigOption::KEY_USER => $data[ConfigOption::INPUT_KEY_DB_USER],
+ ConfigOption::KEY_PASSWORD => $data[ConfigOption::INPUT_KEY_DB_PASSWORD],
+ ConfigOption::KEY_PREFIX => $data[ConfigOption::INPUT_KEY_DB_PREFIX]
+ ]);
+
+ $userName = $data[AdminAccount::KEY_USER];
+ $userEmail = $data[AdminAccount::KEY_EMAIL];
+ $userTable = $dbConnection->getTableName('admin_user');
+ $result = $dbConnection->fetchRow(
+ "SELECT user_id, username, email FROM {$userTable} WHERE username = :username OR email = :email",
+ ['username' => $userName, 'email' => $userEmail]
+ );
+ $setup = $this->setupFactory->create();
+ $adminAccount = $this->adminAccountFactory->create(
+ $setup,
+ [AdminAccount::KEY_USER => $userName, AdminAccount::KEY_EMAIL => $userEmail]
+ );
+ } catch (\Exception $e) {
+ return;
+ }
+
+ if (!empty($result)) {
+ $adminAccount->validateUserMatches($result['username'], $result['email']);
+ }
+ }
+}
diff --git a/setup/view/magento/setup/create-admin-account.phtml b/setup/view/magento/setup/create-admin-account.phtml
index 8c08d127aac65..35c0c911b184c 100644
--- a/setup/view/magento/setup/create-admin-account.phtml
+++ b/setup/view/magento/setup/create-admin-account.phtml
@@ -29,7 +29,7 @@ $passwordWizard = sprintf(
@@ -41,6 +41,25 @@ $passwordWizard = sprintf(