I'm currently using Feeds to import events from an iCal source, and using Feeds Tamper / rewrite plugin to pass some static values to the created nodes. However, it's now giving the following error, causing the import to fail:
An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /drupal/batch?id=225&op=do StatusText: Service unavailable (with message) ResponseText: Recoverable fatal error: Object of class FeedsDateTime could not be converted to string in feeds_tamper_rewrite_callback() (line 45 of /var/www/html/techwrap.co.uk/drupal/sites/all/modules/feeds_tamper/plugins/rewrite.inc).
These are not date or time fields, but links, plain text and location fields. Disabling all the fields set to rewrite in Tamper solves the issue, but strangely I have one field set to rewrite a static term into a node reference field, and that works without any problem. Other plugins also work fine.
I've tried different versions of Feeds Tamper, Feeds and Date iCal. Also tried usual tricks of deleting / recreating importers.
Comment | File | Size | Author |
---|---|---|---|
#7 | feeds-datetime-stringable-2225019-7.patch | 2.96 KB | twistor |
#6 | feeds-datetime-stringable-2225019-6.patch | 2.96 KB | twistor |
Comments
Comment #1
twistor CreditAttribution: twistor commentedCan you give me some information about your setup?
I can't reproduce this.
Comment #2
RedEight CreditAttribution: RedEight commentedI'm experiencing the same error. After tracking down the issue, here is what is happening. Feeds Tamper, in feeds_tamper/plugins/rewrite.inc line 45 calls strtr(). strtr() is a function defined in php for string translation with two implementations. The implementation used by Feeds Tamper is strtr( string, array). The array is a set of Key Value pairs where the key is the string to replace and the value is the string to replace with. The reason we are getting this error is that the FeedsDateTime objects don't have a __toString() method because DateTime does not define a __toString().
There are a couple ways to fix this.
1: Toss some code into rewrite.inc to handle this case.
Replace
With
The advantages of this are that it only effects Feeds Tamper and any tampered FeedsDateTime rewrites.
2: Extend FeedsDateTime in the Feeds module to have a __toString method.
Add the following to the class definition for FeedsDateTime located on line 559 in /sites/all/modules/feeds/plugins/FeedsParser.inc
This has the benefit of fixing this issue in any module that blindly assumes FeedsDateTime objects can be handled as strings.
The biggest concern with this fix is that we are modifying a class to have a new method and this could adversely affect code that assumed FeedsDateTime objects do not have a __toString() method.
This would break if you ever updated to a newer version of Feeds if the module maintainer has not added this 'fix' to the Feeds module.
3: Write a custom module that extends FeedsDateTime class to include out __toString() method.
I haven't explored this yet, but this would be the cleanest of the solutions. I'm not familiar enough with php and drupal at this time to feel comfortably dropping untested code here for a custom module. If I end up rolling this solution I'll come back and post it for completion purposes...
Twistor, I'm curious to see what you think the correct solution would be to this issue.
Comment #3
twistor CreditAttribution: twistor commentedYou're on the right track. The __toString() method is most of the solution. I am more curious about what module/parser is puttin DateTime objects in there like that, so I can track down the fix more correctly.
Comment #4
RedEight CreditAttribution: RedEight commentedI'm pretty sure that would be the Date iCal module. https://www.drupal.org/project/date_ical
I know I'm using it and, judging by the reference to iCals in the original post, I think it's safe to assume that rudeboypeter was also using it.
Comment #5
twistor CreditAttribution: twistor commentedFeedsDateTime needs __toString() method. We can't simply extend FeedsElemement since it already extends DateTime. Blech, this is crappy.
The iCal parser should be returning FeedsDateTimeElement, not FeedsDateTime, but that doesn't do the right thing either. We should store the original un-modified string to use in the __toString() method, rather than some generic conversion.
Comment #6
twistor CreditAttribution: twistor commentedMaybe we should just always return a formatted date?
I'm not sure.
Comment #7
twistor CreditAttribution: twistor commentedComment #10
twistor CreditAttribution: twistor as a volunteer commented