Overridable and reusable deduping without system variable

alex_b - July 21, 2008 - 18:06
Project:New Aggregator for Drupal core
Version:7.x-0.1-alpha2
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

Now overridable deduping depends on a special variable:

// aggregator.module
foreach ($processors as $processor) {
        if (count($processors) == 1 && $deduper != FALSE) {
          module_invoke($deduper, 'aggregator_process', 'unique', $node);
        }
        else {
          module_invoke($processor, 'aggregator_process', 'unique', $node);
        }
        $items = module_invoke($processor, 'aggregator_process', 'save', $node);

// a processor, e. g. aggregator.light.inc
case 'unique':
  // ...
  $node->feed->items[$k]->unique = ($iid == FALSE ? TRUE : $iid);

This is not necessary if all unique hooks are called before saving, and the unique flag is converted into an array of unique flags:

// aggregator.module
foreach ($processors as $processor) {
  module_invoke($processor, 'aggregator_process', 'unique', $node);
}
foreach ($processors as $processor) {
  $items = module_invoke($processor, 'aggregator_process', 'save', $node);
}

// a processor, e. g. aggregator.light.inc
case 'unique':
  // ...
  $node->feed->items[$k]->unique['aggregator_light'] = ($iid == FALSE ? TRUE : $iid);

This change makes deduping overridable and reusable for other modules without the necessity of an additional system variable. An important detail here is that the order of $processors must respect the module weights. I think at the moment it doesn't. This will allow site builders and module contributors to tweak and reuse unique flags for specific use cases.

#1

alex_b - July 21, 2008 - 18:10
Category:bug report» task
 
 

Drupal is a registered trademark of Dries Buytaert.