/** * Get updates from CampaignChain. * * @return array|string */ public function getUpdates() { if (!$this->loadRepositories()) { return Repository::STATUS_NO_REPOSITORIES; } $modules = $this->getModulesFromRepository(); // Is a higher version of an already installed package available? foreach ($modules as $key => $module) { $version = $this->packageService->getVersion($module->name); if (!$version) { // Not installed at all. unset($modules[$key]); } elseif (version_compare($version, $module->version, '<')) { // Older version installed. $modules[$key]->versionInstalled = $version; } else { unset($modules[$key]); } } return $modules; }
/** * @param string $bundleComposer * * @return bool|Bundle */ private function getBundle($bundleComposer) { if (!file_exists($bundleComposer)) { return false; } $bundleComposerData = file_get_contents($bundleComposer); $normalizer = new GetSetMethodNormalizer(); $normalizer->setIgnoredAttributes(array('require', 'keywords')); $encoder = new JsonEncoder(); $serializer = new Serializer(array($normalizer), array($encoder)); $bundle = $serializer->deserialize($bundleComposerData, 'CampaignChain\\CoreBundle\\Entity\\Bundle', 'json'); // Set the version of the installed bundle. $version = $this->packageService->getVersion($bundle->getName()); /* * If version does not exist, this means two things: * * 1) Either, it is a package in require-dev of composer.json, but * CampaignChain is not in dev mode. Then we don't add this package. * * 2) Or it is a bundle in Symfony's src/ directory. Then we want to * add it. */ if (!$version) { // Check if bundle is in src/ dir. $bundlePath = str_replace($this->rootDir . DIRECTORY_SEPARATOR, '', $bundleComposer); if (strpos($bundlePath, 'src' . DIRECTORY_SEPARATOR) !== 0) { // Not in src/ dir, so don't add this bundle. return false; } else { $version = 'dev-master'; } } $bundle->setVersion($version); // Set relative path of bundle. $bundle->setPath(str_replace($this->rootDir . DIRECTORY_SEPARATOR, '', str_replace(DIRECTORY_SEPARATOR . 'composer.json', '', $bundleComposer))); return $bundle; }