Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Port the date mapper from Feed Element Mapper.
Port tests for it.
Document.
Comment | File | Size | Author |
---|---|---|---|
#43 | 623448-43_datemapper.patch | 50.66 KB | alex_b |
#41 | 623448-41_datemapper.patch | 49.66 KB | David Goode |
#40 | 623448-40_datemapper.patch | 49.31 KB | alex_b |
#39 | 623448-39_datemapper.patch | 45.4 KB | David Goode |
#38 | 623448-38_datemapper.patch | 47.97 KB | alex_b |
Comments
Comment #1
alex_b CreditAttribution: alex_b commentedAs an example for the API, take a look at mappers/content.inc should be used. For documenting the Mapping API, I opened an issue #623466: Document mapping API.
Comment #2
nickbits CreditAttribution: nickbits commentedAlex,
I just want to check this with you before I start any work on it, am I correct in saying that if I port "feedapi_mapper_date.inc" (i.e. from the FeedAPI module) to Feeds, then along with the "iCal parser" module I should be able to import iCal info from another site and map the date information on one of my event nodes (CCK)?
I just want to double check I understand this correctly and I have not missed any other file or module required before I start working on it.
Nick
Comment #3
ekes CreditAttribution: ekes commentedThe ical parser (in HEAD) is roughly integrated with feeds and dumping everything out ready for mapping. So yes in theory once the mapper bit is migrated it's ready to roll.
It may want some tweaking the way the information is presented from the parser for mapping, but that should be easy. But at the moment, I've certainly not had time, to get it from the parsed feed to the field (the mapping bit :) for the date section of the feed items. So if you have that would be brilliant. Any changes to the parser let me know :-)
Comment #4
nickbits CreditAttribution: nickbits commentedHi ekes,
Thanks for that. Same problem here, lack of time. I figured if I used FeedsAPI, it would be quicker, but eventually I would be switching to Feeds so therefore might as well put something back in to the community whilst helping to develop my site. Will see if I can find time this weekend to have a crack at it.
Nick
Comment #5
pbuyle CreditAttribution: pbuyle commentedHas anyone started to work on this ?
Comment #6
nickbits CreditAttribution: nickbits commented@mongolito404 I was planning on starting last week, just have not had the time.
Comment #7
nickbits CreditAttribution: nickbits commentedHi,
This may be me missing something, again! I have started to work on this, porting the date mapper. My first hurle, and I ahve abrely started, is that I cannot get a date to show in the source. I have created an Event type, it has a date field, I create a new feed type to import nodes to, but I do not see the date field listed in the source.
Can anyone tell me what I am doing wrong?
Please note, I have not started the coding yet as this is the first thing I need to see before I can start work on the mapping.
Regards,
Nick
Comment #8
pbuyle CreditAttribution: pbuyle commentedYou have to implement hook_feeds_node_processor_targets_alter($targets, $content_type) to see your date field as a target. Sources are item fields provided by the parser. The parser don't know about content types, it would not provides any sources for their fields.
Comment #9
nickbits CreditAttribution: nickbits commentedHi,
Just got it. I was not expecting to have to do that. Think that is something that needs to be documented.
Thanks,
Nick
Comment #10
nickbits CreditAttribution: nickbits commented@mongolito404, I have just re-read what you said, and must have misread it. I do not ahve a problem with the target, that appears to be working okay. I understand that the source doesn't know the content type, hence the reason we use mappers.
The problem I have is that the source I am expecting to see is not that and I am not sure if it is me missing something or a bug.
I am using the iCal Parser (http://drupal.org/project/parser_ical), which I have read should be compatable with Feeds. I have created a news feed, associations and event type with rel. fields. I see the field/entry to map to with the date mapper in the target. I do not see anything representing a date in the source though which is what I would expect from the iCal Parser.
So the question is, is it the iCal parser that should be putting an entry in the source drop down?
1. I am assuming YES. If so, can someone else please confirm that this is a bug before I chase it up within that module.
2. If NO, can someone point out what idiotic thing I am doing wrong?
Cheers,
Nick
Comment #11
nickbits CreditAttribution: nickbits commentedHi,
Okay, think I have figure it out. I did not realise the iCal Parser adds the dropdown box (see attached images), thought this was Feeds. So with the iCal parser enabled, it tells the mapper what the sources are. There is no way to enter one manually. Am I right in assuming I should be able to enter in to the source box, the name of the field on the feed I want to map? i.e. VEVENT?
Nick
Comment #12
nickbits CreditAttribution: nickbits commentedHi All,
Okay the code I have so far is below, not a lot I know, but still learning the Feeds API system so bear with me. I am not able to do any more work until Sat. so if anyone wants to pick it up, code for date.inc is:
Nick
Comment #13
nickbits CreditAttribution: nickbits commentedHi,
So I mnaged to sneak in a little more work, only a few lines plus a patch file. It does work, but is very limited and basic. Needs a lot of refinement and work, but it is a start. I am using the output of the iCal Parser to feed in to this mapper. Do look at it and add to it.
Nick
Comment #14
pbuyle CreditAttribution: pbuyle commentedThere is 3 type of date fields: date, datetime and datestamp (deprecated but used to support legacy data).
If some parsers output dates as start date and end date, a single target is needed. But parsers could also output two separated sources (CSV for instance). So two targets are needed. Worse, parses could also output the date and time as separated sources. So we the mapper would need separated targets for these. So I think we need the following targets
- Dates (start date, end date) as a single fields => $field[0]['value'] and $field[0]['value2']
- Start date => $field[$i]['value']
- End date => $field[$i]['value2']
- Start time => $field[$i]['value']
- End time => $field[$i]['value2']
Using Drupal and PHP date functions, it should be possible to parse a time source and to its overwrite only the time parts of the full datetime already sets in the field to merge a two separated sources in a single field 'value'.
Comment #15
nickbits CreditAttribution: nickbits commented@mongolito404, I now see that in the old FeedAPI mapper. Am disecting the old mapper and slowly porting it over. I ahve attached an updated copy of the code. Still not a lot, but only doing short periods at it when I get the chance. Anyway, with any luck that should now be on the right lines. Do let me know if I have made any more idiotic mistakes, wouldn't be so bad if I could spend more time at it i one go...
Nick
Comment #16
caver456 CreditAttribution: caver456 commentedsubscribing
Good work, from a newbie who is really looking forward to the Feeds iCal parser integration!
Comment #17
nickbits CreditAttribution: nickbits commentedHi all,
Just a quick update, I won't be doing anymore work on this for a couple of days.
Nick
Comment #18
pbuyle CreditAttribution: pbuyle commentedIf so, I will work on it.
Comment #19
nickbits CreditAttribution: nickbits commented@mongolito404, if you could that would be great. I will ahve some time at the weekend, but nothing before then.
Nick
Comment #20
pbuyle CreditAttribution: pbuyle commentedHere is the current state of my work.
I simplified it. It only supports full date time (no date only or time only). It should also supports iCal but it has not been tested.
The provided test case tests for many different date formats, many of them fail because of missing code.
The current todos with this code are:
- In date_feeds_node_processor_targets_alter: Only provides "end date" target if field allow it.
- In date_feeds_set_target :
- Add support for the field format when parsing values
- Add support for common formats when parsing values on PHP < 5.3 (see _create_date_from_known_formats)
- Write _create_date_from_known_formats for PHP < 5.3
- In FeedsMapperDateTestCase
- Test for iCal
- Test end date
I'm not sure if support for date formats must be included in the mapper. I think parsers must handle the date formats required by the file formats they support. The common syndication and SimplePie parses do it and provide their dates as UNIX timestamp. Generic parses like CSV should provide configurable data conversion. For date by probably for other types as well (probably using a hook or plugins).
Comment #21
nickbits CreditAttribution: nickbits commented@mongolito404, wow, that is impressive. Will test it out late, obviously I need to read up on the Feeds API!
Comment #22
nickbits CreditAttribution: nickbits commentedHi mongolito404,
That is some nice work, did not relise the testing was there as well. Anyway, will ahve a play over the weekend and see if I can add some more of the missing code.
Nick
Comment #23
bdragon CreditAttribution: bdragon commentedI think the timezone conversion is wrong.
From what I'm reading, I *think* you should be using
instead of
as the data is going into a node_save() style save rather than a drupal_execute() style save.
Comment #24
rjbrown99 CreditAttribution: rjbrown99 commentedI am testing it with imported date fields that look like this:
12/08/2009
All of the imported fields look like that. They all import properly, so at least in that case it looks good to me.
Comment #25
bdragon CreditAttribution: bdragon commentedAnother minor nit that is rather annoying is the use of a variable that doesn't seem to be set anywhere:
-- which is making it hard to see which is which. Suggest just using (begin) and (end) respectively...
Comment #26
David Goode CreditAttribution: David Goode commentedHey all! I'm looking into this too. @mongolito404, could you upload the date.csv simpletest file you're using?
Thanks,
David
Comment #27
David Goode CreditAttribution: David Goode commentedHey! Here is a direct port of the old feedapi date mapper to feeds--it keeps the identical functionality of date parts and that date creation class and so on. I have lightly tested it so far, including with the new ical parser, and it gets stuff through on so on. I haven't tested timezone stuff thoroughly yet.
Does anyone know if there were any issues with the old feedapi date mapper? The code possibly could be cleaner, but I guess there were use cases that had to be supported for only mapping various parts at a time, like the time from one field and the date from another? I am going to work on this a bit more, including testing and possibly contemplating just scrapping this old method and rearchitecting, perhaps along the lines of mongolito's slimmed down version. Any input on important use cases, past precedent for this mapper, or other suggestions would be very helpful.
David
Comment #28
David Goode CreditAttribution: David Goode commentedFor some context, the reason the date mapper ballooned into its current state is encapsulated in this lengthy issue: #215979: Create a CCK date field mapper. Basically, the use cases for mapping certain parts and similar stem from certain csv type date exports. I'm going to test the mapper, and if it works I'd be in favor of just leaving it basically as is, at least for now.
Comment #29
David Goode CreditAttribution: David Goode commentedSlightly tweaked patch, includes raw field for the RSS parser published date so that the date mapper can use it correctly if there are timezone conversions or similar.
Comment #30
alex_b CreditAttribution: alex_b commentedUse FeedsDateConstructor instead of feeds_date_constructor as we use D7 CamelCase style in Feeds.
_raw source is good, obviously it will present a compatibility problem if ever we switch to a stronger date type that supports various date formats with one source element. *We should really only use it as a stop gap until we get solid Date handling.*
Comment #31
BenK CreditAttribution: BenK commentedSubscribing....
Comment #32
David Goode CreditAttribution: David Goode commentedHey, currently working on a complete refactor that will be very pretty and OO, although at this point it will probably require PHP 5, perhaps (but hopefully this can be avoided) 5.2.
David
Comment #33
rjbrown99 CreditAttribution: rjbrown99 commentedI have been using the patch from #20 but #29 seems to be newer and quite different.
Which one are we all thinking will be the winner here? I'm re-rolling my Feeds and want to test whichever one is more likely to be the final accepted solution.
#20 has been working well for me but my date needs are very basic.
Comment #34
alex_b CreditAttribution: alex_b commentedFrom my point of view, #29 is holding the torch now. I've spoken to David, he is currently tweaking the date patch to make it work properly with more advanced features in iCal and Date module (recurring dates, date granularity).
Further he is picking up the improved source element type negotiation introduced with #624088: Mapper: ImageField/FileField (formalize feed elements).
Comment #35
David Goode CreditAttribution: David Goode commentedHey, preliminary working 3rd version of patch. This one is kinda completely different from the other two...again :-( It is now object oriented and does cool stuff like merging date parts intelligently. I will do some more testing and add comments + my simpletests tomorrow. Also, iCal parsing is now contained in its own class that extends these, and it should live in the parser_ical module. I'll submit that patch there too soon, and I'll post the link.
David
Comment #36
alex_b CreditAttribution: alex_b commentedJust talked through this patch with David offline. This is what we found:
- Comment on functionality of FeedsDateTimeField and FeedsDateTime, explain difference
- Comments on every method
- Rename any variables with names like $fsedt or $byparts.
- Move timezone resolving into FeedsDateTimeField class
- Move FeedsDateTime into libraries directory FeedsDateTime.inc
- Give it another round of code clean up:
Attaching a patch that contains some minor cleanups that we did as we went.
Comment #37
David Goode CreditAttribution: David Goode commentedSignificantly improved code factorization and brevity; clarity fixes as in Alex's patch; added date mapper test that should pass. See relevant ical parser patch ticket #614120: 2.x feeds module version. I will add a test for that one soon.
David
Comment #38
alex_b CreditAttribution: alex_b commented- FeedsDateTimeField::buildField() -> ::buildDateField();
- Implement FeedsDateTimeField::__toString()
- Remove timestamp_raw from common_syndication_parser - let's keep full date support for syndication parser for a separate issue. This will effect the TZ part of the tests (and may make googlenewstz.rss2 obsolete)
- Rename FeedsDateTimeField -> FeedsDateTimeElement
- Date tests not successful on my setup (all CCK value assertions fail). PHP 5.2.6
Comment #39
David Goode CreditAttribution: David Goode commentedAll done but failing the tests on not-my-setup :-)
Comment #40
alex_b CreditAttribution: alex_b commentedTests still failing on my end. This is very close otherwise.
Did some further cleanup:
- Code style fixes
- More verbose comments on new classes
- Moved FeedsElement classes to bottom of FeedsParser.inc to have them all together (at some point we could move these classes to their own includes/FeedsElement.inc)
The tests are failing in date_feeds_set_target(), Apache thread crashes with "exit signal Bus error (10)"
Comment #41
David Goode CreditAttribution: David Goode commentedFixed fatal error.
Comment #42
alex_b CreditAttribution: alex_b commentedGreat - reviewing now.
Comment #43
alex_b CreditAttribution: alex_b commented- Small fix to make PHP 5.2 accept "GMT+" and "GMT-" TZ offsets.
- Removed debug output.
RTBC.
Comment #44
alex_b CreditAttribution: alex_b commentedCommitted!
Thank you everybody.
Comment #45
stefan81 CreditAttribution: stefan81 commentedI installed the module (6.x-1.0-alpha9) and cant find my cck date fields in the mapping settings.
Did I miss to download a mapper.inc somewhere?
... UPDATE: sorry, just saw that this is part of 6.x-1.0-alpha10
Is it stable enough to work with?