Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Drupal 8 migration path from Drupal 6 & 7 #284

Open
dharizza opened this issue Jun 28, 2017 · 7 comments
Open

Drupal 8 migration path from Drupal 6 & 7 #284

dharizza opened this issue Jun 28, 2017 · 7 comments
Labels

Comments

@dharizza
Copy link

Hello!
Is there any work done on an upgrade path from D6 to D8? I saw in #240 it may be required to go stable.
If it's still not implemented, I'd try to help if you point me in the right direction.
Thanks!

@pfrenssen
Copy link
Contributor

To my knowledge this is not yet being worked on inside the OG code base so if you are willing you are free to start a PR, that would be really helpful!

I know that @claudiu-cristea has been working on a migrate path from D6 to D8 for a client project that uses OG. You could have a look there for inspiration. Here are some of the relevant files:

@joachim-n
Copy link

joachim-n commented Jan 25, 2018

Here's code that another developer on my project wrote for a migrate source plugin from D6 OG memberships (the og_uid table) for migrating them to D8 Membership entities.

It's not complete, as it assumes there aren't any roles other than member and admin, but it's a good starting point :)

<?php

namespace Drupal\PROJECT_migrate\Plugin\migrate\source;

use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

/**
 * Source plugin for OG user membership data.
 *
 * Allows limiting to a particular group type with the 'node_type' configuration
 * option.
 *
 * @MigrateSource(
 *   id = "og_memberships"
 * )
 */
class OgMembership extends DrupalSqlBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
    // Get all D6 og membership records.
    $query = $this->select('og_uid', 'ou')
      ->fields('ou', ['nid', 'og_role', 'is_active', 'is_admin', 'uid', 'created', 'changed', 'last_visit']);
    $query->condition('ou.nid', 0, '<>');
    $query->condition('ou.uid', 0, '<>');

    if (isset($this->configuration['node_type'])) {
      $query->innerJoin('node', 'n', 'ou.nid = n.nid');
      $query->condition('n.type', $this->configuration['node_type']);
    }

    $query->orderBy('ou.created');
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return [
      'nid' => $this->t('The OG node ID.'),
      'og_role' => $this->t('The OG role.'),
      'is_active' => $this->t('Whether membership is active.'),
      'is_admin' => $this->t('Whether membership is admin.'),
      'uid' => $this->t('The user ID.'),
      'created' => $this->t('Membership creation time.'),
      'changed' => $this->t('Membership changed time.'),
      'last_visit' => $this->t('Membership last_visit time.'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['nid']['type'] = 'integer';
    $ids['uid']['type'] = 'integer';
    return $ids;
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    if (parent::prepareRow($row) === FALSE) {
      return FALSE;
    }

    // Add group type (network or microsite).
    $query = $this->select('node', 'n');
    $og_group_type = $query->fields('n', ['type'])
      ->condition('n.nid', $row->getSourceProperty('nid'))
      ->execute()
      ->fetchField();
    $row->setSourceProperty("og_group_type", $og_group_type);

    // Add admin role names.
    $og_roles = [];
    if ($row->getSourceProperty('is_admin')) {
      $og_roles[] = 'node-' . $og_group_type . '-administrator';
    }
    $row->setSourceProperty("og_roles", $og_roles);

    return TRUE;
  }

}

mradcliffe added a commit to mradcliffe/og that referenced this issue Oct 16, 2018
mradcliffe added a commit to mradcliffe/og that referenced this issue Oct 22, 2018
@mradcliffe
Copy link
Contributor

PR up for review and manual testing for both 6 and 7 migrations.

mradcliffe added a commit to mradcliffe/og that referenced this issue Dec 17, 2018
@semiaddict
Copy link

I am testing out the D7 migration on a fairly simple use case (one group entity type, one content entity type and one group membership type) using the og_migrate module.

Here are some notes:

  1. d7_field_instance generated the following error: Missing bundle entity, entity type og_membership_type, entity id og_membership_type_default. A non-existent config entity name returned by FieldStorageConfigInterface::getBundles(): entity type: og_membership, bundle: og_membership_type_default, field name: og_membership_request
  2. d7_field_formatter_settings, and d7_field_instance_widget_settings generated the following error: Missing bundle entity, entity type og_membership_type, entity id og_membership_type_default. (core/lib/Drupal/Core/Entity/EntityType.php:910)
  3. I had to manually check the "Group content" checkbox for the bundle under admin/structure/types/manage/TYPE to create the og_audience field before running d7_og_entity_membership

I am not sure how to go about contributing to the module.
Should I create a pull request, or add a patch as we are used to do on drupal.org ?

Attached is a patch that tries to address the issues 1 and 2 and fixes some other minor issues (module name and package name, and a typo in d7_og_group).

og_migrate-og_membership_type_default.zip

@mradcliffe
Copy link
Contributor

Thank you, @semiaddict . I am not sure either the best way of contributing on github. It would be much easier on drupal.org with the familiar patch system where anyone can contribute on an issue rather than only one person being able to contribute code on a Pull Request (without lots of finagling).

I can take a look at your zip file over on my branch, but if I forget to do so, then there are two options:

  1. If I don't have PRs enabled on my fork, then you would fork yourself, branch off my branch, and make a new PR and tests are run. On the other hand, this clutters up the pull request lists and makes it more confusing imo :(
  2. If I do have PRs enabled on my fork, then you could fork, and make a PR off of my branch. And I'd probably squash and merge. Unfortunately tests aren't run on forks. :(

@semiaddict
Copy link

Thank you @mradcliffe.

I found what was causing the og_audience field to not be created: a simple typo in the d7_og_field_instance plugin (tags should be migration_tags) !

It seems that PRs are enabled on your branch.
I will try to create a PR tomorrow with this change and those created in the patch above.

@semiaddict
Copy link

semiaddict commented Jan 25, 2019

Hi @mradcliffe.

I just created a pull request on your branch.

One thing to note: the og_migrate_migrate_prepare_row hook will not work properly with migrations created using the migrate_upgrade module unless the migration-prefix is set to empty, as any other prefix (even the default one) will alter the ids of all migrations.
I modified og_migrate_migrate_prepare_row to use the plugin id instead of the migration id to make it work with prefixed migration_upgrade exports.

mradcliffe pushed a commit to mradcliffe/og that referenced this issue Feb 18, 2019
…ation and og field migration

* Alter the default membership type bundle name in field migration rows
* Fix some typos in migration plugins and improved migration module info
* Use the source plugin id instead of the migration id in hook_migrate_prepare_row
* Replace two migration ids with their corresponding source plugin ids in og_migrate_migrate_prepare_row
* Fixed comments in hook_migrate_prepare_row
* Fix the OgFieldD7MigrateTest kernel test
* Add dependencies in the OgFieldD7MigrateTest kernel test
* Skip migrating the og_membership_request field on the default group membership type
* Fix a typo in og_migrate_migrate_prepare_row
* Fix and improve handling default membership type in og_migrate_migrate_prepare_row
* Fix a couple of coding standard issues and add assetions for the form and view displays of the default membership type
mradcliffe added a commit to mradcliffe/og that referenced this issue Feb 18, 2019
mradcliffe added a commit to mradcliffe/og that referenced this issue Feb 18, 2019
mradcliffe added a commit to mradcliffe/og that referenced this issue Feb 18, 2019
mradcliffe added a commit to mradcliffe/og that referenced this issue Mar 27, 2019
@MPParsley MPParsley changed the title Migrate path Drupal 8 migration path May 11, 2019
@MPParsley MPParsley changed the title Drupal 8 migration path Drupal 8 migration path from Drupal 6 & 7 May 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants