I'm encountering an issue I'm not sure how to work around. Here's the scenario.
I have two migrations, one which imports user pictures, and another which imports users. The UserMigration depends on UserPictureMigration. But since I need to import UserPictureMigration first, I've implemented a createStub() function in UserMigration.
In that stub function, I check to see if a user exists by the ID (which in this case is email). If so, I return the existing UID. Otherwise, I create a new stub user and return its UID.
This creates a mapping record which always has rollback_action = 0. However, I want to prevent deleting certain existing users (like site admins) when rolling back my UserMigration.
I cannot find a good way to do this. In Migration::createStubWrapper(), where the stub function is called, an ID mapping is created, which uses $this->defaultRollbackAction to determine what rollback action should be associated with that mapping.
Is there a way for me to override this somehow during the stub creation process? One idea I had was in UserMigration to set the defaultRollbackAction to MigrateMap::ROLLBACK_PRESERVE, but then all the stub'd users get that value. I can override it per user in prepareRow(), but that requires me to run the UserMigration before I rollback UserPictureMigration, which means I have to also rollback UserMigration.
Any ideas?
Comments
Comment #1
mikeryanSo, I'm assuming the reason you need stubs is that users reference pictures as fields, and that you want the user's uid in the file_managed table (i.e., pictures and users have circular references), correct? migrate_d2d deals with this by migrating the files with a default uid, and having the user migration update file_managed directly with the newly-created uid. See http://cgit.drupalcode.org/migrate_d2d/tree/user.inc#n238
Comment #2
mikeryan