Commit 688e42fd authored by catch's avatar catch
Browse files

Issue #2683421 by xjm, alexpott, hussainweb: Remove incremental and rollback...

Issue #2683421 by xjm, alexpott, hussainweb: Remove incremental and rollback options from the UI (and add them back when they are more stable)
parent 4da00503
Loading
Loading
Loading
Loading
+7 −113
Changes for core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php: 7 added lines, 113 removed lines.
Original line number Diff line number Diff line
@@ -25,16 +25,6 @@ class MigrateUpgradeForm extends ConfirmFormBase {

  use MigrationCreationTrait;

  /**
   * If a migration has previously run, perform an incremental migration.
   */
  const MIGRATE_UPGRADE_INCREMENTAL = 1;

  /**
   * If a migration has previously run, roll it back and start fresh.
   */
  const MIGRATE_UPGRADE_ROLLBACK = 2;

  /**
   * Mapping of known migrations and their source and destination modules.
   *
@@ -705,21 +695,15 @@ public function buildOverviewForm(array $form, FormStateInterface $form_state) {
    $form['#title'] = $this->t('Drupal Upgrade');

    if ($date_performed = $this->state->get('migrate_drupal_ui.performed')) {
      // @todo Add back support for rollbacks and incremental migrations.
      //   https://www.drupal.org/node/2687843
      //   https://www.drupal.org/node/2687849
      $form['upgrade_option_item'] = [
        '#type' => 'item',
        '#prefix' => $this->t('<p>An upgrade has already been performed on this site.</p>'),
        '#prefix' => $this->t('An upgrade has already been performed on this site. To perform a new migration, create a clean and empty new install of Drupal 8. Rollbacks and incremental migrations are not yet supported through the user interface. For more information, see the <a href=":url">upgrading handbook</a>.', [':url' => 'https://www.drupal.org/upgrade/migrate']),
        '#description' => $this->t('<p>Last upgrade: @date</p>', ['@date' => $this->dateFormatter->format($date_performed)]),
      ];
      $form['upgrade_option'] = array(
        '#type' => 'radios',
        '#title' => $this->t('You have two options:'),
        '#default_value' => static::MIGRATE_UPGRADE_INCREMENTAL,
        '#options' => [
          static::MIGRATE_UPGRADE_INCREMENTAL => $this->t('<strong>Rerun</strong>: Import additional configuration and content that was not available when running the upgrade previously.'),
          static::MIGRATE_UPGRADE_ROLLBACK => $this->t('<strong>Rollback</strong>: Remove content and configuration entities (such as fields and node types). Default values of other configuration will not be reverted (such as site name).'),
        ],
      );
      $validate = ['::validateCredentialForm'];
      return $form;
    }
    else {
      $form['info_header'] = [
@@ -769,19 +753,7 @@ public function buildOverviewForm(array $form, FormStateInterface $form_state) {
   *   The current state of the form.
   */
  public function submitOverviewForm(array &$form, FormStateInterface $form_state) {
    switch ($form_state->getValue('upgrade_option')) {
      case static::MIGRATE_UPGRADE_INCREMENTAL:
        $form_state->setValue('step', 'confirm');
        break;

      case static::MIGRATE_UPGRADE_ROLLBACK:
        $form_state->setValue('step', 'confirm');
        break;

      default:
    $form_state->setValue('step', 'credentials');
        break;
    }
    $form_state->setRebuild();
  }

@@ -894,15 +866,11 @@ public function buildCredentialForm(array $form, FormStateInterface $form_state)
   *   The current state of the form.
   */
  public function validateCredentialForm(array &$form, FormStateInterface $form_state) {
    // Skip if rollback was chosen.
    if ($form_state->getValue('upgrade_option') == static::MIGRATE_UPGRADE_ROLLBACK) {
      return;
    }

    // Retrieve the database driver from the form, use reflection to get the
    // namespace, and then construct a valid database array the same as in
    // settings.php.
    if ($driver = $form_state->getValue('driver')) {
    $driver = $form_state->getValue('driver');
    $drivers = $this->getDatabaseTypes();
    $reflection = new \ReflectionClass($drivers[$driver]);
    $install_namespace = $reflection->getNamespaceName();
@@ -919,32 +887,6 @@ public function validateCredentialForm(array &$form, FormStateInterface $form_st
      }
      return;
    }
    }
    else {
      $database = [];
      // Migration templates that had matching tags for the source Drupal
      // version where converted to migration entities. Find one of those
      // migrations to be able to look up the matching database credentials
      // from state.
      $definitions = $this->pluginManager->getDefinitions();
      foreach ($definitions as $id => $definition) {
        /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
        $migration = $this->pluginManager->createInstance($id);
        $is_drupal_migration = FALSE;
        foreach ($migration->get('migration_tags') as $migration_tag) {
          if (substr($migration_tag, 0, 7) === 'Drupal ') {
            $is_drupal_migration = TRUE;
            break;
          }
        }
        if ($is_drupal_migration) {
          $source = $migration->get('source');
          if ($database = $this->state->get($source['database_state_key'])['database']) {
            break;
          }
        }
      }
    }

    try {
      $connection = $this->getConnection($database);
@@ -1005,7 +947,7 @@ public function submitCredentialForm(array &$form, FormStateInterface $form_stat
  }

  /**
   * Confirmation form for rollbacks, missing migrations, etc.
   * Confirmation form for missing migrations, etc.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
@@ -1019,14 +961,6 @@ public function buildConfirmForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);
    $form['actions']['submit']['#submit'] = ['::submitConfirmForm'];

    if ($rollback = $form_state->getValue('upgrade_option') == static::MIGRATE_UPGRADE_ROLLBACK) {
      $form_state->setStorage(['upgrade_option' => static::MIGRATE_UPGRADE_ROLLBACK]);
      $form['rollback'] = [
        '#markup' => $this->t('All previously imported content, as well as configuration such as field definitions, will be removed.'),
      ];
      $form['actions']['submit']['#value'] = $this->t('Perform rollback');
    }
    else {
    $form['actions']['submit']['#value'] = $this->t('Perform upgrade');

    $table_data = [];
@@ -1110,7 +1044,6 @@ public function buildConfirmForm(array $form, FormStateInterface $form_state) {
      '#title' => '<ul><li>' . $this->t('@count available upgrade paths', ['@count' => $available_count]) . '</li><li>' . $this->t('@count missing upgrade paths', ['@count' => $missing_count]) . '</li></ul>',
      '#weight' => -15,
    ];
    }

    return $form;
  }
@@ -1125,45 +1058,7 @@ public function buildConfirmForm(array $form, FormStateInterface $form_state) {
   */
  public function submitConfirmForm(array &$form, FormStateInterface $form_state) {
    $storage = $form_state->getStorage();
    if (isset($storage['upgrade_option']) && $storage['upgrade_option'] == static::MIGRATE_UPGRADE_ROLLBACK) {
      $migrations = $this->pluginManager->createInstances([]);

      // Assume we want all those tagged 'Drupal %'.
      foreach ($migrations as $migration_id => $migration) {
        $keep = FALSE;
        $tags = $migration->get('migration_tags');
        foreach ($tags as $tag) {
          if (strpos($tag, 'Drupal ') === 0) {
            $keep = TRUE;
            break;
          }
        }
        if (!$keep) {
          unset($migrations[$migration_id]);
        }
      }
      // Roll back in reverse order.
      $migrations = array_reverse($migrations);

      $batch = [
        'title' => $this->t('Rolling back upgrade'),
        'progress_message' => '',
        'operations' => [
          [
            [MigrateUpgradeRunBatch::class, 'run'],
            [array_keys($migrations), 'rollback', []],
          ],
        ],
        'finished' => [
          MigrateUpgradeRunBatch::class,
          'finished',
        ],
      ];
      batch_set($batch);
      $form_state->setRedirect('migrate_drupal_ui.upgrade');
      $this->state->delete('migrate_drupal_ui.performed');
    }
    else {
    $migrations = $storage['migrations'];
    $config['source_base_path'] = $storage['source_base_path'];
    $batch = [
@@ -1184,7 +1079,6 @@ public function submitConfirmForm(array &$form, FormStateInterface $form_state)
    $form_state->setRedirect('<front>');
    $this->state->set('migrate_drupal_ui.performed', REQUEST_TIME);
  }
  }

  /**
   * Returns all supported database driver installer objects.
+4 −30
Changes for core/modules/migrate_drupal_ui/src/MigrateUpgradeRunBatch.php: 4 added lines, 30 removed lines.
Original line number Diff line number Diff line
@@ -64,11 +64,14 @@ class MigrateUpgradeRunBatch {
   * @param int[] $initial_ids
   *   The full set of migration IDs to import.
   * @param string $operation
   *   The operation to perform, 'import' or 'rollback'.
   *   The operation to perform. Only 'import' is currently supported.
   * @param array $config
   *   An array of additional configuration from the form.
   * @param array $context
   *   The batch context.
   *
   * @todo Remove the $operation parameter and conditionals for it below, and
   *   refactor this method. https://www.drupal.org/node/2687851
   */
  public static function run($initial_ids, $operation, $config, &$context) {
    if (!static::$listenersAdded) {
@@ -78,10 +81,6 @@ public static function run($initial_ids, $operation, $config, &$context) {
        $event_dispatcher->addListener(MigrateEvents::MAP_SAVE, [static::class, 'onMapSave']);
        $event_dispatcher->addListener(MigrateEvents::IDMAP_MESSAGE, [static::class, 'onIdMapMessage']);
      }
      else {
        $event_dispatcher->addListener(MigrateEvents::POST_ROW_DELETE, [static::class, 'onPostRowDelete']);
        $event_dispatcher->addListener(MigrateEvents::MAP_DELETE, [static::class, 'onMapDelete']);
      }
      static::$maxExecTime = ini_get('max_execution_time');
      if (static::$maxExecTime <= 0) {
        static::$maxExecTime = 60;
@@ -131,9 +130,6 @@ public static function run($initial_ids, $operation, $config, &$context) {
        if ($operation == 'import') {
          $migration_status = $executable->import();
        }
        else {
          $migration_status = $executable->rollback();
        }
      }
      catch (\Exception $e) {
        static::logger()->error($e->getMessage());
@@ -149,11 +145,6 @@ public static function run($initial_ids, $operation, $config, &$context) {
              $context['sandbox']['num_processed'], 'Upgraded @migration (processed 1 item total)', 'Upgraded @migration (processed @num_processed items total)',
              ['@migration' => $migration_name, '@num_processed' => $context['sandbox']['num_processed']]);
          }
          else {
            $message = static::getTranslation()->formatPlural(
              $context['sandbox']['num_processed'], 'Rolled back @migration (processed 1 item total)', 'Rolled back @migration (processed @num_processed items total)',
              ['@migration' => $migration_name, '@num_processed' => $context['sandbox']['num_processed']]);
          }
          $context['sandbox']['messages'][] = $message;
          static::logger()->notice($message);
          $context['sandbox']['num_processed'] = 0;
@@ -222,13 +213,6 @@ public static function run($initial_ids, $operation, $config, &$context) {
            '@max' => $context['sandbox']['max'],
          ]) . "<br />\n" . $context['message'];
        }
        else {
          $context['message'] = t('Currently rolling back @migration (@current of @max total tasks)', [
            '@migration' => $migration_name,
            '@current' => $context['sandbox']['current'],
            '@max' => $context['sandbox']['max'],
          ]) . "<br />\n" . $context['message'];
        }
      }
    }
    else {
@@ -281,9 +265,6 @@ protected static function displayResults($results) {
      if ($results['operation'] == 'import') {
        drupal_set_message(static::getTranslation()->formatPlural($successes, 'Completed 1 upgrade task successfully', 'Completed @count upgrade tasks successfully'));
      }
      else {
        drupal_set_message(static::getTranslation()->formatPlural($successes, 'Completed 1 rollback task successfully', 'Completed @count rollback tasks successfully'));
      }
    }

    // If we had failures, log them and show the migration failed.
@@ -292,10 +273,6 @@ protected static function displayResults($results) {
        drupal_set_message(static::getTranslation()->formatPlural($failures, '1 upgrade failed', '@count upgrades failed'));
        drupal_set_message(t('Upgrade process not completed'), 'error');
      }
      else {
        drupal_set_message(static::getTranslation()->formatPlural($failures, '1 rollback failed', '@count rollbacks failed'));
        drupal_set_message(t('Rollback process not completed'), 'error');
      }
    }
    else {
      if ($results['operation'] == 'import') {
@@ -303,9 +280,6 @@ protected static function displayResults($results) {
        // but we didn't have failures so this is fine.
        drupal_set_message(t('Congratulations, you upgraded Drupal!'));
      }
      else {
        drupal_set_message(t('Rollback of the upgrade is complete - you may now start the upgrade process from scratch.'));
      }
    }

    if (\Drupal::moduleHandler()->moduleExists('dblog')) {