Posted by Dave Reid on September 16, 2011 at 4:44am
28 followers
| Project: | Metatag |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
| Issue tags: | D7 stable release blocker, upgrade path |
Issue Summary
The Metatag module needs to be able to automatically import settings from Nodewords during its hook_install() implementation to make the upgrade process seamless. If possible this should be included with v1.0.
Original description
Once we have reached a 1.0 release, one of the immediate tasks to be done is to work on a migration script from Nodewords for D6 to Metatags. We'll likely have to try and support both 6.x-1.x and 6.x-2.x branches. Leaving as postponed for now as this is *not* a stable release blocker.
Comments
#1
It's a separate though related issue, but I'm tempted to can the 6.x-2.x branch and just merge some of the functionality back into 6.x-1.x, without the clusterfsck :p
#2
subscribe
#3
Might I suggest that we approach this in a way that is similar to how the CCK module handles migrating d6 CCK fields to d7 fields. A dummy nodewords-7.x-1.x module can contain a nodewords_migrate submodule that will assist in migrating the data. Then uninstalling the nodewords module can cleanup old variables and database tables.
I am going to start working on this so please provide feedback if this feels like the correct approach or if there is a better way to handle this.
#4
I have been working on a project migrating a site from drupal 5 all the way to drupal 7. I have started working on a module to upgrade the nodeword data, based off the metatags_quick_import module. I haven't gotten a chance to finish a beta module but I did manage to write a quick script to move the data from the {nodeword} table to the {metatag} table.
Use this at your own risk. You should only use this if you are comfortable with php and mysql. I have only tested this for moving descriptions and keywords but it works in a pinch.
<?php//collects the nodeword data
$query ='SELECT id, type, name, content FROM {nodewords}';
$result = db_query($query);
//collect and place nodeword data in array for metatag data
foreach ($result as $row) {
$nodewords_data[$row->id]['entity_type'] = $row->type;
$nodewords_data[$row->id]['data'][$row->name]['value'] = trim(strip_tags($row->content));
}
//merg the nodeword data into the metatag data
foreach($nodewords_data as $entity_id => $metatag_data){
$id = (int)$entity_id;
db_merge('metatag')
->key(array(
'entity_type' => $metatag_data['entity_type'],
'entity_id' => $id,
))
->fields(array(
'data' => serialize($metatag_data['data']),
))
->execute();
}
?>
If you load this script into a pages body content with the php filter selected, then ping the page the data will be formatted and moved to the {metatag} table.
Hopefully this will help in some way.
#5
Hi timbhowe,
thank you very much for your code snippet. I'm still waiting for a running upgrade path for nodewords to upgrade my sites from Drupal 6 to 7.
I tried your code an have 2 problems.
1: The column "type" is a number (like 5), but the column entity_type of meta tag is a string like 'node', so I have to convert:
if ($row->type == '5')$nodewords_data[$row->id]['entity_type'] = 'node';
else
...
2. After that I run the code and see the descriptions and key words in my meta tag fields in this kind:
a:1:{s:5:"value";s:128:"...Text...";}
I don't know what a:1:{s:5:"value";s:128:" means.
Have you any idea what the problem is?
Jan
#6
Restoring proper issue details. Please leave them alone, as this is an issue set by the maintainer as a reminder to himself! Thanks. =)
#7
Hey Jan,
I'll try to answer your questions the best I can but I have some of my own that could help me better understand your situation.
1. I don't know why you would have to convert the 'node->type'. It should be pulling the 'type' field out of the {nodeword} table which is stored as a varchar(25) and refers to the type of content the meta tag is associated. You may want to take a peek at you DB or your content types machine readable names.
2. What you are seeing is a serialized array of meta tags. The way the MetaTag module store the meta tag information is in a serialized multi-dimensional array in the 'data' field stored as a longblob in the {metatag} table. It is built like so:
array(2) {["description"]=>
array(1) {
["value"]=>
string(100) "Drupal 7 with the metatag module is the best. YAH!"
}
["keywords"]=>
array(1) {
["value"]=>
string(60) "metatags, drupal, drupal 7, awsomeness"
}
}
I have only really worked with descriptions and keywords but the structure should hold true with other meta tag types supported.
I'm not really sure why you would be seeing the serialized array if you are using Drupal 7 and the Metatags module then when you go in to edit a node it should unserialized the data and place it in the correct field.
I hope this helps but if you are still having issues let me know an I'll see what I can do.
Thanks
Tim
#8
Hi Tim,
yes, i have the latest versions of drupal 6 / 7 and nodewords / meta tag.
I have (had) 3 drupal 6 sites, which I upgraded now to drupal 7 and from nodewords to meta tag with this script:
<?php
//collects the nodeword data
$query ='SELECT id, type, name, content FROM {nodewords} where name = '."'description' or name = 'keywords'";
$result = db_query($query);
//collect and place nodeword data in array for metatag data
foreach ($result as $row) {
if ($row->type == '5')
$nodewords_data[$row->id]['entity_type'] = 'node';
else
continue;
$s = trim(strip_tags($row->content));
// trim the right tags
$pos = strrpos($s, '";}');
if ($pos > 0)
{
$s = substr($s, 0, $pos);
}
// trim the left tags
$pos = strrpos($s, '"');
if ($pos > 0)
{
$s = substr($s, ($pos+1));
}
$nodewords_data[$row->id]['data'][$row->name]['value'] = $s;
// echo $s;
}
//merge the nodeword data into the metatag data
foreach($nodewords_data as $entity_id => $metatag_data){
$id = (int)$entity_id;
db_merge('metatag')
->key(array(
'entity_type' => $metatag_data['entity_type'],
'entity_id' => $id,
))
->fields(array(
'data' => serialize($metatag_data['data']),
))
->execute();
}
?>
In the attachement you can see a screenshot of my nodewords table.
Jan
#10
I have posted a potential starting point here: #1434756: Potential starting point
#11
I vote to officially get behind the Metatag Migrate module. To that aim I've requested to be made a co-maintainer.
#12
There appears to be some working code to try out, and it now includes a Drush command, I think we should try this out and merge it in as a submodule for doing the migration. Dave, whaddya think?
#13
Going to work on it this week.
#14
I've imported the code from AntoineSolutions and drupalninja99 (#1434756: Potential starting point) and pushed it up as the nodewords_migrate branch, I'll continue to work on it there.
#15
Can we have a separate project for nodewords_migrate? I think that would be easier.
#16
I want to have it included with either Nodewords or Metatag to make it easier for most people - I decided to not include it in Nodewords to avoid people thinking there'll be a D7 version, which meant it had to go in Metatag.
#17
While I understand the need to keep the core module clean, I strongly feel that the upgrade should be as seamless as possible, thus the upgrade should be triggered automatically upon installation.
#18
@DamienMcKenna Where do you stand with your progress on getting this going and what kind of ball park time frame are you looking at to have something usable?
I ask because I have a handful of sites I plan to upgrade from D6 -> D7 this winter (2012-2013) and desperately need the ability to easily migrate the metatag info. I keep holding out in hopes that this will be available but would like to have an idea on the time frame so I have a better idea of what I need to do for the upgrade.
Thanks!
Phil
#19
@philsward: A reasonable question. My #1 goal has been to make Metatag stable and then deal with migration issues; we're close to having Metatag completely stable, so I'm hoping in November to do the upgrade paths for Nodewords & Page_Title.
#20
@DamienMcKenna Sounds good! Thanks!
#21
Hopefully not hijacking the thread too much, but what's the current advised course of action? I've a D6 site that I don't know what to do with in regard to this module. Most other stuff is done and I'd like to push it live but naturally don't want to castrate my SEO work. TIA.
#22
#23
Tag.
#24
#25
I found these:
http://drupal.org/node/1165096
http://drupal.org/node/1201046
#26
FYI the sql code worked for my Drupal 6 to 7 nodewords to metatags upgrade (it populated the metatag table) BUT and a big BUT the code does not populate the language field of the metatag table and thus when viewing a page all the meta tag desc and title fields are blank.
I simply populated the language field with the letters "ind" (it means undefined I think) for all records and now it works. Perhaps some boffin can add this to the SQL code :)
#27
Hi, Undefined has the letters 'und'
Greetings, Martijn
#28
FYI I'm going to be working on this over the next week.
The first decision is: leverage the Migrate module, or just built something custom? Using Migrate means that we'd have roll-back ability, and Drush integration, but it (obviously) adds a dependency. I'll look into it.
#29
Thanks DamienMcKenna! I am just starting this migration and was planning to script the migration. However, do you have any idea how long this will take to get something we can test?
#30
I'm aiming to have something working next week.
#31
A presentation from Ken Rickard on using Migrate to import content: http://2011.drupalcampatlanta.com/session/migrating-data-drupal-7/