Gizra / og

https://www.drupal.org/project/og
92 stars 133 forks source link

Drupal 8 migration path from Drupal 6 & 7 #284

Open dharizza opened 7 years ago

dharizza commented 7 years ago

Hello! Is there any work done on an upgrade path from D6 to D8? I saw in https://github.com/Gizra/og/issues/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 commented 7 years ago

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 commented 6 years ago

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 commented 5 years ago

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

semiaddict commented 5 years ago

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_fieldinstance 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_formattersettings, and _d7_field_instance_widgetsettings 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 ogaudience 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_oggroup).

og_migrate-og_membership_type_default.zip

mradcliffe commented 5 years ago

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 commented 5 years ago

Thank you @mradcliffe.

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

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 commented 5 years ago

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.