You are here

function _globallink_update_7710_update_core in GlobalLink Connect for Drupal 7.7

Utility functions for update 7710. Updates the submission and document tables - Active submissions.

1 call to _globallink_update_7710_update_core()
_globallink_update_7710_update_database in ./globallink.install
Utility function for update 7710. Updates the new database tables.

File

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

Code

function _globallink_update_7710_update_core() {
  $core_subs = db_select('globallink_core', 'gc')
    ->fields('gc', array(
    'source',
    'target',
    'submission',
    'submission_ticket',
    'project_code',
  ))
    ->distinct()
    ->condition('status', 'Sent for Translations', '=')
    ->execute();
  $num = $core_subs
    ->rowCount();
  if ($num != 0) {
    foreach ($core_subs as $core_sub) {
      db_insert('globallink_submission')
        ->fields(array(
        'submission' => $core_sub->submission,
        'submission_ticket' => $core_sub->submission_ticket,
        'sub_target_lang_code' => $core_sub->target,
        'source_lang_code' => $core_sub->source,
        'project_code' => $core_sub->project_code,
        'status' => 'Sent for Translations',
        'created' => REQUEST_TIME,
        'updated' => REQUEST_TIME,
      ))
        ->execute();
      $sub_rids = db_select('globallink_submission', 'gs')
        ->fields('gs', array(
        'rid',
      ))
        ->condition('submission', $core_sub->submission, '=')
        ->condition('submission_ticket', $core_sub->submission_ticket, '=')
        ->condition('sub_target_lang_code', $core_sub->target, '=')
        ->condition('source_lang_code', $core_sub->source, '=')
        ->condition('project_code', $core_sub->project_code, '=')
        ->execute();
      foreach ($sub_rids as $sub_rid) {
        $rid = $sub_rid->rid;
      }
      $core_docs = db_select('globallink_core', 'gc')
        ->fields('gc', array(
        'nid',
        'vid',
        'type',
        'title',
        'target',
        'document_ticket',
        'status',
      ))
        ->condition('target', $core_sub->target, '=')
        ->condition('source', $core_sub->source, '=')
        ->condition('submission', $core_sub->submission, '=')
        ->condition('submission_ticket', $core_sub->submission_ticket, '=')
        ->execute();
      foreach ($core_docs as $core_doc) {
        $status = $core_doc->status;
        if ($status == 'Pending Translations') {
          $status = 'Translation Imported';
        }
        db_insert('globallink_document')
          ->fields(array(
          'submission_rid' => $rid,
          'document_ticket' => $core_doc->document_ticket,
          'entity_type' => 'node',
          'entity_type_name' => 'Node',
          'object_type' => $core_doc->type,
          'object_id' => $core_doc->nid,
          'object_parent_id' => $core_doc->nid,
          'object_version_id' => $core_doc->vid,
          'object_title' => $core_doc->title,
          'target_lang_code' => $core_doc->target,
          'target_status' => $status,
          'target_last_sent' => REQUEST_TIME,
          'target_last_updated' => REQUEST_TIME,
        ))
          ->execute();
      }
    }
  }
  $other_subs = db_select('globallink_core', 'gc')
    ->fields('gc', array(
    'source',
    'target',
    'submission',
    'submission_ticket',
    'project_code',
  ))
    ->distinct()
    ->condition('status', 'Error', '=')
    ->execute();
  $num = $other_subs
    ->rowCount();
  if ($num != 0) {
    foreach ($other_subs as $other_sub) {
      $results = db_select('globallink_submission', 'gs')
        ->fields('gs')
        ->condition('submission_ticket', $other_sub->submission_ticket, '=')
        ->condition('source_lang_code', $other_sub->source, '=')
        ->condition('sub_target_lang_code', $other_sub->target, '=')
        ->condition('submission', $other_sub->submission, '=')
        ->condition('project_code', $other_sub->project_code, '=')
        ->execute();
      $number_of_rows = $results
        ->rowCount();
      if ($number_of_rows > 0) {
        continue;
      }
      else {
        db_insert('globallink_submission')
          ->fields(array(
          'submission' => $other_sub->submission,
          'submission_ticket' => $other_sub->submission_ticket,
          'sub_target_lang_code' => $other_sub->target,
          'source_lang_code' => $other_sub->source,
          'project_code' => $other_sub->project_code,
          'status' => 'Error',
          'created' => REQUEST_TIME,
          'updated' => REQUEST_TIME,
        ))
          ->execute();
        $other_rids = db_select('globallink_submission', 'gs')
          ->fields('gs', array(
          'rid',
        ))
          ->condition('submission', $other_sub->submission, '=')
          ->condition('submission_ticket', $other_sub->submission_ticket, '=')
          ->condition('sub_target_lang_code', $other_sub->target, '=')
          ->condition('source_lang_code', $other_sub->source, '=')
          ->condition('project_code', $other_sub->project_code, '=')
          ->execute();
        foreach ($other_rids as $other_rid) {
          $o_rid = $other_rid->rid;
        }
        $other_core_docs = db_select('globallink_core', 'gc')
          ->fields('gc', array(
          'nid',
          'vid',
          'type',
          'title',
          'target',
          'document_ticket',
          'status',
        ))
          ->condition('target', $other_sub->target, '=')
          ->condition('source', $other_sub->source, '=')
          ->condition('submission', $other_sub->submission, '=')
          ->condition('submission_ticket', $other_sub->submission_ticket, '=')
          ->execute();
        foreach ($other_core_docs as $other_core_doc) {
          $status = $other_core_doc->status;
          if ($status == 'Pending Translations') {
            $status = 'Translation Imported';
          }
          db_insert('globallink_document')
            ->fields(array(
            'submission_rid' => $o_rid,
            'document_ticket' => $other_core_doc->document_ticket,
            'entity_type' => 'node',
            'entity_type_name' => 'Node',
            'object_type' => $other_core_doc->type,
            'object_id' => $other_core_doc->nid,
            'object_parent_id' => $other_core_doc->nid,
            'object_version_id' => $other_core_doc->vid,
            'object_title' => $other_core_doc->title,
            'target_lang_code' => $other_core_doc->target,
            'target_status' => $status,
            'target_last_sent' => REQUEST_TIME,
            'target_last_updated' => REQUEST_TIME,
          ))
            ->execute();
        }
      }
    }
  }
}