You are here

pmperson.install in Drupal PM (Project Management) 7.3

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() {
  module_load_include('inc', 'pm', 'includes/pm.install');
  $module = 'pmperson';

  // Set standardised message.
  pm_disable_message($module, 'user accounts');
}

/**
 * Implements hook_uninstall().
 */
function pmperson_uninstall() {
  module_load_include('inc', 'pm', 'includes/pm.install');
  $module = 'pmperson';

  // Delete items created by his module.
  pm_uninstall_variables($module);
  pm_uninstall_fields($module);

  // Set standardised message.
  pm_uninstall_message($module, 'user accounts');
}

/**
 * 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