Exemple #1
0
 /**
  * Build cache
  */
 protected function build()
 {
     $this->cached = $this->cache->load('cached', function (&$dependencies) {
         $dependencies[Cache::EXPIRE] = new DateTime('+1 day');
         $cached = [];
         // Addons counts
         $cached['addons'] = $this->addonRepository->findActive()->countStored();
         return $cached;
     });
 }
Exemple #2
0
 /**
  * Build cache
  */
 protected function build()
 {
     $this->data = $this->cache->load('routes', function (&$dependencies) {
         $dependencies[Cache::EXPIRE] = new DateTime('+24 h');
         $dependencies[Cache::TAGS] = ['routing', 'routes'];
         $data = ['addons' => [], 'owners' => []];
         foreach ($this->repository->findAll() as $addon) {
             $data['addons'][$addon->id] = strtolower($addon->owner . '/' . $addon->name);
             $data['owners'][strtolower($addon->owner)] = strtolower($addon->owner);
         }
         return $data;
     });
 }
Exemple #3
0
 /**
  * @return Form
  */
 protected function createComponentForm()
 {
     $form = new Form();
     $form->addText('addon', 'Addon URL')->addRule($form::REQUIRED, 'URL is required')->addRule($form::URL, 'URL is not valid')->addRule($form::PATTERN, 'Only GitHub urls are allowed', self::GITHUB_REGEX);
     $tags = $this->tagRepository->fetchPairs();
     $form->addMultiSelect('tags', 'Tags', $tags);
     $form->addSubmit('add', 'Add addon');
     $form->onSuccess[] = function (Form $form) {
         $matches = Strings::match($form->values->addon, '#' . self::GITHUB_REGEX . '#');
         if (!$matches) {
             $this->presenter->flashMessage('Invalid addon name.', 'warning');
             $this->presenter->redirect('this');
             return;
         }
         list($all, $owner, $name) = $matches;
         $addon = new Addon();
         $this->addonRepository->attach($addon);
         $addon->state = Addon::STATE_QUEUED;
         $addon->createdAt = new DateTime();
         $addon->owner = $owner;
         $addon->name = $name;
         $addon->github = new Github();
         if ($form->values->tags) {
             $addon->tags->add($form->values->tags);
         }
         try {
             $this->addonRepository->persistAndFlush($addon);
             $this->presenter->flashMessage('Addon successful added to the cron process queue. Thank you.', 'info');
         } catch (UniqueConstraintViolationException $e) {
             $this->presenter->flashMessage('There is already addon "' . ($owner . '/' . $name) . '" in our database.', 'warning');
         } catch (PDOException $e) {
             $this->presenter->flashMessage('Database error has occurred.', 'danger');
         }
         $this->presenter->redirect('this');
     };
     return $form;
 }
Exemple #4
0
 /**
  * @return ICollection|Addon[]
  */
 public function findMostPopular()
 {
     return $this->addonRepository->findOrdered('popularity')->limitBy(3);
 }
Exemple #5
0
 /**
  * @param string $tag
  * @return ICollection|Addon[]
  */
 public function findByTag($tag)
 {
     $collection = $this->addonRepository->findOrdered($this->search->by)->findBy(['this->tags->name' => $tag, 'state' => Addon::STATE_ACTIVE]);
     $collection = $this->formatLimit($collection);
     return $collection;
 }
 public function renderDefault()
 {
     $status = $this->cache->load('data', function (&$dependencies) {
         $dependencies[Cache::EXPIRE] = new DateTime('+30 minutes');
         $dependencies[Cache::TAGS] = ['status', 'status.page'];
         $status = [];
         // Build addons status ===========================================
         $status['addons']['active']['composer'] = $this->addonRepository->findBy(['state' => Addon::STATE_ACTIVE, 'type' => Addon::TYPE_COMPOSER])->countStored();
         $status['addons']['active']['bower'] = $this->addonRepository->findBy(['state' => Addon::STATE_ACTIVE, 'type' => Addon::TYPE_BOWER])->countStored();
         $status['addons']['active']['untype'] = $this->addonRepository->findBy(['state' => Addon::STATE_ACTIVE, 'type' => Addon::TYPE_UNTYPE])->countStored();
         $status['addons']['active']['unknown'] = $this->addonRepository->findBy(['state' => Addon::STATE_ACTIVE, 'type' => Addon::TYPE_UNKNOWN])->countStored();
         $status['addons']['active']['total'] = $this->addonRepository->findBy(['state' => Addon::STATE_ACTIVE])->countStored();
         $status['addons']['queued']['composer'] = $this->addonRepository->findBy(['state' => Addon::STATE_QUEUED, 'type' => Addon::TYPE_COMPOSER])->countStored();
         $status['addons']['queued']['bower'] = $this->addonRepository->findBy(['state' => Addon::STATE_QUEUED, 'type' => Addon::TYPE_BOWER])->countStored();
         $status['addons']['queued']['untype'] = $this->addonRepository->findBy(['state' => Addon::STATE_QUEUED, 'type' => Addon::TYPE_UNTYPE])->countStored();
         $status['addons']['queued']['unknown'] = $this->addonRepository->findBy(['state' => Addon::STATE_QUEUED, 'type' => Addon::TYPE_UNKNOWN])->countStored();
         $status['addons']['queued']['total'] = $this->addonRepository->findBy(['state' => Addon::STATE_QUEUED])->countStored();
         $status['addons']['archived']['composer'] = $this->addonRepository->findBy(['state' => Addon::STATE_ARCHIVED, 'type' => Addon::TYPE_COMPOSER])->countStored();
         $status['addons']['archived']['bower'] = $this->addonRepository->findBy(['state' => Addon::STATE_ARCHIVED, 'type' => Addon::TYPE_BOWER])->countStored();
         $status['addons']['archived']['untype'] = $this->addonRepository->findBy(['state' => Addon::STATE_ARCHIVED, 'type' => Addon::TYPE_UNTYPE])->countStored();
         $status['addons']['archived']['unknown'] = $this->addonRepository->findBy(['state' => Addon::STATE_ARCHIVED, 'type' => Addon::TYPE_UNKNOWN])->countStored();
         $status['addons']['archived']['total'] = $this->addonRepository->findBy(['state' => Addon::STATE_ARCHIVED])->countStored();
         $status['addons']['total']['composer'] = $this->addonRepository->findBy(['type' => Addon::TYPE_COMPOSER])->countStored();
         $status['addons']['total']['bower'] = $this->addonRepository->findBy(['type' => Addon::TYPE_BOWER])->countStored();
         $status['addons']['total']['untype'] = $this->addonRepository->findBy(['type' => Addon::TYPE_UNTYPE])->countStored();
         $status['addons']['total']['unknown'] = $this->addonRepository->findBy(['type' => Addon::TYPE_UNKNOWN])->countStored();
         $status['addons']['total']['total'] = $this->addonRepository->findAll()->countStored();
         // Build github status =============================================
         if ($response = $this->github->limit()) {
             $status['github']['core']['limit'] = $response['resources']['core']['limit'];
             $status['github']['core']['remaining'] = $response['resources']['core']['remaining'];
             $status['github']['core']['reset'] = DateTime::from($response['resources']['core']['reset']);
             $status['github']['search']['limit'] = $response['resources']['search']['limit'];
             $status['github']['search']['remaining'] = $response['resources']['search']['remaining'];
             $status['github']['search']['reset'] = DateTime::from($response['resources']['search']['reset']);
         }
         return $status;
     });
     // Fill template
     $this->template->status = $status;
 }