In views you can add a "Global: Custom text" field that uses Token module to build a field using placeholders. I made one of these in the view for a TW base table but that particular field isn't present in the options for Migrate. :(

CommentFileSizeAuthor
#12 migrate.module.patch1.6 KBwapnik
#9 migrate.module.patch1.56 KBwapnik

Comments

mikeryan’s picture

OK, I'll have to look at it... But, off the top of my head, Migrate operates by pulling the db query for the view, altering it to join the map and message tables, then executing it. The custom text thing almost certainly is something Views applies after running the query, so this may take some work. With a little luck, maybe it's as simple as calling one Views function to invoke the right handler...

robertdouglass’s picture

It's a problem worth solving. It might be the inroad to us being able to write more complex handlers that do complicated logic while importing. Then again, it might be simpler to create our own handlers that get specified during mapping.

mikeryan’s picture

Category: bug » feature
Priority: Normal » Minor

I've looked more closely, and while I haven't worked out exactly how to obtain such fields from Views, it's clear that implementing this would require quite a bit of work - the central processing loop in migrate_content_process() would need redesign. This isn't something I foresee taking on in the forseeable future, but if someone else can come up with a patch I'll add it.

kle’s picture

What a pity.

Really - this would be very great - but I'm not able to write a patch.

Anyway - a wonderful module.

dww’s picture

Just found this issue. I need this functionality, too. ;) I've got an old customer database with first and last names. I made a little custom text field in my view to glue them together into a single field I wanted to use for the Drupal username field, but alas, no go. I guess I'll just have to do the munging myself in hook_migrate_prepare_user()...

mikeryan’s picture

Also note that this applies to field rewriting.

mathieu’s picture

Indeed this would be great, for all the stated reasons. I did the same thing as dww for the same issue... and then found my way here. Unfortunately, I don't think I can do anything about it.

rogerpfaff’s picture

subscribe

wapnik’s picture

Status: Active » Needs review
StatusFileSize
new1.56 KB

Patch here for 1.x-dev. This isn't a solution that a views developer would actually like, but works for me (partially). There are some problems with it and things that must be decide, like telling the view somehow not to rewrite <tag> to &lt;tag&gt;. I'm not sure if it's not an issue for the table wizard. Or migrating datetimes, which worked when importing directly from the query. The view is messing these dates.

I'm not sure if this is the right direction.
What do you think?

wapnik’s picture

no feedback?

mikeryan’s picture

Status: Needs review » Needs work

That patch kills the itemlimit support.

wapnik’s picture

Status: Needs work » Needs review
StatusFileSize
new1.6 KB

here is a fix

mikeryan’s picture

Status: Needs review » Fixed

I've committed this patch - I hope people will give the dev build a try before we cut a new (final?) release of Migrate 1.

Thanks.

wapnik’s picture

Status: Fixed » Needs work

I think this is not finished yet.

The issue with bad dates solved here, but as i have mentioned here before, there is still a problem that views are encoding the content of fields with check_plain($value) when rendering strings by default (views_handler_field). I think we don't want to leave it like that.

I see two solutions for that:

  1. Bruteforce apply decode_entities($field) function on rendered fields before pushing results to the database.
  2. Or bundling the table wizard with a handler that will render the content without check_plain.

What do you think, which way to go?

Anonymous’s picture

This patch causes HTML entities to be encoded (like wapnik says in #14) and it also formats the primary key of my table as a number with a comma.

WD php: User warning: Duplicate entry '1' for key 'PRIMARY'                                                                                    [error]
query: INSERT INTO migrate_map_story
              (sourceid, destid, needs_update)
              VALUES('1,977', 2778, 0) in _db_query() (line 141 of drupal/includes/database.mysqli.inc).
mikeryan’s picture

Should've tested more thoroughly, I've reverted to the previous version of migrate.module.

The entity encoding thing is probably the tip of the iceberg, I wouldn't count on that being the only case where Views munges things.

wapnik’s picture

and the answer on my question please? your opinion

mikeryan’s picture

Well, no - this probably isn't the only thing affected, hacking a work-around for it is not how I would go. I would go back to the drawing board and not run the results through Views rendering.

wapnik’s picture

Status: Needs work » Needs review

Another try for solving this using a different handler in Table wizard issue #770472.

aLearningGuy’s picture

I'm guessing this is the same problem here for views_customfield?

aLearningGuy’s picture

it aint pretty, but here's my work around - make your view, use your custom shiz and then use views_bonus to create a csv feed. and export that file - then import your csv file into your database as a custom table - use table wizard to analyze it and you should now have everything you need to successfully complete the import...

If someone understands what I am saying here and it works for them - and you can explain it more clearly than I am here please feel free to do so :)

texas-bronius’s picture

@whoisrobertpope wow, I think you might be onto something here.. Is that really the best way? I hear tell of Data + Migrate, but nothing concrete.

To whom it may concern: I have created the most beautiful migration view with all my original table fields and a pair of customfield fields to handle perfect many:1 mapping of old-system Event Type IDs to Drupal taxonomy terms, but as is pointed out in this thread, Migrate won't hear of it. I will try the import -> massage -> export -> import suggested by whoisrobertpope as a next stab.

aLearningGuy’s picture

don't forget you may need to set a primary key in the DB in order to use your re-imported table in a view :)

texas-bronius’s picture

@whoisrobertpope Just a follow-up.. Your backwoods workaround worked like a charm! I used Talend Open Studio to create the iterim import table so I wouldn't have to worry about column names and whatnot.

mikeryan’s picture

Status: Needs review » Closed (won't fix)

Migrate V1 is in bugfix-only mode, no new features will be added.