You are here

function lingotek_migration_3 in Lingotek Translation 7.6

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.4 lingotek.util.inc \lingotek_migration_3()
  5. 7.5 lingotek.util.inc \lingotek_migration_3()

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

1 call to lingotek_migration_3()
lingotek_update_7211 in ./lingotek.install
Upgrade lingotek table entries from drupal_codes to lingotek_locales

File

./lingotek.util.inc, line 1181
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;
      $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;
    }
  }
  $ret['total_affected_rows'] = $total_affected_rows;

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