@@ -17,12 +17,12 @@ class AdminAccount
17
17
/**#@+
18
18
* Data keys
19
19
*/
20
- const KEY_USER = 'admin-user ' ;
21
- const KEY_PASSWORD = 'admin-password ' ;
22
- const KEY_EMAIL = 'admin-email ' ;
23
- const KEY_FIRST_NAME = 'admin-firstname ' ;
24
- const KEY_LAST_NAME = 'admin-lastname ' ;
25
- const KEY_PREFIX = 'db-prefix ' ;
20
+ public const KEY_USER = 'admin-user ' ;
21
+ public const KEY_PASSWORD = 'admin-password ' ;
22
+ public const KEY_EMAIL = 'admin-email ' ;
23
+ public const KEY_FIRST_NAME = 'admin-firstname ' ;
24
+ public const KEY_LAST_NAME = 'admin-lastname ' ;
25
+ public const KEY_PREFIX = 'db-prefix ' ;
26
26
/**#@- */
27
27
28
28
/**
@@ -154,8 +154,7 @@ private function trackPassword($adminId, $passwordHash)
154
154
}
155
155
156
156
/**
157
- * Validates that the username and email both match the user,
158
- * and that password exists and is different from user name.
157
+ * Validate that the username and email both match the user,and that password exists and is different from username.
159
158
*
160
159
* @return void
161
160
* @throws \Exception If the username and email do not both match data provided to install
@@ -164,12 +163,14 @@ private function trackPassword($adminId, $passwordHash)
164
163
public function validateUserMatches ()
165
164
{
166
165
if (empty ($ this ->data [self ::KEY_PASSWORD ])) {
166
+ // phpcs:ignore Magento2.Exceptions.DirectThrow
167
167
throw new \Exception (
168
168
'"Password" is required. Enter and try again. '
169
169
);
170
170
}
171
171
172
172
if (strcasecmp ($ this ->data [self ::KEY_PASSWORD ], $ this ->data [self ::KEY_USER ]) == 0 ) {
173
+ // phpcs:ignore Magento2.Exceptions.DirectThrow
173
174
throw new \Exception (
174
175
'Password cannot be the same as the user name. '
175
176
);
@@ -191,6 +192,7 @@ public function validateUserMatches()
191
192
if ((strcasecmp ($ email , $ this ->data [self ::KEY_EMAIL ]) == 0 ) &&
192
193
(strcasecmp ($ username , $ this ->data [self ::KEY_USER ]) != 0 )) {
193
194
// email matched but username did not
195
+ // phpcs:ignore Magento2.Exceptions.DirectThrow
194
196
throw new \Exception (
195
197
'An existing user has the given email but different username. '
196
198
. 'Username and email both need to match an existing user or both be new. '
@@ -199,6 +201,7 @@ public function validateUserMatches()
199
201
if ((strcasecmp ($ username , $ this ->data [self ::KEY_USER ]) == 0 ) &&
200
202
(strcasecmp ($ email , $ this ->data [self ::KEY_EMAIL ]) != 0 )) {
201
203
// username matched but email did not
204
+ // phpcs:ignore Magento2.Exceptions.DirectThrow
202
205
throw new \Exception (
203
206
'An existing user has the given username but different email. '
204
207
. 'Username and email both need to match an existing user or both be new. '
@@ -236,30 +239,30 @@ private function saveAdminUserRole($adminId)
236
239
}
237
240
238
241
/**
239
- * Gets the "Administrators" role id, the special role created by data fixture in Authorization module.
242
+ * Gets an administrators role id, the special role created by data fixture in Authorization module.
240
243
*
241
- * @return int The id of the Administrators role
242
- * @throws \Exception If Administrators role not found or problem connecting with database.
244
+ * @return int The id of an administrators role
245
+ * @throws \Exception If an administrators role not found or problem connecting with database.
243
246
*/
244
247
private function retrieveAdministratorsRoleId ()
245
248
{
246
- // Get Administrators role id to use as parent_id
249
+ // Get an administrators role id to use as parent_id
247
250
$ administratorsRoleData = [
248
251
'parent_id ' => 0 ,
249
252
'tree_level ' => 1 ,
250
253
'role_type ' => Group::ROLE_TYPE ,
251
254
'user_id ' => 0 ,
252
255
'user_type ' => UserContextInterface::USER_TYPE_ADMIN ,
253
- 'role_name ' => 'Administrators ' ,
254
256
];
255
257
$ result = $ this ->connection ->fetchRow (
256
258
'SELECT * FROM ' . $ this ->getTableName ('authorization_role ' ) . ' ' .
257
259
'WHERE parent_id = :parent_id AND tree_level = :tree_level AND role_type = :role_type AND ' .
258
- 'user_id = :user_id AND user_type = :user_type AND role_name = :role_name ' ,
260
+ 'user_id = :user_id AND user_type = :user_type ORDER BY sort_order DESC ' ,
259
261
$ administratorsRoleData
260
262
);
261
263
if (empty ($ result )) {
262
- throw new \Exception ('No Administrators role was found, data fixture needs to be run ' );
264
+ // phpcs:ignore Magento2.Exceptions.DirectThrow
265
+ throw new \Exception ('No administrators role was found, data fixture needs to be run ' );
263
266
} else {
264
267
// Found at least one, use first
265
268
return $ result ['role_id ' ];
0 commit comments