It would useful if the og_membership.inc MigrateDestinationOGMembership called the prepare() function right before the og_membership is saved and the complete() function after the roles are created in the import() function. This would be useful and also keep inline with the migrate conventions of commonly implemented functions. See other Migrate destination plugins import() functions for examples.

Files: 
CommentFileSizeAuthor
#16 MigrateDestinationOGMembership_missing_calls-1884874-7973501.patch4.41 KBLSU_JBob
PASSED: [[SimpleTest]]: [MySQL] 894 pass(es).
[ View ]
#12 MigrateDestinationOGMembership_missing_calls-1884874-2.patch3.33 KBAngry Dan
PASSED: [[SimpleTest]]: [MySQL] 846 pass(es).
[ View ]
#8 MigrateDestinationOGMembership_missing_calls-1884874-1.patch2.55 KBsvilleintel
PASSED: [[SimpleTest]]: [MySQL] 745 pass(es).
[ View ]
#8 webform.inc_.txt9.02 KBsvilleintel
#8 menu_links.inc_.txt9.39 KBsvilleintel
#8 menu.inc_.txt5.37 KBsvilleintel
#7 destination.txt3.35 KBsvilleintel
#7 entity.txt5.57 KBsvilleintel
#4 MigrateDestinationOGMembership_missing_calls-1884874-0.patch1.26 KBsvilleintel
PASSED: [[SimpleTest]]: [MySQL] 745 pass(es).
[ View ]

Comments

Title:MigrateDestinationOGMembership prepare() call missingMigrateDestinationOGMembership prepare() and complete() calls missing

Patch please :)

I just had a brief play with it before and noticed its not a matter of a simple
$this->complete($entity, $row); The class needs to extend MigrateDestinationEntity and not MigrateDestination. I will try write up and add a patch tomorrow morning.

Status:Active» Needs review
StatusFileSize
new1.26 KB
PASSED: [[SimpleTest]]: [MySQL] 745 pass(es).
[ View ]

So i have attached a patch which now makes MigrateDestinationOGMembership extend MigrateDestinationEntity rather than MigrateDestination. Note: MigrateDestinationEntity extends MigrateDestination.

I noticed that some other destinations in Migrate such as menu and menu_links etc extend MigrateDestination directly and have their own implementation of prepare() and complete() very similar to MigrateDestinationEntity. Rather than re-using code i thought it would make more sense just to extend MigrateDestinationEntity and in this way it will use this classes prepare() and complete().

If anyone thinks it would be better to leave the class extend MigrateDestination and include prepare() and complete() functions like menu.inc (MigrateDestinationMenu) and menu_links.inc (MigrateDestinationMenuLinks) please let me know or write a patch. Other wise i think this way is fine.

+++ b/includes/migrate/plugins/destinations/og_membership.incundefined
@@ -8,7 +8,11 @@
+    ¶

Trailing space.

+++ b/includes/migrate/plugins/destinations/og_membership.incundefined
@@ -8,7 +8,11 @@
+  public function __construct($bundle = 'og_membership_type_default', array $options = array()) {

Just to understand - why hardcode the default value of the bundle?

I was not entirely sure on the bundle to be honest and as I believe the parent class MigrateDestinationEntity requires a bundle to be specified in the constructor. I also thought that if anyone else was instantiating the class in their code with just new MigrateDestinationOGMembership() then atleast it will still hopefully continue to work. I must admit though I'm not entirely sure on what the default bundle is or if it should have one. Perhaps someone such as yourself would have a better understanding of the working internals of og and be able to help out.

Sorry about the trailing space.

StatusFileSize
new5.57 KB
new3.35 KB

Attached is the MigrateDestinationEntity class. As you can see it already has the complete() and prepare() functions aswell as other helper functions implemented. You can also see here how i was mentioning the constructor requires a bundle.

The other way to do this and avoid specifying any bundle is to leave MigrateDestinationOGMembership extend MigrateDestination, (and like some other destination plugins such as menu and menu_links in the Migrate module) is to just implement the code directly into the MigrateDestinationOGMembership class ourselves. This code was taken from menu.inc and menu_links.inc destinations

  /**
   * Implementation of MigrateDestination::prepare().
   */
  public function prepare($menu, stdClass $row) {
    // We do nothing here but allow child classes to act.
    $migration = Migration::currentMigration();
    $menu->migrate = array(
      'machineName' => $migration->getMachineName(),
    );
    // Call any general handlers.
    migrate_handler_invoke_all('menu', 'prepare', $menu, $row);
    // Then call any prepare handler for this specific Migration.
    if (method_exists($migration, 'prepare')) {
      $migration->prepare($menu, $row);
    }
  }
  public function complete($menu, stdClass $row) {
    // We do nothing here but allow child classes to act.
    $migration = Migration::currentMigration();
    $menu->migrate = array(
      'machineName' => $migration->getMachineName(),
    );
    // Call any general handlers.
    migrate_handler_invoke_all('menu', 'complete', $menu, $row);
    // Then call any complete handler for this specific Migration.
    if (method_exists($migration, 'complete')) {
      $migration->complete($menu, $row);
    }
  }

As you can see the code is very similar to that of MigrateDestinationEntity and such we could avoid code re-use by inheriting from that class. Im happy either way. If you think its best we dont have a bundle then ill leave MigrateDestinationOGMembership extend MigrateDestination and write a patch including these two functions. Otherwise we could use the patch i uploaded above.

Please let me know your thoughts.

StatusFileSize
new5.37 KB
new9.39 KB
new9.02 KB
new2.55 KB
PASSED: [[SimpleTest]]: [MySQL] 745 pass(es).
[ View ]

This is a patch that implements the second way I was mentioning and still lets MigrateDestinationOGMembership extend MigrateDestination without having to specify a bundle. The class now has its own prepare() and complete() functions which prepare handlers before calling any user implemented prepare() and complete() functions. I base this on other destination migrations implementations see attached.

Status:Needs review» Fixed

Committed, thanks.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Title:MigrateDestinationOGMembership prepare() and complete() calls missingMigrateDestinationOGMembership should extend MigrateDestinationEntity
Status:Closed (fixed)» Needs work

Svilleintel, you were closer with your first patch. MigrateDestinationOGMembership should extend MigrateDestinationEntity because og_membership's are entities - just like any node, taxonomy term or user.

You were also correct with your bundle choice. It's a bit of an over simplification of the way things are done in OG, but more than sufficient for now. Rather than use the text, I'd suggest the constant OG_MEMBERSHIP_TYPE_DEFAULT instead though.

+1 for the approach in your original patch to be committed.

Status:Needs work» Needs review
StatusFileSize
new3.33 KB
PASSED: [[SimpleTest]]: [MySQL] 846 pass(es).
[ View ]

Following my Angry Dan style comment yesterday, I've created a new patch which correctly extends MigrateDestinationEntity, drops the extra methods and includes proper field handling.

IF we're already there, shouldn't it extend MigrateDestinationEntityAPI?

That would put an unnecessary dependency on Migrate Extras, a module by it's very principle which needs to be considered deprecated.

What are the benefits of MigrateDestinationEntityAPI over MigrateDestinationEntity that we would see when migrating OG memberships?

I tired out the patch in #12 and am still getting an error after trying to import group memberships. I have all the fields set defined in the fields in MigrateDestinationOGMembership

Error I get is "Missing bundle property on entity of type og_membership"

StatusFileSize
new4.41 KB
PASSED: [[SimpleTest]]: [MySQL] 894 pass(es).
[ View ]

I updated Angry Dan's patch to include a "type" field. "Type" refers to the entity type for OG Membership entites, whereas "entity_type" refers to the related entity's type (a user) and "group_type" refers to the type of the group entity (node).

Issue summary:View changes

forgot to mention the missing complete() function also