Infojunkie on #663860-22: hook_feeds_after_parse()

One of the main uses for hook_feeds_after_parse will be to adjust item values. Today, class FeedsImportBatch does not allow to read or modify its items except through setItems() and addItem(). What's needed is either:

* A reference accessor to the items array, such as getItems() in #8 above, or
* A reference accessor to each item individually along with an iterator, or
* Making items public

Comments

alex_b’s picture

> A reference accessor to each item individually along with an iterator.

My gut is telling me that this is what we should go for. Passing each item by reference will save us an array copy - this will save us some resources when iterating through items for processing them.

kvvnn’s picture

alex_b’s picture

twistor’s picture

A reference accessor to each item individually along with an iterator.

This is no longer possible as the iterator class doesn't allow passing items by reference. So we should just make items public.

twistor’s picture

Status: Active » Needs review
infojunkie’s picture

Works for me!

infojunkie’s picture

Status: Needs review » Needs work

...but it seems patch in #4 was not made against the latest 6.x-1.x-dev. Please re-roll.

twistor’s picture

Status: Needs work » Needs review
StatusFileSize
new725 bytes
new725 bytes

Here you go.

alex_b’s picture

Status: Needs review » Needs work

#8 - great.

If we do so, we should go and make all protected items on FeedsImportBatch public and deprecate set/add/get methods.

twistor’s picture

Status: Needs work » Needs review
StatusFileSize
new14.69 KB

As you requested. The only thing I'm not sure of is $current_item and its associated shiftItem() and currentItem(). While it's pretty much the same to do:

while ($item = array_shift($batch->items)) {
  //awesome code here
}

That doesn't set current_item in the process. So what I'm thinking is leave FeedsImportBatch::shiftItem() but deprecate FeedsImportBatch::currentItem() and make current_item public. Also, the logic in currentItem() doesn't accomplish anything since array_shift will return NULL on an empty array.

twistor’s picture

This patch is currently broken because of the getRaw() methods on FeedsFileBatch and FeedsHTTPBatch. Those actually perform the reading when called. Will post another patch soon with the getRaw() method moved back.

twistor’s picture

stevetweeddale’s picture

Subscribing

alex_b’s picture

StatusFileSize
new13.36 KB

This is looking good, removed @deprecated from feedNode(). Running tests now.

alex_b’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Active

On further inspection: FeedsBatch::feedNode() should be deprecated. I never liked this weirdo anyways.

Committed to 6.x. Thank you

http://drupal.org/cvs?commit=441446

Needs port to 7.x 2.x.

alex_b’s picture

Status: Active » Patch (to be ported)
alex_b’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new7.83 KB

Deleting a lot of code. Running tests, if good, will commit asap.

alex_b’s picture

Title: FeedsImportBatch: make items accessible for modification » Make parsed items accessible for modification
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

awm’s picture

subscribe

twistor’s picture

Assigned: twistor » Unassigned