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; }
/** * @param array $args * @return int */ public function run(array $args = []) { /** @var ICollection|Addon[] $addons */ $addons = $this->addonRepository->findActive(); // FILTER ADDONS ============================================= if (isset($args['rest']) && $args['rest'] === TRUE) { $addons = $addons->findBy(['this->github->extra' => NULL]); } else { if (isset($args['type'])) { switch ($args['type']) { case 'composer': $addons = $addons->findBy(['type' => Addon::TYPE_COMPOSER]); break; case 'bower': $addons = $addons->findBy(['type' => Addon::TYPE_BOWER]); break; case 'unknown': $addons = $addons->findBy(['type' => Addon::TYPE_UNKNOWN]); break; } } } // DO YOUR JOB =============================================== $counter = 0; foreach ($addons as $addon) { // Readme if ($response = $this->github->readme($addon->owner, $addon->name)) { $addon->github->extra->append('github', ['readme' => $response]); } else { $this->log('Skip (readme): ' . $addon->fullname); } // Composer if (in_array($addon->type, [NULL, Addon::TYPE_UNKNOWN, Addon::TYPE_COMPOSER])) { if ($response = $this->github->composer($addon->owner, $addon->name)) { if ($addon->type !== Addon::TYPE_COMPOSER) { $addon->type = Addon::TYPE_COMPOSER; } $addon->github->extra->append('github', ['composer' => $response]); if ($url = $addon->github->extra->get(['github', 'composer', 'download_url'], NULL)) { if ($content = @file_get_contents($url)) { $composer = @json_decode($content, TRUE); $addon->github->extra->set('composer', $composer); } else { $this->log('Skip (composer) [invalid composer.json]: ' . $addon->fullname); } } else { $this->log('Skip (composer) [can not download composer.json]: ' . $addon->fullname); } } else { $this->log('Skip (composer): ' . $addon->fullname); } } // Bower if (in_array($addon->type, [NULL, Addon::TYPE_UNKNOWN, Addon::TYPE_BOWER])) { if ($response = $this->github->bower($addon->owner, $addon->name)) { if ($addon->type !== Addon::TYPE_BOWER) { $addon->type = Addon::TYPE_BOWER; } $addon->github->extra->append('github', ['bower' => $response]); if ($url = $addon->github->extra->get(['github', 'bower', 'download_url'], NULL)) { if ($content = @file_get_contents($url)) { $composer = @json_decode($content, TRUE); $addon->github->extra->set('bower', $composer); } else { $this->log('Skip (bower) [invalid bower.json]: ' . $addon->fullname); } } else { $this->log('Skip (bower) [can not download bower.json]: ' . $addon->fullname); } } else { $this->log('Skip (bower): ' . $addon->fullname); } } // Untype if (in_array($addon->type, [NULL, Addon::TYPE_UNKNOWN])) { $addon->type = Addon::TYPE_UNTYPE; } // Persist $this->addonRepository->persistAndFlush($addon); // Increase counting $counter++; } return $counter; }
/** * @param array $args * @return int */ public function run(array $args = []) { /** @var ICollection|Addon[] $addons */ $addons = $this->addonRepository->findActive(); if (isset($args['rest']) && $args['rest'] === TRUE) { $addons = $this->addonRepository->findBy(['state' => Addon::STATE_QUEUED]); } else { if (isset($args['type'])) { switch ($args['type']) { case 'composer': $addons = $addons->findBy(['type' => Addon::TYPE_COMPOSER]); break; case 'bower': $addons = $addons->findBy(['type' => Addon::TYPE_BOWER]); break; case 'unknown': $addons = $addons->findBy(['type' => Addon::TYPE_UNKNOWN]); break; } } } // DO YOUR JOB =============================================== $counter = 0; $added = 0; foreach ($addons as $addon) { // Base metadata $response = $this->github->repo($addon->owner, $addon->name); if ($response && !isset($response['message'])) { $github = $addon->github; // Increase adding counting if ($addon->state == Addon::STATE_QUEUED) { $added++; } $github->description = $response['description']; $github->homepage = !empty($response['homepage']) ? $response['homepage'] : NULL; $github->stars = $response['stargazers_count']; $github->watchers = $response['watchers_count']; $github->issues = $response['open_issues_count']; $github->fork = boolval($response['fork']); $github->language = $response['language']; $github->forks = $response['forks_count']; $github->createdAt = new DateTime($response['created_at']); $github->updatedAt = new DateTime($response['updated_at']); $github->pushedAt = new DateTime($response['pushed_at']); $addon->state = Addon::STATE_ACTIVE; } else { $addon->state = Addon::STATE_ARCHIVED; if (isset($response['message'])) { $this->log('Skip (' . $response['message'] . '): ' . $addon->fullname); } else { $this->log('Skip (base): ' . $addon->fullname); } } $addon->updatedAt = new DateTime(); $this->addonRepository->persistAndFlush($addon); // Increase counting $counter++; } if ($added > 0) { $this->cacher->cleanByTags(['routing']); } return $counter; }