Ejemplo n.º 1
0
 /**
  * @return string
  */
 protected function updateProviders()
 {
     $providersJsonPath = $this->app->config('json_path') . '/' . '/providers.json';
     if (file_exists($providersJsonPath)) {
         $providers = json_decode(file_get_contents($providersJsonPath), true);
     } else {
         $providers = [];
     }
     $providers['providers'][$this->extension->getName()] = $this->sha;
     $json = json_encode($providers);
     file_put_contents($providersJsonPath, $json);
     return hash('sha256', $json);
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 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]);
 }
Ejemplo n.º 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);
 }