Please help on submit_post and post_time

Discussion forum for MOD Writers regarding MOD Development.
Locked
samer.joudi
Registered User
Posts: 2
Joined: Wed Sep 02, 2009 4:49 pm

Please help on submit_post and post_time

Post by samer.joudi »

Hi;

I am trying to migrate some old articles (news, articles, etc...) from my old custom website into phpBB (3.0.5) as topics and posts.

I know I should use submit_post function to accomplish this, and I have already migrating some articles for test.

My problem is in controlling time of the post, because I want to give the new posts the same time and date the original articles were posted on, and not the date and time I am migrating the contents.

I found all examples on the web using the following code which simply use the current date and time:

Code: Select all

'post_time'         => 0,
But I need to set a specific time, but I couldn't....

I tried using the unix timestamp directly:

Code: Select all

'post_time'         => 1167609600,
and using the strtotime function:

Code: Select all

'post_time'         => strtotime('2007-01-01'),
but the new post will always take the current date and time...

Please help............
User avatar
RMcGirr83
Former Team Member
Posts: 21613
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Please help on submit_post and post_time

Post by RMcGirr83 »

in includes/functions_posting.php within the submit_post function there is this

Code: Select all

'post_time'			=> $current_time,
$current_time is the time of the server, if you wanted to change that and you have the time set in your data array, then you would change it to

Code: Select all

'post_time'			=> $data['post_time'],
and the time that you have set will then be inserted into the database.
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
samer.joudi
Registered User
Posts: 2
Joined: Wed Sep 02, 2009 4:49 pm

Re: Please help on submit_post and post_time

Post by samer.joudi »

Thank you very much... I will try this and come back to you if I need further help.
richbouchard
Registered User
Posts: 31
Joined: Tue Jul 14, 2009 5:42 pm

Re: Please help on submit_post and post_time

Post by richbouchard »

RMcGirr83 wrote:in includes/functions_posting.php within the submit_post function there is this

Code: Select all

'post_time'			=> $current_time,
... change it to ...

Code: Select all

'post_time'			=> $data['post_time'],
and the time that you have set will then be inserted into the database.
This concept worked well for me, but I found that just changing 'post_time' left me with posts showing the correct time, but topics still displaying the server time. So I changed 'topic_time' as well, further down in submit_post. However... now the last post time on the index was showing server time while topics and posts were correct.

The third time I went back into includes/functions_posting.php I was getting nervous about making so many changes (trying to keep my board as vanilla as possible to avoid upgrade hassles) so I came up with a plan to minimise adjustments. Not sure if it was the right thing to do, but it was simple and it worked!

What I did was, reset includes/functions_posting.php to its vanilla configuration with all times being set to $current_time. Then I found

Code: Select all

	$current_time = time();
near the top of that file and changed it to:

Code: Select all

//	$current_time = time();
	$current_time = $data['post_time'];
to effectively fool the script into thinking the current time is the post time on each execution.

Then I re-ran my post import script and everything worked like a charm. All posts imported from my old forum with post, topic and last post times all set as required.

Undid the one-line change above so that new posts will use $current_time and bailed out before I did any more damage!

Hope this helps someone down the line.

Cheers,

Rich
kazkotx
Registered User
Posts: 21
Joined: Mon Sep 22, 2008 3:23 pm

Re: Please help on submit_post and post_time

Post by kazkotx »

This would take care of it permanently. Seems to me that this should be a default situation for the code anyway so that other scripts will be able to function.

Code: Select all

   if ($data['post_time'] != null) {
      $current_time = $data['post_time'];
   } else   {
      $current_time = time();
   }
User avatar
tbackoff
Former Team Member
Posts: 7064
Joined: Thu Jun 04, 2009 1:41 am
Location: cheerleading practice
Name: Tabitha Backoff

Re: Please help on submit_post and post_time

Post by tbackoff »

That's too much code. :P

Code: Select all

$time = (isset($data['post_time'])) ? $data['post_time'] : time();
Flying is the second best thrill to cheerleaders; being caught is the first.
Locked

Return to “[3.0.x] MOD Writers Discussion”