Пример #1
0
 /**
  * @return
  */
 public function update()
 {
     $extensionRepository = $this->app->container->get('extension.repository');
     $vendorDir = $this->app->config('json_path') . '/' . $this->extension->getVendor();
     if (!is_dir($vendorDir)) {
         mkdir($vendorDir);
     }
     $jsonPackage = $this->extension->serialize();
     $repositoryName = $this->extension->getPackageName();
     $this->sha = hash('sha256', $jsonPackage);
     $jsonPathSha = $vendorDir . '/' . $repositoryName . '$' . $this->sha . '.json';
     file_put_contents($jsonPathSha, $jsonPackage);
     $linkPath = $vendorDir . '/' . $repositoryName . '.json';
     if (file_exists($linkPath)) {
         $targetPath = readlink($linkPath);
         unlink($linkPath);
     }
     symlink($jsonPathSha, $vendorDir . '/' . $repositoryName . '.json');
     $shaProviders = $this->updateProviders();
     $this->updateRootPackageJson($shaProviders);
 }
Пример #2
0
 /**
  * @var Extension
  * @var bool
  */
 public function indexExtension(Extension $extension, $update = false)
 {
     $id = $extension->getName();
     $packageDocument = new \Elastica\Document($id, ['id' => $id, 'name' => $id, 'description' => $extension->getDescription(), 'tags' => $extension->getVersions(), 'keywords' => $extension->getKeywords(), 'stars' => $extension->getStars()]);
     $elasticaIndex = $this->client->getIndex('packages');
     $elasticaType = $elasticaIndex->getType('packages');
     if ($update) {
         $elasticaType->updateDocument($packageDocument);
     } else {
         $elasticaType->addDocument($packageDocument);
     }
     $elasticaType->getIndex()->refresh();
 }
Пример #3
0
 /**
  * @return array|null
  */
 public function getAll()
 {
     $extensionsSerialize = $this->redisClient->hgetall(self::EXTENSION_HASH_STORE);
     if (!$extensionsSerialize) {
         return;
     }
     $result = [];
     foreach ($extensionsSerialize as $serialized) {
         $extension = new Extension();
         $extension->unserialize($serialized);
         $meta = json_decode($this->redisClient->hget(self::EXTENSIONMETA_HASH_STORE, $extension->getName()), true);
         $extension->setWatchers($meta['watchers']);
         $extension->setStars($meta['stars']);
         $result[$extension->getName()] = $extension;
     }
     return $result;
 }
Пример #4
0
 /**
  * POST /package/register.
  */
 public function registerPackageAction()
 {
     $token = $_SESSION['github.token'];
     $repo = $this->app->request()->post('repository');
     $log = new BufferIO();
     try {
         $driver = new \PickleWeb\Repository\Github($repo, $token, $this->app->config('cache_dir'), $log);
         if ($driver->getOwnerId() != $this->app->user()->getGithubId()) {
             $this->app->flash('error', 'You are not the owner of this repository. Please request the owner to register.');
             $this->app->redirect('/package/register?repository=' . $repo);
         }
         $extension = new \PickleWeb\Entity\Extension();
         $extension->setFromRepository($driver, $log);
         $redis = $this->app->container->get('redis.client');
         $extensionRepository = $this->app->container->get('extension.repository');
         if ($extensionRepository->find($extension->getName())) {
             $this->app->flash('error', $extension->getName() . ' is already registred');
             $this->app->redirect('/package/register?repository=' . $repo);
             return;
         }
         $extension->setStars($driver->getStars());
         $extension->setWatchers($driver->getWatchers());
         $vendorName = $extension->getVendor();
         $repository = $extension->getPackageName();
         $extensionMeta = ['watchers' => $extension->getStars(), 'stars' => $extension->getWatchers()];
     } catch (\RuntimeException $exception) {
         /* todo: handle bad data in a better way =) */
         $this->app->flash('error', 'An error occurred while retrieving extension data. Please veriry your tag and try again later.' . $exception->getMessage());
         $this->app->redirect('/package/register?repository=' . $repo);
     }
     $serializedExtension = $extension->serialize();
     $transaction = hash('sha256', $serializedExtension);
     file_put_contents($this->app->config('cache_dir') . '/' . $transaction . '.json', $serializedExtension);
     $serializedMeta = json_encode($extensionMeta);
     file_put_contents($this->app->config('cache_dir') . '/' . $transaction . '_meta.json', $serializedMeta);
     $latest = $extension->getPackages()['dev-master'];
     $this->app->render('extension/confirm.html', ['log' => $log->getOutput(), 'transaction' => $transaction, 'latest' => $latest, 'tags' => $extension->getPackages(), 'vcs' => $repo]);
 }
Пример #5
0
 /**
  * GET /package/register.
  */
 public function registerAction()
 {
     if (!$this->app->request()->get('confirm')) {
         $this->app->render('extension/register.html', ['repository' => $this->app->request()->get('repository')]);
         return;
     }
     $transaction = $this->app->request()->get('id');
     $pathTransaction = $this->app->config('cache_dir') . '/' . $transaction . '.json';
     $pathMetaTransaction = $this->app->config('cache_dir') . '/' . $transaction . '_meta.json';
     if (!file_exists($pathTransaction)) {
         $this->app->flash('error', 'No active registration process');
         $this->app->redirect('/package/register');
         exit;
     }
     $serializeExtension = file_get_contents($pathTransaction);
     unlink($pathTransaction);
     $extension = new Extension();
     $extension->unserialize($serializeExtension);
     $serializeExtensionMeta = file_get_contents($pathMetaTransaction);
     unlink($pathMetaTransaction);
     $extensionMeta = json_decode($serializeExtensionMeta, true);
     $extension->setWatchers($extensionMeta['watchers']);
     $extension->setStars($extensionMeta['stars']);
     $packageName = $extension->getName();
     $vendorName = $extension->getVendor();
     $pathTransactionLog = $transaction . 'log';
     if (file_exists($pathTransactionLog)) {
         unlink($pathTransactionLog);
     }
     $user = $this->app->user();
     $user->addExtension($packageName);
     $userRepository = $this->app->container->get('user.repository');
     $userRepository->persist($user);
     $redis = $this->app->container->get('redis.client');
     $extensionRepository = $this->app->container->get('extension.repository');
     $extensionRepository->persist($extension, $user);
     $rest = new Rest($extension, $this->app);
     $rest->update();
     $es = $this->app->container->get('elastica.client');
     $indexer = new Indexer($es);
     $indexer->indexExtension($extension);
     $this->app->flash('warning', $packageName . ' has been registred');
     $this->app->redirect('/package/' . $packageName);
 }
Пример #6
0
 /**
  * @param string $username
  *
  * Hook for github hooks. Only release and tag are supported.
  */
 public function hookAction($vendor, $repository)
 {
     $this->validPayload($vendor, $repository);
     $payloadPost = $this->app->request->getBody();
     $payload = json_decode($payloadPost);
     if (!$payload) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'invalid Payload'], 200);
         return;
     }
     $hubEvent = $this->app->request()->headers()->get('X-GitHub-Event');
     if ($hubEvent == 'ping') {
         $this->app->jsonResponse(['status' => 'ping', 'message' => 'hook setup'], 200);
         return;
     }
     if (!($hubEvent == 'create' || $hubEvent == 'delete')) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'operation not supported'], 400);
         return;
     }
     if (!($payload->ref_type == 'tag' || $payload->ref_type == 'release')) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'Only tag/release hooks are supported', 1], 200);
         return;
     }
     $extensionName = $payload->repository->full_name;
     $tag = $payload->ref;
     $repository = $payload->repository->git_url;
     $time = $payload->repository->pushed_at;
     $ownerId = $payload->repository->owner->id;
     $userRepository = $this->app->container->get('user.repository');
     $this->user = $userRepository->findByProviderId('github', $ownerId);
     if (!$this->user) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'Owner Id not found'], 401);
         return;
     }
     $versionParser = new VersionParser();
     try {
         $normalizedVersion = $versionParser->normalize($tag);
     } catch (\Exception $e) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'Invalid tag <' . $tag . '>'], 400);
         return;
     }
     if (!$normalizedVersion) {
         $this->app->jsonResponse(['status' => 'error', 'message' => 'This tag does not look like a release tag'], 200);
         return;
     }
     if (!$this->findRegisteredExension($extensionName)) {
         return;
     }
     $log = new BufferIO();
     try {
         $driver = new \PickleWeb\Repository\Github($repository, false, $this->app->config('cache_dir'), $log);
         $extension = new Extension();
         $extension->setFromRepository($driver, $log);
     } catch (\Exception $e) {
         $this->app->jsonResponse(['status' => 'error', 'message' => $extensionName . '-' . $tag . ' error on import:' . $e->getMessage()], 500);
         return;
     }
     $vendorName = $extension->getVendor();
     $packageName = $extension->getPackageName();
     $stargazersCount = $payload->repository->stargazers_count;
     $watchersCount = $payload->repository->watchers_count;
     /* only to set the meta, may be cleaner to do it in there */
     $extension->setStars($stargazersCount);
     $extension->setWatchers($watchersCount);
     $json = $extension->serialize();
     if (!$json) {
         $this->app->jsonResponse(['status' => 'error', 'message' => $extensionName . '-' . $tag . ' error on import: fail to store'], 500);
         return;
     }
     $redis = $this->app->container->get('redis.client');
     $extensionRepository = $this->app->container->get('extension.repository');
     $extensionRepository->persist($extension, $this->user);
     $rest = new Rest($extension, $this->app);
     $rest->update();
     $es = $this->app->container->get('elastica.client');
     $indexer = new Indexer($es);
     $indexer->index($extension);
     $this->app->jsonResponse(['status' => 'success', 'message' => $extensionName . '-' . $tag . ' imported'], 200);
     return;
 }