News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Can't change thread alert settings in 2.1rc2

Started by m4z, September 01, 2019, 08:32:53 AM

Previous topic - Next topic

m4z

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".]
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

vbgamer45

Check your SMF's error log should have the full error message/trace since it is a DB error.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

m4z

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
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

Illori

are you checking the SMF error log in the admin panel? it does not look to me like you are doing that.

m4z

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)
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

m4z

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,
                    )
            );
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

shawnb61

@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
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

shawnb61

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! 
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp


m4z

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:)
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

m4z

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 with the nightly upgrade archive.

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.

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?
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

shawnb61

I would first open up Notify.php & make sure the fixes from the PR are applied.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

m4z

They are; I can even see the second block (~L155) from the admin error log messages (referring to L145).
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

m4z

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...]
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

m4z

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)

"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

shawnb61

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)
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

m4z

QuoteAfter db_f_a: $log = 1
$log was NOT empty
$log after assignment: 1
After if: $log = 1
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

m4z

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)
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

shawnb61

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'...
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

m4z

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.
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

Advertisement: