You are here

function lingotek_migration_3 in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.7 lingotek.util.inc \lingotek_migration_3()
  2. 7.2 lingotek.util.inc \lingotek_migration_3()
  3. 7.3 lingotek.util.inc \lingotek_migration_3()
  4. 7.5 lingotek.util.inc \lingotek_migration_3()
  5. 7.6 lingotek.util.inc \lingotek_migration_3()

Migration 3 - Upgrade lingotek table entries from drupal_codes to lingotek_locales (whenever applicable)

2 calls to lingotek_migration_3()
lingotek_cleanup_utility in ./lingotek.util.inc
Clean-up utility
lingotek_update_7211 in ./lingotek.install
Upgrade lingotek table entries from drupal_codes to lingotek_locales

File

./lingotek.util.inc, line 1249
Utility functions.

Code

function lingotek_migration_3() {
  $ret = array();
  $field_name_prefix = 'target_sync_status_';
  $result = db_query("SELECT lingokey, COUNT(*) as num FROM {lingotek} WHERE lingokey LIKE :pattern GROUP BY lingokey", array(
    ':pattern' => db_like($field_name_prefix) . '%',
  ));
  $total_affected_rows = 0;
  foreach ($result as $record) {
    $old_key = $record->lingokey;
    $code = @end(explode("_", $old_key));
    $lingotek_locale = Lingotek::convertDrupal2Lingotek($code, FALSE);

    //will return FALSE when lingotek_locales are passed in (so, they'll be skipped)
    if ($lingotek_locale) {
      $new_key = $field_name_prefix . $lingotek_locale;

      //dpm($old_key . " => " . $new_key);
      $query = db_update('lingotek', $ret)
        ->fields(array(
        'lingokey' => $new_key,
      ))
        ->condition('lingokey', $old_key, '=');
      try {
        $affected_rows = $query
          ->execute();
      } catch (PDOException $e) {

        // skip these:  manually delete for later rows that key violation constraint issues (if it already exists it need not succeed)
        $affected_rows = 0;
      }
      $total_affected_rows += $affected_rows;
    }
    else {

      //dpm("skip: ".$old_key);
    }
  }
  $ret['total_affected_rows'] = $total_affected_rows;

  //drupal_set_message("fields updated");
  return $ret;
}