Jump to content

Help importing comment dates


Orlando Hamsho
 Share

Recommended Posts

I have been working on a considerably large project for a while which involves, amongst other things, importing quite a considerable amount of data from a wordpress site.

Alas, through the means I have been given (CSV reading loops/ Direct SQL manipulation / The processwire wordpress import module, btw THANK YOU) I have managed to get most of it working and the site is nearly done... except for one thing.

All of my comment's dates are set as the one in which they were created... on the new site.

Now I do happen to have a CSV that contains all of the data I need to work with, and have even set up a quick test on a sample page with only a single comment.

So, the problem here is that no matter how many times I save the field, the created time doesn't seem to change at all.

Just to verify.

$article = $pages->get("template=article,name=health-care-and-neighborhood-watch");
echo $article->title."__WPID: ".$article->post_id."<br>";
if (($handle = fopen("comments.csv", "r")) !== FALSE) {
   $article->of(false);
   while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      //$data[1] is the article id;
      //$data[7] is the approval date, we're using that as created.
      if($data[1]==$article->post_id){
         foreach($article->comments as $c){
            if($c->cite==$data[2]&&$c->text=$data[8]){
               echo "Previous date: ".date("Y-m-d",$c->created);
               $c->created=strtotime($data[7]);
               echo "<br>"."New and Improved date: ".date("Y-m-d",$c->created);
            }
         }
      }
   }
   if($article->save()){
      echo "<br> SAVED! :)";
   }
   fclose($handle);
}else{
   echo "File not found";
}

I am targeting the right page. Output formatting is off. The page is supposedly even getting saved, but the created value for that comment does not seem to change in between different loops.

Is there something I am missing to make my import happen? Or is there another way in which I can get my comments imported differently?

I would very much appreciate this help.

Link to comment
Share on other sites

Hi Orlando,

If I remember correctly it's not possible to modify the created timestamp with the ProcessWire API. What works is to fire an SQL query for this job, something like this:

UPDATE field_<comment_field_name> SET created=<timestamp> WHERE pages_id = <page_id>

Edit: Welcome to ProcessWire  :)

  • Like 1
Link to comment
Share on other sites

@matijazp

Does quiet work to modify the created date?

'quiet' => boolean - When true, modified date and modified_users_id won't be updated (default=false)

Also comments are not pages, so I guess it will not work.

  • Like 1
Link to comment
Share on other sites

$p = $pages->get(1234);
$p->created = '2015-07-09 11:12:13';
$p->save(array('quiet' => true));

It's not documented, but quiet allows for changing the created date in this line: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Pages.php#L1082

Thank you a lot guys, I had no idea this method even existed, guess you learn something new everyday :).

Sadly due to the way comments work (Them not being pages) the method doesn't seem to have the wanted effect, tried it a couple times and the result kept on being the same.

Hi Orlando,

If I remember correctly it's not possible to modify the created timestamp with the ProcessWire API. What works is to fire an SQL query for this job, something like this:

UPDATE field_<comment_field_name> SET created=<timestamp> WHERE pages_id = <page_id>

Edit: Welcome to ProcessWire  :)

This totally worked (with minor modifications) , I just completed the import of 1500+ comment dates on a single go after testing out this method. Now I do have some issues that pertain to my .csv's data, but those are another topic entirely. Thank you so much Wanze.

Anyway, thanks to all of you guys for helping me out here, there really is always a way to work things around, even if it means thinking outside the box. It'll be nice being a part of this community :P

  • Like 1
Link to comment
Share on other sites

Hi Orlando - glad you found the MigratorWordpress importer useful. 

All of my comment's dates are set as the one in which they were created... on the new site.

I assume the comments were imported automatically via MigratorWordpress? I think this is a bug in the module. The "Import Created / Modified Dates" settings is not working for comments. Was this your situation or was your initial comments import handled outside of MigratorWordpress?

Either way, I'll add it to my list to fix this.

  • 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

×
×
  • Create New...