Mercurial > hg > isophonics-drupal-site
comparison core/scripts/update-countries.sh @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
6 * Updates CLDR codes in CountryManager.php to latest data. | 6 * Updates CLDR codes in CountryManager.php to latest data. |
7 * | 7 * |
8 * We rely on the CLDR data set, because it is easily accessible, scriptable, | 8 * We rely on the CLDR data set, because it is easily accessible, scriptable, |
9 * and in the right human-readable format. | 9 * and in the right human-readable format. |
10 */ | 10 */ |
11 | |
12 use Drupal\Core\Locale\CountryManager; | |
11 | 13 |
12 // Determine DRUPAL_ROOT. | 14 // Determine DRUPAL_ROOT. |
13 $dir = dirname(__FILE__); | 15 $dir = dirname(__FILE__); |
14 while (!defined('DRUPAL_ROOT')) { | 16 while (!defined('DRUPAL_ROOT')) { |
15 if (is_dir($dir . '/core')) { | 17 if (is_dir($dir . '/core')) { |
43 // Read in existing codes. | 45 // Read in existing codes. |
44 // @todo Allow to remove previously existing country codes. | 46 // @todo Allow to remove previously existing country codes. |
45 // @see https://www.drupal.org/node/1436754 | 47 // @see https://www.drupal.org/node/1436754 |
46 require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManagerInterface.php'; | 48 require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManagerInterface.php'; |
47 require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php'; | 49 require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php'; |
48 $existing_countries = \Drupal\Core\Locale\CountryManager::getStandardList(); | 50 $existing_countries = CountryManager::getStandardList(); |
49 $countries = $existing_countries; | 51 $countries = $existing_countries; |
50 | 52 |
51 // Parse the source data into an array. | 53 // Parse the source data into an array. |
52 $data = json_decode(file_get_contents($uri)); | 54 $data = json_decode(file_get_contents($uri)); |
53 | 55 |
54 foreach ($data->main->en->localeDisplayNames->territories as $code => $name) { | 56 foreach ($data->main->en->localeDisplayNames->territories as $code => $name) { |
55 // Use any alternate codes the Drupal community wishes to. | 57 // Use any alternate codes the Drupal community wishes to. |
56 $alt_codes = array( | 58 $alt_codes = [ |
57 // 'CI-alt-variant', // Use CI-alt-variant instead of the CI entry. | 59 // 'CI-alt-variant', // Use CI-alt-variant instead of the CI entry. |
58 ); | 60 ]; |
59 if (in_array($code, $alt_codes)) { | 61 if (in_array($code, $alt_codes)) { |
60 // Just use the first 2 character part of the alt code. | 62 // Just use the first 2 character part of the alt code. |
61 $code = strtok($code, '-'); | 63 $code = strtok($code, '-'); |
62 } | 64 } |
63 | 65 |
64 // Skip any codes we wish to exclude from our country list. | 66 // Skip any codes we wish to exclude from our country list. |
65 $exclude_codes = array( | 67 $exclude_codes = [ |
66 'EU', // The European Union is not a country. | 68 // The European Union is not a country. |
67 'ZZ', // Don't allow "Unknown Region". | 69 'EU', |
68 ); | 70 // Don't allow "Unknown Region". |
71 'ZZ', | |
72 ]; | |
69 if (in_array($code, $exclude_codes)) { | 73 if (in_array($code, $exclude_codes)) { |
70 continue; | 74 continue; |
71 } | 75 } |
72 | 76 |
73 // Ignore every territory that doesn't have a 2 character code. | 77 // Ignore every territory that doesn't have a 2 character code. |
93 } | 97 } |
94 | 98 |
95 // Replace the actual PHP code in standard.inc. | 99 // Replace the actual PHP code in standard.inc. |
96 $file = DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php'; | 100 $file = DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php'; |
97 $content = file_get_contents($file); | 101 $content = file_get_contents($file); |
98 $content = preg_replace('/(\$countries = array\(\n)(.+?)(^\s+\);)/ms', '$1' . $out . '$3', $content); | 102 $content = preg_replace('/(\$countries = \[\n)(.+?)(^\s+\];)/ms', '$1' . $out . '$3', $content, -1, $count); |
99 file_put_contents($file, $content); | 103 file_put_contents($file, $content); |