Jump to content

Module: Import Pages from CSV file


ryan

Recommended Posts

  • 1 month later...

I will need to import bunch of news items soon, and planning to use this for the job. Any clues how to get date field working Ryan?

It would be pretty trivial to write custom import script also, but I have looking for opportunity to test this module.

Link to comment
Share on other sites

I think this will depend somewhat on what format those dates will be in from your spreadsheet (CSV). If it's a unix timestamp, or any format consistent with what PHP's strtotime() will accept (which includes quite a lot of formats), then you should be able to import dates pretty easily. I think all you'd need to do is add FieldtypeDate to the list of allowed fieldtypes at the top of the modules:

<?php
        protected $fieldtypes = array(
                'FieldtypePageTitle',
                'FieldtypeText',
                'FieldtypeTextarea',
                'FieldtypeInteger',
                'FieldtypeFloat',
                'FieldtypeEmail',
                'FieldtypeURL',
                'FieldtypeCheckbox',
                'FieldtypeFile',
                'FieldtypeDate' // add this line
                );

I don't have a good example to test from at the moment though will try to test it tomorrow. But let me know if you get a chance to test, and if that works I'll go ahead and add it to the module permanently. Looking at it now, I'm not sure why I didn't add it before. But it's the end of the day here so my mind is tired and I may be missing something. :)

Link to comment
Share on other sites

I went ahead and tested this. I didn't modify anything and it imported dates just fine. This was my test CSV (I just pasted it):

"title","body","date","images"
"Uusi uutinen","Tämä on leipäteksti, jossa on "lainaus".","12-06-2011 12:45:11","http://www.avoine.fi/@Bin/213898/ulkona1.jpeg"

Only strange this was that body text was in this format in tinyMCE field:

Tämä on leipäteksti, jossa on lainaus"."

Not sure if they should be escaped in csv?

Link to comment
Share on other sites

Thanks Antti, glad that it's working alright and that the dates imported how they should. That's interesting that your CSV file had unescaped quotes in it. That will confuse any CSV parser. What did you use to export the CSV? Nico's right that quotes should be escaped with a backslash.

Link to comment
Share on other sites

I didn't export that CSV from anywhere - I just wrote that myself as test case. I wasn't sure should the content be escaped so tested it without escaping - I was little bit surprised with the result (it worked, sorta) :)

Link to comment
Share on other sites

  • 1 month later...

Thanks for the nudge in the right direction diogo - that's me being a complete noob with PW.

In case anyone else comes across this: under 'Admin' -> 'Setup' -> 'Import Pages From CSV' choose to edit the page and under 'Process' in the 'Content' tab select 'importPagesCSV' from the drop down.

Link to comment
Share on other sites

I think that process should be right after install, so there have been something strange in your situation raydale.

Ah, so I'm not being quite such a noob :)

In my case I wasn't taken through any extra steps and just left at the standard module overview screen (the one with 'Module Information').

Link to comment
Share on other sites

I'm having problems using this module in PW 2.2. I have installed the module and then under 'Setup' and 'Import Pages From CSV' - I get the following message: "This page has no Process assigned."

Testing here in 2.2, but I can't duplicate. Can you think of any other factors involved? Has your site been through a profile export/import (like 2.0-2.1 upgrade)? Have any admin-related pages been renamed? Let me know if you can think of anything else that might be different from a stock installation.

Tahnks,

Ryan

Link to comment
Share on other sites

Hi Ryan,

The only thing I can think of is that I have renamed the admin pages url from 'processwire' to 'admin'. I will probably be doing a bit of work on this over the next few days with different localhost installations - so I'll see if I can reproduce it then.

Link to comment
Share on other sites

It shouldn't matter if you've renamed the admin page, but thanks for mentioning it. Those are the kind of things that are good to know. Let me know if you find that you can reproduce it.

Thanks,

Ryan

Link to comment
Share on other sites

  • 2 weeks later...

I am trying to import some events which have two date fields - a start and end date.

I enabled the FieldtypeDate in the module as suggested by Ryan :

protected $fieldtypes = array(
 'FieldtypePageTitle',
 'FieldtypeText',
 'FieldtypeTextarea',
 'FieldtypeInteger',
 'FieldtypeFloat',
 'FieldtypeEmail',
 'FieldtypeURL',
 'FieldtypeCheckbox',
 'FieldtypeFile',
 'FieldtypeDate' // add this line
 );

However there seems to be some odd results after importing. Some event pages have imported both start and end date. others have only a start or end date. and then some have no dates at all. I have tried various times and made sure that the dates are in the correct format (d/m/Y) but no luck.

Here is the CSV file I was using

http://db.tt/h0fGuBHU

Was there any progress with the page field type import?

Link to comment
Share on other sites

After some further testing, I may have worked out part of the issue.

Both the date fields were changed to use European style dates d/m/Y

However despite changing this in the field settings (output and input tabs) it was still only accepting the US style m/d/Y - hence why it was importing only valid US style dates and skiping the rest.

I have tried lots of variations for European style dates in the field settings and csv but it only accepts US style m/d/Y

After changing the main wire config file

$config->dateFormat = 'd-m-Y H:i:s';  

it accepted the dates, but in my scripts it still seems to be calculating with the US style (I am adding / subtracting dates to work out time differences) - any date like 28/05/2012 is calculated wrong - this is still confusing me.

I am using the latest PW 2.2 from Github download.

Thanks,

Michael

Link to comment
Share on other sites

Michael, have you tried changing your dates in the CSV to the d-m-Y format? I believe it should import then. The FieldtypeDatetime module sanitizes any string input with PHP's strtotime() function. That function accepts d-m-Y format if you use dashes in the input (rather than slashes).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...