/**
  * @override \ComponentManager\Step\Step
  *
  * @param \ComponentManager\Task\InstallTask $task
  */
 public function execute($task, LoggerInterface $logger)
 {
     $resolvedComponentVersions = $task->getResolvedComponentVersions();
     foreach ($resolvedComponentVersions as $resolvedComponentVersion) {
         $logger->info('Installing component', ['component' => $resolvedComponentVersion->getComponent()->getName(), 'packageRepository' => $resolvedComponentVersion->getPackageRepository()->getName(), 'version' => $resolvedComponentVersion->getVersion()->getVersion(), 'release' => $resolvedComponentVersion->getVersion()->getRelease()]);
         $projectLockFile = $this->project->getProjectLockFile();
         $component = $resolvedComponentVersion->getComponent();
         $packageSource = $this->project->getPackageSource($resolvedComponentVersion->getSpecification()->getPackageSource());
         $typeDirectory = $this->moodle->getPluginTypeDirectory($component->getPluginType());
         $targetDirectory = $this->platform->joinPaths([$typeDirectory, $component->getPluginName()]);
         $tempDirectory = $this->platform->createTempDirectory();
         $sourceDirectory = $packageSource->obtainPackage($tempDirectory, $resolvedComponentVersion, $this->filesystem, $logger);
         if ($resolvedComponentVersion->getFinalVersion() === null) {
             $logger->warning('Package source did not indicate final version; defaulting to desired version', ['version' => $resolvedComponentVersion->getVersion()->getVersion()]);
             $resolvedComponentVersion->setFinalVersion($resolvedComponentVersion->getVersion()->getVersion());
         }
         $logger->debug('Downloaded component source', ['packageSource' => $packageSource->getName(), 'sourceDirectory' => $sourceDirectory]);
         if ($this->filesystem->exists($targetDirectory)) {
             $logger->info('Component directory already exists; removing', ['targetDirectory' => $targetDirectory]);
             $this->filesystem->remove($targetDirectory);
         }
         $logger->info('Copying component source to Moodle directory', ['sourceDirectory' => $sourceDirectory, 'targetDirectory' => $targetDirectory]);
         $this->filesystem->mirror($sourceDirectory, $targetDirectory);
         $logger->info('Pinning component at installed final version', ['finalVersion' => $resolvedComponentVersion->getFinalVersion()]);
         $projectLockFile->addResolvedComponentVersion($resolvedComponentVersion);
         $logger->info('Cleaning up after component installation', ['tempDirectory' => $tempDirectory]);
         try {
             $this->filesystem->chmod([$tempDirectory], 0750, 00, true);
             $this->filesystem->remove([$tempDirectory]);
         } catch (IOException $e) {
             $logger->warning('Unable to clean up temporary directory', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'tempDirectory' => $tempDirectory]);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Get a ready-to-run process instance.
  *
  * @param mixed[] $arguments
  *
  * @return \Symfony\Component\Process\Process
  */
 protected function getProcess($arguments)
 {
     $prefix = [$this->platform->getPhpExecutable(), $this->platform->getPhpScript(), 'moodle'];
     if ($this->moodleDir) {
         $prefix = array_merge($prefix, ['--moodle-dir', $this->moodleDir]);
     }
     $arguments = array_merge($prefix, $arguments);
     $builder = new ProcessBuilder($arguments);
     $builder->setEnv('XDEBUG_CONFIG', '');
     return $builder->getProcess();
 }
 public function dispose()
 {
     $this->assertState(static::STATE_READY);
     try {
         $this->platform->removeTempDirectory($this->config->dataroot);
     } catch (PlatformException $e) {
         if ($e->getCode() !== PlatformException::CODE_UNKNOWN_TEMP_DIRECTORY) {
             throw $e;
         }
     }
     $this->state = static::STATE_DISPOSED;
 }
 /**
  * Attempt to build an individual component.
  *
  * @param \ComponentManager\ResolvedComponentVersion $resolvedComponentVersion
  * @param \Psr\Log\LoggerInterface $logger
  *
  * @return void
  *
  * @throws \ComponentManager\Exception\ComponentProjectException
  */
 protected function tryComponent(ResolvedComponentVersion $resolvedComponentVersion, LoggerInterface $logger)
 {
     $component = $resolvedComponentVersion->getComponent();
     $typeDirectory = $this->moodle->getPluginTypeDirectory($component->getPluginType());
     $targetDirectory = $this->platform->joinPaths([$typeDirectory, $component->getPluginName()]);
     $componentProjectFilename = $this->platform->joinPaths([$typeDirectory, $component->getPluginName(), ComponentProjectFile::FILENAME]);
     $logContext = ['component' => $component->getName(), 'componentProjectFilename' => $componentProjectFilename];
     if (!$this->filesystem->exists($componentProjectFilename)) {
         $logger->debug('Component project file not found; skipping build', $logContext);
         return;
     }
     $componentProjectFile = new ComponentProjectFile($componentProjectFilename);
     try {
         $buildScript = $componentProjectFile->getScript(ComponentProjectFile::SCRIPT_BUILD);
     } catch (ComponentProjectException $e) {
         $logger->info('Component project file doesn\'t contain a build script; skipping build', $logContext);
         return;
     }
     $logger->info('Running build script for component', $logContext);
     $process = new Process($buildScript, $targetDirectory);
     $process->setTimeout(3600);
     $process->run(function ($type, $buffer) use($logger) {
         $buffer = sprintf('%s: %s', ComponentProjectFile::SCRIPT_BUILD, $buffer);
         switch ($type) {
             case Process::ERR:
                 $logger->error($buffer);
                 break;
             case Process::OUT:
                 $logger->debug($buffer);
                 break;
         }
     });
     if (!$process->isSuccessful()) {
         throw new ComponentProjectException($process->getErrorOutput(), ComponentProjectException::CODE_SCRIPT_FAILED);
     }
 }
 /**
  * Get project.
  *
  * @param string|null $projectFilename
  * @param string|null $projectLockFilename
  *
  * @return \ComponentManager\Project\Project
  */
 protected function getProject($projectFilename = null, $projectLockFilename = null)
 {
     $workingDirectory = $this->platform->getWorkingDirectory();
     if ($this->project === null) {
         if ($projectFilename === null) {
             $projectFilename = $this->platform->joinPaths([$workingDirectory, static::PROJECT_FILENAME]);
         } else {
             $projectFilename = $this->platform->expandPath($projectFilename);
         }
         if ($projectLockFilename === null) {
             $projectLockFilename = $this->platform->joinPaths([$workingDirectory, static::PROJECT_LOCK_FILENAME]);
         } else {
             $projectLockFilename = $this->platform->expandPath($projectLockFilename);
         }
         $this->logger->info('Parsing project file', ['filename' => $projectFilename]);
         $this->project = new Project(new ProjectFile($projectFilename), new ProjectLockFile($projectLockFilename), $this->packageRepositoryFactory, $this->packageSourceFactory, $this->packageFormatFactory);
     }
     return $this->project;
 }
 /**
  * @override \ComponentManager\Platform\Platform
  */
 public function execute($task, LoggerInterface $logger)
 {
     $logger->info('Removing temporary directories');
     $this->platform->removeTempDirectories();
 }