You are here

function pmperson_migrate in Drupal PM (Project Management) 8

Same name and namespace in other branches
  1. 7.3 pmperson/includes/pmperson.migrate.inc \pmperson_migrate()
  2. 7.2 pmperson/includes/pmperson.migrate.inc \pmperson_migrate()

Helper function for migrating between PM Person nodes and Drupal users.

1 call to pmperson_migrate()
pmperson_update_7104 in pmperson/pmperson.install
Migrate PM Person nodes to fields on Drupal users.

File

pmperson/includes/pmperson.migrate.inc, line 12
Migration functions for the PM Person module.

Code

function pmperson_migrate(&$sandbox) {
  _pmperson_migrate_create_pmperson_node_type();

  // Create a new Drupal user for PM Person nodes that are not associated
  // with an existing Drupal user.
  if (empty($sandbox['pmperson_current_nid_of_user_being_created'])) {
    $sandbox['pmperson_current_nid_of_user_being_created'] = 0;
  }
  if (pmperson_migrate_create_users_if_required($sandbox) == FALSE) {
    $sandbox['#finished'] = 0;
    return;
  }

  // Create and attach fields to Drupal's user account.
  if (empty($sandbox['pmperson_fields_and_instance_created'])) {
    pmperson_migrate_create_fields($sandbox);
    $sandbox['#finished'] = 0.25;
    return;
  }

  // Migrate data from pmperson node to Drupal user account.
  if (empty($sandbox['pmperson_current_nid_of_field_being_migrated'])) {
    $sandbox['pmperson_current_nid_of_field_being_migrated'] = 0;
  }
  if (pmperson_migrate_field_data($sandbox) == FALSE) {
    $sandbox['#finished'] = 0.5;
    return;
  }

  // Delete all pmperson nodes.
  if (empty($sandbox['pmperson_current_nid_of_node_being_deleted'])) {
    $sandbox['pmperson_current_nid_of_node_being_deleted'] = 0;
  }
  if (pmperson_migrate_content_kill($sandbox) == FALSE) {
    $sandbox['#finished'] = 0.75;
    return;
  }

  // Delete pmperson node type.
  node_type_delete('pmperson');

  // Delete variables previously set by the PM Person module (now redundant).
  variable_del('node_options_pmperson');
  variable_del('node_permissions_pmperson');
  module_load_include('inc', 'pm', 'includes/pm.permission.migrate');
  pm_permission_migrate_execute('pmperson');
  $sandbox['#finished'] = 1;
  return 'PM Person nodes have been migrated to fields on Drupal users.';
}