/**
  * {@inheritdoc}
  */
 public function execute()
 {
     try {
         $this->status->add('Starting composer update...');
         if (isset($this->params['components'])) {
             $packages = [];
             foreach ($this->params['components'] as $compObj) {
                 $packages[] = implode(' ', $compObj);
             }
             foreach ($packages as $package) {
                 if (strpos($package, 'magento/product-enterprise-edition') !== false) {
                     $this->composerApp->runComposerCommand(['command' => 'remove', 'packages' => ['magento/product-community-edition'], '--no-update' => true]);
                 }
             }
             $this->status->add($this->composerApp->runComposerCommand(['command' => 'require', 'packages' => $packages, '--no-update' => true]));
         } else {
             throw new \RuntimeException('Cannot find component to update');
         }
         $this->status->add($this->composerApp->runComposerCommand(['command' => 'update']));
         $this->status->add('Composer update completed successfully');
         $this->createSetupUpgradeTasks();
     } catch (\Exception $e) {
         $this->status->setUpdateError(true);
         throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
     }
     return $this;
 }
 function testRunCommand()
 {
     $inputData = ['command' => 'update', MagentoComposerApplication::COMPOSER_WORKING_DIR => '.'];
     $this->composerApplication->expects($this->once())->method('resetComposer');
     $this->inputFactory->expects($this->once())->method('create')->with($inputData);
     $this->consoleOutput->expects($this->once())->method('fetch')->willReturn('Nothing to update');
     $this->composerApplication->expects($this->once())->method('run')->willReturn(0);
     $message = $this->application->runComposerCommand($inputData);
     $this->assertEquals('Nothing to update', $message);
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Exception
  */
 public function testExecuteException()
 {
     $om = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $jobUpdate = $om->create('Magento\\Update\\Queue\\JobUpdate', ['composerApp' => $this->composerApp, 'status' => $this->status, 'params' => ['components' => [['name' => 'vendor/package', 'version' => '1.0']]], 'queue' => $this->queue, 'name' => 'setup:upgrade']);
     $this->status->expects($this->atLeastOnce())->method('add');
     $this->composerApp->expects($this->at(0))->method('runComposerCommand')->with(['command' => 'require', 'packages' => ['vendor/package 1.0'], '--no-update' => true])->willReturn('Success');
     $this->composerApp->expects($this->at(1))->method('runComposerCommand')->with(['command' => 'update'])->will($this->throwException(new \Exception('Exception')));
     $this->status->expects($this->once())->method('setUpdateError')->with(true);
     $jobUpdate->execute();
 }
 /**
  * Constructor
  *
  * @param MagentoComposerApplicationFactory $applicationFactory
  * @throws \Exception
  */
 public function __construct(
     MagentoComposerApplicationFactory $applicationFactory
 ) {
     $this->application = $applicationFactory->create();
     $this->composer = $this->application->createComposer();
     $this->locker = $this->composer->getLocker();
 }
 /**
  * Run Composer dependency check
  *
  * @param array $packages
  * @return array
  * @throws \Exception
  */
 public function runReadinessCheck(array $packages)
 {
     $composerJson = $this->composerJsonFinder->findComposerJson();
     $this->file->copy($composerJson, $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/composer.json');
     $workingDir = $this->directoryList->getPath(DirectoryList::VAR_DIR);
     try {
         foreach ($packages as $package) {
             if (strpos($package, 'magento/product-enterprise-edition') !== false) {
                 $this->magentoComposerApplication->runComposerCommand(['command' => 'remove', 'packages' => ['magento/product-community-edition'], '--no-update' => true], $workingDir);
             }
         }
         $this->requireUpdateDryRunCommand->run($packages, $workingDir);
         return ['success' => true];
     } catch (\RuntimeException $e) {
         $message = str_replace(PHP_EOL, '<br/>', htmlspecialchars($e->getMessage()));
         return ['success' => false, 'error' => $message];
     }
 }
 /**
  * Retrieve all available versions for a package
  *
  * @param string $package
  * @return array
  * @throws \RuntimeException
  */
 private function getPackageAvailableVersions($package)
 {
     $versionsPattern = '/^versions\\s*\\:\\s(.+)$/m';
     $commandParams = [self::PARAM_COMMAND => self::COMPOSER_SHOW, self::PARAM_PACKAGE => $package, self::PARAM_AVAILABLE => true];
     $result = $this->application->runComposerCommand($commandParams);
     $matches = [];
     preg_match($versionsPattern, $result, $matches);
     if (!isset($matches[1])) {
         throw new \RuntimeException(sprintf('Couldn\'t get available versions for package %s', $commandParams[self::PARAM_PACKAGE]));
     }
     return explode(', ', $matches[1]);
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     try {
         $this->status->add('Starting composer remove...');
         if (isset($this->params['components'])) {
             $packages = [];
             foreach ($this->params['components'] as $compObj) {
                 $packages[] = $compObj['name'];
             }
             $this->status->add($this->composerApp->runComposerCommand(['command' => 'remove', 'packages' => $packages, '--no-update' => true]));
         } else {
             throw new \RuntimeException('Cannot find component to uninstall');
         }
         $this->status->add($this->composerApp->runComposerCommand(['command' => 'update']));
         $this->status->add('Composer remove completed successfully');
         $this->queue->addJobs([['name' => \Magento\Update\Queue\JobFactory::NAME_MAINTENANCE_MODE, 'params' => ['enable' => false]]]);
     } catch (\Exception $e) {
         $this->status->setUpdateError(true);
         throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
     }
     return $this;
 }
 /**
  * @param array $systemPackages
  * @return array
  */
 public function getInstalledSystemPackages($systemPackages)
 {
     $systemPackages = [];
     $locker = $this->magentoComposerApplication->createComposer()->getLocker();
     /** @var \Composer\Package\CompletePackage $package */
     foreach ($locker->getLockedRepository()->getPackages() as $package) {
         $packageName = $package->getName();
         if ($this->composerInfo->isSystemPackage($packageName)) {
             if ($packageName == 'magento/product-community-edition') {
                 if ($this->composerInfo->isPackageInComposerJson($packageName)) {
                     $systemPackages[] = $packageName;
                 }
             } else {
                 $systemPackages[] = $packageName;
             }
         }
     }
     return $systemPackages;
 }
Example #9
0
 /**
  * @param array $systemPackages
  * @return array
  * @throws \RuntimeException
  */
 public function getInstalledSystemPackages($systemPackages)
 {
     $systemPackages = [];
     $locker = $this->magentoComposerApplication->createComposer()->getLocker();
     /** @var \Composer\Package\CompletePackage $package */
     foreach ($locker->getLockedRepository()->getPackages() as $package) {
         $packageName = $package->getName();
         if ($this->composerInfo->isSystemPackage($packageName)) {
             if ($packageName == 'magento/product-community-edition') {
                 if ($this->composerInfo->isPackageInComposerJson($packageName)) {
                     $systemPackages[] = $packageName;
                 }
             } else {
                 $systemPackages[] = $packageName;
             }
         }
     }
     if (empty($systemPackages)) {
         throw new \RuntimeException('We\'re sorry, no components are available because you cloned the Magento 2 GitHub repository. ' . 'You must manually update components as discussed in the ' . '<a href="http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/dev_options.html">' . 'Installation Guide</a>.');
     }
     return $systemPackages;
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage
  */
 public function testRunException()
 {
     $this->application->expects($this->at(1))->method('runComposerCommand')->willThrowException(new \RuntimeException($this->errorMessage));
     $this->infoCommand->expects($this->once())->method('run')->willReturn($this->packageInfo);
     $this->requireUpdateDryRunCommand->run(['3rdp/e 1.2.0'], '');
 }
Example #11
0
 public function testRunInstalled()
 {
     $this->application->expects($this->once())->method('runComposerCommand')->willReturn($this->installedOutput);
     $result = $this->infoCommand->run('3rdp/a', true);
     $this->assertEquals(['name' => '3rdp/a', 'descrip.' => 'Plugin project A', 'versions' => '* 1.0.0', 'keywords' => '', 'type' => 'library', 'names' => '3rdp/a', 'current_version' => '1.0.0', 'available_versions' => [], 'new_versions' => []], $result);
 }