예제 #1
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]);
 }