コード例 #1
0
 /**
  * @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]);
         }
     }
 }
コード例 #2
0
 /**
  * Require the configuration file.
  *
  * @return void
  *
  * @throws \ComponentManager\Exception\MoodleException
  */
 public function configure()
 {
     $this->assertState(static::STATE_NEW);
     /* This value should be overwritten shortly, either by the definition in
      * the Moodle instance's configuration or by our own "fake"
      * configuration used to load the plugin manager. */
     $CFG = null;
     $constants = ['ABORT_AFTER_CONFIG', 'CLI_SCRIPT', 'IGNORE_COMPONENT_CACHE'];
     foreach ($constants as $constant) {
         define($constant, true);
     }
     $path = $this->platform->joinPaths([$this->rootDirectory, static::CONFIG_FILENAME]);
     if (is_file($path)) {
         require_once $path;
         if (!is_object($CFG)) {
             throw new MoodleException("The Moodle configuration file \"{$path}\" did not define \$CFG", MoodleException::CODE_NOT_CONFIGURED);
         }
     } else {
         /* We don't have a configured site, so we'll have to fake it.
          * Only an extremely slim portion of Moodle will function
          * correctly in this state, as we've not actually done most of
          * the Moodle setup dance. It seems to be enough to run the
          * plugin manager. */
         global $CFG;
         $CFG = (object) ['dirroot' => $this->rootDirectory, 'dataroot' => $this->platform->createTempDirectory(), 'wwwroot' => 'http://localhost'];
         require_once "{$CFG->dirroot}/lib/setup.php";
     }
     $this->config = $CFG;
     $this->state = static::STATE_READY;
 }
コード例 #3
0
 /**
  * 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);
     }
 }
コード例 #4
0
 /**
  * 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;
 }