You are here

function tmgmt_smartling_update_8004 in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 tmgmt_smartling.install \tmgmt_smartling_update_8004()
  2. 8 tmgmt_smartling.install \tmgmt_smartling_update_8004()
  3. 8.2 tmgmt_smartling.install \tmgmt_smartling_update_8004()

Migrate users from fake xml (html) to new xml format.

File

./tmgmt_smartling.install, line 76
Update function for the tmgmt_smartling module.

Code

function tmgmt_smartling_update_8004() {
  $translator_ids = \Drupal::configFactory()
    ->listAll('tmgmt.translator');
  foreach ($translator_ids as $id) {
    $config = \Drupal::configFactory()
      ->getEditable($id);
    if ($config && $config
      ->get('plugin') === 'smartling' && $config
      ->get('settings')['export_format'] === 'html') {
      $config
        ->set('settings.export_format', 'xml')
        ->save(TRUE);
    }
  }

  // There are might be affected titles with encoded special chars. Fix it.
  \Drupal::database()
    ->update('node_field_data', [
    'allow_delimiter_in_query' => TRUE,
  ])
    ->expression('title', "REPLACE(title, '&', '&')")
    ->condition('title', '%&%', 'LIKE')
    ->condition('langcode', 'en', '!=')
    ->execute();
  \Drupal::database()
    ->update('node_field_revision', [
    'allow_delimiter_in_query' => TRUE,
  ])
    ->expression('title', 'REPLACE(title, \'&\', \'&\')')
    ->condition('title', '%&%', 'LIKE')
    ->condition('langcode', 'en', '!=')
    ->execute();
}