diff --git a/metatag.install b/metatag.install index cbeef58..d6b7315 100644 --- a/metatag.install +++ b/metatag.install @@ -201,7 +201,9 @@ function metatag_schema() { */ function metatag_install() { drupal_set_message(t("Thank you for installing the Metatag module. It is recommended to read the module's README.txt file as there are some known issues that may afffect this site.", array('!url' => url(drupal_get_path('module', 'metatag') . '/README.txt')))); -} + // Convert old records from the Page Title module. + metatag_update_7016(); + } /** * Implements hook_uninstall(). @@ -914,3 +916,38 @@ function metatag_update_7015() { // Add the new primary key. db_add_primary_key('metatag', array('entity_type', 'entity_id', 'revision_id', 'language')); } + +/** + * Migrate data from the page_title module, if available. + */ +function metatag_update_7016() { + if (db_table_exists('page_title')) { + $converted = 0; + $suffix = ' | [site:name]'; + $page_titles = db_select('page_title', 'pt') + ->fields('pt', array('type', 'id', 'page_title')) + ->execute(); + + // Loop over each of the page_title records. + while ($pt_data = $page_titles->fetchObject()) { + // Load any possible existing meta tags for this object. + $existing_data = metatag_metatags_load_multiple($pt_data->type, array($pt_data->id)); + if (!empty($existing_data)) { + foreach ($existing_data[$pt_data->id] as $tag => $value) { + $existing_data[$pt_data->id] = array( + $tag => array( + 'value' => $value, + ), + ); + } + } + $existing_data[$pt_data->id]['title']['value'] = trim($pt_data->page_title) . $suffix; + metatag_metatags_save($pt_data->type, $pt_data->id, $existing_data[$pt_data->id]); + $converted += db_delete('page_title') + ->condition('type', $pt_data->type) + ->condition('id', $pt_data->id) + ->execute(); + } + drupal_set_message(t('Meta tag: Migrated !count record(s) from the Page Title module.', array('!count' => $converted))); + } +} \ No newline at end of file