Hi there,
How would I go about altering the post date on a topic or post within a topic?
Hi there,
How would I go about altering the post date on a topic or post within a topic?
There is no way to do this at the current timeā¦ no pun intended.
Poo
Does ānot possibleā also include from the command-line?
Itās probably possible via Ruby command line or direct SQL, of course. I only meant the web UI.
Hereās how to do it via the command line
# ssh into your server
cd /var/discourse # or /var/docker on pre-V1 install
./launcher enter app
rails c
post = Post.find_by(id: 1234)
post.created_at = DateTime.new(2001,2,3,0,0,42) # year, month, day, hour, minute, seconds
post.save
Awesome! This seems to have worked, but Iām unclear on what Iām supposed to do or how to safely exit once Iāve altered the date/time.
Looking at my test install, the date for that post hasnāt changedā¦ Iām sure Iām missing something? Thanks for your help!
CTRL + D is how you exit
Or by typing exit
or !!!
.
Hmā¦ I manage to exit out. I was doing it properly (but wanted to ask in case I was just being a moron), but get a message saying:
Unable to write to your history file, history not saved
Thanks again for your help and patience guys; Ruby is still pretty new to me but Iām learning to love it.
Yeah, thatās a different thing all together, one that you probably donāt need to worry about. It is simply telling you it didnāt save the commands you entered so when you connect later you could use history
to see what commands you ran previously.
If you re-run rails c and type history
, you should get a blank list. If you enter a few commands and run it again, you will see a list of the commands you have run up to that point.
Is there something else I need to do to get the changes to show up on the front-end then? The post I edited is still showing the original date. Reboot Discourse, perhaps?
Iām not sure, @zogstrip does he need to rebake the post? Or clear any caches?
Disregard my last questionā¦ In looking at the output in red in those screenshots above, I donāt seem to be targeting the post I think I amā¦ The summary text in there is coming from one of the posts that get created when making a new category.
How would I properly determine a postās ID? This one, for example:
http://forum.curiouscosmos.com/t/object-floating-above-newfoundland-iceberg/37/2?u=cosmo
Performing a view source, contains this:
<article class="boxed" id="post_2" data-bindattr-28="28" data-post-id="39" data-bindattr-29="29" data-user-id="1">
Which has data-post-id="39"
I canāt promise that is the correct answer thoughā¦
Yessir, that was it! I suppose it helps if Iām actually changing the correct post ID
Thank you for all your help!
By the way, you can also find the post by the topic id and post number which are perhaps easier to read from the forum via the share link instead of inspecting source:
Post.find_by(topic_id: 123, post_number: 45)
This is working excellently, though I do have one more question:
How do I force a refresh or update of the last āactivityā on the thread listing page? If all of the dates within a thread have a date of May or June, the last activity shouldnāt say 22 minutes ago
Thanks guys
You can see how Discourse does this internally in the PostCreator
class:
https://github.com/discourse/discourse/blob/v1.0.0/lib/post_creator.rb#L195-L203
So in your case, this should do:
t = Topic.find(123)
t.last_posted_at = t.posts.last.created_at
t.bumped_at = t.posts.last.created_at
t.save!
Thanks! That pointed me in the right direction.
I found that I had to also update bumped_at and updated_at (or whatever their proper names are, Iām not looking at the screen right now).
The bumped_at field is what is displayed & sorted by.