Skip to content

Commit b42bec6

Browse files
committed
Remove old routes and controller actions for syncing repositories
1 parent 4cd2096 commit b42bec6

File tree

3 files changed

+0
-226
lines changed

3 files changed

+0
-226
lines changed

module/ZfModule/config/module.config.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,6 @@
2424
],
2525
],
2626
],
27-
'zf-module' => [
28-
'type' => 'Segment',
29-
'options' => [
30-
'route' => '/module',
31-
'defaults' => [
32-
'controller' => Controller\IndexController::class,
33-
'action' => 'index',
34-
],
35-
],
36-
'may_terminate' => true,
37-
'child_routes' => [
38-
'list' => [
39-
'type' => 'Segment',
40-
'options' => [
41-
'route' => '/list[/:owner]',
42-
'constrains' => [
43-
'owner' => '[a-zA-Z][a-zA-Z0-9_-]*',
44-
],
45-
'defaults' => [
46-
'action' => 'organization',
47-
],
48-
],
49-
],
50-
'add' => [
51-
'type' => 'Literal',
52-
'options' => [
53-
'route' => '/add',
54-
'defaults' => [
55-
'action' => 'add',
56-
],
57-
],
58-
],
59-
'remove' => [
60-
'type' => 'Literal',
61-
'options' => [
62-
'route' => '/remove',
63-
'defaults' => [
64-
'action' => 'remove',
65-
],
66-
],
67-
],
68-
],
69-
],
7027
],
7128
],
7229
'view_manager' => [

module/ZfModule/src/ZfModule/Controller/IndexController.php

Lines changed: 0 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
namespace ZfModule\Controller;
44

55
use Application\Service\RepositoryRetriever;
6-
use EdpGithub\Collection\RepositoryCollection;
7-
use Zend\Http;
86
use Zend\Mvc\Controller\AbstractActionController;
97
use Zend\View\Model\ViewModel;
108
use ZfModule\Mapper;
11-
use ZfModule\Service;
129

1310
class IndexController extends AbstractActionController
1411
{
@@ -17,28 +14,20 @@ class IndexController extends AbstractActionController
1714
*/
1815
private $moduleMapper;
1916

20-
/**
21-
* @var Service\Module
22-
*/
23-
private $moduleService;
24-
2517
/**
2618
* @var RepositoryRetriever
2719
*/
2820
private $repositoryRetriever;
2921

3022
/**
3123
* @param Mapper\Module $moduleMapper
32-
* @param Service\Module $moduleService
3324
* @param RepositoryRetriever $repositoryRetriever
3425
*/
3526
public function __construct(
3627
Mapper\Module $moduleMapper,
37-
Service\Module $moduleService,
3828
RepositoryRetriever $repositoryRetriever
3929
) {
4030
$this->moduleMapper = $moduleMapper;
41-
$this->moduleService = $moduleService;
4231
$this->repositoryRetriever = $repositoryRetriever;
4332
}
4433

@@ -74,170 +63,4 @@ public function viewAction()
7463

7564
return $viewModel;
7665
}
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-
}
24366
}

module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
namespace ZfModule\Controller;
44

55
use Application\Service\RepositoryRetriever;
6-
use Zend\Mvc\Controller\ControllerManager;
76
use Zend\ServiceManager\FactoryInterface;
87
use Zend\ServiceManager\ServiceLocatorInterface;
98
use ZfModule\Mapper;
10-
use ZfModule\Service;
119

1210
class IndexControllerFactory implements FactoryInterface
1311
{
@@ -23,15 +21,11 @@ public function createService(ServiceLocatorInterface $controllerManager)
2321
/* @var Mapper\Module $moduleMapper */
2422
$moduleMapper = $serviceManager->get('zfmodule_mapper_module');
2523

26-
/* @var Service\Module $moduleService */
27-
$moduleService = $serviceManager->get('zfmodule_service_module');
28-
2924
/* @var RepositoryRetriever $repositoryRetriever */
3025
$repositoryRetriever = $serviceManager->get(RepositoryRetriever::class);
3126

3227
return new IndexController(
3328
$moduleMapper,
34-
$moduleService,
3529
$repositoryRetriever
3630
);
3731
}

0 commit comments

Comments
 (0)