Jump to content
ryan

Module: Import Pages from CSV file

Recommended Posts

Ehm, how can I change the user template - it's not in the templates list in "setup"?

Share this post


Link to post
Share on other sites

There is filter options above template list. Choose system templates and you are good to go.

Share this post


Link to post
Share on other sites

There is filter option at the top of the list of templates.

Expand it and change "Show system templates?" to "yes".

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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. :)

Share this post


Link to post
Share on other sites

Thanks Ryan. I don't have csv yet, but I am telling the client in which format the date's should be. I will test this at beginning of January, but it seems like it should be work or with very trivial work.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Forget to say: absolutely brilliant module Ryan. Very friendly UI and it was breeze to use!

Share this post


Link to post
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.

Share this post


Link to post
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) :)

Share this post


Link to post
Share on other sites

If you would export a .csv from your database it should escapes '"'s automatically :)

Share this post


Link to post
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."

Share this post


Link to post
Share on other sites

@raydale I didn't use the module yet, but i would say that you have to look for that page in the tree, and edit it to assign to it the module process.

  • Like 1

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

I assumed it would work by doing this. But it should be working by default...

Share this post


Link to post
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').

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Maybe you should first rebuild a timestamp with "strtotime()". Then you can use it in every format you want/need.

Share this post


Link to post
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).

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
    • By MoritzLost
      Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu:

      This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem.
      As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user.
×
×
  • Create New...