1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2014 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
namespace Magento \Backend \Controller \Adminhtml \System \Account ;
7
7
11
11
use Magento \Framework \Controller \ResultFactory ;
12
12
use Magento \Framework \Exception \State \UserLockedException ;
13
13
use Magento \Security \Model \SecurityCookie ;
14
+ use Magento \User \Model \User ;
14
15
15
16
/**
16
17
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18
+ * @SuppressWarnings(PHPMD.AllPurposeAction)
17
19
*/
18
20
class Save extends \Magento \Backend \Controller \Adminhtml \System \Account
19
21
{
@@ -25,8 +27,11 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
25
27
/**
26
28
* Get security cookie
27
29
*
30
+ * @deprecated 100.1.0 This method is deprecated because dependency injection should be used instead of
31
+ * directly accessing the SecurityCookie instance.
32
+ * Use dependency injection to get an instance of SecurityCookie.
33
+ * @see \Magento\Backend\Controller\Adminhtml\System\Account::__construct()
28
34
* @return SecurityCookie
29
- * @deprecated 100.1.0
30
35
*/
31
36
private function getSecurityCookie ()
32
37
{
@@ -81,7 +86,29 @@ public function execute()
81
86
} else {
82
87
$ user ->save ();
83
88
$ user ->sendNotificationEmailsIfRequired ();
84
- $ this ->messageManager ->addSuccessMessage (__ ('You saved the account. ' ));
89
+
90
+ $ modifiedFields = $ this ->getModifiedFields ($ user );
91
+ if (!empty ($ modifiedFields )) {
92
+ $ countModifiedFields = count ($ modifiedFields );
93
+ // validate how many fields were modified to display them correctly
94
+ if ($ countModifiedFields > 1 ) {
95
+ $ lastModifiedField = array_pop ($ modifiedFields );
96
+ $ modifiedFieldsText = implode (', ' , $ modifiedFields );
97
+ $ successMessage = __ (
98
+ 'The %1 and %2 of this account have been modified successfully. ' ,
99
+ $ modifiedFieldsText ,
100
+ $ lastModifiedField
101
+ );
102
+ } else {
103
+ $ successMessage = __ (
104
+ 'The %1 of this account has been modified successfully. ' ,
105
+ reset ($ modifiedFields )
106
+ );
107
+ }
108
+ $ this ->messageManager ->addSuccessMessage ($ successMessage );
109
+ } else {
110
+ $ this ->messageManager ->addSuccessMessage (__ ('You saved the account. ' ));
111
+ }
85
112
}
86
113
} catch (UserLockedException $ e ) {
87
114
$ this ->_auth ->logout ();
@@ -103,4 +130,22 @@ public function execute()
103
130
$ resultRedirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
104
131
return $ resultRedirect ->setPath ("*/*/ " );
105
132
}
133
+
134
+ /**
135
+ * Get user modified fields
136
+ *
137
+ * @param User $user
138
+ * @return array
139
+ */
140
+ private function getModifiedFields (User $ user )
141
+ {
142
+ $ modifiedFields = [];
143
+ $ propertiesToCheck = ['password ' , 'username ' , 'firstname ' , 'lastname ' , 'email ' ];
144
+ foreach ($ propertiesToCheck as $ property ) {
145
+ if ($ user ->getOrigData ($ property ) !== $ user ->{'get ' . ucfirst ($ property )}()) {
146
+ $ modifiedFields [] = $ property ;
147
+ }
148
+ }
149
+ return $ modifiedFields ;
150
+ }
106
151
}
0 commit comments