You are here

pmperson.install in Drupal PM (Project Management) 7.2

Installation and update functions for PM Person module.

File

pmperson/pmperson.install
View source
<?php

/**
 * @file
 * Installation and update functions for PM Person module.
 */

/**
 * Implements hook_install().
 */
function pmperson_install() {

  // Create user fields.
  module_load_include('inc', 'pmperson', 'includes/pmperson.migrate');
  $sandbox = array();
  pmperson_migrate_create_fields($sandbox);
}

/**
 * Implements hook_disable().
 */
function pmperson_disable() {
  drupal_set_message(t('The PM Person module has been disabled, but user fields have not been deleted.'), 'warning');
}

/**
 * Implements hook_uninstall().
 */
function pmperson_uninstall() {

  // Clean up field instances (and field) and its data.
  module_load_include('inc', 'pmperson', 'includes/pmperson.field_instance');
  module_load_include('inc', 'pmperson', 'includes/pmperson.field_base');
  $declared_field_bases = pmperson_default_field_bases();
  $declared_field_instances = pmperson_default_field_instances();
  $field_instance = field_info_instances('user', 'user');
  foreach ($declared_field_instances as $declared_instance) {
    $instance = $field_instance[$declared_instance['field_name']];
    if ($instance) {

      // Only delete field base if declared by this module.
      $delete_field_base = isset($declared_field_bases[$declared_instance['field_name']]);
      field_delete_instance($instance, $delete_field_base);
    }
  }
}

/**
 * Implements hook_update_last_removed().
 */
function pmperson_update_last_removed() {
  return 6201;
}

/**
 * Migrate PM Person nodes to fields on Drupal users.
 */
function pmperson_update_7104(&$sandbox) {
  $t = get_t();
  module_load_include('inc', 'pmperson', 'includes/pmperson.migrate');

  // Check if update could be performed.
  $link = l(PMPERSON_RESOLVE_DEPENDENCIES_LINK, PMPERSON_RESOLVE_DEPENDENCIES_LINK);
  if (pmperson_migrate_update_could_be_performed() == FALSE) {
    drupal_set_message($t('Cannot perform update. Please visit !link to check how to resolve this issue.', array(
      '!link' => $link,
    )), 'warning', FALSE);
    throw new DrupalUpdateException($t('Cannot perform update. Please visit !link to check how to resolve this issue.', array(
      '!link' => PMPERSON_RESOLVE_DEPENDENCIES_LINK,
    )));
  }
  return pmperson_migrate($sandbox);
}

/**
 * Implements hook_requirements().
 */
function pmperson_requirements($phase) {
  $requirements = array();
  if ($phase == 'update') {
    module_load_include('inc', 'pmperson', 'includes/pmperson.migrate');
    if (pmperson_migrate_update_could_be_performed() == FALSE) {
      $t = get_t();

      // Rebuild the menu to allow access to PMPERSON_RESOLVE_DEPENDENCIES_LINK.
      menu_rebuild();
      $link = l($t('migration conflicts page'), PMPERSON_RESOLVE_DEPENDENCIES_LINK);
      $requirements['pmperson_migrate'] = array(
        'title' => $t('PM Person migration'),
        'value' => $t('Migration to Drupal users cannot be performed. Resolve the conflicts listed on the !link and try again.', array(
          '!link' => $link,
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_update_dependencies().
 */
function pm_update_dependencies() {

  // pmperson_update_7103() enables pmpermission module.
  // pmperson migration depends on its completion.
  $dependencies['pmperson'][7104] = array(
    'pm' => 7103,
  );
  return $dependencies;
}

Functions