Example #1
0
 public function update(CompletePackage $package, $installPath = null)
 {
     $plugin = $this->findOneByName($package->getName());
     if ($plugin == null) {
         error_log('Tried to update a plugin that wasn\'t in the database: ' . $package->getName());
     }
     $plugin->setVersion($package->getVersion());
     $plugin->setDescription($package->getDescription());
     $plugin->setHomepage($package->getHomepage());
     $plugin->setAuthors($package->getAuthors());
     // getSupport() is always going to return empty an array. Maybe this will change in the future
     $plugin->setSupport($package->getSupport());
     $plugin->setDateUpdated(new \DateTime());
     // Get full package json file. The package json from composer update/install does not include support properties
     // https://github.com/CourseBit/Inkstand/issues/4
     if ($installPath != null) {
         $packageJson = json_decode(file_get_contents(sprintf('%s/composer.json', $installPath)));
         if (!empty($packageJson) && isset($packageJson->support)) {
             $plugin->setSupport($packageJson->support);
         }
     }
     $plugin->setBundleClass($package->getExtra()['bundle_class']);
     $plugin->setBundleTitle($package->getExtra()['bundle_title']);
     $this->entityManager->persist($plugin);
     $this->entityManager->flush();
 }
 /**
  * Group packages in a repository by vendor and return a sorted and grouped list.
  *
  * @param RepositoryInterface $repository
  *
  * @return array
  */
 protected function buildGroupedPackagesList(RootPackageInterface $rootPackage, RepositoryInterface $repository, $requiresList, $dependencyMap, $notInstalledList)
 {
     $groupedPackages = array();
     $requires = $rootPackage->getRequires();
     $extra = $rootPackage->getExtra();
     $versionLocks = isset($extra['contao']['version-locks']) ? (array) $extra['contao']['version-locks'] : array();
     /** @var \Composer\Package\PackageInterface $package */
     foreach ($repository->getPackages() as $package) {
         // skip aliases
         if ($package instanceof AliasPackage) {
             continue;
         }
         $name = $package->getPrettyName();
         list($group) = explode('/', $name);
         $dependencyOf = false;
         if (isset($dependencyMap[$package->getName()])) {
             $dependencyOf = $dependencyMap[$package->getName()];
         }
         if (count($package->getReplaces())) {
             foreach (array_keys($package->getReplaces()) as $replace) {
                 if (isset($dependencyMap[$replace])) {
                     $dependencyOf = $dependencyMap[$replace];
                     break;
                 }
             }
         }
         $item = (object) array('group' => $group, 'name' => $package->getPrettyName(), 'package' => $package, 'dependencyOf' => $dependencyOf, 'installing' => false, 'removeable' => in_array($name, $requiresList), 'removing' => !in_array($name, $requiresList) && !isset($dependencyMap[$name]), 'pinable' => $package->getStability() != 'dev', 'pinned' => array_key_exists($name, $versionLocks), 'versionConstraint' => $this->createConstraint('=', $package->getVersion()), 'requireConstraint' => isset($requires[$package->getName()]) ? $requires[$package->getName()]->getConstraint() : false);
         if (isset($groupedPackages[$group])) {
             $groupedPackages[$group][] = $item;
         } else {
             $groupedPackages[$group] = array($item);
         }
     }
     /** @var Link $notInstalledPackageConstraint */
     foreach ($notInstalledList as $notInstalledPackageName => $notInstalledPackageConstraint) {
         list($group) = explode('/', $notInstalledPackageName);
         $package = new CompletePackage($notInstalledPackageName, $notInstalledPackageConstraint->getPrettyConstraint(), $notInstalledPackageConstraint->getPrettyConstraint());
         $item = (object) array('group' => $group, 'name' => $notInstalledPackageName, 'version' => $notInstalledPackageConstraint->getPrettyConstraint(), 'package' => $package, 'dependencyOf' => false, 'installing' => true, 'removeable' => true, 'removing' => false, 'pinable' => false, 'pinned' => false, 'versionConstraint' => $this->createConstraint('=', $package->getVersion()), 'requireConstraint' => false);
         if (isset($groupedPackages[$group])) {
             $groupedPackages[$group][] = $item;
         } else {
             $groupedPackages[$group] = array($item);
         }
     }
     foreach (array_keys($groupedPackages) as $group) {
         usort($groupedPackages[$group], function ($a, $b) {
             return strnatcasecmp($a->package->getPrettyName(), $b->package->getPrettyName());
         });
     }
     uksort($groupedPackages, 'strnatcasecmp');
     return $groupedPackages;
 }