/**
  * @param AddonVersion
  * @return void
  * @throws \NetteAddons\DuplicateEntryException
  * @throws \PDOException
  */
 public function setVersionDependencies(AddonVersion $version)
 {
     foreach (AddonVersion::getLinkTypes() as $key => $type) {
         foreach ($version->{$key} as $packageName => $versionNumber) {
             if (strpos($packageName, '/') !== FALSE && ($dep = $this->findAddon($packageName))) {
                 $depId = $dep->getPrimary();
             } else {
                 $depId = NULL;
             }
             $this->createRow(array('versionId' => $version->id, 'dependencyId' => $depId, 'packageName' => $packageName, 'version' => $versionNumber, 'type' => $type));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates Addon entity from Nette\Database row.
  *
  * @todo   Consider lazy loading for versions and tags.
  *
  * @param \Nette\Database\Table\ActiveRow
  * @param AddonVotes
  * @return Addon
  */
 public static function fromActiveRow(ActiveRow $row, AddonVotes $addonVotes = NULL)
 {
     $addon = new static();
     $addon->id = (int) $row->id;
     $addon->name = $row->name;
     $addon->composerVendor = $row->composerVendor;
     $addon->composerName = $row->composerName;
     $addon->userId = (int) $row->user->id;
     $addon->shortDescription = $row->shortDescription;
     $addon->description = $row->description;
     $addon->descriptionFormat = $row->descriptionFormat;
     $addon->defaultLicense = $row->defaultLicense;
     $addon->repository = $row->repository;
     $addon->repositoryHosting = $row->repositoryHosting;
     $addon->demo = $row->demo;
     $addon->updatedAt = $row->updatedAt ? DateTime::from($row->updatedAt) : NULL;
     $addon->deletedAt = $row->deletedAt;
     $addon->deletedBy = $row->ref('deletedBy');
     $addon->type = $row->type;
     $addon->stars = $row->stars;
     foreach ($row->related('versions') as $versionRow) {
         $version = AddonVersion::fromActiveRow($versionRow);
         $version->addon = $addon;
         $addon->versions[$version->version] = $version;
     }
     foreach ($row->related('tags') as $tagRow) {
         $addon->tags[$tagRow->tag->id] = Tag::fromActiveRow($tagRow->tag);
     }
     foreach ($row->related('addons_resources') as $resourceRow) {
         $addon->resources[$resourceRow->type] = $resourceRow->resource;
     }
     if ($addonVotes) {
         $addon->votes = $addonVotes->calculatePopularity($row);
     }
     return $addon;
 }
 /**
  * Imports versions from GitHub repository.
  *
  * @param \NetteAddons\Model\Addon
  * @return \NetteAddons\Model\AddonVersion[]
  * @throws \NetteAddons\IOException
  */
 public function importVersions(Addon $addon)
 {
     $versions = array();
     foreach ($this->getVersions() as $v => $hash) {
         $composer = $this->getComposerJson($hash);
         $version = new AddonVersion();
         $version->addon = $addon;
         // version
         if ($composer && isset($composer->version)) {
             $version->version = $composer->version;
             // warning: multiple tags may have the same composer version
         } else {
             $version->version = $v;
         }
         // license
         if ($composer && isset($composer->license)) {
             $version->license = implode(', ', (array) $composer->license);
         } else {
             $version->license = $addon->defaultLicense;
         }
         // package links
         if ($composer) {
             foreach (AddonVersion::getLinkTypes() as $key => $type) {
                 if (!empty($composer->{$type})) {
                     $version->{$key} = get_object_vars($composer->{$type});
                 }
             }
         }
         // time
         if ($composer && isset($composer->time)) {
             $version->updatedAt = new \DateTime($composer->time);
         } else {
             $version->updatedAt = new \DateTime($this->repository->getCommit($hash)->commit->author->date);
         }
         // dist
         $version->distType = 'zip';
         $version->distUrl = $this->repository->getArchiveLink('zip', $hash);
         // source
         $version->sourceType = 'git';
         $version->sourceUrl = $addon->repository;
         $version->sourceReference = $hash;
         // composer.json
         $version->composerJson = Utils\Composer::createComposerJson($version, $composer);
         $versions[$version->version] = $version;
         // ensures that versions are unique
     }
     return array_values($versions);
 }