Projet

Général

Profil

Révision 3115e37e

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/i18n/i18n_field/i18n_field.module
463 463
  }
464 464
}
465 465

  
466
/**
467
 * Prime the cache to avoid single db queries for entity fields / properties.
468
 *
469
 * This is mainly uses when large operations are occuring like a flush of the
470
 * entity_property_infos().
471
 */
472
function i18n_field_prime_caches() {
473
  global $language;
474
  static $cache_primed;
475

  
476
  // Fill the cache. This should avoid single db queries when filling the
477
  // properties.
478
  if (empty($cache_primed)) {
479
    $cache_primed = TRUE;
480
    $text_group = i18n_string_textgroup('field');
481
    // Load all strings at once to avoid callbacks for each individual string.
482
    $text_group->load_strings();
483
    $text_group->multiple_translation_search(array('type' => '*', 'objectid' => '*', 'property' => '*'), $language->language);
484
  }
485
}
486

  
466 487
/**
467 488
 * Callback to translate entity property info for a fields.
468 489
 *
......
485 506
    return;
486 507
  }
487 508

  
509
  i18n_field_prime_caches();
488 510
  $name = $field['field_name'];
489 511
  $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
490 512
  $property['label'] = i18n_field_translate_property($instance, 'label', $language->language);
......
498 520
    if ($info = drupal_static('i18n_object_info')) {
499 521
      // Clean static and permanent cache of the data and then re-run the property
500 522
      // building.
501
      drupal_static_reset('entity_get_property_info');
502
      cache_clear_all('entity_property_info:' . $GLOBALS['language']->language, 'cache');
503
      entity_get_property_info();
523
      // Use a lock to avoid stampeding.
524
      $lock_name = 'i18n_field_entity_property_callback_fallback:' . $GLOBALS['language']->language;
525
      // See if another request is already doing this. If so we bail out here as
526
      // we won't help with anything at the moment.
527
      if (!lock_may_be_available($lock_name)) {
528
        return;
529
      }
530
      if (lock_acquire($lock_name)) {
531
        i18n_field_prime_caches();
532
        // Inject translated properties.
533
        $entity_property_info = entity_get_property_info();
534
        foreach ($entity_property_info as $entity_type => $properties) {
535
          if (isset($properties['bundles'])) {
536
            foreach ($properties['bundles'] as $bundle => $bundle_properties) {
537
              if ($bundle_properties['properties']) {
538
                foreach ($bundle_properties['properties'] as $bundle_property => $bundle_property_info) {
539
                  if ($instance = field_info_instance($entity_type, $bundle_property, $bundle)) {
540
                    $property = &$entity_property_info[$entity_type]['bundles'][$instance['bundle']]['properties'][$bundle_property];
541
                    $property['label'] = i18n_field_translate_property($instance, 'label', $GLOBALS['language']->language);
542
                  }
543
                }
544
              }
545
            }
546
          }
547
        }
548
        // Inject into static cache.
549
        $entity_get_property_info = &drupal_static('entity_get_property_info', array());
550
        $entity_get_property_info = $entity_property_info;
551
        // Write permanent cache.
552
        cache_set('entity_property_info:' . $GLOBALS['language']->language, $entity_property_info);
553
        lock_release($lock_name);
554
      }
504 555
    }
505 556
    else {
506 557
      watchdog('i18n_field', 'Unable to run fall-back handling for entity property translation due missing "i18n_object_info" cache', array(), WATCHDOG_WARNING);

Formats disponibles : Unified diff