Changeset 8558 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php
- Timestamp:
- 03/30/2019 10:12:10 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php
r8548 r8558 134 134 } 135 135 136 $variants = $this->get_locale_variants( $locale_slug , $project_ids);136 $variants = $this->get_locale_variants( $locale_slug ); 137 137 // If there were no results for the current variant in the current project branch, it should still show it. 138 138 if ( ! in_array( $set_slug, $variants, true ) ) { … … 188 188 } 189 189 190 $sub_project s = $this->get_active_sub_projects( $sub_project, true);191 $sub_project _slugs = array();190 $sub_project_statuses = array(); 191 $sub_projects = $this->get_active_sub_projects( $sub_project, true ); 192 192 if ( $sub_projects ) { 193 $sub_project_ids = array();194 $sub_project_statuses = array();195 193 foreach ( $sub_projects as $key => $_sub_project ) { 196 $sub_project_slugs[] = $_sub_project->slug; 197 $status = $this->get_project_status( $_sub_project, $locale_slug, $set_slug, null, false ); 198 199 $sub_project_ids[] = $_sub_project->id; 200 201 $sub_project_statuses[ $_sub_project->slug ] = $status; 202 } 203 204 $variants = $this->get_locale_variants( $locale_slug, $sub_project_ids ); 205 206 unset( $sub_project_ids ); 207 } else { 208 $variants = $this->get_locale_variants( $locale_slug, array( $sub_project->id ) ); 209 } 194 $sub_project_statuses[ $_sub_project->slug ] = $this->get_project_status( 195 $_sub_project, 196 $locale_slug, 197 $set_slug, 198 null, 199 false 200 ); 201 } 202 } 203 204 $sub_project_slugs = array_keys( $sub_project_statuses ); 205 206 $variants = $this->get_locale_variants( $locale_slug ); 210 207 211 208 $locale_contributors = $this->get_locale_contributors( $sub_project, $locale_slug, $set_slug ); … … 221 218 * Whether a translation set slug exists for a locale. 222 219 * 220 * For performance reasons, this checks the wp/dev project which is the canonical 221 * source for all available and active locales. 222 * 223 223 * @param \GP_Locale $locale The locale. 224 224 * @param string $slug The slug of a translation set. … … 226 226 */ 227 227 private function translation_set_slug_exists( $locale, $slug ) { 228 /*$cache_key = "translation_set_slugs:{$locale->slug}"; 229 $slugs = wp_cache_get( $cache_key, $this->cache_group ); 230 231 if ( false === $slugs ) { 232 global $wpdb; 233 $slugs = $wpdb->get_col( $wpdb->prepare( 234 "SELECT DISTINCT(slug) FROM {$wpdb->gp_translation_sets} WHERE locale = %s", 235 $locale->slug 236 ) ); 237 238 wp_cache_set( $cache_key, $slugs, $this->cache_group, DAY_IN_SECONDS ); 239 }*/ 240 241 // Hardcoded list because the query above doesn't perform well due to a missing index. 242 $slugs = [ 243 'default' => [ 244 'default', 245 ], 246 'ca' => [ 247 'default', 248 'valencia', 249 ], 250 'de' => [ 251 'default', 252 'formal', 253 ], 254 'de-ch' => [ 255 'default', 256 'informal', 257 ], 258 'nl' => [ 259 'default', 260 'formal', 261 ], 262 'pt' => [ 263 'default', 264 'informal', 265 'ao90', 266 ], 267 ]; 268 269 if ( isset( $slugs[ $locale->slug ] ) ) { 270 return in_array( $slug, $slugs[ $locale->slug ], true ); 271 } 272 273 return in_array( $slug, $slugs['default'], true ); 228 global $wpdb; 229 230 $id = $wpdb->get_var( $wpdb->prepare( 231 "SELECT id FROM {$wpdb->gp_translation_sets} WHERE locale = %s AND slug = %s AND project_id = %d", 232 $locale->slug, 233 $slug, 234 2 // wp/dev 235 ) ); 236 237 return null !== $id; 274 238 } 275 239 … … 346 310 347 311 /** 348 * Retrieves non-default slugs of translation sets for a list of 349 * project IDs. 350 * 351 * @param string $locale Slug of a GlotPress locale. 352 * @param array $project_ids List of project IDs. 353 * @return array List of non-default slugs. 354 */ 355 private function get_locale_variants( $locale, $project_ids ) { 312 * Retrieves all slugs of translation sets for a locale. 313 * 314 * For performance reasons, this checks the wp/dev project which is the canonical 315 * source for all available and active locales. 316 * 317 * @param string $locale Slug of a GlotPress locale. 318 * @return array List of translation set slugs. 319 */ 320 private function get_locale_variants( $locale ) { 356 321 global $wpdb; 357 322 358 $project_ids = implode( ',', $project_ids ); 359 $slugs = $wpdb->get_col( $wpdb->prepare( " 360 SELECT DISTINCT slug 361 FROM {$wpdb->gp_translation_sets} 362 WHERE 363 project_id IN( $project_ids ) 364 AND locale = %s 365 ", $locale ) ); 366 367 return $slugs; 323 return $wpdb->get_col( $wpdb->prepare( 324 "SELECT slug FROM {$wpdb->gp_translation_sets} WHERE locale = %s AND project_id = %d", 325 $locale, 326 2 // wp/dev 327 ) ); 368 328 } 369 329
Note: See TracChangeset
for help on using the changeset viewer.