Simple Machines Community Forum

SMF Support => SMF 2.1.x Support => Topic started by: m4z on September 01, 2019, 08:32:53 AM

Title: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 01, 2019, 08:32:53 AM
Hi (hope this isn't a duplicate)!

In my private installation, when I view a thread and want to change the notification settings by clicking on the top or bottom "No alerts or emails" button and choose any of the four available options, I see a huge "Loading..." banner at the top of the page and nothing further happens (when reloading after a while, the setting hasn't changed). Subscribing to boards works fine.

My admin log contains the following two errors:
First:

Second:

The code section mentioned in the first error is this:

   138: $smcFunc['db_insert']($insert ? 'insert' : 'replace',
   139: '{db_prefix}log_topics',
   140: array(
   141: 'id_member' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'unwatched' => 'int',
   142: ),
   143: $log,
   144: array('id_member', 'id_topic')
==>145: );



When I inspect my action in Chromium, I see a XHR with a response of 500:

Request headers:

GET /index.php?action=notifytopic;topic=38;mode=3;[hexstring]=[hexstring];xml HTTP/1.1
Host: [my-forum]
Connection: keep-alive
Accept: */*
DNT: 1
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Referer: https://[my-forum]/index.php?topic=38.msg125;boardseen
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7,es-ES;q=0.6,es;q=0.5,ru-RU;q=0.4,ru;q=0.3
Cookie: SMFCookie[number]=[stuff1][my-forum][morestuff1]; PHPSESSID=[evenmorestuff1]; SMFCookie[number]=[stuff2][another-forum-on-another-subdomain][morestuff2]; PHPSESSID=[evenmorestuff2]


Response (invisible to the user):

<div id="fatal_error">
<div class="cat_bar">
<h3 class="catbg">
An error has occurred
</h3>
</div>
<div class="windowbg">
<div class="padding">
The database value you're trying to insert does not exist: 0
</div>
</div>
</div>
<div class="centertext">
<a class="button" href="javascript:document.location=document.referrer">Back</a>
</div>
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: d3vcho on September 01, 2019, 08:44:08 AM
I couldn't replicate the error. Are you using RC2 or latest GitHub build?
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 01, 2019, 08:57:59 AM
RC2 (plus some manual bugfixes in one of the two installations I tested this in). Will try to get a full picture, maybe update (most likely no today)...
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: d3vcho on September 01, 2019, 09:34:48 AM
You should use latest GitHub build. RC2 was released a few months ago and there has been a lot of work done in 2.1.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 01, 2019, 09:45:53 AM
Yeah, haven't had time yet to look into release/update management (or even to set up backups) for my staging and production forums. Are there any docs on best practices, or should I just put my staging and prod forum dirs into different git branches?
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: d3vcho on September 01, 2019, 03:02:30 PM
There are no docs for that. We just recommend not to use SMF 2.1 on production sites because as it's an under-development version, you may encounter errors and bugs. Although some people decide to run it, it depends on your skills in general. There are some people that maintain their production sites up to the latest GitHub build, some others up to the latest release (RC2 in our case)... It just depends on what do you want and what how much are you willing to risk based on your skills.

If you have 2 sites and one of them is in production, I would recommend sticking with RC2 in the production one and keep the other one updated with latest GitHub build as a playground.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 04, 2019, 06:04:03 PM
Quote from: d3vcho(); on September 01, 2019, 03:02:30 PM
We just recommend not to use SMF 2.1 on production sites because as it's an under-development version, you may encounter errors and bugs. Although some people decide to run it, it depends on your skills in general. There are some people that maintain their production sites up to the latest GitHub build, some others up to the latest release (RC2 in our case)... It just depends on what do you want and what how much are you willing to risk based on your skills.

Yeah, I think I know what I'm doing (and have seen and reported my share of bugs), although I'm not strong and PHP and always short on time. ;)
My small user group was involved in the decision and preferred being beta testers. (Also, "production" in my case just means "a bunch of friends needed a private forum for a hobby", no SLAs or anything, just unpaid volunteer work.)


Quote from: d3vcho(); on September 01, 2019, 03:02:30 PM
If you have 2 sites and one of them is in production, I would recommend sticking with RC2 in the production one and keep the other one updated with latest GitHub build as a playground.

The point of the staging or "beta" forum is to be exactly the same as the production site, only with less users and no (precious) content, to test any small to major change before touching the production forum.
I'll try to update my third, previously unmentioned, throw-away "alpha" forum to HEAD once I've figured out a way to manage my changes (I will probably just put the forum dirs into different git branches later this month, to be able to cherry-pick file changes across them, and because I have no better idea right now).
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 08, 2019, 08:55:51 AM
My problem persists in the current Github ("release-2.1" branch) HEAD (6ba1e53c0b65edb202fa17b9dc0088f610fdbfd8, 2019-09-01).
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: shawnb61 on September 08, 2019, 11:37:38 AM
I cannot replicate this - either under RC2 or the current github, in my WAMP or Linux environments. 

Could you copy the support info from under Admin | Main | Support & Credits?  That would provide the mysql & php versions. 

Do you have any mods installed?

Was RC2 your initial install?  Or did you install 2.1 prior to RC2?

When upgrading to the current github, did you run the upgrader, or just overwrite the files? 
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 08, 2019, 11:49:47 AM
Quote from: shawnb61 on September 08, 2019, 11:37:38 AM
I cannot replicate this - either under RC2 or the current github, in my WAMP or Linux environments. 

Could you copy the support info from under Admin | Main | Support & Credits?  That would provide the mysql & php versions. 

Yeah, later today. A mod uninstall just broke my playground install, will have to reinstall.


Quote from: shawnb61 on September 08, 2019, 11:37:38 AM
Do you have any mods installed?

None that should matter:


Quote from: shawnb61 on September 08, 2019, 11:37:38 AM
Was RC2 your initial install?  Or did you install 2.1 prior to RC2?

Initial install.


Quote from: shawnb61 on September 08, 2019, 11:37:38 AM
When upgrading to the current github, did you run the upgrader, or just overwrite the files?

I dropped the database, then copied over the files from a current git checkout with the following script, then ran the installer. I hope this gives me a fresh install.

# cat /root/git/smf-alpha-deploy.bash
#!/bin/bash

set -e

GITCO="/root/git/SMF2.1"
TARGET="/home/alpha-smf/public_html"

# TODO only works once per day
mv ${TARGET}{,.$(date +%F)}
mkdir ${TARGET}
cp -r ${GITCO}/* ${TARGET}/

# some files aren't where they're supposed to be
rm -rf ${TARGET}/other
cp ${GITCO}/other/{install*,Settings.php,readme.html} ${TARGET}/

chown -R alpha-smf.www-data ${TARGET}/
chmod -R 775 ${TARGET}/
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: Arantor on September 08, 2019, 01:59:05 PM
May be relevant to note that this is Postgres (judging by comments in other threads) which means it might not work properly and probably has never been tested in PGSQL before now.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 08, 2019, 03:49:33 PM
Quote from: m4z on September 08, 2019, 11:49:47 AM
Quote from: shawnb61 on September 08, 2019, 11:37:38 AM
I cannot replicate this - either under RC2 or the current github, in my WAMP or Linux environments. 

Could you copy the support info from under Admin | Main | Support & Credits?  That would provide the mysql & php versions. 

Yeah, later today. A mod uninstall just broke my playground install, will have to reinstall.

Support Information:
Quote
Version Information:
Forum version: SMF 2.1 RC2
Current SMF version: SMF 2.1 RC2
GD version: 2.1.1-dev
PostgreSQL engine: PostgreSQL
PostgreSQL version: 9.4.22
PHP: 5.6.40-0+deb8u4
Server version: lighttpd

I haven't installed the mods again, the problem exists without them, too.


Quote from: Arantor on September 08, 2019, 01:59:05 PM
May be relevant to note that this is Postgres (judging by comments in other threads) which means it might not work properly and probably has never been tested in PGSQL before now.

Yeah I figured this would be visible in the support info (and I was in a hurry). I also can't judge if the DB type has any influence on Notification behavior. From your comment I assume it does?
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: Arantor on September 08, 2019, 04:09:39 PM
I'm just suggesting that it might be a PGSQL-specific bug because that stuff has never, ever been thoroughly tested on PGSQL.

I don't think it misbehaves on MySQL but it's been a long time since I checked.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: albertlast on September 08, 2019, 04:23:04 PM
Can you please check the postgres log in you data directy of postgres?
Ther should be listen query from smf which created errors.

Based on the error message you mention,
the error don't sound like a postgres issue.

Please had in mind that gdpr helper is not working on postgres,
as fare i know.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 08, 2019, 04:45:09 PM
Quote from: albertlast on September 08, 2019, 04:23:04 PM
Can you please check the postgres log in you data directy of postgres?
Ther should be listen query from smf which created errors.

Based on the error message you mention,
the error don't sound like a postgres issue.

This is all I have for the last install:
Quote
2019-09-08 19:37:50 UTC [14086-1] alpha-smf@alpha-smf ERROR:  relation "alphasmf_settings" does not exist at character 36
2019-09-08 19:37:50 UTC [14086-2] alpha-smf@alpha-smf STATEMENT:
                                SELECT variable, value
                                FROM alphasmf_settings
2019-09-08 19:37:50 UTC [14080-1] alpha-smf@alpha-smf ERROR:  relation "alphasmf_settings" does not exist at character 34
2019-09-08 19:37:50 UTC [14080-2] alpha-smf@alpha-smf STATEMENT:
                        SELECT variable, value
                        FROM alphasmf_settings

The error about char 36 is in the logs 14 times, the last one about char 34 only once. IIRC, I had errors like this on every install, right when the DB tables are created the first time. I always assumed this was some code testing for pre-existing tables.


Quote from: albertlast on September 08, 2019, 04:23:04 PM
Please had in mind that gdpr helper is not working on postgres,
as fare i know.

I have it working and been using it for a few months (https://www.simplemachines.org/community/index.php?topic=560637.msg4017874#msg4017874) (I can install and use it without problems, just not uninstall it (https://www.simplemachines.org/community/index.php?topic=560637.msg4030485#msg4030485) ;D). But as I stated above, the problem persists whether I install any mods or not.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: albertlast on September 08, 2019, 04:53:35 PM
But the table alphasmf_settings exists now?

You gdpr fix looks very wrong,
the mod author or you should use the smf db_insert api like mention below.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 08, 2019, 05:06:42 PM
Quote from: albertlast on September 08, 2019, 04:53:35 PM
But the table alphasmf_settings exists now?

Quotealpha-smf=> select * from alphasmf_settings;
[...]
(212 rows)

I guess I'd have more than my 2 errors (mentioned in the first post) in the error log if that table was missing.



Quote from: albertlast on September 08, 2019, 04:53:35 PM
You gdpr fix looks very wrong,
the mod author or you should use the smf db_insert api like mention below.

I'm not surprised, I only have a very basic understanding of SMF and GDPRHelper code, and haven't had time to look into the db_* functions yet. I'll keep it in mind, but it's totally OT here. ;)
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: albertlast on September 11, 2019, 12:39:17 AM
Tested with the nightly version of today,
with
pg 11
php 7.3

no error message appears by changing the notify type,
when clicken on the top right of a thread and choose one mode.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 11, 2019, 02:35:12 AM
Thanks for testing, I'll see how the nightly behaves on my server (sometime later this week).
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 16, 2019, 04:23:50 PM
I'm having the same problem with the nightly from an hour ago. :-\

Any way to make the logs more verbose?
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 16, 2019, 04:31:17 PM
Ah, another bit of info I haven't seen before... [edit: The full URL is "https://(redacted)/index.php?action=notifytopic;topic=1;mode=3;[hex]=[hex];xml".]
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: vbgamer45 on September 16, 2019, 04:37:11 PM
Check your SMF's error log should have the full error message/trace since it is a DB error.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 16, 2019, 04:59:36 PM
Ah, didn't know that file existed. No luck though:

root@(redacted):~# ls ~nightly-smf/public_html/
DCO.txt              SSI.php              Sources/             avatars/             db_last_error.php    proxy.php            subscriptions.php
LICENSE              Settings.php         Themes/              cache/               favicon.ico          readme.html
Packages/            Settings_bak.php     agreement.txt        cron.php             index.php            ssi_examples.php
README.md            Smileys/             attachments/         custom_avatar/       last_commit_dff7140  ssi_examples.shtml
root@(redacted):~# cat ~nightly-smf/public_html/db_last_error.php
root@(redacted):~# ll ~nightly-smf/public_html/db_last_error.php
-rwxrwxr-x 1 nightly-smf www-data 0 Sep 16 13:00 /home/nightly-smf/public_html/db_last_error.php*
root@(redacted):~#


In my other forums that had the problem, that logfile doesn't even exist.

And still nothing in lighttpd access and error logs, or DB logs.
I increased my pgsql loglevel now, and interestingly I now for the first time managed to accidentally subscribe to a topic, and then received the following error when I tried to to it again:


ERROR:  duplicate key value violates unique constraint "nightlysmf_log_notify_pkey"
DETAIL:  Key (id_member, id_topic, id_board)=(1, 0, 1) already exists.
STATEMENT:
                                INSERT INTO nightlysmf_log_notify("id_member", "id_board")
                                VALUES
                                        (1, 1)

(This seems to be a common problem when using postgresql, I'm seeing it a lot, mostly about
"INSERT INTO alphasmf_log_online("session", "id_member", "id_spider", "log_time", "ip", "url")".)


I don't know how I managed to achieve enabling the notifications, and I can't reproduce it.  :-X
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: Illori on September 16, 2019, 05:04:35 PM
are you checking the SMF error log in the admin panel? it does not look to me like you are doing that.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 16, 2019, 05:15:27 PM
Yeah sorry/thanks, I just noticed I'm being a doorknob... it has been a long day.

Same errors in nightly like in the GH version from 2019-09-01, and like in rc2:

Quote
Type of error: Critical
The database value you're trying to insert does not exist: 0
Function: TopicNotify
https://(redacted)/index.php?action=notifytopic;topic=2;mode=3;[hex]=[hex];xml
/home/nightly-smf/public_html/Sources/Notify.php (Line 145)

   138: $smcFunc['db_insert']($insert ? 'insert' : 'replace',
   139: '{db_prefix}log_topics',
   140: array(
   141: 'id_member' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'unwatched' => 'int',
   142: ),
   143: $log,
   144: array('id_member', 'id_topic')
==>145: );
   146:
   147: require_once($sourcedir . '/Subs-Notify.php');



Quote
Type of error: General
The database value you're trying to insert does not exist: 0
https://(redacted)/index.php?action=notifytopic;topic=2;mode=3;[hex]=[hex];xml
(no code to display)
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 16, 2019, 05:20:59 PM
Damn, I just noticed this seems to be the exact same problem I'm seeing all over with postgresql: INSERTs into tuples that contain fields that are part of a PK are a problem; don't know enough about postgres to comment if this is "expected", though. Here's what I had to do to get "GDPR Helper" to work, f.e.:

            $t = time();
    // replace doesn't work, can't replace part of PK in postgres(?)
            $smcFunc['db_insert']('ignore',
                    '{db_prefix}themes',
            array('id_member' => 'int', 'id_theme' => 'int',
                          'variable' => 'string', 'value' => 'string'),
                    array($user_info['id'], $settings['theme_id'],
             'gpdr_policydate', $t),
            array('id_member', 'id_theme', 'variable', 'value')
            );
    // TODO doesn't work the first time
            $smcFunc['db_query']('', '
                    UPDATE {db_prefix}themes
                    SET
                        value = {string:value}
                WHERE id_member = {int:id_member} AND
            id_theme = {int:id_theme} AND
            variable = {string:variable}',
                    array(
                            'id_member' => $user_info['id'],
                            'id_theme' => $settings['theme_id'],
                            'variable' => 'gpdr_policydate',
                            'value' => $t,
                    )
            );
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: shawnb61 on September 16, 2019, 06:53:25 PM
@albertlast -
Are your notification settings being saved?   If you refresh the page, do they reflect your change or does it revert to a previous value?

@m4z -
I am not getting error messages at all.  BUT...  The notification setting is not getting saved, and as near as I can tell, notifications aren't working at all. 

I think I am seeing the same thing as you, but without the error messages.  I have also checked the pg log - nothing there. 

Everything is fine on MySQL.  I haven't been able to get notifications to work at all on pg. 

Pg 10
php 5.6, 7.3


NOTE: I logged this on github: https://github.com/SimpleMachines/SMF2.1/issues/5806
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: shawnb61 on September 16, 2019, 10:34:40 PM
Quote from: m4z on September 16, 2019, 05:20:59 PM
Damn, I just noticed this seems to be the exact same problem I'm seeing all over with postgresql: INSERTs into tuples that contain fields that are part of a PK are a problem; don't know enough about postgres to comment if this is "expected", though. Here's what I had to do to get "GDPR Helper" to work, f.e.:

            $smcFunc['db_insert']('ignore',
                    '{db_prefix}themes',
            array('id_member' => 'int', 'id_theme' => 'int',
                          'variable' => 'string', 'value' => 'string'),
                    array($user_info['id'], $settings['theme_id'],
             'gpdr_policydate', $t),
            array('id_member', 'id_theme', 'variable', 'value')
            );


These are bugs, & they really aren't about pg - they're about calling SMF's smcFunc['db_insert'] properly.  The 5 first parameters passed are: method (e.g., 'ignore'), table, columns, data, keys.  The keys array is meant to list the columns in the primary key.  Above, you'll see 4 columns listed - id_member, id_theme, variable, value.  But if you check the table, you'll see that the real pk is id_theme, id_member, variable:
https://github.com/SimpleMachines/SMF2.1/blob/dff71408bc055e9ad8eafc33e35b4618c800b096/other/install_2-1_postgresql.sql#L1597

MySQL is forgiving here...  Pg is picky, and the smcFunc call must be exact.  If you're having problems with smcFunc['db_insert'], first thing to do is to ensure the parameters passed are correct, including the pk. 

As you find issues, log them up on github.  PRs even! 
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: albertlast on September 17, 2019, 12:25:51 AM
Here the pr for this issue: https://github.com/SimpleMachines/SMF2.1/pull/5807
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 17, 2019, 03:15:17 AM
Quote from: shawnb61 on September 16, 2019, 10:34:40 PM
These are bugs, & they really aren't about pg - they're about calling SMF's smcFunc['db_insert'] properly.  The 5 first parameters passed are: method (e.g., 'ignore'), table, columns, data, keys.  The keys array is meant to list the columns in the primary key.  Above, you'll see 4 columns listed - id_member, id_theme, variable, value.  But if you check the table, you'll see that the real pk is id_theme, id_member, variable[...]

MySQL is forgiving here...  Pg is picky, and the smcFunc call must be exact.  If you're having problems with smcFunc['db_insert'], first thing to do is to ensure the parameters passed are correct, including the pk.

Ah, misinterpretation on my part then; I noticed the mismatch in this case, but I don't think it existed in every issue I saw. Might have been other syntax issues though.


Quote from: shawnb61 on September 16, 2019, 10:34:40 PM
As you find issues, log them up on github.  PRs even!

Thanks, will do. I like to get issues confirmed, that's why I post them here first and "enjoy" the "can't reproduce"-s to figure out the details. O:)
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 18, 2019, 06:10:27 PM
Sorry to drift slightly OT, but I'm not sure whether I'm doing something stupid here: I tried to verify the fix, basically by following this guide (https://wiki.simplemachines.org/smf/How_to_upload_a_fresh_set_of_files) with the nightly upgrade archive (https://www.simplemachines.org/community/index.php?topic=558451.msg3958589#msg3958589).

Here's what I did:

# su - nightly-smf
$ wget http://0exclusive.de/smf/smf2.1_nightly_upgrade.zip -O smf2.1_nightly_upgrade_$(date +%F).zip
$ unzip smf2.1_nightly_upgrade_$(date +%F).zip -d public_html/
  (replace [A]ll)
$ rm public_html/upgrade*

# chown -R nightly-smf.www-data ~nightly-smf/public_html/
# chmod -R 775 ~nightly-smf/public_html/


I see a new file "last_commit_e9d1eb6", which is the merge commit of the fix (https://github.com/SimpleMachines/SMF2.1/commit/e9d1eb6349b049111a693444a5237f9884b3b6c0).

There are no notable files (besides Settings.php) that are not from the upgrade zip:

nightly-smf@(redacted):~$ find public_html/ ! -newer smf2.1_nightly_upgrade_2019-09-18.zip | sort
public_html/Packages/1568743440.zip
public_html/Settings.php
public_html/Settings_bak.php
public_html/cache/db_last_error.php
nightly-smf@(redacted):~$ cat public_html/cache/db_last_error.php
<?php
$db_last_error 
0;
?>
nightly-smf@(redacted):~$


I'm still seeing the same erratic behavior and error message in the admin logs. Can somebody explain? Do I need a fresh install to verify?
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: shawnb61 on September 18, 2019, 10:07:21 PM
I would first open up Notify.php & make sure the fixes from the PR are applied.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 19, 2019, 02:34:32 AM
They are; I can even see the second block (~L155) from the admin error log messages (referring to L145).
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 19, 2019, 02:45:13 AM
Hmm, I thought this was about the array mismatch between L141/144, but even with this patch it doesn't work:

--- public_html/Sources/Notify.php.orig 2019-09-19 06:37:03.992508881 +0000
+++ public_html/Sources/Notify.php      2019-09-19 06:39:42.090987719 +0000
@@ -141,7 +141,7 @@
                                        'id_member' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'unwatched' => 'int',
                                ),
                                $log,
-                               array('id_member', 'id_topic')
+                               array('id_member', 'id_topic', 'id_msg', 'unwatched')
                        );

                        require_once($sourcedir . '/Subs-Notify.php');


[Edit: Ah, nvm, reread your post, keys is supposed to be the PK...]
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 19, 2019, 03:29:19 AM
I've reached the limits of my PHP-fu. With this patch:

--- public_html/Sources/Notify.php.orig 2019-09-19 06:37:03.992508881 +0000
+++ public_html/Sources/Notify.php      2019-09-19 07:25:32.494821654 +0000
@@ -118,9 +118,11 @@
                                )
                        );
                        $log = $smcFunc['db_fetch_assoc']($request);
+                       file_put_contents('log.txt', "After db_f_a: \$log = " . var_export($log) . "\n", FILE_APPEND);
                        $smcFunc['db_free_result']($request);
                        if (empty($log))
                        {
+                               file_put_contents('log.txt', "\$log was empty\n", FILE_APPEND);
                                $insert = true;
                                $log = array(
                                        'id_member' => $user_info['id'],
@@ -131,10 +133,14 @@
                        }
                        else
                        {
+                               file_put_contents('log.txt', "\$log was NOT empty\n", FILE_APPEND);
                                $insert = false;
                                $log['unwatched'] = empty($mode) ? 1 : 0;
+                               file_put_contents('log.txt', "\$log after assignment: " . var_export($log) . "\n", FILE_APPEND);
                        }

+                       file_put_contents('log.txt', "After if: \$log = " . var_export($log) . "\n", FILE_APPEND);
+
                        $smcFunc['db_insert']($insert ? 'insert' : 'replace',
                                '{db_prefix}log_topics',
                                array(


... it looks like the variable never gets set, I have no clue, why (and no clue why it's empty and not empty):

After db_f_a: $log =
$log was NOT empty
$log after assignment:
After if: $log =



[Edit: For completeness, here's my table contents:]
nightly-smf=> select * from nightlysmf_log_topics ;
id_member | id_topic | id_msg | unwatched
-----------+----------+--------+-----------
         1 |        5 |    540 |         0
         1 |        2 |    540 |         0
         1 |        4 |    540 |         0
         1 |        1 |    540 |         0
(4 rows)

Title: Re: Can't change thread alert settings in 2.1rc2
Post by: shawnb61 on September 20, 2019, 11:55:00 PM
I'm still clueless here.  My pg implementation has no issue. 

But I can tell you that var_export has some limitations according to the php manual...  You need to specify a return parameter of TRUE, but even that doesn't work when output buffering is used.
Instead  of:
var_export($log)
Try:
print_r($log, TRUE)
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 21, 2019, 03:04:36 AM
QuoteAfter db_f_a: $log = 1
$log was NOT empty
$log after assignment: 1
After if: $log = 1
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 21, 2019, 05:30:40 AM
Monkeypatched a bit more:

--- public_html/Sources/Notify.php.orig 2019-09-19 06:37:03.992508881 +0000
+++ public_html/Sources/Notify.php      2019-09-21 09:26:21.096114743 +0000
@@ -105,8 +105,12 @@
                if (isset($_GET['mode']))
                {
                        $mode = (int) $_GET['mode'];
+                       file_put_contents('log.txt', "\$mode = " . print_r($mode) . "\n", FILE_APPEND);
                        $alertPref = $mode <= 1 ? 0 : ($mode == 2 ? 1 : 3);
+                       file_put_contents('log.txt', "\$alertPref = " . print_r($alertPref) . "\n", FILE_APPEND);

+                       $format = 'db_query: current_user=%s, current_topic=%s';
+                       file_put_contents('log.txt', sprintf($format, $user_info['id'], $topic) . "\n", FILE_APPEND);
                        $request = $smcFunc['db_query']('', '
                                SELECT id_member, id_topic, id_msg, unwatched
                                FROM {db_prefix}log_topics
@@ -117,10 +121,13 @@
                                        'current_topic' => $topic,
                                )
                        );
+                       file_put_contents('log.txt', "db_query returns " . print_r($request) . "\n", FILE_APPEND);
                        $log = $smcFunc['db_fetch_assoc']($request);
+                       file_put_contents('log.txt', "db_fetch_assoc returns " . print_r($log) . "\n", FILE_APPEND);
                        $smcFunc['db_free_result']($request);
                        if (empty($log))
                        {
+                               file_put_contents('log.txt', "\$log was empty\n", FILE_APPEND);
                                $insert = true;
                                $log = array(
                                        'id_member' => $user_info['id'],
@@ -128,12 +135,17 @@
                                        'id_msg' => 0,
                                        'unwatched' => empty($mode) ? 1 : 0,
                                );
+                               file_put_contents('log.txt', "\$log after force-assignment: " . print_r($log) . " (unw=" . $log['unwatched'] . ")" . "\n", FILE_APPEND);
                        }
                        else
                        {
+                               file_put_contents('log.txt', "\$log was NOT empty\n", FILE_APPEND);
                                $insert = false;
                                $log['unwatched'] = empty($mode) ? 1 : 0;
+                               file_put_contents('log.txt', "\$log after assignment: " . print_r($log) . " (unw=" . $log['unwatched'] . ")" . "\n", FILE_APPEND);
                        }
+                       file_put_contents('log.txt', "After if: \$log = " . print_r($log) . "\n", FILE_APPEND);
+                       file_put_contents('log.txt', "(" . print_r($log['id_member']) . ", " . print_r($log['id_topic']) . ", " . print_r($log['id_msg']) . ", " . print_r($l
og['unwatched']) . ")\n", FILE_APPEND);

                        $smcFunc['db_insert']($insert ? 'insert' : 'replace',
                                '{db_prefix}log_topics',
@@ -149,6 +161,7 @@

                        if ($mode > 1)
                        {
+                               file_put_contents('log.txt', "\$mode > 1, enabling notification\n", FILE_APPEND);
                                // Turn notification on.  (note this just blows smoke if it's already on.)
                                $smcFunc['db_insert']('ignore',
                                        '{db_prefix}log_notify',
@@ -158,6 +171,8 @@
                                );
                        }
                        else
+                       {
+                               file_put_contents('log.txt', "\$mode <=0, removing notification\n", FILE_APPEND);
                                $smcFunc['db_query']('', '
                                        DELETE FROM {db_prefix}log_notify
                                        WHERE id_topic = {int:topic}
@@ -167,6 +182,7 @@
                                                'member' => $user_info['id'],
                                        )
                                );
+                       }
                }
        }



But got nothing out of it:
Quote$mode = 1
$alertPref = 1
db_query: current_user=1, current_topic=2
db_query returns 1
db_fetch_assoc returns 1
$log was NOT empty
$log after assignment: 1 (unw=0)
After if: $log = 1
(1, 1, 1, 1)


Going back to other things for now... Will maybe monkeypatch Subs-Notify.php the same way later. (Unless somebody drops a hint on smarter debugging with PHP, I really have no clue what I'm doing. ;D)
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: shawnb61 on September 21, 2019, 05:00:28 PM
It looks like your prior query, vs log_topics is returning something very strange... 

Does this work?
SELECT id_member, id_topic, id_msg, unwatched
FROM alphasmf_log_topics
WHERE id_member = 1
AND id_topic = 2


I see you've used different prefixes; substitute the prefix with the one you're currently using.

Re-reading the thread, it looks like you have also had a number of errors during the install.  Maybe we should re-install, ensure we get no errors, & retry?

You should have either received an array w/4 values or false.  You received a '1'...
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 22, 2019, 06:39:39 AM
Quote from: shawnb61 on September 21, 2019, 05:00:28 PM
It looks like your prior query, vs log_topics is returning something very strange... 

Does this work?
SELECT id_member, id_topic, id_msg, unwatched
FROM alphasmf_log_topics
WHERE id_member = 1
AND id_topic = 2


Yes:

nightly-smf=> SELECT id_member, id_topic, id_msg, unwatched FROM nightlysmf_log_topics WHERE id_member = 1 AND id_topic = 2;
id_member | id_topic | id_msg | unwatched
-----------+----------+--------+-----------
         1 |        2 |    541 |         0
(1 row)


Since this is a test install with only ~3 topics, the whole table is pretty short:

nightly-smf=> select * from nightlysmf_log_topics ;
id_member | id_topic | id_msg | unwatched
-----------+----------+--------+-----------
         1 |        5 |    540 |         0
         1 |        4 |    540 |         0
         1 |        1 |    540 |         0
         1 |        2 |    541 |         0
(4 rows)



Quote from: shawnb61 on September 21, 2019, 05:00:28 PM
I see you've used different prefixes; substitute the prefix with the one you're currently using.

Yeah, my initial report was for rc2, now I'm using a nightly install (from a few days ago).


Quote from: shawnb61 on September 21, 2019, 05:00:28 PM
Re-reading the thread, it looks like you have also had a number of errors during the install.  Maybe we should re-install, ensure we get no errors, & retry?

Are you referring to what I said about "some bugfixes"? That only applied to my rc2 installs, where I have patched a few issues I encountered, so my users don't fill up the error log (and until i manage to update them to a nightly or HEAD). The nightly I am currently using (from the 19. or 20.) didn't produce any errors during install, and I've only used it to debug this very issue.


Quote from: shawnb61 on September 21, 2019, 05:00:28 PM
You should have either received an array w/4 values or false.  You received a '1'...

Ok, I assumed as much but began doubting my (limited) understanding of PHP/SMF sources. I'll add more monkeypatched debug output.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on September 22, 2019, 08:40:50 AM
Quote from: m4z on September 22, 2019, 06:39:39 AM
Quote from: shawnb61 on September 21, 2019, 05:00:28 PM
You should have either received an array w/4 values or false.  You received a '1'...

Ok, I assumed as much but began doubting my (limited) understanding of PHP/SMF sources. I'll add more monkeypatched debug output.

Whatever is causing this, it behaves differently when directly print_r'ing to the page, I'm seeing array data there (but having other problems, like I can't pre- or append context messages before the printed variables, for whatever reason).

Interestingly, once I added (file writing) debug code to the previously working BoardNotify function to look for any differences, that function exhibited the bug, too.

Got other things to do, this is leading me nowhere.
Title: Re: Can't change thread alert settings in 2.1rc2
Post by: m4z on October 27, 2019, 07:21:03 AM
Sorry for missing this... I updated my forums at the end of September already, and can confirm the fix by albertlast works wonderfully. Marking as solved.

As for the debugging, I've got FirePhp[sic] to work, that works much better and outputs what it's supposed to be outputting (although it's kind of limited, and hindered by the alert checking script spamming stuff every few seconds).