فهرست منبع

updated CER from 7.x-2.x-dev (2013-mai-01) to 7.x-2.x-dev (2014-aoû-08)

Bachir Soussi Chiadmi 9 سال پیش
والد
کامیت
b85dc130d6

+ 35 - 11
sites/all/modules/contrib/fields/cer/cer.admin.inc

@@ -12,10 +12,18 @@ function cer_settings_form($form = array(), &$form_state) {
   $channels = array();
 
   foreach (_cer_get_fields() as $field) {
+    // A field that hasn't been instantiated yet will not have a 'bundles' key, which
+    // means it's useless to us, so skip over it.
+    if (! isset($field['bundles'])) {
+      continue;
+    }
+
     foreach ($field['bundles'] as $entity_type => $bundles) {
       foreach ($bundles as $bundle) {
         $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
-        $channels = array_merge($channels, _cer_find_channels($instance));
+        if ($instance) {
+          $channels = array_merge($channels, _cer_find_channels($instance));
+        }
        }
      }
    }
@@ -33,7 +41,7 @@ function cer_settings_form($form = array(), &$form_state) {
       $form['values']["enabled_{$count}"] = array(
         '#type' => 'checkbox',
         '#default_value' => cer_preset_enabled($formatted_key),
-        '#title' => theme('cer_label', array('key' => $key)),
+        '#title' => filter_xss(theme('cer_label', array('key' => $key))),
       );
     }
 
@@ -130,9 +138,14 @@ function cer_update_form_submit($form, &$form_state) {
     'error_message' => t('Corresponding entity references - existing entity update has encountered an error.'),
   );
 
-  $entities = entity_load($form_state['values']['type'], FALSE);
-  foreach ($entities as $entity) {
-    $batch['operations'][] = array('cer_processing_entity', array('update', $entity, $form_state['values']['type']));
+  $entity_type = $form_state['values']['type'];
+  $query = new EntityFieldQuery();
+  $query->entityCondition('entity_type', $entity_type);
+  $result = $query->execute();
+  if (isset($result[$entity_type])) {
+    foreach ($result[$entity_type] as $entity_id => $stub) {
+      $batch['operations'][] = array('cer_processing_entity', array('update', $entity_id, $entity_type));
+    }
   }
   batch_set($batch);
 }
@@ -224,17 +237,28 @@ function _cer_get_target_bundles($field) {
   // method of finding a field's target bundles.
   //
   if ($field['settings']['handler'] == 'views') {
-    $view = views_get_view($field['settings']['handler_settings']['view']['view_name']);
-    $view->set_display($field['settings']['handler_settings']['view']['display_name']);
+    $view_name = $field['settings']['handler_settings']['view']['view_name'];
 
-    $info = entity_get_info($field['settings']['target_type']);
-    if ($info['entity keys']['bundle'] && $handler = $view->display_handler->get_handler('filter', $info['entity keys']['bundle'])) {
-      $target_bundles = $handler->value;
+    $view = views_get_view($view_name);
+    if ($view) {
+      $view->set_display($field['settings']['handler_settings']['view']['display_name']);
+
+      $info = entity_get_info($field['settings']['target_type']);
+      if ($info['entity keys']['bundle'] && $handler = $view->display_handler->get_handler('filter', $info['entity keys']['bundle'])) {
+        $target_bundles = $handler->value;
+      }
+    }
+    else {
+      drupal_set_message(t('Could not get target bundles for %field (failed to load view %view).', array('%view' => $view_name, '%field' => $field['field_name'])), 'error');
     }
   }
-  else {
+  elseif (isset($field['settings']['handler_settings']['target_bundles'])) {
     $target_bundles = $field['settings']['handler_settings']['target_bundles'];
   }
+  else {
+    $info = entity_get_info($field['settings']['target_type']);
+    $target_bundles = array_keys($info['bundles']);
+  }
 
   return $target_bundles;
 }

+ 2 - 2
sites/all/modules/contrib/fields/cer/cer.info

@@ -8,9 +8,9 @@ dependencies[] = ctools
 files[] = handler.inc
 
 configure = admin/config/system/cer
-; Information added by drupal.org packaging script on 2013-05-01
+; Information added by Drupal.org packaging script on 2014-08-08
 version = "7.x-2.x-dev"
 core = "7.x"
 project = "cer"
-datestamp = "1367412087"
+datestamp = "1407528862"
 

+ 20 - 1
sites/all/modules/contrib/fields/cer/cer.install

@@ -38,4 +38,23 @@ function cer_schema() {
  */
 function cer_update_7001() {
   db_rename_table('corresponding_entity_references', 'cer');
-}
+}
+
+/**
+ * Disable presets which refer to fields that don't exist. (Issue #2122531)
+ */
+function cer_update_7002() {
+  $presets = db_query('SELECT entity_types_content_fields FROM {cer} WHERE 1')->fetchCol();
+
+  foreach ($presets as $preset) {
+    $keys = explode('*', $preset);
+    
+    $left = field_info_instance($keys[0], $keys[2], $keys[1]);
+    $right = field_info_instance($keys[3], $keys[5], $keys[4]);
+
+    if (empty($left) || empty($right)) {
+      db_query('UPDATE {cer} SET enabled = 0 WHERE entity_types_content_fields = :preset', array(':preset' => $preset));
+      drupal_set_message(t('CER preset %preset was disabled because it uses non-existent fields.', array('%preset' => $preset)), 'warning');
+    }
+  }
+}

+ 21 - 3
sites/all/modules/contrib/fields/cer/cer.module

@@ -191,7 +191,7 @@ function cer_preset_delete($key) {
  *  The operation being performed on the entity (insert, update, or delete).
  *
  * @param object $entity
- *  The entity.
+ *  The entity or the entity's id.
  *
  * @param string $entity_type
  *  The entity type.
@@ -201,6 +201,11 @@ function cer_preset_delete($key) {
  *  during bulk update) or NULL if we're not in a batch job.
  */
 function cer_processing_entity($op, $entity, $entity_type, &$context = NULL) {
+  // Load the entity if we're given an ID rather than an entity.
+  if (!is_object($entity)) {
+    $entity = entity_load($entity_type, array($entity));
+    $entity = reset($entity);
+  }
   // If the entity is of the wrong type, entity_extract_IDs() will throw
   // EntityMalformedException and rightfully bail out here.
   list (, , $bundle) = entity_extract_IDs($entity_type, $entity);
@@ -291,10 +296,23 @@ function cer_ctools_plugin_api($owner, $api) {
 function _cer_update($entity_type, $entity) {
   $entity->original = isset($entity->original) ? $entity->original : NULL;
 
+  $extract_ids = entity_extract_IDs($entity_type, $entity);
+  $id = array_shift($extract_ids);
+
   field_attach_presave($entity_type, $entity);
   field_attach_update($entity_type, $entity);
 
-  $extract_ids = entity_extract_IDs($entity_type, $entity);
-  $id = array_shift($extract_ids);
+  // Issue #2212499.
+  if ($entity_type == 'node') {
+    $entity->changed = time();
+
+    db_update('node')
+      ->fields(array(
+        'changed' => $entity->changed,
+      ))
+      ->condition('nid', $id)
+      ->execute();
+  }
+
   entity_get_controller($entity_type)->resetCache(array($id));
 }

+ 24 - 4
sites/all/modules/contrib/fields/cer/handler.inc

@@ -169,8 +169,16 @@ class CerHandler extends CerHandlerBase implements CerHandlerInterface {
   /**
    * Implements CerHandlerInterface::insert().
    */
-  public function insert() {
-    foreach ($this->getReferencedEntities() as $referenced_entity) {
+  public function insert($ids = NULL) {
+
+    if (empty($ids)) {
+      $entities = $this->getReferencedEntities();
+    }
+    else {
+      $entities = entity_load($this->remote['entity_type'], $ids);
+    }
+
+    foreach ($entities as $referenced_entity) {
       $this->reference($referenced_entity);
       _cer_update($this->remote['entity_type'], $referenced_entity);
     }
@@ -191,7 +199,11 @@ class CerHandler extends CerHandlerBase implements CerHandlerInterface {
       }
     }
 
-    $this->insert();
+    $added = array_diff($this->getLocalReferenceIDs(), $this->getReferenceIDs($original, $this->local));
+
+    if (!empty($added)) {
+      $this->insert($added);
+    }
   }
 
   /**
@@ -264,7 +276,15 @@ class CerHandler extends CerHandlerBase implements CerHandlerInterface {
       }
     }
     else {
-      throw new CerException(t('Cannot create invalid reference to remote entity.'));
+      $variables = array(
+        '!local_field' => $this->local['field_name'],
+        '!local_type' => $this->local['entity_type'],
+        '!local_id' => $this->id,
+        '!remote_field' => $this->remote['field_name'],
+        '!remote_type' => $this->remote['entity_type'],
+        '!remote_id' => $this->getRemoteEntityID($entity),
+      );
+      watchdog('cer', 'Failed to reference !remote_field on !remote_type !remote_id from !local_field on !local_type !local_id.', $variables, WATCHDOG_ERROR);
     }
   }
 

+ 2 - 2
sites/all/modules/contrib/fields/cer/tests/cer_tests.info

@@ -8,9 +8,9 @@ dependencies[] = cer
 
 files[] = crud.test
 files[] = fields.test
-; Information added by drupal.org packaging script on 2013-05-01
+; Information added by Drupal.org packaging script on 2014-08-08
 version = "7.x-2.x-dev"
 core = "7.x"
 project = "cer"
-datestamp = "1367412087"
+datestamp = "1407528862"