1 | <?php |
||
22 | class AccountCommand extends AbstractCommand |
||
23 | { |
||
24 | /** |
||
25 | * The name and signature of the console command. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $signature = 'aimeos:account |
||
30 | {email? : E-Mail adress of the (admin) user (will ask for if not given)} |
||
31 | {site=default : Site to create account for} |
||
32 | {--password= : Secret password for the account (will ask for if not given)} |
||
33 | {--super : If account should have super user privileges for all sites} |
||
34 | {--admin : If account should have site administrator privileges} |
||
35 | {--editor : If account should have limited editor privileges} |
||
36 | {--api : If account should be able to access the APIs} |
||
37 | '; |
||
38 | |||
39 | /** |
||
40 | * The console command description. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $description = 'Creates new (admin) accounts'; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Execute the console command. |
||
49 | * |
||
50 | * @return mixed |
||
51 | */ |
||
52 | public function handle() |
||
53 | { |
||
54 | if( ( $code = $this->argument( 'email' ) ) === null ) { |
||
55 | $code = $this->ask( 'E-Mail' ); |
||
56 | } |
||
57 | |||
58 | if( ( $password = $this->option( 'password' ) ) === null ) { |
||
59 | $password = $this->secret( 'Password' ); |
||
60 | } |
||
61 | |||
62 | $context = $this->getLaravel()->make( 'Aimeos\Shop\Base\Context' )->get( false, 'command' ); |
||
63 | $context->setEditor( 'aimeos:account' ); |
||
64 | |||
65 | $localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
||
66 | $localeItem = $localeManager->bootstrap( $this->argument( 'site' ), '', '', false ); |
||
67 | $context->setLocale( $localeItem ); |
||
68 | |||
69 | $this->addGroups( $context, $this->createCustomerItem( $context, $code, $password ) ); |
||
70 | } |
||
71 | |||
72 | |||
73 | /** |
||
74 | * Associates the user to the group by their given IDs |
||
75 | * |
||
76 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
77 | * @param string $userid Unique user ID |
||
78 | * @param string $groupid Unique group ID |
||
79 | */ |
||
80 | protected function addListItem( \Aimeos\MShop\Context\Item\Iface $context, $userid, $groupid ) |
||
109 | |||
110 | |||
111 | /** |
||
112 | * Adds the group to the given user |
||
113 | * |
||
114 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
115 | * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object |
||
116 | */ |
||
117 | protected function addGroups( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user ) |
||
135 | |||
136 | |||
137 | /** |
||
138 | * Adds the group to the given user |
||
139 | * |
||
140 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
141 | * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object |
||
142 | * @param string $group Unique customer group code |
||
143 | */ |
||
144 | protected function addGroup( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user, $group ) |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Returns the customer item for the given e-mail and set its password |
||
156 | * |
||
157 | * If the customer doesn't exist yet, it will be created. |
||
158 | * |
||
159 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
160 | * @param string $email Unique e-mail address |
||
161 | * @param string $password New user password |
||
162 | * @return \Aimeos\MShop\Customer\Item\Iface Aimeos customer item object |
||
163 | */ |
||
164 | protected function createCustomerItem( \Aimeos\MShop\Context\Item\Iface $context, $email, $password ) |
||
184 | |||
185 | |||
186 | /** |
||
187 | * Get the console command arguments. |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | protected function getArguments() |
||
198 | |||
199 | |||
200 | /** |
||
201 | * Returns the customer group item for the given code |
||
202 | * |
||
203 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
204 | * @param string $code Unique customer group code |
||
205 | * @return \Aimeos\MShop\Customer\Item\Group\Iface Aimeos customer group item object |
||
206 | */ |
||
207 | protected function getGroupItem( \Aimeos\MShop\Context\Item\Iface $context, $code ) |
||
226 | |||
227 | |||
228 | /** |
||
229 | * Get the console command options. |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | protected function getOptions() |
||
243 | } |
||
244 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.