phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Thread owner bug

Goto page 1, 2  Next
 
Search this topic... | Search phpBB2 Discussion... | Search Box
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Author Message
hoimyr
Board Member



Joined: 16 Apr 2009

Posts: 115
Location: Oslo


flag
PostPosted: Wed Jun 27, 2012 8:55 am 
Post subject: Thread owner bug

Hi folks!

I just noticed something that can be a bug. When a moderator or admin changes som users first post the original user stop getting notifications via e-mail on replies. Even if its ticked on! I just put up an test on my site with new users and did some testing. Have any of you noticed this or is this only a bug on my site? I want the original users to continue to own their posts and get notifications. I guess we need to change something in the posting.php icon_eek.gif

edit: I constantly have to either help users with adding bbcodes or attachments and i also get this problem when i make a users post "featured" so it goes on the frontpage. If not i havent bother with it..but we end up doing this alot. Im now studying the includes/functions_post.php to figgure it out.. But im no php coder so if anyone knows a quick fix please let me know. Thanks!
Back to top
drathbun
Board Member



Joined: 24 Jul 2008

Posts: 663
Location: Texas


flag
PostPosted: Fri Jun 29, 2012 2:23 pm 
Post subject: Re: Thread owner bug

Does it work this way in a standard phpBB2 board? Because I don't know that I have ever noticed this. You might set up a test board with no MODs just to see if you can recreate the problem first. If you can, then it should be present in essentially every phpBB2 board, and a fix would be more global. Otherwise you're looking only at MOD code that you may have installed.
_________________
phpBBDoctor Blog
Back to top
dogs and things
Board Member



Joined: 18 Nov 2008

Posts: 621
Location: Spain


flag
PostPosted: Fri Jun 29, 2012 6:48 pm 
Post subject: Re: Thread owner bug

I wouldn┤t be surprised if this is standard behaviour.

A few years back I discovered a related misbehaviour: Notify of Reply gets activated by Admin edits. I never got round to fixing that one.

_________________
phpBB2 will never die, I hope!
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 428
Location: Qu├ębec


flag
PostPosted: Sat Jun 30, 2012 3:05 am 
Post subject: Re: Thread owner bug

I'll keep posting here, but an update should be made in that thread if we find a solution. I've been curious about that bug from the start so I looked around a bit tonight. Basically it seems it all happens in posting.php at line 402 (vanilla):

Code:
if ( $mode != 'newtopic' && $userdata['session_logged_in'] && $is_auth['auth_read'] )
   {
      $sql = "SELECT topic_id
         FROM " . TOPICS_WATCH_TABLE . "
         WHERE topic_id = $topic_id
            AND user_id = " . $userdata['user_id'];
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
      }

      $notify_user = ( $db->sql_fetchrow($result) ) ? TRUE : $userdata['user_notify'];
      $db->sql_freeresult($result);
   }
   else
   {
      $notify_user = ( $userdata['session_logged_in'] && $is_auth['auth_read'] ) ? $userdata['user_notify'] : 0;
   }

The problem being that notification preferences are checked based on $userdata['user_id'] -- in other words, the person editing the post. So we can confirm that it is standard behaviour.

The good news is that if I'm not mistaken, the fix is pretty simple. We first use get_userdata() to get the original poster's preferences, then apply them where appropriate:
Code:
-- REMOVED - DID NOT WORK - SEE BELOW --

Notice we don't change the else clause since it's for new topics, therefore the actual user's preferences are used (there is no existing poster_id).
This is only theory, not tested. If anyone would like to go ahead and test the various behaviours with this edit, we could perhaps include it in our list of unofficial-but-almost-mandatory updates.
Back to top
hoimyr
Board Member



Joined: 16 Apr 2009

Posts: 115
Location: Oslo


flag
PostPosted: Sat Jun 30, 2012 6:02 pm 
Post subject: Re: Thread owner bug

This is awesome. Good work!! I can test the code on a fresh board and do more testing on my other boards.
Back to top
hoimyr
Board Member



Joined: 16 Apr 2009

Posts: 115
Location: Oslo


flag
PostPosted: Sat Jun 30, 2012 10:07 pm 
Post subject: Re: Thread owner bug

I get this error when i tried the code:
Code:

Could not obtain topic watch information

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

SELECT topic_id FROM phpbb3_topics_watch WHERE topic_id = 7 AND user_id =

Line : 414
File : posting.php


testing:
Image link
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 428
Location: Qu├ębec


flag
PostPosted: Sat Jun 30, 2012 10:39 pm 
Post subject: Re: Thread owner bug

I can't test the actual notifications but the code doesn't produce an error on my local server. If you are certain you pasted the modified code correctly, can you attach a copy of your entire posting.php so I can see if MODs are interfering?
Back to top
dogs and things
Board Member



Joined: 18 Nov 2008

Posts: 621
Location: Spain


flag
PostPosted: Sun Jul 01, 2012 6:49 am 
Post subject: Re: Thread owner bug

I got the same error, but not always.

As a MOD I was able to edit posts without an error.

But neither me as a MOD nor ordinary users could reply to topics, when anybody hits the reply button in an existing topic the error that Hoimyr has posted popped up and as I see it the error is caused by your modified SQL query, Salvatos.

This is the error my boards pops up:
Code:
Could not obtain topic watch information

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

SELECT topic_id FROM phpbb_topics_watch WHERE topic_id = 10798 AND user_id =

Line : 709
File : posting.php


Line 709 says:
Code:
         message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);

Thank you for looking into this.

_________________
phpBB2 will never die, I hope!
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 428
Location: Qu├ębec


flag
PostPosted: Sun Jul 01, 2012 7:29 am 
Post subject: Re: Thread owner bug

Oh, thanks for the pointer. I had overlooked what the if clause actually included. Here's v2 (take note I didn't include the else part this time since it's not being changed):

Code:
if ( $mode != 'newtopic' && $userdata['session_logged_in'] && $is_auth['auth_read'] )
   {
      // Hotfix by Salvatos: Get preferences from original poster when editing
      // Preserves notification settings when admins and mods edit
      if ( $mode == 'editpost' ) // Should other modes be added? delete_poll? topicreview?
      {
         $poster_userdata = get_userdata($post_data['poster_id']);
      }
      else
      {
         $poster_userdata['user_id'] = $userdata['user_id'];
         $poster_userdata['user_notify'] = $userdata['user_notify'];
      }
      
      $sql = "SELECT topic_id
         FROM " . TOPICS_WATCH_TABLE . "
         WHERE topic_id = $topic_id
            AND user_id = " . $poster_userdata['user_id'];
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
      }

      $notify_user = ( $db->sql_fetchrow($result) ) ? TRUE : $poster_userdata['user_notify'];
      $db->sql_freeresult($result);
   }


Again, not tested for notifications but I've verified that it's getting the correct IDs when replying and editing. Let me know how it goes. Though it's late so I may have overlooked something else icon_wink.gif
Back to top
hoimyr
Board Member



Joined: 16 Apr 2009

Posts: 115
Location: Oslo


flag
PostPosted: Sun Jul 01, 2012 5:19 pm 
Post subject: Re: Thread owner bug

Got late here to..
Nice! I get no errors on a fresh board now. icon_smile.gif
I will do more testing the next hour and report back here.

edit: updated the tests in the post over!
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 428
Location: Qu├ębec


flag
PostPosted: Sun Jul 01, 2012 8:40 pm 
Post subject: Re: Thread owner bug

Looking at the updated results... this looks like a headache in the making icon_razz.gif
I'll look into it later, not sure it will be tonight. If anyone wants to jump in, be my guest icon_smile.gif

Edit: Wait, can someone tell me what the always notify option is supposed to do exactly? Does it just tick the box automatically for you or is it supposed to override it?
Back to top
dogs and things
Board Member



Joined: 18 Nov 2008

Posts: 621
Location: Spain


flag
PostPosted: Sun Jul 01, 2012 9:10 pm 
Post subject: Re: Thread owner bug

Yes, seems like this is quite more complicated as it seemed.

Fortunately, there┤s no hurry, as it probably has been like this for ages.

_________________
phpBB2 will never die, I hope!
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 428
Location: Qu├ębec


flag
PostPosted: Sun Jul 01, 2012 10:11 pm 
Post subject: Re: Thread owner bug

Hmmm I think I see where it could be going wrong. Well it can't be right, but we'll see if it completes the fix.

Step 0. Backup and stuff icon_smile.gif

Step 1. Apply the hotfix in my previous post.

Step 2. Still in posting.php, FIND
Code:
user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);

REPLACE WITH
Code:
$poster_id = ( isset($poster_userdata['user_id']) ) ? $poster_userdata['user_id'] : $userdata['user_id'];
         user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user, $poster_id);

Here we use $userdata if $poster_userdata isn't set, because that should mean this is not an edit. Caveat: That's only true if we include all necessary modes in the first fix (cf. comment there), so we'll have to look into that somehow.

Step 3. OPEN includes/functions_post.php. FIND
Code:
function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$post_id, &$notify_user)

REPLACE WITH
Code:
function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$post_id, &$notify_user, &$poster_id)


Note: global $userdata, $user_ip; just underneath can probably be removed, and $user_ip in particular doesn't even seem to be used as it stands, but I'll leave them in for now. Feel free to comment them out and report back, it should have no effect.

Step 4. We replace every $userdata['user_id'] with $poster_id. In every scenario the code is actually interested in the original poster regardless of the posting mode, not whoever is performing the action, and knowing we disregard mod/admin preferences if they're involved.
FIND
Code:
AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . ")

REPLACE WITH
Code:
AND tw.user_id NOT IN (" . $poster_id . ", " . ANONYMOUS . $user_id_sql . ")


FIND
Code:
AND user_id = " . $userdata['user_id'];

REPLACE WITH
Code:
AND user_id = " . $poster_id;


FIND
Code:
AND user_id = " . $userdata['user_id'];

REPLACE WITH
Code:
AND user_id = " . $poster_id;

(Yes, it occurs a second time, 12 lines after.)

FIND
Code:
VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";

REPLACE WITH
Code:
VALUES (" . $poster_id . ", $topic_id, 0)";


Step 5. SAVE/CLOSE and test.

Good luck... icon_smile.gif
I don't expect perfect results but this should mostly fix the admin interaction issue, the rest would be making sure the Always notify me thing works as it should. I prefer to go step by step.
Back to top
hoimyr
Board Member



Joined: 16 Apr 2009

Posts: 115
Location: Oslo


flag
PostPosted: Mon Jul 02, 2012 8:13 am 
Post subject: Re: Thread owner bug

Great work Salvatos!! Cool. Im at work now but ill try it first thing when i get home!

Do we need to test other things just to be shure that everything is working? How about editing polls aso? Or is that the same as other posts?
I can modify my little excel sheet and test other things. Just let me know.
Back to top
drathbun
Board Member



Joined: 24 Jul 2008

Posts: 663
Location: Texas


flag
PostPosted: Mon Jul 02, 2012 3:39 pm 
Post subject: Re: Thread owner bug

I am trying to understand the problem being solved here... if an admin edits the first post of an existing topic, then no notification should be sent. It's just an edit.
Quote:
When a moderator or admin changes som users first post the original user stop getting notifications via e-mail on replies. Even if its ticked on!

Now that would tell me that perhaps there is something else that happens when the administrator edits that turns off the notification. But editing should not trigger a notification...

_________________
phpBBDoctor Blog
Back to top
Display posts from previous:   
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Page 1 of 2 All times are GMT
Goto page 1, 2  Next
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0316 seconds using 15 queries. (SQL 0.0016 Parse 0.0012 Other 0.0288)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo