Пример #1
0
 /**
  * Get Components info action
  *
  * @return \Zend\View\Model\JsonModel
  * @throws \RuntimeException
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function componentsAction()
 {
     $lastSyncData = $this->updatePackagesCache->getPackagesForUpdate();
     $components = $this->composerInformation->getInstalledMagentoPackages();
     $allModules = $this->getAllModules();
     $components = array_replace_recursive($components, $allModules);
     foreach ($components as $component) {
         $components[$component['name']]['update'] = false;
         $components[$component['name']]['uninstall'] = false;
         $components[$component['name']]['moduleName'] = $this->packageInfo->getModuleName($component['name']);
         if ($this->composerInformation->isPackageInComposerJson($component['name'])) {
             if ($component['type'] !== \Magento\Framework\Composer\ComposerInformation::METAPACKAGE_PACKAGE_TYPE) {
                 $components[$component['name']]['uninstall'] = true;
             }
             if (isset($lastSyncData['packages'][$component['name']]['latestVersion']) && version_compare($lastSyncData['packages'][$component['name']]['latestVersion'], $component['version'], '>')) {
                 $components[$component['name']]['update'] = true;
             }
         }
         if ($component['type'] === \Magento\Framework\Composer\ComposerInformation::MODULE_PACKAGE_TYPE) {
             $components[$component['name']]['enable'] = $this->enabledModuleList->has($components[$component['name']]['moduleName']);
             $components[$component['name']]['disable'] = !$components[$component['name']]['enable'];
         } else {
             $components[$component['name']]['enable'] = false;
             $components[$component['name']]['disable'] = false;
         }
         $componentNameParts = explode('/', $component['name']);
         $components[$component['name']]['vendor'] = $componentNameParts[0];
     }
     $packagesForInstall = $this->marketplaceManager->getPackagesForInstall();
     $lastSyncData = $this->formatLastSyncData($packagesForInstall, $lastSyncData);
     return new \Zend\View\Model\JsonModel(['success' => true, 'components' => array_values($components), 'total' => count($components), 'lastSyncData' => $lastSyncData]);
 }
 public function testGetPackagesForUpdate()
 {
     $packageName = 'magento/module-store';
     $this->setupDirectory('testSkeleton');
     /** @var \Magento\Setup\Model\UpdatePackagesCache $updatePackagesCache */
     $updatePackagesCache = $this->objectManager->create('Magento\\Setup\\Model\\UpdatePackagesCache', ['applicationFactory' => new MagentoComposerApplicationFactory($this->composerJsonFinder, $this->directoryList), 'filesystem' => $this->filesystem, 'dateTime' => new DateTime(), 'composerInformation' => $this->composerInformation]);
     $requiredPackages = $this->composerInformation->getInstalledMagentoPackages();
     $this->assertArrayHasKey($packageName, $requiredPackages);
     $this->assertTrue($updatePackagesCache->syncPackagesForUpdate());
     $packagesForUpdate = $updatePackagesCache->getPackagesForUpdate();
     $this->assertArrayHasKey('packages', $packagesForUpdate);
     $this->assertArrayHasKey($packageName, $packagesForUpdate['packages']);
     $this->assertTrue(version_compare($packagesForUpdate['packages'][$packageName]['latestVersion'], $requiredPackages[$packageName]['version'], '>'));
 }
 /**
  * Execute uninstall on a component
  *
  * @param array $component
  * @return void
  * @throw \RuntimeException
  */
 private function executeComponent(array $component)
 {
     if (!isset($component[self::COMPONENT_NAME])) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException('Job parameter format is incorrect');
     }
     $componentName = $component[self::COMPONENT_NAME];
     $installedPackages = $this->composerInformation->getInstalledMagentoPackages();
     if (isset($installedPackages[$componentName]['type'])) {
         $type = $installedPackages[$componentName]['type'];
     } else {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException('Component type not set');
     }
     if (!in_array($type, [self::COMPONENT_MODULE, self::COMPONENT_THEME, self::COMPONENT_LANGUAGE, self::COMPONENT])) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException('Unknown component type');
     }
     switch ($type) {
         case self::COMPONENT_MODULE:
             $dataOption = isset($this->params[self::DATA_OPTION]) && $this->params[self::DATA_OPTION] === 'true';
             $this->moduleUninstall->uninstall($this->output, $componentName, $dataOption);
             break;
         case self::COMPONENT_THEME:
             $this->themeUninstall->uninstall($this->output, $componentName);
             break;
     }
 }
 public function testGetPackagesForUpdate()
 {
     $packageName = 'magento/module-store';
     $this->setupDirectory('testSkeleton');
     /** @var UpdatePackagesCache $updatePackagesCache|\PHPUnit_Framework_MockObject_MockObject */
     $updatePackagesCache = $this->getMock('Magento\\Setup\\Model\\UpdatePackagesCache', [], [], '', false);
     $packages = ['packages' => [$packageName => ['latestVersion' => '1000.100.200']]];
     $updatePackagesCache->expects($this->once())->method('syncPackagesForUpdate')->willReturn(true);
     $updatePackagesCache->expects($this->once())->method('getPackagesForUpdate')->willReturn($packages);
     $requiredPackages = $this->composerInformation->getInstalledMagentoPackages();
     $this->assertArrayHasKey($packageName, $requiredPackages);
     $this->assertTrue($updatePackagesCache->syncPackagesForUpdate());
     $packagesForUpdate = $updatePackagesCache->getPackagesForUpdate();
     $this->assertArrayHasKey('packages', $packagesForUpdate);
     $this->assertArrayHasKey($packageName, $packagesForUpdate['packages']);
     $this->assertTrue(version_compare($packagesForUpdate['packages'][$packageName]['latestVersion'], $requiredPackages[$packageName]['version'], '>'));
 }
Пример #5
0
 /**
  * Get Components info action
  *
  * @return \Zend\View\Model\JsonModel
  * @throws \RuntimeException
  */
 public function componentsAction()
 {
     $objectManager = $this->objectManagerProvider->get();
     $enabledModuleList = $objectManager->get('Magento\\Framework\\Module\\ModuleList');
     $this->fullModuleList = $objectManager->get('Magento\\Framework\\Module\\FullModuleList');
     $this->packageInfo = $objectManager->get('Magento\\Framework\\Module\\PackageInfoFactory')->create();
     $lastSyncData = [];
     $authDetails = $this->packagesAuth->getAuthJsonData();
     if ($authDetails) {
         $lastSyncData = $this->packagesData->syncPackagesData();
     }
     $components = $this->composerInformation->getInstalledMagentoPackages();
     $allModules = $this->getAllModules();
     $components = array_replace_recursive($components, $allModules);
     foreach ($components as $component) {
         $components[$component['name']]['update'] = false;
         $components[$component['name']]['uninstall'] = false;
         $components[$component['name']]['moduleName'] = $this->packageInfo->getModuleName($component['name']);
         if ($this->composerInformation->isPackageInComposerJson($component['name'])) {
             if ($component['type'] !== \Magento\Framework\Composer\ComposerInformation::METAPACKAGE_PACKAGE_TYPE) {
                 $components[$component['name']]['uninstall'] = true;
             }
             if (isset($lastSyncData['packages'][$component['name']]['latestVersion']) && version_compare($lastSyncData['packages'][$component['name']]['latestVersion'], $component['version'], '>')) {
                 $components[$component['name']]['update'] = true;
             }
         }
         if ($component['type'] === \Magento\Framework\Composer\ComposerInformation::MODULE_PACKAGE_TYPE) {
             $components[$component['name']]['enable'] = $enabledModuleList->has($components[$component['name']]['moduleName']);
             $components[$component['name']]['disable'] = !$components[$component['name']]['enable'];
         } else {
             $components[$component['name']]['enable'] = false;
             $components[$component['name']]['disable'] = false;
         }
         $componentNameParts = explode('/', $component['name']);
         $components[$component['name']]['vendor'] = $componentNameParts[0];
     }
     return new \Zend\View\Model\JsonModel(['success' => true, 'components' => array_values($components), 'total' => count($components), 'lastSyncData' => $lastSyncData]);
 }
 /**
  * Get Components from composer info command
  *
  * @return JsonModel
  * @throws \RuntimeException
  */
 public function componentsAction()
 {
     try {
         $components = $this->composerInformation->getInstalledMagentoPackages();
         foreach ($components as $component) {
             if (!$this->composerInformation->isPackageInComposerJson($component['name'])) {
                 unset($components[$component['name']]);
                 continue;
             }
             $componentNameParts = explode('/', $component['name']);
             $packageInfo = $this->infoCommand->run($component['name']);
             if (!$packageInfo) {
                 throw new \RuntimeException('Package info not found for ' . $component['name']);
             }
             if ($packageInfo[InfoCommand::NEW_VERSIONS]) {
                 $currentVersion = $packageInfo[InfoCommand::CURRENT_VERSION];
                 $components[$component['name']]['version'] = $currentVersion;
                 $versions = [];
                 foreach ($packageInfo[InfoCommand::NEW_VERSIONS] as $version) {
                     $versions[] = ['id' => $version, 'name' => $version];
                 }
                 $versions[] = ['id' => $packageInfo[InfoCommand::CURRENT_VERSION], 'name' => $packageInfo[InfoCommand::CURRENT_VERSION]];
                 $versions[0]['name'] .= ' (latest)';
                 $versions[count($versions) - 1]['name'] .= ' (current)';
                 $components[$component['name']]['vendor'] = $componentNameParts[0];
                 $components[$component['name']]['updates'] = $versions;
                 $components[$component['name']]['dropdownId'] = 'dd_' . $component['name'];
                 $components[$component['name']]['checkboxId'] = 'cb_' . $component['name'];
             } else {
                 unset($components[$component['name']]);
             }
         }
         return new JsonModel(['components' => array_values($components), 'total' => count($components), 'responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]);
     } catch (\Exception $e) {
         return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR]);
     }
 }
Пример #7
0
 /**
  * Sync list of available for install versions for packages
  *
  * @return array
  * @throws \RuntimeException
  */
 public function getPackagesForInstall()
 {
     $actualInstallackages = [];
     $installPackagesInfo = $this->syncPackagesForInstall();
     try {
         $installPackages = $installPackagesInfo['packages'];
         $availablePackageNames = array_column($this->composerInformation->getInstalledMagentoPackages(), 'name');
         $metaPackageByPackage = $this->getMetaPackageForPackage($installPackages);
         foreach ($installPackages as $package) {
             if (!in_array($package['name'], $availablePackageNames) && in_array($package['type'], $this->composerInformation->getPackagesTypes()) && strpos($package['name'], 'magento/product-') === false && strpos($package['name'], 'magento/project-') === false) {
                 $package['metapackage'] = isset($metaPackageByPackage[$package['name']]) ? $metaPackageByPackage[$package['name']] : '';
                 $actualInstallackages[$package['name']] = $package;
                 $actualInstallackages[$package['name']]['version'] = $package['versions'][0];
             }
         }
         $installPackagesInfo['packages'] = $actualInstallackages;
         return $installPackagesInfo;
     } catch (\Exception $e) {
         throw new \RuntimeException('Error in getting new packages to install');
     }
 }