/**
  * Merge extra config into a RootPackageInterface
  *
  * @param RootPackageInterface $root
  * @param PluginState $state
  */
 public function mergeExtra(RootPackageInterface $root, PluginState $state)
 {
     $extra = $this->package->getExtra();
     unset($extra['merge-plugin']);
     if (!$state->shouldMergeExtra() || empty($extra)) {
         return;
     }
     $rootExtra = $root->getExtra();
     $unwrapped = self::unwrapIfNeeded($root, 'setExtra');
     if ($state->replaceDuplicateLinks()) {
         $unwrapped->setExtra(array_merge($rootExtra, $extra));
     } else {
         foreach (array_intersect(array_keys($extra), array_keys($rootExtra)) as $key) {
             $this->logger->info("Ignoring duplicate <comment>{$key}</comment> in " . "<comment>{$this->path}</comment> extra config.");
         }
         $unwrapped->setExtra(array_merge($extra, $rootExtra));
     }
 }
Ejemplo n.º 2
0
 /**
  * Merge extra config into a RootPackage
  *
  * @param RootPackage $root
  * @param PluginState $state
  */
 public function mergeExtra(RootPackage $root, PluginState $state)
 {
     $extra = $this->package->getExtra();
     unset($extra['merge-plugin']);
     if (!$state->shouldMergeExtra() || empty($extra)) {
         return;
     }
     $rootExtra = $root->getExtra();
     if ($state->replaceDuplicateLinks()) {
         $root->setExtra(array_merge($rootExtra, $extra));
     } else {
         foreach ($extra as $key => $value) {
             if (isset($rootExtra[$key])) {
                 $this->logger->debug("Ignoring duplicate <comment>{$key}</comment> in " . "<comment>{$this->path}</comment> extra config.");
             }
         }
         $root->setExtra(array_merge($extra, $rootExtra));
     }
 }
Ejemplo n.º 3
0
 /**
  * @param \Composer\Package\CompletePackage $package
  * @return CM_App_Package
  * @throws CM_Exception_Invalid
  */
 protected function _getPackageFromComposerPackage(\Composer\Package\CompletePackage $package)
 {
     $pathRelative = '';
     if (!$package instanceof \Composer\Package\RootPackage) {
         $vendorDir = $this->_getComposerVendorDir();
         $pathRelative = $vendorDir . $package->getPrettyName() . '/';
     }
     $extra = $package->getExtra();
     $modules = array();
     if (array_key_exists('cm-modules', $extra)) {
         $modules = $extra['cm-modules'];
     }
     return new CM_App_Package($package->getName(), $pathRelative, $modules);
 }
Ejemplo n.º 4
0
 /**
  * Returns the list of installed plugin packages, with extra information
  * relative to their options. Local packages (i.e. not manager by composer)
  * are also included in the list.
  *
  * @return CompletePackageInterface[]
  */
 public function getPluginList()
 {
     $repoPackages = $this->getInstalledByType(self::CLAROLINE_PLUGIN_TYPE);
     $registeredPlugins = $this->om->getRepository('ClarolineCoreBundle:Plugin')->findAll();
     $packages = [];
     foreach ($registeredPlugins as $plugin) {
         $targetPackage = null;
         $isInRepo = true;
         // looks for the corresponding package
         foreach ($repoPackages as $package) {
             $packageParts = explode('/', $package->getName());
             $bundleParts = explode('-', $packageParts[1]);
             $vendorName = $packageParts[0];
             $bundleName = '';
             foreach ($bundleParts as $part) {
                 $bundleName .= $part;
             }
             if (strtoupper($plugin->getVendorName()) === strtoupper($vendorName) && strtoupper($plugin->getBundleName()) === strtoupper($bundleName)) {
                 $targetPackage = $package;
                 break;
             }
         }
         // builds a "fake" package if the plugin is not managed by composer
         if (!$targetPackage) {
             $isInRepo = false;
             $vendorName = strtolower($plugin->getVendorName());
             $bundleParts = preg_split('/(?=[A-Z])/', $plugin->getBundleName());
             array_shift($bundleParts);
             $bundleName = strtolower(implode('-', $bundleParts));
             $targetPackage = new CompletePackage("{$vendorName}/{$bundleName}", '9999999-dev', 'unknown / local');
         }
         // adds plugin options info in the "extra" attribute
         $extra = $targetPackage->getExtra();
         $extra['is_in_repo'] = $isInRepo;
         $extra['has_options'] = $plugin->hasOptions();
         $extra['plugin_short_name'] = $plugin->getShortName();
         $targetPackage->setExtra($extra);
         $packages[] = $targetPackage;
     }
     return $packages;
 }
Ejemplo n.º 5
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();
 }