You are here

function globallink_update_7710 in GlobalLink Connect for Drupal 7.7

Upgrade from 7.x to 7.7

File

./globallink.install, line 3353
Installation file for GlobalLink module.

Code

function globallink_update_7710() {
  $schema['globallink_submission'] = array(
    'description' => 'GlobalLink Submission Table',
    'fields' => array(
      'rid' => array(
        'description' => 'The row id',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => FALSE,
      ),
      'submission' => array(
        'description' => 'The submission name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'pd_submission_id' => array(
        'description' => 'The PD submission ID',
        'type' => 'int',
        'length' => 11,
        'not null' => FALSE,
      ),
      'submission_ticket' => array(
        'description' => 'The submission ticket',
        'type' => 'varchar',
        'length' => 45,
        'not null' => TRUE,
      ),
      'source_lang_code' => array(
        'description' => 'The source language code',
        'type' => 'varchar',
        'length' => 5,
        'not null' => TRUE,
      ),
      'source_lang_name' => array(
        'description' => 'The source language name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'sub_target_lang_code' => array(
        'description' => 'The submission target language code',
        'type' => 'varchar',
        'length' => 5,
        'not null' => TRUE,
      ),
      'sub_target_lang_name' => array(
        'description' => 'The submission target language name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'project_code' => array(
        'description' => 'The project code',
        'type' => 'varchar',
        'length' => 45,
        'not null' => TRUE,
      ),
      'project_name' => array(
        'description' => 'The project name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'status' => array(
        'description' => 'The status of submission',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'created' => array(
        'description' => 'The created date',
        'type' => 'int',
        'length' => 11,
        'not null' => FALSE,
      ),
      'updated' => array(
        'description' => 'The updated date',
        'type' => 'int',
        'length' => 11,
        'not null' => FALSE,
      ),
      'due_date' => array(
        'description' => 'The due date for the submission',
        'type' => 'varchar',
        'length' => 50,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'rid',
    ),
    'indexes' => array(
      'status' => array(
        'status',
      ),
    ),
  );
  $schema['globallink_document'] = array(
    'description' => 'Globallink Document Table',
    'fields' => array(
      'rid' => array(
        'description' => 'The row id',
        'type' => 'serial',
        'unsigned' => FALSE,
        'not null' => TRUE,
      ),
      'submission_rid' => array(
        'description' => 'The submission id as foreign key',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
      ),
      'document_ticket' => array(
        'description' => 'The document ticket',
        'type' => 'varchar',
        'length' => 50,
        'not null' => FALSE,
        'default' => '',
      ),
      'entity_type' => array(
        'description' => 'The entity type',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'entity_type_name' => array(
        'description' => 'The entity type display name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'object_type' => array(
        'description' => 'the object type',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'object_type_name' => array(
        'description' => 'the object type display name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'object_id' => array(
        'description' => 'The object ID',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'object_parent_id' => array(
        'description' => 'The object parent ID',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'object_version_id' => array(
        'description' => 'The object version ID',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'object_title' => array(
        'description' => 'The object title',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'target_lang_code' => array(
        'description' => 'The target langauge code',
        'type' => 'varchar',
        'length' => 5,
        'not null' => FALSE,
      ),
      'target_status' => array(
        'description' => 'The target status',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'target_ticket' => array(
        'description' => 'The target ticket',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'target_last_sent' => array(
        'description' => 'Target was sent last',
        'type' => 'int',
        'length' => 11,
        'not null' => FALSE,
      ),
      'target_last_updated' => array(
        'description' => 'Target last updated',
        'type' => 'int',
        'length' => 11,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'rid',
    ),
    'indexes' => array(
      'submission_rid' => array(
        'submission_rid',
      ),
      'entity_type' => array(
        'entity_type',
      ),
      'target_status' => array(
        'target_status',
      ),
    ),
  );
  db_create_table('globallink_submission', $schema['globallink_submission']);
  db_create_table('globallink_document', $schema['globallink_document']);
  $delete_field_types = [
    'paragraphs',
    'entityreference',
    'list_integer',
    'list_text',
    'taxonomy_term_reference',
    'list_boolean',
    'boolean',
    'list_float',
  ];
  db_delete('globallink_field_config')
    ->condition('field_type', $delete_field_types, 'IN')
    ->execute();

  //Copy core data into submission and document
  _globallink_update_7710_update_database();

  //Updating the target language names to DB.
  $db_results = db_select('globallink_submission', 'gs')
    ->fields('gs', array(
    'sub_target_lang_code',
  ))
    ->distinct()
    ->execute()
    ->fetchAll();
  foreach ($db_results as $db_result) {
    $locale_codes = db_select('globallink_locale', 'gl')
      ->fields('gl', array(
      'drupal_locale_desc',
    ))
      ->condition('locale_code', $db_result->sub_target_lang_code, '=')
      ->execute();
    foreach ($locale_codes as $locale_code) {
      db_update('globallink_submission')
        ->fields(array(
        'sub_target_lang_name' => $locale_code->drupal_locale_desc,
      ))
        ->condition('sub_target_lang_code', $db_result->sub_target_lang_code, '=')
        ->execute();
    }
  }

  //Updating the source langauage name to DB.
  $source_lang_codes = db_select('globallink_submission', 'gs')
    ->fields('gs', array(
    'source_lang_code',
  ))
    ->distinct()
    ->execute()
    ->fetchAll();
  foreach ($source_lang_codes as $souce_lang_code) {
    $src_locales = db_select('globallink_locale', 'gl')
      ->fields('gl', array(
      'drupal_locale_desc',
    ))
      ->condition('locale_code', $souce_lang_code->source_lang_code, '=')
      ->execute();
    foreach ($src_locales as $src_locale) {
      db_update('globallink_submission')
        ->fields(array(
        'source_lang_name' => $src_locale->drupal_locale_desc,
      ))
        ->condition('source_lang_code', $souce_lang_code->source_lang_code, '=')
        ->execute();
    }
  }

  // Updating project names.
  module_load_include('inc', 'globallink', 'globallink_settings');
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_common');
  $pd4 = globallink_get_project_director_details();
  $projects = globallink_get_user_pdProjects($pd4);
  $project_codes = db_select('globallink_submission', 'gs')
    ->fields('gs', array(
    'project_code',
  ))
    ->distinct()
    ->execute();
  foreach ($project_codes as $project_code) {
    if (isset($projects[$project_code->project_code])) {
      $project_name = $projects[$project_code->project_code]->name;
      db_update('globallink_submission')
        ->fields(array(
        'project_name' => $project_name,
      ))
        ->condition('project_code', $project_code->project_code, '=')
        ->execute();
    }
  }
}