Jump to content

Comments: Howto import an existing guestbook?


kolewu
 Share

Recommended Posts

Hello,

I'm new into ProcessWire and I love it! Originally I have planned to evaluate several CMS and then decide which one to use -- but after some hours with PW I decided not to look any further :)

But now I'm stuck with the guestbook from the old site and beg for help: How can I import the old postings with the correct date into comments?

Since they have their own database table and are not organized as (sub)pages, I cannot use the import module, right?

And because the old guestbook has had an optional website field: how can I preserve this? I know that the comments should be enhanced with this type of field sometimes (+1 from me for this feature!) ...

Thank you

Uwe

Link to comment
Share on other sites

Thank you Mats!

I wonder how I have not found this ... maybe I have only searched the site and not the forums.

Will try to use the infos as soon as possible -- unfortunately the old guestbook is not from a CMS but an hardwired cgi-script and I have to convert the HTML table, but this is not a PW problem :D

Link to comment
Share on other sites

OK, here I am again. The import has been successfully carried out with the help of the links above but after solving some problems ...

The first step was to convert the old guestbook to json and after it was converted to CSV this web app http://www.cparker15...es/csv-to-json/

Then I spent some time to work around the scripting problems but with this template, the json file was successfully converted to comments.

<?php
# moderation of comments must be disabled before running this script
# likewise the email sending for a comment should be switched off
$file = './guestbook.json';
$data = json_decode(file_get_contents($file), true);
if(!$data || $data == false) throw new WireException("Can't load data from $file.");
$p = $wire->pages->get("/gaestebuch/");
$p->setOutputFormatting(false);
foreach (array_reverse($data) as $item) {
$c = new Comment();
$c->text = trim($item['text']);
$c->cite = trim($item['name']);
$c->email = trim($item['email']);
$c->homepage = trim($item['website']);
$c->created = strtotime(trim($item['date']));
# setting status has no effect if moderation is set to "only new"
$c->status = 1;
$p->comments->add($c);
}
$p->save('comments');
$p->setOutputFormatting(true);
echo 'import successful';

The following problems had to be solved

  • json_decode() only returns an array with the data and not with any metadata, so the result is the return value and not in $data['status'].
  • Output formatting has to be disabled around the save.
  • If moderation for the comments is set to always or only new, setting status doesn't has any effect -- so the moderation mode must be set to none before the import.
  • If email notification for comments is enabled, every new comment triggers an email -- so it would be wise to disable email notification before import.

Now I only miss a field for a website and since it is part of the roadmap for the next PW version I would like to know if there is a (preliminiary) implementation that I can use to import this field in a compatible manner.

May this be helpful to anyone.

  • Like 1
Link to comment
Share on other sites

Now I only miss a field for a website and since it is part of the roadmap for the next PW version I would like to know if there is a (preliminiary) implementation that I can use to import this field in a compatible manner.

Thanks for posting this. The website field isn't in there yet, but it planned for 2.3, so I will try to go ahead and get this into the dev branch here shortly.

Link to comment
Share on other sites

While we are at the comments API, I was considering implementing a "search" feature on comments, but it seems that find() API can't be used for this :

Error Exception: Operator '*=' is not implemented in FieldtypeComments

Error Exception: Operator '~=' is not implemented in FieldtypeComments

Do you have plans to implement these operators ?

thanks

Link to comment
Share on other sites

Interesting, I didn't realize we didn't have those implemented for FieldtypeComments, but you are right. We've already got the fulltext index there to do it, so definitely need to add this support. I have added it and will test locally before pushing to the dev branch.

  • Like 1
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...