1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||||||
5 | * @copyright Aimeos (aimeos.org), 2015-2016 |
||||||
6 | * @package laravel |
||||||
7 | * @subpackage Command |
||||||
8 | */ |
||||||
9 | |||||||
10 | |||||||
11 | namespace Aimeos\Shop\Command; |
||||||
12 | |||||||
13 | use Symfony\Component\Console\Input\InputOption; |
||||||
14 | use Symfony\Component\Console\Input\InputArgument; |
||||||
15 | |||||||
16 | |||||||
17 | /** |
||||||
18 | * Creates new accounts or resets their passwords |
||||||
19 | * @package laravel |
||||||
20 | * @subpackage Command |
||||||
21 | */ |
||||||
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( ( $email = $this->argument( 'email' ) ) === null ) { |
||||||
55 | $email = $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::create( $context, 'locale' ); |
||||||
66 | $localeItem = $localeManager->bootstrap( $this->argument( 'site' ), '', '', false ); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
67 | $context->setLocale( $localeItem ); |
||||||
68 | |||||||
69 | $manager = \Aimeos\MShop::create( $context, 'customer' ); |
||||||
70 | |||||||
71 | try { |
||||||
72 | $item = $manager->findItem( $email ); |
||||||
0 ignored issues
–
show
The method
findItem() does not exist on Aimeos\MShop\Common\Manager\Iface . It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface . Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
73 | } catch( \Aimeos\MShop\Exception $e ) { |
||||||
74 | $item = $manager->createItem(); |
||||||
75 | } |
||||||
76 | |||||||
77 | $item = $item->setCode( $email )->setLabel( $email )->setPassword( $password )->setStatus( 1 ); |
||||||
78 | $item->getPaymentAddress()->setEmail( $email ); |
||||||
79 | |||||||
80 | $item = $manager->saveItem( $this->addGroups( $context, $item ) ); |
||||||
0 ignored issues
–
show
The method
saveItem() does not exist on Aimeos\MShop\Common\Manager\Iface . Did you maybe mean saveItems() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
81 | |||||||
82 | \Illuminate\Foundation\Auth\User::findOrFail( $item->getId() ) |
||||||
83 | ->forceFill( ['superuser' => ( $this->option( 'super' ) ? 1 : 0 )] ) |
||||||
84 | ->save(); |
||||||
85 | } |
||||||
86 | |||||||
87 | |||||||
88 | /** |
||||||
89 | * Adds the group to the given user |
||||||
90 | * |
||||||
91 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||||||
92 | * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object |
||||||
93 | * @return \Aimeos\MShop\Customer\Item\Iface Updated customer object |
||||||
94 | */ |
||||||
95 | protected function addGroups( \Aimeos\MShop\Context\Item\Iface $context, |
||||||
96 | \Aimeos\MShop\Customer\Item\Iface $user ) : \Aimeos\MShop\Customer\Item\Iface |
||||||
97 | { |
||||||
98 | if( $this->option( 'admin' ) ) { |
||||||
99 | $user = $this->addGroup( $context, $user, 'admin' ); |
||||||
100 | } |
||||||
101 | |||||||
102 | if( $this->option( 'editor' ) ) { |
||||||
103 | $user = $this->addGroup( $context, $user, 'editor' ); |
||||||
104 | } |
||||||
105 | |||||||
106 | if( $this->option( 'api' ) ) { |
||||||
107 | $user = $this->addGroup( $context, $user, 'api' ); |
||||||
108 | } |
||||||
109 | |||||||
110 | return $user; |
||||||
111 | } |
||||||
112 | |||||||
113 | |||||||
114 | /** |
||||||
115 | * Adds the group to the given user |
||||||
116 | * |
||||||
117 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||||||
118 | * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object |
||||||
119 | * @param string $group Unique customer group code |
||||||
120 | */ |
||||||
121 | protected function addGroup( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user, |
||||||
122 | string $group ) : \Aimeos\MShop\Customer\Item\Iface |
||||||
123 | { |
||||||
124 | $msg = 'Add "%1$s" group to user "%2$s" for site "%3$s"'; |
||||||
125 | $this->info( sprintf( $msg, $group, $user->getCode(), $this->argument( 'site' ) ) ); |
||||||
126 | |||||||
127 | $groupId = $this->getGroupItem( $context, $group )->getId(); |
||||||
128 | return $user->setGroups( array_merge( $user->getGroups(), [$groupId] ) ); |
||||||
129 | } |
||||||
130 | |||||||
131 | |||||||
132 | /** |
||||||
133 | * Returns the customer group item for the given code |
||||||
134 | * |
||||||
135 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||||||
136 | * @param string $code Unique customer group code |
||||||
137 | * @return \Aimeos\MShop\Customer\Item\Group\Iface Aimeos customer group item object |
||||||
138 | */ |
||||||
139 | protected function getGroupItem( \Aimeos\MShop\Context\Item\Iface $context, string $code ) : \Aimeos\MShop\Customer\Item\Group\Iface |
||||||
140 | { |
||||||
141 | $manager = \Aimeos\MShop::create( $context, 'customer/group' ); |
||||||
142 | |||||||
143 | try |
||||||
144 | { |
||||||
145 | $item = $manager->findItem( $code ); |
||||||
146 | } |
||||||
147 | catch( \Aimeos\MShop\Exception $e ) |
||||||
148 | { |
||||||
149 | $item = $manager->createItem(); |
||||||
150 | $item->setLabel( $code ); |
||||||
151 | $item->setCode( $code ); |
||||||
152 | |||||||
153 | $manager->saveItem( $item ); |
||||||
154 | } |
||||||
155 | |||||||
156 | return $item; |
||||||
157 | } |
||||||
158 | } |
||||||
159 |