12 July 2012

The feedapi2feeds module was provided to migrate from feedapi to feeds. It was last updated back in 2009, but continued development on the feeds module has broken the upgrade script (see issue). While it was not my approach, someone could theoretically install an old version of the feeds module, convert, and then upgrade the feeds module. I believe that this git command would shift the feeds module to the correct place: git checkout bd4aa29802998b7f4d842a26c883a8a3931f62e3

However, I had both modules functioning on a site until I could deal with the migration, which was why I was ultimately unable (or decided not) to utilize the feedapi2feeds module. Fortunately, our use case was trivial. We sync RSS feeds to nodes -- all other applications had been moved to feeds without any need for historical data.

Here is a quick drush script that migrated a data type for me quickly. It is a quick-and-dirty script that violates some standards (e.g., no use of t()) and will not be polished for contribution since there is no apparent need for it, but I've provided here in case it might be of some help.

  $sql = "SELECT nid FROM {node} WHERE type = 'feed_content_type_name' ORDER BY nid";
  foreach (db_fetch_col(db_query($sql)) as $nid) {
    // Update the feed config.
    $feed = node_load($nid);
    drush_print("Migrate $nid = " . $feed->title);
    $source = $feed->feed->url;
    $config = array(
      'FeedsHTTPFetcher' => array(
        'source' => $source
    $sql = "REPLACE INTO {feeds_source} (id, feed_nid, config, source) VALUES ('feed', %d, '%s', '%s')";
    db_query($sql, $nid, serialize($config), $source);
    drush_print("Updated the source = $source", 3);
    // Migrate the current feed items.
    $sql = "SELECT * FROM {feedapi_node_item} INNER JOIN {feedapi_node_item_feed} ON nid = feed_item_nid WHERE feed_nid = %d ORDER BY nid";
    $result = db_query($sql, $nid); 
    $cnt = 0; 
    while ($row = db_fetch_object($result)) { 
      // nid, url, timestamp, arrived, guid 
      $sql = "REPLACE INTO {feeds_node_item} (nid, id, feed_nid, imported, url, guid, hash) "   
           . "VALUES (%d, 'feed', %d, '%s', '%s', '%s', '')"; 
      db_query($sql, $row->nid, $nid, $row->arrived, $row->url, $row->guid); 
      if ($cnt % 500 == 0) { 
        drush_print("Migrated $cnt items...", 3); 
    drush_print("Migrated $cnt total items.", 3); 

blog comments powered by Disqus