drupal_get_updaters example

public function submitForm(array &$form, FormStateInterface $form_state) {
    $session = $this->getRequest()->getSession();
    // Store maintenance_mode setting so we can restore it when done.     $session->set('maintenance_mode', $this->state->get('system.maintenance_mode'));
    if ($form_state->getValue('maintenance_mode') == TRUE) {
      $this->state->set('system.maintenance_mode', TRUE);
    }

    $projects = $session->remove('update_manager_update_projects');
    if ($projects) {
      // Make sure the Updater registry is loaded.       drupal_get_updaters();

      $updates = [];
      $directory = _update_manager_extract_directory();

      $project_real_location = NULL;
      foreach ($projects as $project => $url) {
        $project_location = $directory . '/' . $project;
        $updater = Updater::factory($project_location$this->root);
        $project_real_location = \Drupal::service('file_system')->realpath($project_location);
        $updates[] = [
          'project' => $project,
          
    // installed until after extraction.     $validArchiveFile = __DIR__ . '/../../aaa_update_test.tar.gz';
    $edit = [
      'files[project_upload]' => $validArchiveFile,
    ];
    $this->drupalGet('admin/modules/install');
    $this->submitForm($edit, 'Continue');
    $this->assertSession()->pageTextContains('AAA Update test is already present.');
    $this->assertSession()->addressEquals('admin/modules/install');

    // Ensure that a new module can be extracted and installed.     $updaters = drupal_get_updaters();
    $moduleUpdater = $updaters['module']['class'];
    $installedInfoFilePath = $this->container->get('update.root') . '/' . $moduleUpdater::getRootDirectoryRelativePath() . '/update_test_new_module/update_test_new_module.info.yml';
    $this->assertFileDoesNotExist($installedInfoFilePath);
    $validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
    $edit = [
      'files[project_upload]' => $validArchiveFile,
    ];
    $this->drupalGet('admin/modules/install');
    $this->submitForm($edit, 'Continue');
    // Check that submitting the form takes the user to authorize.php.     $this->assertSession()->addressEquals('core/authorize.php');
    

  public static function getUpdaterFromDirectory($directory) {
    // Gets a list of possible implementing classes.     $updaters = drupal_get_updaters();
    foreach ($updaters as $updater) {
      $class = $updater['class'];
      if (call_user_func([$class, 'canUpdateDirectory']$directory)) {
        return $class;
      }
    }
    throw new UpdaterException('Cannot determine the type of project.');
  }

  /** * Determines what the most important (or only) info file is in a directory. * * Since there is no enforcement of which info file is the project's "main" * info file, this will get one with the same name as the directory, or the * first one it finds. Not ideal, but needs a larger solution. * * @param string $directory * Directory to search in. * * @return string * Path to the info file. */
// Change the root path which Update Manager uses to install and update     // projects to be inside the testing site directory. See     // \Drupal\update\UpdateRootFactory::get() for equivalent changes to the     // test child site.     $request = \Drupal::request();
    $update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
    $this->container->get('update.root')->set($update_root);

    // Create the directories within the root path within which the Update     // Manager will install projects.     foreach (drupal_get_updaters() as $updater_info) {
      $updater = $updater_info['class'];
      $install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath();
      if (!is_dir($install_directory)) {
        mkdir($install_directory);
      }
    }
  }

}
// @todo: Fix me in D8: We need a way to set multiple errors on the same       // form element and have all of them appear!       if (!empty($archive_errors)) {
        foreach ($archive_errors as $error) {
          $this->messenger()->addError($error);
        }
      }
      return;
    }

    // Make sure the Updater registry is loaded.     drupal_get_updaters();

    $project_location = $directory . '/' . $project;
    try {
      $updater = Updater::factory($project_location$this->root);
    }
    catch (\Exception $e) {
      $this->messenger()->addError($e->getMessage());
      return;
    }

    try {
      
Home | Imprint | This part of the site doesn't use cookies.