1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Opensoft\RolloutBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Opensoft\RolloutBundle\Rollout\GroupDefinitionAwareRollout; |
6
|
|
|
use Opensoft\RolloutBundle\Rollout\UserProviderInterface; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Richard Fullmer <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class DefaultController extends Controller |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var GroupDefinitionAwareRollout |
19
|
|
|
*/ |
20
|
|
|
private $rollout; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var UserProviderInterface |
24
|
|
|
*/ |
25
|
|
|
private $userProvider; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param GroupDefinitionAwareRollout $rollout |
29
|
|
|
* @param UserProviderInterface $userProvider |
30
|
|
|
*/ |
31
|
|
|
public function __construct(GroupDefinitionAwareRollout $rollout, UserProviderInterface $userProvider) |
32
|
|
|
{ |
33
|
|
|
$this->rollout = $rollout; |
34
|
|
|
$this->userProvider = $userProvider; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return Response |
39
|
|
|
*/ |
40
|
|
|
public function indexAction() |
41
|
|
|
{ |
42
|
|
|
return $this->render('OpensoftRolloutBundle:Default:index.html.twig', array('rollout' => $this->rollout)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $feature |
47
|
|
|
* |
48
|
|
|
* @return RedirectResponse |
49
|
|
|
*/ |
50
|
|
|
public function activateAction($feature) |
51
|
|
|
{ |
52
|
|
|
$this->rollout->activate($feature); |
53
|
|
|
|
54
|
|
|
$this->addFlash('success', sprintf("Feature '%s' is now globally activated", $feature)); |
55
|
|
|
|
56
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $feature |
61
|
|
|
* |
62
|
|
|
* @return RedirectResponse |
63
|
|
|
*/ |
64
|
|
|
public function deactivateAction($feature) |
65
|
|
|
{ |
66
|
|
|
$this->rollout->deactivate($feature); |
67
|
|
|
|
68
|
|
|
$this->addFlash('danger', sprintf("Feature '%s' is now globally deactivated", $feature)); |
69
|
|
|
|
70
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $feature |
75
|
|
|
* |
76
|
|
|
* @return RedirectResponse |
77
|
|
|
*/ |
78
|
|
|
public function incrementPercentageAction($feature) |
79
|
|
|
{ |
80
|
|
|
return $this->changePercentage($feature, 10); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $feature |
85
|
|
|
* |
86
|
|
|
* @return RedirectResponse |
87
|
|
|
*/ |
88
|
|
|
public function decrementPercentageAction($feature) |
89
|
|
|
{ |
90
|
|
|
return $this->changePercentage($feature, -10); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $feature |
95
|
|
|
* @param string $group |
96
|
|
|
* |
97
|
|
|
* @return RedirectResponse |
98
|
|
|
*/ |
99
|
|
|
public function activateGroupAction($feature, $group) |
100
|
|
|
{ |
101
|
|
|
$this->rollout->activateGroup($feature, $group); |
102
|
|
|
|
103
|
|
|
$this->addFlash('info', sprintf("Feature '%s' is now active in group '%s'", $feature, $group)); |
104
|
|
|
|
105
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string $feature |
110
|
|
|
* @param string $group |
111
|
|
|
* |
112
|
|
|
* @return RedirectResponse |
113
|
|
|
*/ |
114
|
|
|
public function deactivateGroupAction($feature, $group) |
115
|
|
|
{ |
116
|
|
|
$this->rollout->deactivateGroup($feature, $group); |
117
|
|
|
|
118
|
|
|
$this->addFlash('info', sprintf("Feature '%s' is no longer active in group '%s'", $feature, $group)); |
119
|
|
|
|
120
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param Request $request |
125
|
|
|
* @param string $feature |
126
|
|
|
* |
127
|
|
|
* @return RedirectResponse |
128
|
|
|
*/ |
129
|
|
View Code Duplication |
public function activateUserAction(Request $request, $feature) |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$requestUser = $request->get('user'); |
132
|
|
|
$user = $this->userProvider->findByRolloutIdentifier($requestUser); |
133
|
|
|
|
134
|
|
|
if ($user) { |
135
|
|
|
$this->rollout->activateUser($feature, $user); |
136
|
|
|
|
137
|
|
|
$this->addFlash( |
138
|
|
|
'info', |
139
|
|
|
sprintf( |
140
|
|
|
"User '%s' was activated in feature '%s'", |
141
|
|
|
$user->getRolloutIdentifier(), |
142
|
|
|
$feature |
143
|
|
|
) |
144
|
|
|
); |
145
|
|
|
} else { |
146
|
|
|
$this->addFlash('danger', sprintf("User '%s' not found", $requestUser)); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param string $feature |
154
|
|
|
* @param string $id |
155
|
|
|
* |
156
|
|
|
* @return RedirectResponse |
157
|
|
|
*/ |
158
|
|
View Code Duplication |
public function deactivateUserAction($feature, $id) |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
$user = $this->userProvider->findByRolloutIdentifier($id); |
161
|
|
|
|
162
|
|
|
if ($user) { |
163
|
|
|
$this->rollout->deactivateUser($feature, $user); |
164
|
|
|
|
165
|
|
|
$this->addFlash( |
166
|
|
|
'info', |
167
|
|
|
sprintf( |
168
|
|
|
"User '%s' was deactivated from feature '%s'", |
169
|
|
|
$user->getRolloutIdentifier(), |
170
|
|
|
$feature |
171
|
|
|
) |
172
|
|
|
); |
173
|
|
|
} else { |
174
|
|
|
$this->addFlash('danger', sprintf("User '%s' not found", $id)); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $feature |
182
|
|
|
* |
183
|
|
|
* @return RedirectResponse |
184
|
|
|
*/ |
185
|
|
|
public function removeAction($feature) |
186
|
|
|
{ |
187
|
|
|
$this->rollout->remove($feature); |
188
|
|
|
|
189
|
|
|
$this->addFlash('info', sprintf("Feature '%s' was removed from rollout.", $feature)); |
190
|
|
|
|
191
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param Request $request |
196
|
|
|
* @param string $feature |
197
|
|
|
* |
198
|
|
|
* @return RedirectResponse |
199
|
|
|
*/ |
200
|
|
|
public function setRequestParamAction(Request $request, $feature) |
201
|
|
|
{ |
202
|
|
|
$requestParam = $request->get('requestParam'); |
203
|
|
|
|
204
|
|
|
if ($requestParam === null) { |
205
|
|
|
$this->addFlash('danger', 'Missing "requestParam" value'); |
206
|
|
|
|
207
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
$this->rollout->activateRequestParam($feature, $requestParam); |
211
|
|
|
|
212
|
|
|
$this->addFlash('info', sprintf('Feature "%s" requestParam changed to "%s"', $feature, $requestParam)); |
213
|
|
|
|
214
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Abstract out common functionality |
219
|
|
|
* |
220
|
|
|
* @param string $feature |
221
|
|
|
* @param int $increment |
222
|
|
|
* |
223
|
|
|
* @return RedirectResponse |
224
|
|
|
*/ |
225
|
|
|
private function changePercentage($feature, $increment) |
226
|
|
|
{ |
227
|
|
|
$percentage = $this->rollout->get($feature)->getPercentage() + $increment; |
228
|
|
|
$this->rollout->activatePercentage($feature, $percentage); |
229
|
|
|
|
230
|
|
|
$this->addFlash('info', sprintf("Feature '%s' percentage changed to %d%% of all users", $feature, $percentage)); |
231
|
|
|
|
232
|
|
|
return $this->redirectToRoute('opensoft_rollout'); |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.