Module Metatag released and working now (but alpha).
I think support migrate SEO data to Metatag fields very usefull for all.
Any patch yet?

Files: 
CommentFileSizeAuthor
#32 metatag-n1284756-32.patch340 bytesDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]
#29 metatag-n1284756-29.patch2.45 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]
#20 1284756-20.patch889 bytesdsdeiz
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]
#15 1284756-15.patch1.59 KBdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]
#14 1284756-14.patch1.58 KBdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]
#11 migrate_support-11-1284756.patch1.69 KBsylus
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]
#6 1284756-5-ab-metatag-support.patch2.03 KBalanburke
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1284756-5-ab-metatag-support.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#2 metatag.tgz513 byteslancee

Comments

nod_’s picture

Status:Active» Closed (duplicate)

I think it's a duplicate #1312982: Meta tags support

lancee’s picture

StatusFileSize
new513 bytes
jantoine’s picture

@lancee,

Could you provide an example of how to use this your metatag.inc file? I can't figure out how to use MigrateDestinationHandlers.

Thanks!

dsdeiz’s picture

Hi, would like to try my hands on this but was wondering if I'm correctly setting the tags. When doing a node_save(), should the property $node->metatags contain array('description' => array('value' => $description), 'keywords' => array('value' => $keywords));? Was wondering cause when I checked the table that metatags created, it contains a serialized data and when I unserialize it, I got that array. This is what I have when I tried to implement it.

<?php
/**
 * Basic support for metatags.
 */

class MigrateMetatagNodeHandler extends MigrateDestinationHandler {
  public function
__construct() {
   
$this->registerTypes(array('node'));
  }

  public function
fields() {
    return array(
     
'description' => t('Node: Metatag description.'),
     
'keywords' => t('Node: Metatag keywords.'),
    );
  }

  public function
prepare($entity, stdClass $row) {
    if (
module_exists('metatag') && ($entity->description || $entity->keywords)) {
     
$entity->metatags = array();
      if (isset(
$entity->description)) {
       
$entity->metatags['description'] = array('value' => $entity->description);
      }
      if (isset(
$entity->keywords)) {
       
$entity->metatags['keywords'] = array('value' => $entity->keywords);
      }
    }
  }
}
?>
alanburke’s picture

Assigned:Unassigned» alanburke
Status:Closed (duplicate)» Needs review

Working code in this one, so reopening, and set the other as the duplicate.
Patch attached - thanks for the code.

alanburke’s picture

StatusFileSize
new2.03 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1284756-5-ab-metatag-support.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Patch attached

mikeryan’s picture

Project:Migrate Extras» Metatag
Version:7.x-2.2» 7.x-1.x-dev
Component:Migrate Extras Features» Code
Assigned:alanburke» Unassigned
Priority:Major» Normal
Status:Needs review» Needs work

This would best go into the Meta tags module itself. This patch would need the following changes:

1. Add metatag_migrate_api().
2. Rename metatag.inc to metatag.migrate.inc, so hook_migrate_api() can be found automatically.
3. Add metatag.migrate.inc to location.info.

DamienMcKenna’s picture

Thanks guys.

Leaving this as Needs Work as it also should use the APIs to identify which meta tags are available rather than hardcoding a few specific ones.

DamienMcKenna’s picture

Title:Support Metatag fields» Support Migrate module for importing data into Metatag
mjvandermeulen’s picture

@alanburke

An example is needed to understand how to use your patch #6

I'm in the same boat as AntoineSolutions:

I can't figure out how to use MigrateDestinationHandlers.

sylus’s picture

StatusFileSize
new1.69 KB
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]

Here is an updated patch that doesn't use hardcoded values and seems to work fairly well in testing.

Only problem noticed is that can't see to set title metatag as conflicts with title field. Custom Metatags work as expected.

DamienMcKenna’s picture

Ack, the page title problem sucks. I'm somewhat tempted to rename that metatag to "page_title" internally..

Manovra76’s picture

For node all it's ok, but migrate metatag in term.....not work. no message, nothing. Any idea?

damiankloip’s picture

Status:Needs work» Needs review
StatusFileSize
new1.58 KB
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]

I have cleaned up this patch a bit and removed some stuff we don't need.

I'm not sure what I'm missing with the title issue? This seems to be working OK for my purposes so far.

damiankloip’s picture

StatusFileSize
new1.59 KB
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]

Oops, sorry. A working one.

DamienMcKenna’s picture

Status:Needs review» Fixed

Committed! Good work, everyone!

Status:Fixed» Closed (fixed)

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

dsdeiz’s picture

Status:Closed (fixed)» Active

Hi! For the registerTypes bit, perhaps this can be used?

<?php
public function __construct() {
 
$types = array();
  foreach (
entity_get_info() as $entity_type => $entity_info) {
    if (isset(
$entity_info['metatags']) && $entity_info['metatags']) {
     
$types[] = $entity_type;
    }
  }

 
$this->registerTypes($types);
}
?>

This way custom entities can be supported. Also I think there's a type in metatag.api.php:

* To enable Metatag support in custom entities, add 'metatags' => TRUE to the
* entity definition in hook_entity_info(), e.g.:

Oh, and I think the classes are encouraged to be explicitly registered on 2.5 so I guess metatag_migrate_api becomes:

<?php
function metatag_migrate_api() {
 
$api = array(
   
'api' => 2,
   
'destination handlers' => array(
     
'MigrateMetatagHandler',
    ),
  );

  return
$api;
}
?>
DamienMcKenna’s picture

@dsdeiz: Thanks for noticing my #facepalm-worthy typo, I've added a new issue to handle the fix: #1886170: 'metatag'=TRUE incorrect in metatag.api.php

dsdeiz’s picture

StatusFileSize
new889 bytes
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]
dsdeiz’s picture

Status:Active» Needs review
DamienMcKenna’s picture

Status:Needs review» Fixed

Committed, thanks dsdeiz.

robbertnl’s picture

Is an example already available? Do you have to use another MigrateDestination for metatags?
For now i am just doing an dbmerge in my complete function of my import class, which uses MigrateDestinationNode. Dirty, but it works.

DamienMcKenna’s picture

Status:Fixed» Closed (fixed)

1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.

robbertnl’s picture

@#24 Does it include an example?

dsdeiz’s picture

Hi!

You have one destination for every available metatag property (or metatag "fields" - not sure what they're called). Here's an example of available fields/properties: https://www.evernote.com/shard/s276/sh/d0865c92-86ef-4fcf-bc54-a285d54a9...

It's then just a matter of mapping them e.g.:

<?php
    $this
->addFieldMapping('metatag_description', 'description');
   
$this->addFieldMapping('metatag_keywords', 'keywords');
    ...
   
$this->addFieldMapping('metatag_source', 'source');
?>
DamienMcKenna’s picture

Component:Code» Documentation
Category:feature» task
Status:Closed (fixed)» Active

Lets reopen this to add some documentation about it.

dsdeiz’s picture

Hi!

Here's a basic usage assuming the module name is metatag_migrate:

metatag_migrate.inc:

<?php
class MetatagTestMigration extends DynamicMigration {

  public function
__construct() {
   
parent::__construct();

   
$this->description = t('Migrate test.');

   
$this->map = new MigrateSQLMap(
     
$this->machineName,
      array(
       
'id' => array(
         
'type' => 'varchar',
         
'not null' => TRUE,
         
'length' => 254,
         
'description' => 'ID of record.',
        ),
      ),
     
MigrateDestinationNode::getKeySchema()
    );

   
$this->source = new MigrateSourceCSV(
     
drupal_get_path('module', 'metatag_migrate') . '/sample.csv',
      array(),
      array(
'header_rows' => TRUE)
    );

   
$this->destination = new MigrateDestinationNode('article');

   
$this->addFieldMapping('metatag_description', 'description');
   
$this->addFieldMapping('metatag_keywords', 'keywords');
  }
}
?>

metatag_migrate.migrate.inc:

<?php
/**
 * Implements hook_migrate_api().
 */
function metatag_migrate_migrate_api() {
 
$api = array(
   
'api' => 2,
   
'migrations' => array(
     
'MetatagTest' => array('class_name' => 'MetatagTestMigration'),
    ),
  );

  return
$api;
}
?>
DamienMcKenna’s picture

Status:Active» Needs review
StatusFileSize
new2.45 KB
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

This puts dsdeiz's example code into the metatag.migrate.inc file as a comment, and adds a note to the features list in README.txt to mention to look there for full details of how to use the Migrate integration.

DamienMcKenna’s picture

Status:Needs review» Fixed

Committed. Thanks for the example code, dsdeiz!

dsdeiz’s picture

Status:Fixed» Needs work
-function metatag_migrate_api() {
+function example_migrate_api() {

I think it got overridden.

DamienMcKenna’s picture

Status:Needs work» Needs review
StatusFileSize
new340 bytes
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

#facepalm moment - string replacement unchecked.

DamienMcKenna’s picture

Status:Needs review» Fixed

Committed.

DamienMcKenna’s picture

Status:Fixed» Closed (fixed)

Now that v7.x-1.0-beta7 is out, I'm closing this in the interest of keeping the issue queue clean.