/** * Removes a Module * * @return Http\Response * @throws Exception\InvalidDataException * @throws Exception\RepositoryException */ public function removeAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('zfcuser/login'); } $request = $this->getRequest(); if (!$request->isPost()) { throw Exception\InvalidDataException::fromInvalidRequest('Something went wrong with the post values of the request...', $request); } $postParams = $request->getPost(); $repo = $postParams->get('repo'); $owner = $postParams->get('owner'); $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo); if (!$repository instanceof \stdClass) { throw Exception\RepositoryException::fromNotFoundRepository('Not able to fetch the repository from GitHub due to an unknown error.', $owner, $repo); } if ($repository->fork || !$repository->permissions->push) { throw Exception\RepositoryException::fromInsufficientPermissions('You have no permission to remove this module. The reason might be that you are neither the owner nor a collaborator of this repository.', $repository->full_name, ['pushAccess', 'noFork']); } $module = $this->moduleMapper->findByUrl($repository->html_url); if (!$module) { throw Exception\RepositoryException::fromNotFoundRepositoryUrl($repository->name . ' was not found', $repository->html_url); } $this->moduleMapper->delete($module); $this->flashMessenger()->addSuccessMessage($repository->name . ' has been removed from ZF Modules'); return $this->redirect()->toRoute('zfcuser'); }
/** * @return stdClass[] */ public function currentUserModules() { /* @var RepositoryCollection $repositoryCollection */ $repositoryCollection = $this->githubClient->api('current_user')->repos(['type' => 'all', 'per_page' => 100]); return array_filter(iterator_to_array($repositoryCollection), function ($repository) { if (true === $repository->fork) { return false; } if (false === $repository->permissions->push) { return false; } if (!$this->moduleMapper->findByUrl($repository->html_url)) { return false; } return true; }); }