Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function dealer_migrate_menu() {
- $items = array();
- $items['admin/settings/dealer-migrate'] = array(
- 'title' => 'Dealer Migrate',
- 'description' => 'Simple page to migrate old dealer info to the new site.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('_dealer_migrate_action_form'),
- 'type' => MENU_NORMAL_ITEM,
- 'access arguments' => array('access content'),
- );
- return $items;
- }
- function _dealer_migrate_action_form(&$form_state) {
- $form = array();
- $form['migrate'] = array(
- '#type' => 'submit',
- '#value' => t('Migrate Data'),
- '#submit' => array('_dealer_migrate_submit'),
- );
- $form['clear'] = array(
- '#type' => 'submit',
- '#value' => t('Clear transferred data'),
- '#submit' => array('_dealer_migrate_clear'),
- );
- return $form;
- }
- function _dealer_migrate_submit($form_id, &$form_state) {
- $conn = mysql_connect('localhost','root','root');
- mysql_select_db('oldcradlepoint');
- $locationlid = array();
- $locationdata = mysql_query("SELECT * FROM location", $conn);
- while($row = mysql_fetch_array($locationdata)) {
- $locationinsert = array(
- 'lid' => $row['lid'],
- 'street' => $row['street'],
- 'additional' => $row['additional'],
- 'city' => $row['city'],
- 'province' => $row['province'],
- 'postal_code' => $row['postal_code'],
- 'country' => $row['country'],
- 'latitude' => $row['latitude'],
- 'longitude' => $row['longitude'],
- 'source' => $row['source'],
- 'is_primary' => $row['is_primary'],
- );
- drupal_write_record('location', $locationinsert);
- $last = db_last_insert_id('location', 'lid');
- $locationlid[$row['lid']] = $last;
- }
- $newnodenids = array();
- $data = mysql_query("SELECT * FROM node WHERE type = 'dealer'", $conn);
- while($row = mysql_fetch_array($data)) {
- $vid = $row['vid'];
- $nid = $row['nid'];
- $title = $row['title'];
- $data2 = mysql_query("SELECT * FROM content_type_dealer WHERE nid = $nid LIMIT 1", $conn);
- while($row2 = mysql_fetch_array($data2)) {
- $vid = $row2['vid'];
- $nid = $row2['nid'];
- $website = $row2['field_dealer_website_url'];
- $website_title = $row2['field_dealer_website_title'];
- $phone_country_code = $row2['field_dealer_phone_country_code'];
- $phone_area_code = $row2['field_dealer_phone_area_code'];
- $phone_local_number = $row2['field_dealer_phone_local_number'];
- $phone_number = $phone_area_code.$phone_local_number;
- $newnode = new stdClass();
- $newnode->title = $title;
- $newnode->body = "";
- global $user;
- $newnode->uid = $user->uid;
- $newnode->type = 'partner_location';
- $newnode->status = 1;
- $newnode->promote = 0;
- node_save($newnode);
- // because node_save passes in $newnode by REFERENCE, it fills in additional information to the node object once it's saved into the database. Like the new NID it will get
- $new_node_nid = $newnode->nid;
- $newnodenids[$row2['nid']] = $new_node_nid;
- $insert = array(
- 'vid' => $new_node_nid,
- 'nid' => $new_node_nid,
- 'field_dealer_phone_number_number' => $phone_number,
- 'field_dealer_phone_number_country_codes' => 'us',
- 'field_dealer_website_url' => $website,
- 'field_dealer_website_title' => $website_title,
- );
- drupal_write_record('content_type_partner_location', $insert, array("vid"));
- }
- }
- $locationinstancedata = mysql_query("SELECT * FROM location_instance", $conn);
- while($row = mysql_fetch_array($locationinstancedata)) {
- $locationinstance = array(
- 'nid' => $newnodenids[$row['nid']],
- 'vid' => $newnodenids[$row['nid']],
- 'lid' => $locationlid[$row['lid']],
- );
- drupal_write_record('location_instance', $locationinstance);
- }
- }
- function _dealer_migrate_clear($form_id, &$form_state) {
- // code to clear out what you did above
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement