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.
I've done update on date.inc and FeedsParser to have support array of values for dates. (i'm working on the alpha10)
If someone is interested in !
FeedsParser.inc
/**
* Helper method for buildDateField(). Build a FeedsDateTimeElement object
* from a standard formatted node.
*/
protected static function readDateField($node, $field_name,$index=0) {
$field = content_fields($field_name);
$ret = new FeedsDateTimeElement();
if ($node->{$field_name}[$index]['date'] instanceof FeedsDateTime) {
$ret->start = $node->{$field_name}[$index]['date'];
}
if ($node->{$field_name}[$index]['date2'] instanceof FeedsDateTime) {
$ret->end = $node->{$field_name}[$index]['date2'];
}
return $ret;
}
/**
* Build a node's date CCK field from our object.
*
* @param $node
* The node to build the date field on.
* @param $field_name
* The name of the field to build.
*/
public function buildDateField($node, $field_name,$index=0) {
$field = content_fields($field_name);
$oldfield = FeedsDateTimeElement::readDateField($node, $field_name,$index);
// Merge with any preexisting objects on the field; we take precedence.
$oldfield = $this->merge($oldfield);
$use_start = $oldfield->start;
$use_end = $oldfield->end;
// Set timezone if not already in the FeedsDateTime object
$to_tz = date_get_timezone($field['tz_handling'], date_default_timezone_name());
$temp = new FeedsDateTime($to_tz, NULL);
$db_tz = '';
if ($use_start) {
$use_start = $use_start->merge($temp);
if (!date_timezone_is_valid($use_start->getTimezone()->getName())) {
$use_start->setTimezone(new DateTimeZone("UTC"));
}
$db_tz = date_get_timezone_db($field['tz_handling'], $use_start->getTimezone()->getName());
}
if ($use_end) {
$use_end = $use_end->merge($temp);
if (!date_timezone_is_valid($use_end->getTimezone()->getName())) {
$use_end->setTimezone(new DateTimeZone("UTC"));
}
if (!$db_tz) {
$db_tz = date_get_timezone_db($field['tz_handling'], $use_end->getTimezone()->getName());
}
}
if (!$db_tz) {
return;
}
$db_tz = new DateTimeZone($db_tz);
if (!isset($node->{$field_name})) {
$node->{$field_name} = array();
}
if ($use_start) {
$node->{$field_name}[$index]['timezone'] = $use_start->getTimezone()->getName();
$node->{$field_name}[$index]['offset'] = $use_start->getOffset();
$use_start->setTimezone($db_tz);
$node->{$field_name}[$index]['date'] = $use_start;
/**
* @todo the date_type_format line could be simplified based upon a patch
* DO issue #259308 could affect this, follow up on at some point.
* Without this, all granularity info is lost.
* $use_start->format(date_type_format($field['type'], $use_start->granularity));
*/
$node->{$field_name}[$index]['value'] = $use_start->format(date_type_format($field['type']));
}
if ($use_end) {
// Don't ever use end to set timezone (for now)
$node->{$field_name}[$index]['offset2'] = $use_end->getOffset();
$use_end->setTimezone($db_tz);
$node->{$field_name}[$index]['date2'] = $use_end;
$node->{$field_name}[$index]['value2'] = $use_end->format(date_type_format($field['type']));
}
}
}
date.inc
function date_feeds_set_target($node, $target, $feed_element) {
list($field_name, $sub_field) = split(':', $target);
if (!($feed_element instanceof FeedsDateTimeElement)) {
if (is_array($feed_element)) {
$index=0;
foreach ($feed_element as $feed_elem)
{
if ($sub_field == 'end') {
$feed_elem = new FeedsDateTimeElement(NULL, $feed_elem);
}
else {
$feed_elem = new FeedsDateTimeElement($feed_elem, NULL);
}
$feed_elem->buildDateField($node, $field_name, $index);
$index++;
}
}
else
{
if ($sub_field == 'end') {
$feed_element = new FeedsDateTimeElement(NULL, $feed_element);
}
else {
$feed_element = new FeedsDateTimeElement($feed_element, NULL);
}
$feed_element->buildDateField($node, $field_name);
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#39 | feeds-date-array-697842-39.patch | 11.6 KB | eiriksm |
#23 | feeds-date-array-697842-23.patch | 11.6 KB | eiriksm |
#22 | feeds-date-array-697842-22.patch | 11.55 KB | eiriksm |
#17 | date-array-697842.patch | 5.33 KB | franz |
#15 | date-array-697842.patch | 5.41 KB | franz |
Comments
Comment #1
alex_b CreditAttribution: alex_b commentedCan you post a patch ?
http://drupal.org/patch/create
Comment #2
perpignan CreditAttribution: perpignan commentedPatch for Feeds-6.x1.0-alpha11
Comment #3
alex_b CreditAttribution: alex_b commentedSorry, flew under my radar as an active support request. This is feature request that needs review.
Comment #4
alex_b CreditAttribution: alex_b commented- date.inc patch does not apply to HEAD
- please roll one patch (cvs diff -u > example.patch from feeds/ directory)
Comment #5
hampshire CreditAttribution: hampshire commentedThe date patch does not apply to Alpha 15 either.
Does anyone have advice on how I can get this patch working with a later version of the module.
Thanks.
Comment #6
alex_b CreditAttribution: alex_b commentedhampshire: patches are always against the branch HEAD, not cleanly applying patches need to be fixed by hand going through the code...
Comment #7
eiriksmi did some similar editing on the 7 version. any chance this will get into the 7 version?
should i open up a new issue for the 7 version and date arrays?
Comment #8
eiriksmHere is a patch if anyone else is interested.
Patch for 7.2 alpha 3
Comment #9
TripX CreditAttribution: TripX commented+1
Can you commit this? .. or forward it that someone can commit this?
I think this is a frequent feature request.
Comment #10
TripX CreditAttribution: TripX commentedAhmn... there are mistakes in the code.
you wrote f.e. $eed_.... instead of $feed_....
Have you tested it?
Comment #11
eiriksmits tested and works great. although i must admit some of the variables could have more logical values. it's called eed_... to prevent overwriting the feed_... variable if i remember correctly. some of the variables is in norwegian too, not good i guess.
Comment #12
eiriksmHere is a new patch with more sane variables. For people interested, i also had to make a patch for d6 feeds -beta10 for a another project. In here is a patch for that: #1148892: Support array of values for dates (mapping to a date multifield)
Comment #13
eiriksmMade a new patch against -dev. Hopefully this will make it into the module, so i don't have to patch my updates. Using this on several sites now, and it works.
Comment #14
franzIt's not yet complete.
When merging with old data, it always took the first item (not sure if you tried start and end before).
I'm fixing it and it seems better also to replace $fieldnumber with $delta, as it makes more sense (Field key concept).
Comment #15
franzAlso, I think we need to work on a test for this.
Comment #16
eiriksmThanks for that. I am no programmer, so I am glad someone picked this up and looked at it. I agree with the $delta too, very logic. On the sites I am using this I am not using end date, no.
I have never written a test before, but i could look into it when i get the time.
Comment #17
franzhttp://drupal.org/simpletest has some explanation about automated tests, be sure to read it.
Then you can work on the existing test for Date fields on file tests/feeds_mapper_date.test .
I still hadn't change the patch to use $delta, now I did the change.
Comment #18
eiriksmI tried a couple of times to make a test, both with the Feeds test setup and from scratch, but never managed to create a field allowing multiple values. I got my content type set up and a date field added, but couldn't figure out how to change the max allowed values. And that is pretty darn important in this test i would say.
If someone else wants to jump on creating a test for this, feel free.
Comment #19
emilcarpenter CreditAttribution: emilcarpenter commentedThanks eiriksm and franz!
This patch got the dates into the multivalue field...
...but the dates are displayed like 2012-01-16T01:54:18 in Views, regardless of the Short, Medium or Long display type chosen. Does anybody have an idea how to fix this?
(Hope i did not do any error copy-pasting the lines instead of using Netbeans for applying the patch. I'm a beginner...)
I use Feeds 7.x-2.0-alpha4, Date-7.x-2.0-rc1 and Drupal 7.9
Comment #20
emilcarpenter CreditAttribution: emilcarpenter commentedNevermind the question, the dates display fine without Views. Probably some Views multi value issue.
Comment #21
timos CreditAttribution: timos commentedHi and thanks eiriksm and franz !
It seems work well.
will this patch include in the dev version and so on in a future release ?
Chers
Comment #22
eiriksmHello.
OK, so I thought it was about time to get this commited and sat down to write tests for testing importing array of dates.
Included in the attached patch is:
- Patch from #17
- Updated test for date mappers (date module now sets a 15 min increment as default, therefore breaking the field assertions in the test)
- Test for array of dates.
Since none of the parsers included in Feeds supports array of dates (at least I couldn't get that to work), i am using the Feeds X path parser plugin for tests, which is also what i use on the (several) projects I have this patch up and running live with.
Would really like to see this get commited, so hopefully someone will pick this up, and maybe tell me what is missing also.
Thanks again to the maintainers for all your great work on this module, it is such a great tool!
Comment #23
eiriksmUpdated patch with some coding standard issues, and small clarifying commenting stuff. Took the liberty while adding
@param int $delta
to add parameter type to the whole function comment block in question. Should by the way be done several other places, but that is a different issue i guess.Comment #24
franzI don't like the idea of depending on an external module to run those tests. We can instead create a test module that provides a "fake" parser: A parser that you can set the values (including multiple values) as a configuration directly, without the need to involve fetchers or other parsers. This will also decouple this test and potentially others from the fetcher/parser code.
Comment #25
eiriksmI agree on that. But I dont have time for that atm, so will have to postpone it for some time. However, if you (or anyone else) wants to jump on this, feel free :)
Comment #26
franzComment #27
Rob_Feature CreditAttribution: Rob_Feature commentedWhat should the values look like for this patch to work? I applied it and I wasn't able to import multiple, but I have a feeling it's because our source CSV has the dates comma separated, which seems like a big no-no for a CSV file. Any clarity on a format expected by this patch?
Comment #28
franzRob_Feature, the parser must support returning multiple value for a field. The CSV Parser alone doesn't. If you need this feature, use Feeds Tamper module and apply the tamper plugin "Explode" to this field.
Comment #29
franzThis is because of the very nature of CSV data source, which doesn't support multiple values for a field, only through "tweaking" (in this case, a string with comma-separated values).
Comment #30
Rob_Feature CreditAttribution: Rob_Feature commentedWow, awesome Franz. Thanks!
Comment #31
BD3 CreditAttribution: BD3 commented@Rob_Feature Did you ever get this to work? Has it been committed to the latest dev? I cannot seem to get this to work but I am having trouble finding the proper module to patch.
Comment #32
Rob_Feature CreditAttribution: Rob_Feature commentedI did get it to work with the patch here. Honestly, though, I patched before I even tried to do it properly so I'm not sure if the patch 'works' or not. There WAS a dev release after this patch was made so it may need to be re-rolled if it won't apply.
Comment #33
franzPatch still applies clean to latest dev. What we still need is some test changes re #24
Comment #34
BD3 CreditAttribution: BD3 commentedThanks @Rob_Feature and @franz. I was able to successfully apply to the latest dev (2012-Jun-20) and all seems to be working!
Comment #35
eiriksmSo, does anyone want to jump on making the tests? If people are using the patch, let's try to get it in!
Comment #36
BD3 CreditAttribution: BD3 commentedOne thing that isn't working are empty values. It will bring in the date of the import instead. There are a few patches here waiting to be tested #1107522: Framework for expected behavior when importing empty/blank values + text field fix, but they are not compatible with the patch in this issue to support multiple values.
Comment #37
gmclelland CreditAttribution: gmclelland commentedThe patch in #23 fixed the issue for me. Before the patch it would only import the first date in a multivalued date field. After the patch it imports all the dates in the multivalued date field.
Comment #38
Rob_Feature CreditAttribution: Rob_Feature commentedAs an FYI this still applied cleanly to the Sept 8, 2012 dev versino of feeds.
Comment #39
eiriksmUpdated patch for latest dev (and alpha-7).
Comment #40
Frederic wbase CreditAttribution: Frederic wbase commentedI can confirm that the patch of eiriksm in http://drupal.org/node/697842#comment-6673550 is working like charm!
Thanks for the effort.
grts
Frederic
Comment #41
MXTI can confirm that patch provided in #39 works very well: thank you very much!!!
Can this be committed please?
Comment #42
twistor CreditAttribution: twistor commentedAwesome, tests!
Now to check how many other date-related patches this will break.
Comment #43
twistor CreditAttribution: twistor commentedCommitted to 7.x. Had to make a few changes as things conflicted, by I like it.
Thanks all.
Comment #44
twistor CreditAttribution: twistor as a volunteer commented