Hi,
I also want to migrate, but uses custom pages nodewords D6 module (https://www.drupal.org/project/nodewords_pagetitle)
Is there any change to also migrate those..?
Thanks a lot in advance for your reply!
Greetings, Martijn

Comments

damienmckenna’s picture

Title: Drupal 6 Nodewords_Pagetitle custom token_urls upgrade » Upgrade path: Nodewords Pagetitle
Status: Active » Closed (duplicate)

This is being handled by #1281138: Upgrade path: Nodewords.

summit’s picture

Status: Closed (duplicate) » Active

Hi,
Set this to active if that's ok.
Somehow I do not see Nodewords page_title to Metatag migration?
It stops somehow here https://www.drupal.org/node/1658970#comment-9522705 , next issue is not spoken of nodewords_pagetitle anymore?
Am I missing something? Or is nodewords_pagetitle migration handled now? Than I am sorry to reopen this.

greetings and thanks for all your hard work already,
Martijn

damienmckenna’s picture

Component: Integration with other module » Importing/migrating data
Category: Support request » Feature request

There is no separate migration thing for Nodewords PageTitle, it's part of the main Nodwords importer.

summit’s picture

Hi,
Nodewords+pagetitle has the possibility to make custom metatags for specific pages.
I have in my Drupal 6 website a lot of those custom metatags.

I asume with the migration those will also be migrated then? Where can I find them then in the new D7 site?
Sorry if these questions seems stupid, but I just can't find a way to get those 500 specific page based metatags, which are administrated under custom metatags in D6 migrated.

greetings, Martijn

damienmckenna’s picture

Oh, do you mean the by-path functionality, instead of setting the title per-term or per-node?

summit’s picture

H,

Yes I am referring to this functionality!
I use it a lot within my to be migrated website.

greetings, Martijn

damienmckenna’s picture

Title: Upgrade path: Nodewords Pagetitle » Upgrade path: Nodewords Pagetitle, by-path settings

AH! Ok, now I understand. Sorry, that hasn't been done yet.

Out of interest, do you have a one-to-one relationship between the titles and the nodes? Or does it use the same title for multiple nodes?

summit’s picture

Hi, I have not added by-path per node, but more per term path
Say the term path is travel/holland/amsterdam then I have the metatags title, keywords and description of this url and all urls underneath travel/holland/amsterdam/* with these metatags

So I did not use by path functionality for nodes, but more for taxonomy term pages.
greetings, Martijn

damienmckenna’s picture

Ok, thanks, that helps understand what kinds of things we need to write a migration script for.

summit’s picture

Great! Thanks in advance!
Greetings, Martijn

GStegemann’s picture

@Martijn: the Web Links Migration has some support for Nodewords Pagetitle migration. So I assume from what I'm reading here it doesn't work for you. At least during my tests node based Pagetitles were migrated correctly.

summit’s picture

Hi Gerhard,

Yes it is working for the regular metatag pagetitle migration of Weblinks nodes. Thank you for building this Gerhard!

But next to that there was in Drupal 6 the module https://www.drupal.org/project/nodewords_pagetitle.
That module made it possible to give any path its own url, keywords and description, also using tokens. Like a token for second url term.
I used this a lot for term paths. So thats why I refer to that, and there is this issue for. Migrating by path metatags within nodewords on D6.

Sorry if this was unclear for you Gerhard.
Greetings, Martijn

summit’s picture

Hi Damien, Do you may be have a timeframe for this migration from nodewords_pagetitle to Metatag by path?

EDIT: Sorry to ask, but I have a seasonal website, and only small timeframe in autumn to migrate, otherwise I have to do it all manually..

Thanks a lot in advance for your reply!
Greetings, Martijn

summit’s picture

Hi,
I got in PM nice answers where to start...but I am not good enough a programmer to get this done.
These are the starting points..

It could be done by writing a Drush script that converts the by-path values from Nodewords / Nodewords PageTitle into Context variables. 
If there is taken a  look at metatag_context_load_default_context() one can get an idea for what the values should be, and metatag_context_config_edit_form_submit() shows how the different structures are saved.

Can anyone help with these remarks added to this issue?
In my migrationscript I have the following, thanks to Gerhard:)

/**
 * Converts the nodewords type to a metatage type or metatag config instance.
 *
 * @param $type
 *   Nodewords type.
 *
 * @return
 *   Meta tags type or configuration instance.
 */
function nodewords_migrate_type($type) {
//  define('NODEWORDS_TYPE_DEFAULT',    1);
//  define('NODEWORDS_TYPE_ERRORPAGE',  2);
//  define('NODEWORDS_TYPE_FRONTPAGE',  3);
//  define('NODEWORDS_TYPE_NONE',       0);
//  define('NODEWORDS_TYPE_NODE',       5);
//  define('NODEWORDS_TYPE_PAGE',      10);
//  define('NODEWORDS_TYPE_PAGER',      4);
//  define('NODEWORDS_TYPE_TERM',       6);
//  define('NODEWORDS_TYPE_TRACKER',    7);
//  define('NODEWORDS_TYPE_USER',       8);
//  define('NODEWORDS_TYPE_VOCABULARY', 9);
  switch ($type) {
    case 1:
      return 'global';

    case 3:
      return 'global:frontpage';

    case 5:
      return 'node';

    case 6:
      return 'taxonomy_term';

    case 8:
      return 'user';
  }

  return FALSE;
}

/**
 * Converts metatag data from nodewords to meta tags format.
 *
 * @param $type
 *   Metatag type.
 * @param $name
 *   Metatag name.
 * @param $data
 *   Metatag data in nodewords format.
 *
 * @return
 *   Metatag name and data in meta tags format if name is supported by type.
 */
function nodewords_migrate_metatag($type, $name, $data) {
  $empty = array(
    $name => array(
      'value' => '',
    ),
  );

  $default = array(
    $name => $data,
  );
  
  $structured = array(
    $name => array(
      'value' => $data,
    ),
  );

  // Format the metatag based on the type and name.
  switch ($type) {
    // Configurations.
    case 'global':
    case 'global:frontpage':
      switch ($name) {
        // @todo: Create custom meta tags if possible.
        case 'abstract':
        case 'revisit-after':
          return $default;

        // @todo: Convert robots.
        case 'robots':
          return $default;

        //case 'canonical':
        //case 'copyright':
        default:
          return $default;
      }

    // Content.
    //case 'node':
    default:
      switch ($name) {
        // @todo: Create custom meta tags if possible.
        case 'abstract':
          return $default;
          break;
        case 'revisit-after':
          return $empty;
          break;
          
        // Not supported for content.
        case 'canonical':
        case 'copyright':
          return $empty;
          break;
         
        // Robots settings
        case 'robots':
          // Robots needs some extra processing
          $robot_data = array();
          // Convert each value to display the name if it is "on" and 0 if it is off;
          foreach ($data as $robot_key => $robot_val) {
            $robot_data[$robot_key] = ($robot_val == 0 ? 0 : $robot_key);
          }
          // Return the data in the right structure
          return array( $name => array ( 'value' => $robot_data ));
          break;
          
        // Structured data types (where the value is actually more arrays)
        case 'location':
          return $structured;
          break;
          
        // Everything else
        default:
          return $default;
      }
  }
}
----
if (module_exists('metatag')) {
      /**
       * Nodewords -> Metatags.
       *
       * Mapping to the real fields in the Destination from the "fake" fields
       * in the Source row.
       */
      if (!NODEWORDS_PAGE_TITLE) {
        $this->addFieldMapping('metatag_title', 'nodeword_title');
	$this->addUnmigratedSources(array('nodeword_page_title'));
      }
      else {
        $this->addFieldMapping('metatag_title', 'nodeword_page_title');
	$this->addUnmigratedSources(array('nodeword_title'));
      }
      $this->addFieldMapping('metatag_description', 'nodeword_description');
      $this->addFieldMapping('metatag_abstract', 'nodeword_abstract');
      $this->addFieldMapping('metatag_keywords', 'nodeword_keywords');
      $this->addFieldMapping('metatag_robots', 'nodeword_robots');
      /**
       * Meta tag migration useful. Destinations to ignore.
       */
      $destinations_unmigrated = array(
        'metatag_news_keywords',
        'metatag_standout',
        'metatag_generator',
        'metatag_image_src',
        'metatag_canonical',
        'metatag_shortlink',
        'metatag_publisher',
        'metatag_author',
        'metatag_original-source',
        'metatag_revisit-after',
        'metatag_rights',
	'metatag_content-language',
      );
      $this->addUnmigratedDestinations($destinations_unmigrated);
    }
----
  if (module_exists('metatag')) {
      // Meta tag migration useful.

      /**
       * We need to pull the Nodewords from a legacy DB table that has no
       * contemporary Drupal fields.
       */
      $nodewords = $this->queryNodeWords($current_row->nid);

      /**
       * These are the ones we are interested in keeping.
       */
      $metatags = array(
        'title' => 'metatag_title',
        'page_title' => 'metatag_page_title',
        'description' => 'metatag_description',
        'abstract' => 'metatag_abstract',
        'keywords' => 'metatag_keywords',
        'robots' => 'metatag_robots',
      );
    
      /**
       * Other MetaTag options are:
       *
       * 'metatag_news_keywords',
       * 'metatag_standout',
       * 'metatag_generator',
       * 'metatag_copyright',
       * 'metatag_image_src',
       * 'metatag_canonical',
       * 'metatag_shortlink',
       * 'metatag_publisher',
       * 'metatag_author',
       * 'metatag_original-source',
       * 'metatag_revisit-after',
       * 'metatag_rights',
       */

      /**
       * Because these "fields" do not exist in the Source, we fake it.
       */
      foreach ($metatags as $key => $value) {
        if (!empty($nodewords[0]->data[$key])) {
          $current_row->{'nodeword_' . $key} = $nodewords[0]->data[$key]['value'];
        }
        else {
          if ($key == 'title') {
            $current_row->{'nodeword_' . $key} = $current_row->title;
          }
          else {
            $current_row->{'nodeword_' . $key} = '';
          }

        }
      }

      /**
       * Should page titles merged from module Page Title?
       */
      if (NODEWORDS_PAGE_TITLE && MERGE_PAGE_TITLE) {
        // Yes, attempt to merge the D6 page title
	$result_pt = Database::getConnection('default', $this->sourceConnection)
	  ->select('page_title', 'pt')
	  ->fields('pt', array('page_title'))
	  ->condition('pt.type', 'node')
	  ->condition('pt.id', $current_row->nid, '=')
          ->execute()
          ->fetchObject();

	if (is_object($result_pt) && !empty($result_pt->page_title)) {
          // Matching page title found
	  $current_row->{'nodeword_page_title'} = $result_pt->page_title;
	}
      }
    }
----
 /**
   * Helper function to get all the current Nodewords from the Legacy DB by NID.
   *
   * @param $legacy_nid
   * @return array
   */
  protected function queryNodeWords($legacy_nid) {
    $return = array();

    $query = Database::getConnection('default', $this->sourceConnection)
      ->select('nodewords', 'nw')
      ->fields('nw')
      ->condition('nw.id', $legacy_nid, '=');
    $results = $query->execute();

    // Convert nodewords data into the meta tags format.
    foreach ($results as $result) {
      $type = nodewords_migrate_type($result->type);
      $metatag = (object) array(
        'entity_type' => $type,
        'entity_id' => $result->id,
        'entity_type_id' => $result->type,
        'data' => nodewords_migrate_metatag($type, $result->name, unserialize($result->content)),
      );

      // If the metatags value is not empty.
      if (!empty($metatag->data[$result->name]['value'])) {
      
        // If a current records exists.
        if (isset($record)) {
          // If the metatag belongs to the current record.
          if ($metatag->entity_type == $record->entity_type && $metatag->entity_id == $record->entity_id) {
            // Add this metatag to the current record.
            $record->data = array_merge($record->data, $metatag->data);
          }
          else {
            // Store record and create a new one.
            $records[] = $record;
            $record = $metatag;
          }
        }
        else {
          // Create a new record.
          $record = $metatag;
        }
      }
    }
    // Add the last record to the list of records.
    $return[] = $record;

    return $return;
  }
}

See here the whole script: https://www.drupal.org/files/issues/weblinks.migrate.inc__17.txt
greetings and thanks in advance!
Martijn

summit’s picture

Hi,

Would may be the road to context gives possibility to export-import?
See my new issue on context-export module: https://www.drupal.org/node/2579381

greetings, Martijn

GStegemann’s picture

Can someone put some light into the "Nodewords Pagetitle by-path per term" feature?

As far as I know the module Nodewords Page Title is deprecated. Second, I cannot get it working on my test site due to the known API compatiblity issues, see #1301972: Deprecate Nodewords_PageTitle.

How is "Nodewords Pagetitle by-path per term" data stored? What are the rules to migrate it from D6 to D7 Metatag?