dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse


Our Discord Notification Server invitation link is https://discord.gg/jB2qmRrxyD

Author Topic: [batch php] How to reassign a post's authour  (Read 16 times)

Offline smfadmin (OP)

  • SMF (internal) Site
  • Owner
  • Sr. Member
  • *****
  • Administrator
  • *****
  • Admin
  • ****
  • Join Date: Dec 2014
  • Location: Management
  • Posts: 696
  • Reputation Power: 0
  • smfadmin has hidden their reputation power
  • Last Login:Today at 03:53:40 AM
  • Supplied Install Member
[batch php] How to reassign a post's authour
« on: Yesterday at 09:08:36 PM »
📎 Click on me to view all my attachments
ListAttBBC  |  v7.3.0  |  2026-10-26  |  Andrew.human & Claude.ai  |  live 07:10:13
#FileSizeDownloadsInfoDL
00reassign_author_v1.0.1.zip5.3 KB1â„šī¸âŦ‡ī¸
01reassign_author.md2.3 KB1â„šī¸âŦ‡ī¸
02TRANSCRIPT of the chatlog 'Reassign post author PHP script' with Andrew.human and Claude.ai -- SUCCESS.pdf  [native]  [pdf in chunks]484.3 KB4â„šī¸âŦ‡ī¸


📄 Inline textv1.9.1
[lmv=inline] 
> Live  root@forum:22:03:40:/var/www/html# php /var/www/html/reassign_author.php --msgs=49940 --apply --to 3913

reassign_author.php v1.0.0 (2026-10-31)

MODE: APPLY (writing)
Target author: Lada Vasilyeva (member id 3913)
Requested 1: 1 to change, 0 already theirs, 0 not found.
  msg 49940 (topic 7536): smfadmin [id 1] -> Lada Vasilyeva [id 3913]
  post count: member id 1 -1
  post count: member id 3913 +1
Done: 1 post(s) reassigned. Batch id: 20261101011343
VERIFY: PASS (messages and topic first/last poster all agree)
To undo: php reassign_author.php --undo=20261101011343 --apply

> Live  root@forum:22:13:43:/var/www/html#


📝 Inline Markdownv4.6.3 · 2026-11-01

Me: how can i change the author of a post ?

Claude: [October 31, 2026, 11:35:15 PM]

SMF has no built-in way to change the author of a post. The only related feature is Admin > Maintenance > Members > Reattribute Guest Posts, and that only works on posts made by guests. For member-to-member changes it has to be done in the database, so take a backup first.

1. The post itself (smf_messages, or your table prefix):

UPDATE smf_messages
SET id_member = NEW_ID, poster_name = 'NewName', poster_email = 'new@email'
WHERE id_msg = MSG_ID;

2. The topic row. If the post is the first or last message in its topic, the topic stores the member too:

UPDATE smf_topics SET id_member_started = NEW_ID WHERE id_first_msg = MSG_ID;
UPDATE smf_topics SET id_member_updated = NEW_ID WHERE id_last_msg = MSG_ID;

3. Post counts. SMF doesn't adjust these for you. If the board counts posts, add 1 to the new author's smf_members.posts and subtract 1 from the old author's.

Run SELECT id_msg, id_topic, id_member FROM smf_messages WHERE id_msg = MSG_ID; before and after to confirm the change.

Me: Give me a single batch php job to run please and let's call it new reassign_author.php

Claude: [October 31, 2026, 11:38:23 PM]

reassign_author_v1.0.0.zip is delivered. It holds reassign_author.php and a short manual, reassign_author.md.

Run it from the forum root, next to Settings.php:

php reassign_author.php --msgs=101,105-110 --to=Chipper (dry run)
php reassign_author.php --msgs=101,105-110 --to=Chipper --apply (updates
php reassign_author.php --undo=BATCHID --apply (restores)

It prints its version as it starts. The syntax check passed and --help runs, but I have no database here, so the write path has not been run against SMF. Do the dry run first.

Additions you didn't ask for:

  • Dry run is the default. Nothing is written without --apply.
  • Backup and undo. Original values go into a reassign_author_backup table, so a batch can be undone.
  • Cross-check. A read-only check at the end prints VERIFY: PASS or FAIL.
  • Manual. reassign_author.md, per your standing rule.

One assumption to check: to decide which posts adjust a member's post count, I used SMF's board flag count_posts = 0 to mean "counts posts" (SMF stores it inverted). The dry run prints the post-count changes it would make, so a wrong guess would show up before anything is written.

The script is written for PHP 5.3, in case Live is on CentOS 6 defaults.

RuleStatus
@version / @date in doc blockdone (1.0.0, 2026-10-31)
Manual version history entrydone
Version shown at run startdone
Zip with dotted versiondone (reassign_author_v1.0.0.zip)
xmllint on XMLnot needed (no XML)
Unrequested changes listed beforehanddone (above)
Legacy zippernot needed (standalone script, not an SMF package)

Me: WTF is the BATCHID ?

Claude: [November 01, 2026, 12:13:10 AM]

The batch ID is just the date and time the --apply run started, as 14 digits (YYYYMMDDHHMMSS), for example 20261101001310. The script makes it up itself, and you never choose it.

It prints it when an apply finishes, in the line Done: N post(s) reassigned. Batch id: .... The last line of that run is the full undo command with the ID already filled in, so you can copy that line.

If you've lost it, run this against the database and it lists every batch with its post count:

SELECT batch_id, COUNT(*) FROM smf_reassign_author_backup GROUP BY batch_id;

Dry runs don't create a batch, so they never print one.



« Last Edit: Yesterday at 10:33:22 PM by smfadmin »
friendly
0
funny
0
informative
0
agree
0
disagree
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
measure twice, cut once

Tags:
 


dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse





TERMS AND CONDITIONS

In no event will d&u or any person involved in creating, producing, or distributing site information be liable for any direct, indirect, incidental, punitive, special or consequential damages arising out of the use of or inability to use d&u. You agree to indemnify and hold harmless d&u, its domain founders, sponsors, maintainers, server administrators, volunteers and contributors from and against all liability, claims, damages, costs and expenses, including legal fees, that arise directly or indirectly from the use of any part of the d&u site.


TO USE THIS WEBSITE YOU MUST AGREE TO THE TERMS AND CONDITIONS ABOVE


Founded December 2014
SimplePortal 2.3.6 © 2008-2014, SimplePortal