1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.ec-cube.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Controller\Admin\Customer; |
15
|
|
|
|
16
|
|
|
use Eccube\Controller\AbstractController; |
17
|
|
|
use Eccube\Entity\Master\CustomerStatus; |
18
|
|
|
use Eccube\Event\EccubeEvents; |
19
|
|
|
use Eccube\Event\EventArgs; |
20
|
|
|
use Eccube\Form\Type\Admin\CustomerType; |
21
|
|
|
use Eccube\Repository\CustomerRepository; |
22
|
|
|
use Eccube\Util\StringUtil; |
23
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
24
|
|
|
use Symfony\Component\HttpFoundation\Request; |
25
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
26
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
27
|
|
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; |
28
|
|
|
|
29
|
|
|
class CustomerEditController extends AbstractController |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var CustomerRepository |
33
|
|
|
*/ |
34
|
|
|
protected $customerRepository; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var EncoderFactoryInterface |
38
|
|
|
*/ |
39
|
7 |
|
protected $encoderFactory; |
40
|
|
|
|
41
|
|
|
public function __construct( |
42
|
|
|
CustomerRepository $customerRepository, |
43
|
7 |
|
EncoderFactoryInterface $encoderFactory |
44
|
7 |
|
) { |
45
|
|
|
$this->customerRepository = $customerRepository; |
46
|
|
|
$this->encoderFactory = $encoderFactory; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @Route("/%eccube_admin_route%/customer/new", name="admin_customer_new") |
51
|
|
|
* @Route("/%eccube_admin_route%/customer/{id}/edit", requirements={"id" = "\d+"}, name="admin_customer_edit") |
52
|
7 |
|
* @Template("@admin/Customer/edit.twig") |
53
|
|
|
*/ |
54
|
7 |
|
public function index(Request $request, $id = null) |
55
|
|
|
{ |
56
|
7 |
|
$this->entityManager->getFilters()->enable('incomplete_order_status_hidden'); |
57
|
5 |
|
// 編集 |
58
|
5 |
|
if ($id) { |
59
|
|
|
$Customer = $this->customerRepository |
60
|
5 |
|
->find($id); |
61
|
|
|
|
62
|
|
|
if (is_null($Customer)) { |
63
|
|
|
throw new NotFoundHttpException(); |
64
|
5 |
|
} |
65
|
5 |
|
|
66
|
|
|
$oldStatusId = $Customer->getStatus()->getId(); |
67
|
|
|
// 編集用にデフォルトパスワードをセット |
68
|
2 |
|
$previous_password = $Customer->getPassword(); |
69
|
2 |
|
$Customer->setPassword($this->eccubeConfig['eccube_default_password']); |
70
|
2 |
|
// 新規登録 |
71
|
|
|
} else { |
72
|
|
|
$Customer = $this->customerRepository->newCustomer(); |
73
|
|
|
|
74
|
7 |
|
$oldStatusId = null; |
75
|
7 |
|
} |
76
|
|
|
|
77
|
7 |
|
// 会員登録フォーム |
78
|
|
|
$builder = $this->formFactory |
79
|
7 |
|
->createBuilder(CustomerType::class, $Customer); |
80
|
7 |
|
|
81
|
|
|
$event = new EventArgs( |
82
|
7 |
|
[ |
83
|
|
|
'builder' => $builder, |
84
|
7 |
|
'Customer' => $Customer, |
85
|
|
|
], |
86
|
7 |
|
$request |
87
|
|
|
); |
88
|
7 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_INITIALIZE, $event); |
89
|
|
|
|
90
|
7 |
|
$form = $builder->getForm(); |
91
|
2 |
|
|
92
|
2 |
|
$form->handleRequest($request); |
93
|
|
|
|
94
|
2 |
|
if ($form->isSubmitted() && $form->isValid()) { |
95
|
|
|
log_info('会員登録開始', [$Customer->getId()]); |
96
|
2 |
|
|
97
|
|
|
$encoder = $this->encoderFactory->getEncoder($Customer); |
98
|
|
|
|
99
|
2 |
View Code Duplication |
if ($Customer->getPassword() === $this->eccubeConfig['eccube_default_password']) { |
100
|
1 |
|
$Customer->setPassword($previous_password); |
|
|
|
|
101
|
1 |
|
} else { |
102
|
|
|
if ($Customer->getSalt() === null) { |
103
|
2 |
|
$Customer->setSalt($encoder->createSalt()); |
104
|
|
|
$Customer->setSecretKey($this->customerRepository->getUniqueSecretKey()); |
105
|
|
|
} |
106
|
2 |
|
$Customer->setPassword($encoder->encodePassword($Customer->getPassword(), $Customer->getSalt())); |
107
|
2 |
|
} |
108
|
|
|
|
109
|
2 |
|
// 退会ステータスに更新の場合、ダミーのアドレスに更新 |
110
|
|
|
$newStatusId = $Customer->getStatus()->getId(); |
111
|
2 |
|
if ($oldStatusId != $newStatusId && $newStatusId == CustomerStatus::WITHDRAWING) { |
112
|
|
|
$Customer->setEmail(StringUtil::random(60).'@dummy.dummy'); |
113
|
2 |
|
} |
114
|
2 |
|
|
115
|
|
|
$this->entityManager->persist($Customer); |
116
|
2 |
|
$this->entityManager->flush(); |
117
|
|
|
|
118
|
2 |
|
log_info('会員登録完了', [$Customer->getId()]); |
119
|
|
|
|
120
|
2 |
|
$event = new EventArgs( |
121
|
|
|
[ |
122
|
2 |
|
'form' => $form, |
123
|
2 |
|
'Customer' => $Customer, |
124
|
|
|
], |
125
|
|
|
$request |
126
|
|
|
); |
127
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_COMPLETE, $event); |
128
|
|
|
|
129
|
|
|
$this->addSuccess('admin.common.save_complete', 'admin'); |
130
|
|
|
|
131
|
5 |
|
return $this->redirectToRoute('admin_customer_edit', [ |
132
|
5 |
|
'id' => $Customer->getId(), |
133
|
|
|
]); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return [ |
137
|
|
|
'form' => $form->createView(), |
138
|
|
|
'Customer' => $Customer, |
139
|
|
|
]; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: