Exemplo n.º 1
0
 /**
  * @param array $args
  * @return int
  */
 public function run(array $args = [])
 {
     /** @var ICollection|Addon[] $addons */
     $addons = $this->addonRepository->findComposers();
     // DO YOUR JOB ===============================================
     $counter = 0;
     foreach ($addons as $addon) {
         try {
             // Skip addon with bad data
             if ($extra = $addon->github->extra) {
                 if ($composer = $extra->get('composer', FALSE)) {
                     if (!isset($composer['name'])) {
                         throw new InvalidStateException('No composer name at ' . $addon->fullname);
                     }
                     list($owner, $repo) = explode('/', $composer['name']);
                     // Create composer entity if not exist
                     if (!$addon->composer) {
                         $addon->composer = new Composer();
                     }
                     // Basic info
                     $addon->composer->name = Arrays::get($composer, 'name', NULL);
                     $addon->composer->description = Arrays::get($composer, 'description', NULL);
                     $addon->composer->type = Arrays::get($composer, 'type', NULL);
                     // Downloads
                     if ($stats = $this->composer->repo($owner, $repo)) {
                         $addon->composer->downloads = Arrays::get($stats, ['package', 'downloads', 'total'], 0);
                     }
                     // Keywords
                     $keywords = Arrays::get($composer, 'keywords', []);
                     $addon->composer->keywords = $keywords ? implode(',', $keywords) : NULL;
                     // Persist
                     $this->addonRepository->persistAndFlush($addon);
                     // Increase counting
                     $counter++;
                 } else {
                     $this->log('Skip (composer) [no composer data]: ' . $addon->fullname);
                 }
             } else {
                 $this->log('Skip (composer) [no extra data]: ' . $addon->fullname);
             }
         } catch (Exception $e) {
             Debugger::log($e, Debugger::EXCEPTION);
             $this->log('Skip (composer) [exception]: ' . $e->getMessage());
         }
     }
     return $counter;
 }
Exemplo n.º 2
0
 /**
  * @param array $args
  * @return bool
  */
 public function run(array $args = [])
 {
     /** @var ICollection|Addon[] $addons */
     $addons = $this->addonRepository->findComposers();
     // DO YOUR JOB ===============================================
     $counter = 0;
     foreach ($addons as $addon) {
         try {
             // Skip addon with bad data
             if ($extra = $addon->github->extra) {
                 if ($composer = $extra->get('composer', FALSE)) {
                     if (!isset($composer['name'])) {
                         throw new InvalidStateException('No composer name at ' . $addon->fullname);
                     }
                     list($owner, $repo) = explode('/', $composer['name']);
                     if ($stats = $this->composer->stats($owner, $repo)) {
                         $extra->set('composer-stats', ['all' => $stats]);
                     } else {
                         $this->log('Skip (composer stats) [no stats data]: ' . $addon->fullname);
                     }
                     // Persist
                     $this->addonRepository->persistAndFlush($addon);
                     // Increase counting
                     $counter++;
                 } else {
                     $this->log('Skip (composer stats) [no composer data]: ' . $addon->fullname);
                 }
             } else {
                 $this->log('Skip (composer stats) [no extra data]: ' . $addon->fullname);
             }
         } catch (Exception $e) {
             Debugger::log($e, Debugger::EXCEPTION);
             $this->log('Skip (composer stats) [exception]: ' . $e->getMessage());
         }
     }
     return $counter;
 }