Warning: The author of this contribution does not provide support for it anymore.

Change Post Time

PHPBB 3.31 - Modifying the sync function - Change Post Time

PHPBB 3.31 - Modifying the sync function

by Edson Quadros » Tue Oct 13, 2020 3:05 pm

This extension is very useful, but it has a small problem that I solved:
When changing the date of a post leaving it older in the topic, PHPBB still continues to identify the original message as the main message of the topic. That's because PHPBB synchronizes the topic and in this routine ranks the first post with the lowest ID. This is not wrong, but they never imagined that we had an extension to change the posting date and this could be earlier with a smaller date and a larger ID.

The solution to this, I found in the sync function in the file \ includes \ functions_admin.php, where PHPBB synchronizes the topics.
I changed SQL to identify the smallest posting date and not the smallest ID. This change is working perfectly on my forum and from what I have been able to test it did not affect the synchronization that continues to work even without the extension installed, as it simply tells PHPBB to synchronize by date and not by ID, which will be in the same order if no post has the date has been modified so far.
I am sharing it because I worked hard to do this work and I think that many who use this extension should have this same difficulty.
Sorry for my English.

Original SQL:
$sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id

Modified SQL:
$sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) total_posts,
(SELECT b.post_id FROM ' . POSTS_TABLE . ' b WHERE MIN(t.post_time)=b.post_time and t.topic_id=b.topic_id) first_post_id,
(SELECT b.post_id FROM ' . POSTS_TABLE . ' b WHERE MAX(t.post_time)=b.post_time and t.topic_id=b.topic_id) last_post_id
Sorry my English
User avatar
Edson Quadros
Registered User
Posts: 30
Joined: Wed Sep 09, 2020 3:44 pm
Location: Brasil
Name: Edson Quadros

Re: PHPBB 3.31 - Modifying the sync function

by Etabeta » Thu Dec 24, 2020 1:32 pm

Edson Quadros wrote:This extension is very useful, but it has a small problem that I solved:
When changing the date of a post leaving it older in the topic, PHPBB still continues to identify the original message as the main message of the topic. That's because PHPBB synchronizes the topic and in this routine ranks the first post with the lowest ID. This is not wrong, but they never imagined that we had an extension to change the posting date and this could be earlier with a smaller date and a larger ID.

The solution to this, I found in the sync function in the file \ includes \ functions_admin.php, where PHPBB synchronizes the topics.
I changed SQL to identify the smallest posting date and not the smallest ID. This change is working perfectly on my forum and from what I have been able to test it did not affect the synchronization that continues to work even without the extension installed, as it simply tells PHPBB to synchronize by date and not by ID, which will be in the same order if no post has the date has been modified so far.
I am sharing it because I worked hard to do this work and I think that many who use this extension should have this same difficulty.
Sorry for my English.

Original SQL:
$sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id

Modified SQL:
$sql = 'SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) total_posts,
(SELECT b.post_id FROM ' . POSTS_TABLE . ' b WHERE MIN(t.post_time)=b.post_time and t.topic_id=b.topic_id) first_post_id,
(SELECT b.post_id FROM ' . POSTS_TABLE . ' b WHERE MAX(t.post_time)=b.post_time and t.topic_id=b.topic_id) last_post_id

Hi,
I tried the solution you suggested but when I try to resync a forum I get this error (not always, only on some forums):

Errore Generale
SQL ERROR [ mysqli ]
Subquery returns more than 1 row [1242]

SQL

SELECT t.topic_id, t.post_visibility, COUNT(t.post_id) total_posts, (SELECT b.post_id FROM phpbb_posts b WHERE MIN(t.post_time)=b.post_time and t.topic_id=b.topic_id) first_post_id, (SELECT b.post_id FROM phpbb_posts b WHERE MAX(t.post_time)=b.post_time and t.topic_id=b.topic_id) last_post_id FROM phpbb_posts t WHERE (t.topic_id BETWEEN 4035 AND 6035) GROUP BY t.topic_id, t.post_visibility

BACKTRACE

FILE: (not given by php)
LINE: (not given by php)
CALL: msg_handler()
FILE: [ROOT]/phpbb/db/driver/driver.php
LINE: 1023
CALL: trigger_error()

FILE: [ROOT]/phpbb/db/driver/mysqli.php
LINE: 195
CALL: phpbb\db\driver\driver->sql_error()

FILE: [ROOT]/phpbb/db/driver/factory.php
LINE: 345
CALL: phpbb\db\driver\mysqli->sql_query()

FILE: [ROOT]/includes/functions_admin.php
LINE: 1954
CALL: phpbb\db\driver\factory->sql_query()

FILE: [ROOT]/includes/acp/acp_forums.php
LINE: 321
CALL: sync()

FILE: [ROOT]/includes/functions_module.php
LINE: 676
CALL: acp_forums->main()

FILE: [ROOT]/adm/index.php
LINE: 81
CALL: p_master->load_active()
User avatar
Etabeta
Registered User
Posts: 7
Joined: Tue Feb 12, 2019 11:36 pm
Location: Turin, Italy
Name: Luca

Re: PHPBB 3.31 - Modifying the sync function

by Leinad4Mind » Wed May 15, 2024 3:39 pm

The code above could work on not busy forums, but for busy forums (like the last above post where that happened) where 2 users could post at the exact same milisecond, my solution was this:

Code: Select all

$sql = 'SELECT t.topic_id,  t.post_visibility,  COUNT(t.post_id) AS total_posts,
				(SELECT b.post_id FROM ' . POSTS_TABLE . ' b WHERE t.topic_id = b.topic_id ORDER BY b.post_time ASC, b.post_id ASC LIMIT 1) AS first_post_id,
				(SELECT b.post_id FROM ' . POSTS_TABLE . ' b WHERE t.topic_id = b.topic_id ORDER BY b.post_time DESC, b.post_id DESC LIMIT 1) AS last_post_id
			FROM ' . POSTS_TABLE . ' t
			' . $where_sql . '
			GROUP BY t.topic_id, t.post_visibility';
Want to access all my Premium MODs and Extensions? Check out my store
phpBB Portugal Translator and Moderator
User avatar
Leinad4Mind
Translator
Posts: 865
Joined: Sun Jun 01, 2008 11:08 pm