Projet

Général

Profil

Révision 280fe687

Ajouté par Assos Assos il y a environ 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/commerce/modules/line_item/includes/commerce_line_item.controller.inc
139 139
    }
140 140

  
141 141
    try {
142
      // First attempt to delete references for the given line items.
142
      // First attempt to delete references to each line item, building a list
143
      // of modified entities to be saved once each after references to all line
144
      // items have been deleted.
145
      $reference_fields = commerce_info_fields('commerce_line_item_reference');
146
      $modified_entities = array();
147

  
143 148
      foreach ($line_items as $line_item_id => $line_item) {
144
        commerce_line_item_delete_references($line_item);
149
        // Check the data in every line item reference field.
150
        foreach ($reference_fields as $field_name => $field) {
151
          // Query for any entity referencing the deleted line item in this field.
152
          $query = new EntityFieldQuery();
153
          $query->fieldCondition($field_name, 'line_item_id', $line_item->line_item_id, '=');
154
          $result = $query->execute();
155

  
156
          // If no results were returned, continue to next field.
157
          if (empty($result)) {
158
            continue;
159
          }
160

  
161
          // Loop over results for each type of entity returned.
162
          foreach ($result as $entity_type => $data) {
163
            // Load the entities of the current type.
164
            $entities = entity_load($entity_type, array_keys($data));
165

  
166
            // Loop over each entity and remove the reference to the deleted line item.
167
            foreach ($entities as $entity_id => $entity) {
168
              // If we have this entity already, get the reference, otherwise
169
              // store the new entity to save changes later.
170
              if (!isset($modified_entities[$entity_type . ':' . $entity_id])) {
171
                $modified_entities[$entity_type . ':' . $entity_id] = array(
172
                  'entity_type' => $entity_type,
173
                  'entity' => $entity,
174
                );
175
              }
176

  
177
              commerce_entity_reference_delete($entity, $field_name, 'line_item_id', $line_item->line_item_id);
178
            }
179
          }
180
        }
181
      }
182

  
183
      // Save the entities that were modified through deleted references.
184
      foreach ($modified_entities as $entity_data) {
185
        entity_save($entity_data['entity_type'], $entity_data['entity']);
145 186
      }
146 187

  
147 188
      return parent::delete($line_item_ids, $transaction);

Formats disponibles : Unified diff