コード例 #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;
 }