3
3
namespace ZfModule \Controller ;
4
4
5
5
use Application \Service \RepositoryRetriever ;
6
- use EdpGithub \Collection \RepositoryCollection ;
7
- use Zend \Http ;
8
6
use Zend \Mvc \Controller \AbstractActionController ;
9
7
use Zend \View \Model \ViewModel ;
10
8
use ZfModule \Mapper ;
11
- use ZfModule \Service ;
12
9
13
10
class IndexController extends AbstractActionController
14
11
{
@@ -17,28 +14,20 @@ class IndexController extends AbstractActionController
17
14
*/
18
15
private $ moduleMapper ;
19
16
20
- /**
21
- * @var Service\Module
22
- */
23
- private $ moduleService ;
24
-
25
17
/**
26
18
* @var RepositoryRetriever
27
19
*/
28
20
private $ repositoryRetriever ;
29
21
30
22
/**
31
23
* @param Mapper\Module $moduleMapper
32
- * @param Service\Module $moduleService
33
24
* @param RepositoryRetriever $repositoryRetriever
34
25
*/
35
26
public function __construct (
36
27
Mapper \Module $ moduleMapper ,
37
- Service \Module $ moduleService ,
38
28
RepositoryRetriever $ repositoryRetriever
39
29
) {
40
30
$ this ->moduleMapper = $ moduleMapper ;
41
- $ this ->moduleService = $ moduleService ;
42
31
$ this ->repositoryRetriever = $ repositoryRetriever ;
43
32
}
44
33
@@ -74,170 +63,4 @@ public function viewAction()
74
63
75
64
return $ viewModel ;
76
65
}
77
-
78
- public function indexAction ()
79
- {
80
- if (!$ this ->zfcUserAuthentication ()->hasIdentity ()) {
81
- return $ this ->redirect ()->toRoute ('zfcuser/login ' );
82
- }
83
-
84
- $ params = [
85
- 'type ' => 'all ' ,
86
- 'per_page ' => 100 ,
87
- 'sort ' => 'updated ' ,
88
- 'direction ' => 'desc ' ,
89
- ];
90
-
91
- $ repos = $ this ->repositoryRetriever ->getAuthenticatedUserRepositories ($ params );
92
- $ repositories = $ this ->fetchModules ($ repos );
93
-
94
- $ viewModel = new ViewModel (['repositories ' => $ repositories ]);
95
- $ viewModel ->setTerminal (true );
96
-
97
- return $ viewModel ;
98
- }
99
-
100
- public function organizationAction ()
101
- {
102
- if (!$ this ->zfcUserAuthentication ()->hasIdentity ()) {
103
- return $ this ->redirect ()->toRoute ('zfcuser/login ' );
104
- }
105
-
106
- $ owner = $ this ->params ()->fromRoute ('owner ' , null );
107
- $ params = [
108
- 'per_page ' => 100 ,
109
- 'sort ' => 'updated ' ,
110
- 'direction ' => 'desc ' ,
111
- ];
112
-
113
- $ repos = $ this ->repositoryRetriever ->getUserRepositories ($ owner , $ params );
114
- $ repositories = $ this ->fetchModules ($ repos );
115
-
116
- $ viewModel = new ViewModel (['repositories ' => $ repositories ]);
117
- $ viewModel ->setTerminal (true );
118
- $ viewModel ->setTemplate ('zf-module/index/index.phtml ' );
119
-
120
- return $ viewModel ;
121
- }
122
-
123
- /**
124
- * @param RepositoryCollection $repos
125
- * @return array
126
- */
127
- private function fetchModules (RepositoryCollection $ repos )
128
- {
129
- $ repositories = [];
130
-
131
- foreach ($ repos as $ repo ) {
132
- $ isModule = $ this ->moduleService ->isModule ($ repo );
133
- if (!$ repo ->fork && $ repo ->permissions ->push && $ isModule && !$ this ->moduleMapper ->findByName ($ repo ->name )) {
134
- $ repositories [] = $ repo ;
135
- }
136
- }
137
-
138
- return $ repositories ;
139
- }
140
-
141
- /**
142
- * This function is used to submit a module from the site
143
- * @throws Exception\UnexpectedValueException
144
- * @return
145
- **/
146
- public function addAction ()
147
- {
148
- if (!$ this ->zfcUserAuthentication ()->hasIdentity ()) {
149
- return $ this ->redirect ()->toRoute ('zfcuser/login ' );
150
- }
151
-
152
- $ request = $ this ->getRequest ();
153
- if ($ request ->isPost ()) {
154
- $ repo = $ request ->getPost ()->get ('repo ' );
155
- $ owner = $ request ->getPost ()->get ('owner ' );
156
-
157
- $ repository = $ this ->repositoryRetriever ->getUserRepositoryMetadata ($ owner , $ repo );
158
-
159
- if (!($ repository instanceof \stdClass)) {
160
- throw new Exception \RuntimeException (
161
- 'Not able to fetch the repository from github due to an unknown error. ' ,
162
- Http \Response::STATUS_CODE_500
163
- );
164
- }
165
-
166
- if (!$ repository ->fork && $ repository ->permissions ->push ) {
167
- if ($ this ->moduleService ->isModule ($ repository )) {
168
- $ module = $ this ->moduleService ->register ($ repository );
169
- $ this ->flashMessenger ()->addMessage ($ module ->getName () . ' has been added to ZF Modules ' );
170
- } else {
171
- throw new Exception \UnexpectedValueException (
172
- $ repository ->name . ' is not a Zend Framework Module ' ,
173
- Http \Response::STATUS_CODE_403
174
- );
175
- }
176
- } else {
177
- throw new Exception \UnexpectedValueException (
178
- 'You have no permission to add this module. The reason might be that you are ' .
179
- 'neither the owner nor a collaborator of this repository. ' ,
180
- Http \Response::STATUS_CODE_403
181
- );
182
- }
183
- } else {
184
- throw new Exception \UnexpectedValueException (
185
- 'Something went wrong with the post values of the request... '
186
- );
187
- }
188
-
189
- return $ this ->redirect ()->toRoute ('zfcuser ' );
190
- }
191
-
192
- /**
193
- * This function is used to remove a module from the site
194
- * @throws Exception\UnexpectedValueException
195
- * @return
196
- **/
197
- public function removeAction ()
198
- {
199
- if (!$ this ->zfcUserAuthentication ()->hasIdentity ()) {
200
- return $ this ->redirect ()->toRoute ('zfcuser/login ' );
201
- }
202
-
203
- $ request = $ this ->getRequest ();
204
- if ($ request ->isPost ()) {
205
- $ repo = $ request ->getPost ()->get ('repo ' );
206
- $ owner = $ request ->getPost ()->get ('owner ' );
207
-
208
- $ repository = $ this ->repositoryRetriever ->getUserRepositoryMetadata ($ owner , $ repo );
209
-
210
- if (!$ repository instanceof \stdClass) {
211
- throw new Exception \RuntimeException (
212
- 'Not able to fetch the repository from github due to an unknown error. ' ,
213
- Http \Response::STATUS_CODE_500
214
- );
215
- }
216
-
217
- if (!$ repository ->fork && $ repository ->permissions ->push ) {
218
- $ module = $ this ->moduleMapper ->findByUrl ($ repository ->html_url );
219
- if ($ module instanceof \ZfModule \Entity \Module) {
220
- $ this ->moduleMapper ->delete ($ module );
221
- $ this ->flashMessenger ()->addMessage ($ repository ->name . ' has been removed from ZF Modules ' );
222
- } else {
223
- throw new Exception \UnexpectedValueException (
224
- $ repository ->name . ' was not found ' ,
225
- Http \Response::STATUS_CODE_403
226
- );
227
- }
228
- } else {
229
- throw new Exception \UnexpectedValueException (
230
- 'You have no permission to add this module. The reason might be that you are ' .
231
- 'neither the owner nor a collaborator of this repository. ' ,
232
- Http \Response::STATUS_CODE_403
233
- );
234
- }
235
- } else {
236
- throw new Exception \UnexpectedValueException (
237
- 'Something went wrong with the post values of the request... '
238
- );
239
- }
240
-
241
- return $ this ->redirect ()->toRoute ('zfcuser ' );
242
- }
243
66
}
0 commit comments