Skip to content

Commit 0d9b92e

Browse files
committed
Merge remote-tracking branch 'origin/2.3.0-release' into MC-4303
2 parents e402fc8 + e7b5fda commit 0d9b92e

File tree

7 files changed

+275
-77
lines changed

7 files changed

+275
-77
lines changed

app/code/Magento/User/Model/User.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\User\Api\Data\UserInterface;
1515
use Magento\User\Model\Spi\NotificationExceptionInterface;
1616
use Magento\User\Model\Spi\NotificatorInterface;
17+
use Magento\Framework\App\DeploymentConfig;
1718

1819
/**
1920
* Admin user model
@@ -138,6 +139,11 @@ class User extends AbstractModel implements StorageInterface, UserInterface
138139
*/
139140
private $notificator;
140141

142+
/**
143+
* @deprecated
144+
*/
145+
private $deploymentConfig;
146+
141147
/**
142148
* @param \Magento\Framework\Model\Context $context
143149
* @param \Magento\Framework\Registry $registry
@@ -153,6 +159,7 @@ class User extends AbstractModel implements StorageInterface, UserInterface
153159
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
154160
* @param array $data
155161
* @param Json $serializer
162+
* @param DeploymentConfig|null $deploymentConfig
156163
* @param NotificatorInterface|null $notificator
157164
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
158165
*/
@@ -171,6 +178,7 @@ public function __construct(
171178
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
172179
array $data = [],
173180
Json $serializer = null,
181+
DeploymentConfig $deploymentConfig = null,
174182
?NotificatorInterface $notificator = null
175183
) {
176184
$this->_encryptor = $encryptor;
@@ -184,6 +192,8 @@ public function __construct(
184192
$this->validationRules = $validationRules;
185193
$this->serializer = $serializer
186194
?: ObjectManager::getInstance()->get(Json::class);
195+
$this->deploymentConfig = $deploymentConfig
196+
?: ObjectManager::getInstance()->get(DeploymentConfig::class);
187197
$this->notificator = $notificator
188198
?: ObjectManager::getInstance()->get(NotificatorInterface::class);
189199
}
@@ -217,7 +227,11 @@ public function __sleep()
217227
'_encryptor',
218228
'_transportBuilder',
219229
'_storeManager',
220-
'_validatorBeforeSave'
230+
'_validatorBeforeSave',
231+
'validationRules',
232+
'serializer',
233+
'deploymentConfig',
234+
'notificator'
221235
]
222236
);
223237
}
@@ -241,6 +255,9 @@ public function __wakeup()
241255
$this->_encryptor = $objectManager->get(\Magento\Framework\Encryption\EncryptorInterface::class);
242256
$this->_transportBuilder = $objectManager->get(\Magento\Framework\Mail\Template\TransportBuilder::class);
243257
$this->_storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
258+
$this->validationRules = $objectManager->get(UserValidationRules::class);
259+
$this->deploymentConfig = $objectManager->get(DeploymentConfig::class);
260+
$this->notificator = $objectManager->get(NotificatorInterface::class);
244261
}
245262

246263
/**

setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use Symfony\Component\Console\Question\Question;
1717

18+
/**
19+
* Command to create an admin user.
20+
*/
1821
class AdminUserCreateCommand extends AbstractSetupCommand
1922
{
2023
/**
@@ -52,6 +55,8 @@ protected function configure()
5255
}
5356

5457
/**
58+
* Creation admin user in interaction mode.
59+
*
5560
* @param \Symfony\Component\Console\Input\InputInterface $input
5661
* @param \Symfony\Component\Console\Output\OutputInterface $output
5762
*
@@ -129,6 +134,8 @@ protected function interact(InputInterface $input, OutputInterface $output)
129134
}
130135

131136
/**
137+
* Add not empty validator.
138+
*
132139
* @param \Symfony\Component\Console\Question\Question $question
133140
* @return void
134141
*/
@@ -144,7 +151,7 @@ private function addNotEmptyValidator(Question $question)
144151
}
145152

146153
/**
147-
* {@inheritdoc}
154+
* @inheritdoc
148155
*/
149156
protected function execute(InputInterface $input, OutputInterface $output)
150157
{
@@ -165,25 +172,43 @@ protected function execute(InputInterface $input, OutputInterface $output)
165172
/**
166173
* Get list of arguments for the command
167174
*
175+
* @param int $mode The mode of options.
168176
* @return InputOption[]
169177
*/
170-
public function getOptionsList()
178+
public function getOptionsList($mode = InputOption::VALUE_REQUIRED)
171179
{
180+
$requiredStr = ($mode === InputOption::VALUE_REQUIRED ? '(Required) ' : '');
181+
172182
return [
173-
new InputOption(AdminAccount::KEY_USER, null, InputOption::VALUE_REQUIRED, '(Required) Admin user'),
174-
new InputOption(AdminAccount::KEY_PASSWORD, null, InputOption::VALUE_REQUIRED, '(Required) Admin password'),
175-
new InputOption(AdminAccount::KEY_EMAIL, null, InputOption::VALUE_REQUIRED, '(Required) Admin email'),
183+
new InputOption(
184+
AdminAccount::KEY_USER,
185+
null,
186+
$mode,
187+
$requiredStr . 'Admin user'
188+
),
189+
new InputOption(
190+
AdminAccount::KEY_PASSWORD,
191+
null,
192+
$mode,
193+
$requiredStr . 'Admin password'
194+
),
195+
new InputOption(
196+
AdminAccount::KEY_EMAIL,
197+
null,
198+
$mode,
199+
$requiredStr . 'Admin email'
200+
),
176201
new InputOption(
177202
AdminAccount::KEY_FIRST_NAME,
178203
null,
179-
InputOption::VALUE_REQUIRED,
180-
'(Required) Admin first name'
204+
$mode,
205+
$requiredStr . 'Admin first name'
181206
),
182207
new InputOption(
183208
AdminAccount::KEY_LAST_NAME,
184209
null,
185-
InputOption::VALUE_REQUIRED,
186-
'(Required) Admin last name'
210+
$mode,
211+
$requiredStr . 'Admin last name'
187212
),
188213
];
189214
}

setup/src/Magento/Setup/Console/Command/InstallCommand.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
1111
use Magento\Framework\Setup\Declaration\Schema\DryRunLogger;
1212
use Magento\Framework\Setup\Declaration\Schema\OperationsExecutor;
13+
use Magento\Framework\Setup\Declaration\Schema\Request;
14+
use Magento\Setup\Model\AdminAccount;
1315
use Magento\Setup\Model\ConfigModel;
1416
use Magento\Setup\Model\InstallerFactory;
1517
use Magento\Framework\Setup\ConsoleLogger;
@@ -136,7 +138,7 @@ protected function configure()
136138
{
137139
$inputOptions = $this->configModel->getAvailableOptions();
138140
$inputOptions = array_merge($inputOptions, $this->userConfig->getOptionsList());
139-
$inputOptions = array_merge($inputOptions, $this->adminUser->getOptionsList());
141+
$inputOptions = array_merge($inputOptions, $this->adminUser->getOptionsList(InputOption::VALUE_OPTIONAL));
140142
$inputOptions = array_merge($inputOptions, [
141143
new InputOption(
142144
self::INPUT_KEY_CLEANUP_DB,
@@ -251,7 +253,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
251253
}
252254

253255
$errors = $this->configModel->validate($configOptionsToValidate);
254-
$errors = array_merge($errors, $this->adminUser->validate($input));
256+
$errors = array_merge($errors, $this->validateAdmin($input));
255257
$errors = array_merge($errors, $this->validate($input));
256258
$errors = array_merge($errors, $this->userConfig->validate($input));
257259

@@ -320,7 +322,7 @@ private function interactiveQuestions(InputInterface $input, OutputInterface $ou
320322

321323
$output->writeln("");
322324

323-
foreach ($this->adminUser->getOptionsList() as $option) {
325+
foreach ($this->adminUser->getOptionsList(InputOption::VALUE_OPTIONAL) as $option) {
324326
$configOptionsToValidate[$option->getName()] = $this->askQuestion(
325327
$input,
326328
$output,
@@ -411,4 +413,24 @@ private function askQuestion(
411413

412414
return $value;
413415
}
416+
417+
/**
418+
* Performs validation of admin options if at least one of them was set.
419+
*
420+
* @param InputInterface $input
421+
* @return array
422+
*/
423+
private function validateAdmin(InputInterface $input): array
424+
{
425+
if ($input->getOption(AdminAccount::KEY_FIRST_NAME)
426+
|| $input->getOption(AdminAccount::KEY_LAST_NAME)
427+
|| $input->getOption(AdminAccount::KEY_EMAIL)
428+
|| $input->getOption(AdminAccount::KEY_USER)
429+
|| $input->getOption(AdminAccount::KEY_PASSWORD)
430+
) {
431+
return $this->adminUser->validate($input);
432+
}
433+
434+
return [];
435+
}
414436
}

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class Installer
267267
* @param \Magento\Framework\Setup\SampleData\State $sampleDataState
268268
* @param ComponentRegistrar $componentRegistrar
269269
* @param PhpReadinessCheck $phpReadinessCheck
270-
*
270+
* @throws \Magento\Setup\Exception
271271
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
272272
*/
273273
public function __construct(
@@ -345,7 +345,9 @@ public function install($request)
345345
[$request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX]],
346346
];
347347
}
348-
$script[] = ['Installing admin user...', 'installAdminUser', [$request]];
348+
if ($this->isAdminDataSet($request)) {
349+
$script[] = ['Installing admin user...', 'installAdminUser', [$request]];
350+
}
349351

350352
if (!$this->isDryRun($request)) {
351353
$script[] = ['Caches clearing:', 'cleanCaches', [$request]];
@@ -909,6 +911,7 @@ private function throwExceptionForNotWritablePaths(array $paths)
909911
* @param string $type
910912
* @param array $request
911913
* @return void
914+
* @throws \Magento\Framework\Setup\Exception
912915
* @throws \Magento\Setup\Exception
913916
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
914917
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -1473,4 +1476,28 @@ private function cleanupGeneratedFiles()
14731476
$this->log->log($message);
14741477
}
14751478
}
1479+
1480+
/**
1481+
* Checks that admin data is not empty in request array
1482+
*
1483+
* @param \ArrayObject|array $request
1484+
* @return bool
1485+
*/
1486+
private function isAdminDataSet($request)
1487+
{
1488+
$adminData = array_filter($request, function ($value, $key) {
1489+
return in_array(
1490+
$key,
1491+
[
1492+
AdminAccount::KEY_EMAIL,
1493+
AdminAccount::KEY_FIRST_NAME,
1494+
AdminAccount::KEY_LAST_NAME,
1495+
AdminAccount::KEY_USER,
1496+
AdminAccount::KEY_PASSWORD,
1497+
]
1498+
) && $value !== null;
1499+
}, ARRAY_FILTER_USE_BOTH);
1500+
1501+
return !empty($adminData);
1502+
}
14761503
}

setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
use Magento\User\Model\UserValidationRules;
1212
use Symfony\Component\Console\Application;
1313
use Symfony\Component\Console\Helper\QuestionHelper;
14+
use Symfony\Component\Console\Input\InputOption;
1415
use Symfony\Component\Console\Tester\CommandTester;
1516

17+
/**
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
*/
1620
class AdminUserCreateCommandTest extends \PHPUnit\Framework\TestCase
1721
{
1822
/**
@@ -125,11 +129,34 @@ public function testInteraction()
125129
);
126130
}
127131

128-
public function testGetOptionsList()
132+
/**
133+
* @param int $mode
134+
* @param string $description
135+
* @dataProvider getOptionListDataProvider
136+
*/
137+
public function testGetOptionsList($mode, $description)
129138
{
130139
/* @var $argsList \Symfony\Component\Console\Input\InputArgument[] */
131-
$argsList = $this->command->getOptionsList();
140+
$argsList = $this->command->getOptionsList($mode);
132141
$this->assertEquals(AdminAccount::KEY_EMAIL, $argsList[2]->getName());
142+
$this->assertEquals($description, $argsList[2]->getDescription());
143+
}
144+
145+
/**
146+
* @return array
147+
*/
148+
public function getOptionListDataProvider()
149+
{
150+
return [
151+
[
152+
'mode' => InputOption::VALUE_REQUIRED,
153+
'description' => '(Required) Admin email',
154+
],
155+
[
156+
'mode' => InputOption::VALUE_OPTIONAL,
157+
'description' => 'Admin email',
158+
],
159+
];
133160
}
134161

135162
/**

0 commit comments

Comments
 (0)