1 node.install node_update_1010()

Set all nodes to be language agnostic on mono-lingual sites.

Related topics

File

core/modules/node/node.install, line 1079
Install, update and uninstall functions for the node module.

Code

function node_update_1010() {
  $site_config = config('system.core');
  // Because this update may adversely affect sites that once were multilingual
  // but are now mono-lingual, we only apply if we're absolutely sure only a
  // single language is used, both in the configuration and in the node table.
  $language_count = $site_config->get('language_count');
  $default_langcode = $site_config->get('language_default');
  $other_languages = db_query("SELECT COUNT(langcode) FROM {node} WHERE langcode NOT IN (:list)", array(':list' => array('und', $default_langcode)))->fetchField();
  if ($language_count == 1 && $other_languages == 0) {
    db_update('node')
      ->fields(array('langcode' => 'und'))
      ->condition('langcode', $default_langcode)
      ->execute();
    db_update('url_alias')
      ->fields(array('langcode' => 'und'))
      ->condition('source', 'node/%', 'LIKE')
      ->condition('langcode', $default_langcode)
      ->execute();
  }
}