The function content_node_import_prepare() in content.inc for CCK needs to be rewritten to support the new date API in Date Version 2. The functions have changed for converting dates. I don't know how they work exactly just yet, so I can't supply a patch. If I get time to figure it out I'll post one for review. There probably two ways to handle this:

1) to be a way to check which version of date you are using
2) check if date 1 api functions exists, else do what date 2 api does

Comments

johnalbin’s picture

Status: Active » Needs work
StatusFileSize
new1.61 KB

Here's the patch I used on a site recently. It makes node_import compatible with Date 5.x-2.x. Unfortunately, the patch breaks compatibility with Date 5.x-1.x, so it needs work.

johnalbin’s picture

FYI, Karen (the Date module maintainer) says the best approach to check for which version of the Date API is installed over in: #265056: 5.x modules need to support Date 2 API and Date 1 API

jesss’s picture

Subscribing.

datawench’s picture

putting here, because it's been set as the "original" of which http://drupal.org/node/256918 is the duplicate.

the patch almost worked for me, but i got the error that said that "date.inc" couldn't be found.

changed line 95 of node_import/supported/cck/content.inc from

include_once(drupal_get_path('module', 'date') .'/date.inc');

to

include_once(drupal_get_path('module', 'date') .'/date_token.inc');
asb’s picture

Hi,

applying the patch against the current date module (5.x-2.x-dev) from 2008-Jun-21 works fine for me when running it from the "node_import" module's directory:

patch -p0 < date2-update.patch
patching file supported/cck/content.inc

Importing a small bunch of nodes with one date field (year) and some other CCK fields basically is working, except for the known issues in the node_import moduel (cutting of content after non-ascii characters).

However, all imported nodes contain a strange reference to "nid:14536" that I did not select during the importing steps (e.g. under "options" in "Field options"). So be extra careful before doing mass imports when using node_import!

Thanks for the patch & greetings, -asb

BrianKlinger’s picture

Did you check your error log, asb? I just looked at the most recent 5.x-2.x-dev date module (2008-Jun-26) and there is no date/date/date.inc. I did a huge node import and have hundreds of errors in my error log pointing to that reference. Everything worked, btw, (thanks to the patch in here), but I wonder what DIDN'T work with that error over and over. I'm going to try changing date.inc to date_token.inc (as suggested by datawench) and hope that's all I need to resolve the issue.

seaneffel’s picture

Status: Needs work » Needs review

Subscribing. I have the same issues here and applying the patch on the Juune 28 dev version also makes import possible - I think that should be reviewed and committed soon. I am still looking at the line 95 errors.

BrianKlinger’s picture

I changed line 95 as suggested by datawench and haven't seen any line 95 errors since. Not sure if there are other consequences, but I sure haven't noticed any. If there are no other consequences, we should probably get an updated patch that includes that change rolled out. Anyone else?

seaneffel’s picture

I vote go.

dieter@drupal.org’s picture

subscribing

BrianKlinger’s picture

Version: 5.x-1.3 » 5.x-1.6
StatusFileSize
new1.88 KB

If I'm doing this wrong, I'm sorry, someone come along behind and correct my error. I just grabbed version 5.x-1.6 so I could roll a new patch against that latest version available. I then went through and created a patch that includes the original patch in comment #1 and the correction that was written in comment #4. Since the patch I created was against 5.x-1.6, I changed the version number of this post - I hope that was the correct thing to do. Anyway, as I said, this is the latest patch and fixed all problems that I was having. I know nothing about committing patches to CVS and I don't know if anyone is maintaining the node_import module, but hopefully if others find the problem with Date 2 they will be able to at least have this patch to correct it.

As was stated earlier in this thread, I don't really think this patch is the CORRECT way to fix this problem, because this patch will BREAK node import for anyone who uses Date 1, but at least it gives a solution to other Date 2 users.

johnalbin’s picture

Status: Needs review » Needs work

Actually, Brian, I think you did pretty good! :-)

Marking this as “patch (code needs work)” since, yes, its not the CORRECT way to fix it.

svelasco’s picture

How can I apply the patch?

seaneffel’s picture

If you have never done it before, svelasco, the instructions to apply patches in general are here. Sorry for the indirect answer, but other people have answered it better than I already:

http://drupal.org/patch/apply

davidseth’s picture

Just applied and it works perfect! Thanks.

mvc’s picture

Status: Needs work » Needs review
StatusFileSize
new4.1 KB

Based on the advice KarenS gave (#265056: 5.x modules need to support Date 2 API and Date 1 API) I've modified this patch to work with both Date 1 and 2. It worked for me -- as always, if this helps you please mark this issue as 'reviewed and tested by the community'; if not, please mention what went wrong.

asb’s picture

Hi,

applying "date2_import.patch" from July 25, 2008 - 07:03 results on my site in:

patch -p0 < date2_import.patch
patching file supported/cck/content.inc
Hunk #1 FAILED at 92.
1 out of 1 hunk FAILED -- saving rejects to file supported/cck/content.inc.rej

Regards, -asb

mvc’s picture

@asb: If you tell me what version of node import you're using I'll try to look into your problem.

asb’s picture

Hi mvc,

thanks for the offer ;)

Version:

version = "5.x-1.6"
project = "node_import"
datestamp = "1209805811"

Content of content.inc.rej:

/sites/all/modules/node_import/supported/cck$ cat content.inc.rej
*************** function content_node_import_prepare(&$n
*** 96,112 ****
                  if ($field['type'] == 'date') {
                    // Is the imported date a unix timestamp? If so convert it to ISO date.
                    if (is_numeric($value) && date_is_valid($value, DATE_UNIX)) {
-                     $value = date_unix2iso($value);
                    }
                    // If the imported date is a (partial) ISO date, convert it
                    // to date's ISO date.
-                   else if (($date_array = date_iso2array($value)) != 'ERROR') {
-                     $value = date_array2iso($date_array);
                    }
                    // Otherwise, use strtotime and unix2iso to convert
                    // partial ISO or text date into full ISO.
                    else {
-                     $value = date_unix2iso(strtotime($value));
                    }
                  }
                  else {
--- 96,115 ----
                  if ($field['type'] == 'date') {
                    // Is the imported date a unix timestamp? If so convert it to ISO date.
                    if (is_numeric($value) && date_is_valid($value, DATE_UNIX)) {
+                     //$value = date_unix2iso($value);
+                     $value = date_convert($value, DATE_UNIX, DATE_ISO);
                    }
                    // If the imported date is a (partial) ISO date, convert it
                    // to date's ISO date.
+                   //else if (($date_array = date_iso2array($value)) != 'ERROR') {
+                   //  $value = date_array2iso($date_array);
+                   else if (($date_array = date_convert($value, DATE_ISO, DATE_ARRAY)) != NULL) {
+                     $value = date_convert($date_array, DATE_ARRAY, DATE_ISO);
                    }
                    // Otherwise, use strtotime and unix2iso to convert
                    // partial ISO or text date into full ISO.
                    else {
+                     $value = date_convert(strtotime($value), DATE_UNIX, DATE_ISO);
                    }
                  }
                  else {

Thanks again & greetings, -asb

pclux’s picture

I have the exact same config and issue applying patch as asb...was there a resolution to that that didn't get posted perhaps?

LinL’s picture

Applied the patch and all imported OK but all my dates are showing as 1970.

I have date fields with granularity of Year and in my csv file I have put only the year. Like this:

... "John","Smith","1906","1986" ...

I expect I need to put a full date in there, but what would the format be for that?

LinL’s picture

As is so often the case, a night's sleep resolves the problem!

I need to put the dates in ISO format and they work fine. So I changed my csv file to:

... "John","Smith","1906-01-01","1986-01-01" ...

and it imports the dates flawlessly into both a Text field and a Select List field.

Thanks for the patch.

But, I also have a field with a "To Date" defined and this is not working correctly. The From part is imported, but not the To.

(D5.10, Date 5.x-2.1, PHP 5.2.4, MySQL 5.0.51a)

caprenter’s picture

Just to say I used the patch in #11 to fix this issue in drupal 6.4, date 6.x-2.0-rc2, CCK 6.x-2.0-rc7, node import 6.x-1.x-dev, views 6.x-2.0-rc2 (updated on 11th Sept 08)

Thanks very much!

mvc’s picture

@asb, @pclux: I've just confirmed that my patch in #16 applies cleanly against node_import version 1.6. From looking at your .rej file I believe you applied the patch in #1 or #11 before applying my patch. Please try backing up and removing your node_import directory, downloading a clean copy, and then using my patch.

@LinL: a wide variety of date formats are supported (see strtotime() for details), but as you discovered, the year alone isn't one of them.

DanielJohnston’s picture

Works fine in ISO date format for both from and to dates, although it took me a while to realise I had to have my dates in that format first. Subscribing.

Robrecht Jacques’s picture

Status: Needs review » Fixed

Fixed. Will be included in next release of node_import (5.x-1.8) released after the weekend.

traviss359’s picture

Dev version fixed the problem for me, node_import-5.x-1.x-dev.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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