Importing ShareASale Datafeeds into Drupal Part 2

Okay, there is an issue using Node Import to import ShareASale datafeeds.

Either the datafeed itself or the import process makes characters like “&” come up as character codes. I have had the same issue before with xml files, but now is not the time to investigate, just to fix the issue.

My solution, though a little hacky, was to create a page in Drupal with the import format set to “php code” and then paste code to clean these characters.

The three tables to focus on are:

  • term_data
  • node
  • node_revisions

Here is the code:

<?php
$deletes = array (
“&” => “&”,
“‘” => “\’”,
“>” => “>”);
foreach($deletes as $remove=>$replace){
$cleantagquery = “UPDATE {term_data} SET name=REPLACE(name,’$remove’,'$replace’)”;
db_query($cleantagquery);
$cleantitlequery = “UPDATE {node} SET title=REPLACE(title,’$remove’,'$replace’) WHERE type = ‘store’”;
db_query($cleantitlequery);
$cleanrevtitlequery = “UPDATE {node_revisions} SET title=REPLACE(title,’$remove’,'$replace’)”;
db_query($cleanrevtitlequery);
$cleanrevbodyquery = “UPDATE {node_revisions} SET body=REPLACE(body,’$remove’,'$replace’)”;
db_query($cleanrevbodyquery);
}
if(mysql_error()){
echo mysql_error();
}else{
echo “Done!”;
}

?>

Of course, WordPress just changed the character entities back to the character, but you get the idea.

One Response to Importing ShareASale Datafeeds into Drupal Part 2

  • winnie says:

    this looks really good. I hope to hear more details on how you manage to import it. Perhaps you can make a video about it? :P

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>