You are here

function _pmorganization_migrate_migrate_single_node in Drupal PM (Project Management) 7.3

Same name and namespace in other branches
  1. 8 pmorganization/includes/pmorganization.migrate.inc \_pmorganization_migrate_migrate_single_node()
  2. 7.2 pmorganization/includes/pmorganization.migrate.inc \_pmorganization_migrate_migrate_single_node()

Helper function to migrate single pmorganization.

1 call to _pmorganization_migrate_migrate_single_node()
pmorganization_migrate_field_data in pmorganization/includes/pmorganization.migrate.inc
Migrate pmorganization node fields data to drupal user bundle.

File

pmorganization/includes/pmorganization.migrate.inc, line 97
Migration functions for the PM Organization module.

Code

function _pmorganization_migrate_migrate_single_node($nid, $vid, $org) {
  $node = node_load($nid, $vid);
  if ($org->currency) {
    $node->pm_currency[LANGUAGE_NONE][0]['value'] = $org->currency;
  }
  if ($org->orglanguage) {
    $node->pm_orglanguage[LANGUAGE_NONE][0]['value'] = $org->orglanguage;
  }
  if ($org->pricemode) {
    $node->pm_pricemode[LANGUAGE_NONE][0]['value'] = $org->pricemode;
  }
  if ($org->price) {
    $node->pm_price[LANGUAGE_NONE][0]['value'] = $org->price;
  }
  if ($org->email) {
    $node->pm_mail[LANGUAGE_NONE][0]['email'] = $org->email;
  }
  if ($org->www) {
    $node->pm_www[LANGUAGE_NONE][0]['url'] = $org->www;
  }
  if ($org->taxid) {
    $node->pm_taxid[LANGUAGE_NONE][0]['value'] = $org->taxid;
  }
  if ($org->phone) {
    $node->pm_phone[LANGUAGE_NONE][0]['value'] = $org->phone;
  }
  $address = array();
  if ($org->address) {
    $address['premise'] = $org->address;
  }
  if ($org->city) {
    $address['locality'] = $org->city;
  }
  if ($org->provstate) {
    $address['thoroughfare'] = $org->provstate;
  }
  if ($org->country) {
    $address['country'] = $org->country;
  }
  if ($org->zip) {
    $address['postal_code'] = $org->zip;
  }
  $type = array();
  $type['customer'] = $org->iscustomer;
  $type['provider'] = $org->isprovider;
  $i = 0;
  foreach ($type as $key => $value) {
    if ($value) {
      $node->pmorganization_type[LANGUAGE_NONE][$i]['value'] = $key;
      ++$i;
    }
  }
  if ($org->isactive) {
    $node->pm_isactive[LANGUAGE_NONE][0]['value'] = '1';
  }
  $results = db_select('pmperson', 'pmp')
    ->fields('pmp', array(
    'user_uid',
  ))
    ->condition('pmp.organization_nid', $nid)
    ->execute();
  foreach ($results as $pmperson) {
    $node->pmorganization_members[LANGUAGE_NONE][] = array(
      'target_id' => $pmperson->user_uid,
    );
  }
  node_save($node);
  if ($address) {
    $wrapper = entity_metadata_wrapper('node', $node);
    foreach ($address as $key => $value) {
      $wrapper->pm_address->{$key} = $value;
    }
    $wrapper
      ->save();
  }
  return TRUE;
}