You are here

pmorganization.install in Drupal PM (Project Management) 7.2

PM Organization install file.

File

pmorganization/pmorganization.install
View source
<?php

/**
 * @file
 * PM Organization install file.
 */

/**
 * Implements hook_install().
 */
function pmorganization_install() {
  variable_set('node_options_pmorganization', array(
    'status',
  ));
  variable_set('pmpermission_field_org_member_reference', 'pmorganization_members');
  variable_set('pmpermission_node_pmorganization_enabled', TRUE);

  // Create and attaches fields to pmorganization content type.
  module_load_include('inc', 'pmorganization', 'includes/pmorganization.migrate');

  // Parameter $sandbox is passed as a placeholder.
  $sandbox = array();
  pmorganization_migrate_create_fields($sandbox);
}

/**
 * Implements hook_disable().
 */
function pmorganization_disable() {
  drupal_set_message(t('Nodes of type "Organization" have not been deleted on disabling Project Management Organization. Please note that they will now have reduced functionality, and will not be protected by Project Management Organization access controls.'), 'warning');
}

/**
 * Implements hook_uninstall().
 */
function pmorganization_uninstall() {
  variable_del('node_options_pmorganization');
  variable_del('pmpermission_field_org_member_reference');
  variable_del('pmpermission_node_pmorganization_enabled');

  // Clean up field instances (and field) and its data.
  module_load_include('inc', 'pmorganization', 'includes/pmorganization.field_instance');
  module_load_include('inc', 'pmorganization', 'includes/pmorganization.field_base');
  $declared_field_bases = pmorganization_default_field_bases();
  $declared_field_instances = pmorganization_default_field_instances();
  $field_instance = field_info_instances('node', 'pmorganization');
  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 pmorganization_update_last_removed() {
  return 7103;
}

/**
 * Migrate PM Organization nodes to field_api fields.
 */
function pmorganization_update_7104(&$sandbox) {
  if (!module_exists('pmpermission')) {
    module_enable(array(
      'pmpermission',
    ));
  }
  module_load_include('inc', 'pmorganization', 'includes/pmorganization.migrate');
  if (pmorganization_migrate_update_could_be_performed()) {
    return pmorganization_migrate($sandbox);
  }
}

/**
 * Implements hook_requirements().
 */
function pmorganization_requirements($phase) {
  $requirements = array();
  if ($phase == 'update') {
    $enabled = module_enable(array(
      'link',
      'email',
      'addressfield',
    ));
    if (!$enabled) {
      $t = get_t();
      $requirements['pmorganization_migrate'] = array(
        'title' => $t('PM Organization Migrate Issues'),
        'value' => $t('One or more of the required modules cannot be enabled.
          If you download the modules from Drupal.org those would be enabled automatically when update script is run.
          So Please make sure following modules are present: !link, !email & !addressfield', array(
          '!link' => l($t('link'), 'https://drupal.org/project/link'),
          '!email' => l($t('email'), 'https://drupal.org/project/email'),
          '!addressfield' => l($t('addressfield'), 'https://drupal.org/project/addressfield'),
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

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

  // pmperson_update_7104() migrates pmperson data to drupal user.
  // pmorganization migration depends on its completion.
  $dependencies['pmorganization'][7104] = array(
    'pmperson' => 7104,
  );
  return $dependencies;
}