Last active
August 29, 2015 13:56
-
-
Save nlively/8946578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
$content = unserialize($row->content); | |
$nodewords_data[$row->id]['data'][$row->name]['value'] = $content['value']; | |
} | |
//merge the nodeword data into the metatag data | |
foreach($nodewords_data as $entity_id => $metatag_data){ | |
$id = (int)$entity_id; | |
$node = node_load($id); | |
db_merge('metatag') | |
->key(array( | |
'entity_type' => $metatag_data['entity_type'], | |
'entity_id' => $id, | |
)) | |
->fields(array( | |
'language' => $node->language, | |
'revision_id' => $node->vid, | |
'data' => serialize($metatag_data['data']), | |
)) | |
->execute(); | |
} | |
$query = "SELECT * FROM {page_title}"; | |
$result = db_query($query); | |
foreach($result as $row) { | |
$type = ($row->type == 'term') ? 'taxonomy_term' : $row->type; | |
$metatag_data = db_query("SELECT * FROM {metatag} WHERE entity_type = :type AND entity_id = :id", array(':type' => $type, ':id' => $row->id))->fetchObject(); | |
if ($metatag_data) { | |
$data = unserialize($metatag_data->data); | |
} | |
else { | |
$metatag_data = new stdClass(); | |
$data = array(); | |
} | |
if (!is_array($data)) { | |
$data = array(); | |
} | |
$data['title']['value'] = $row->page_title; | |
$language = 'und'; | |
$revision_id = 0; | |
if ($type == 'node') { | |
$revision_id = db_query('SELECT vid FROM {node} WHERE nid = :id', array(':id' => $row->id))->fetchField(); | |
} | |
db_merge('metatag') | |
->key(array( | |
'entity_type' => $type, | |
'entity_id' => $row->id, | |
)) | |
->fields(array( | |
'language' => $language, | |
'revision_id' => $revision_id, | |
'data' => serialize($data), | |
)) | |
->execute(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment