Simple Machines Community Forum

SMF Development => Bug Reports => Topic started by: TheBom on February 14, 2024, 05:02:34 AM

Title: Undefined array key every day
Post by: TheBom on February 14, 2024, 05:02:34 AM
Every day we get 4 errors in ScheduledTasks.php
It happens on line 1413 & 1416

Undefined array key with a number after it.

What is it and what can i do about this?
Title: Re: Undefined array key every day
Post by: Deaks on February 14, 2024, 05:49:41 AM
we need more information, such as what mods you have installed?
Title: Re: Undefined array key every day
Post by: TheBom on February 14, 2024, 06:00:05 AM
Quote from: Deaks on February 14, 2024, 05:49:41 AMwe need more information, such as what mods you have installed?

No mods

Its referring to these 2 if lines, yes we use paid subscriptions but why is it giving these errors on it every night

if ($notifyPrefs[$row['id_member']] & 0x02)
sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);

if ($notifyPrefs[$row['id_member']] & 0x01)
{
$alert_rows[] = array(
'alert_time' => time(),
'id_member' => $row['id_member'],
'id_member_started' => $row['id_member'],
'member_name' => $row['member_name'],
'content_type' => 'paidsubs',
'content_id' => $row['id_sublog'],
'content_action' => 'expiring',
'is_read' => 0,
'extra' => $smcFunc['json_encode'](array(
'subscription_name' => $row['name'],
'end_time' => $row['end_time'],
)),
);
updateMemberData($row['id_member'], array('alerts' => '+'));
}
   }
Title: Re: Undefined array key every day
Post by: Kindred on February 14, 2024, 07:02:28 AM
What are the ACTUAL,  FULL error messages?
Title: Re: Undefined array key every day
Post by: Diego Andrés on February 14, 2024, 07:53:44 AM
I'll take a guess since you're not posting enough information about your error.
Is this your issue? (https://github.com/SimpleMachines/SMF/pull/7778)
Title: Re: Undefined array key every day
Post by: TheBom on February 14, 2024, 09:25:56 AM
Well, i just found a setting to show more info.
Currently this is the only info i got

 https://www.******/forum/cron.php
 /home/*********/domains/******/public_html/forum/Sources/ScheduledTasks.php (Regel 1416)  Backtrace informatie

Fouttype: Cron
FoutmeldingSelecteer
2: Undefined array key 1485
Title: Re: Undefined array key every day
Post by: Kindred on February 14, 2024, 04:11:48 PM
mods installed?
Title: Re: Undefined array key every day
Post by: Arantor on February 15, 2024, 03:33:03 PM
And if you click on the 'backtrace information' button?
Title: Re: Undefined array key every day
Post by: TheBom on February 19, 2024, 05:43:03 AM
Quote from: Arantor on February 15, 2024, 03:33:03 PMAnd if you click on the 'backtrace information' button?

Then i got this:
#0: smf_error_handler()
Aangeroepen van /home/****/domains/****/public_html/forum/Sources/ScheduledTasks.php op regel 1416
#1: scheduled_paid_subscriptions()
Aangeroepen van /home/****/domains/****/public_html/forum/Sources/ScheduledTasks.php op regel 116
#2: AutoTask()
Aangeroepen van /home/****/domains/****/public_html/forum/Sources/Load.php op regel 2638
#3: loadTheme()
Aangeroepen van /home/****/domains/****/public_html/forum/Sources/Load.php op regel 1340
#4: loadBoard()
Aangeroepen van /home/****/domains/****/public_html/forum/index.php op regel 217
#5: smf_main()
Aangeroepen van /home/****/domains/****/public_html/forum/index.php op regel 184

And the URL causing the problem seems for the same day this
https://****/forum/index.php?topic=80350.0
But yesterday it was
https://www.****/forum/index.phphttps://www.****/forum/cron.php
and the day before that its 3-4 times
https://www.****/forum/index.php?topic=109984.msg251301
Title: Re: Undefined array key every day
Post by: Arantor on February 19, 2024, 07:00:56 AM
It's a bug. Somehow you have people who have paid subscriptions but no preferences set up for paid subscriptions to be told about them.

I'll try to give you some better debug notes later (am at work, using an iPad, writing code is hard)
Title: Re: Undefined array key every day
Post by: Arantor on February 19, 2024, 01:00:41 PM
In ScheduledTasks.php, find that troublesome code on the line indicated.

This adds a new bit above the first if statement you found, and will solve the problem (I added the first if block for reference how it should look)

if (!isset($notifyPrefs[$row['id_member']]))
continue;

if ($notifyPrefs[$row['id_member']] & 0x02)
sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
Title: Re: Undefined array key every day
Post by: Doug Heffernan on February 19, 2024, 02:52:11 PM
I've moved this to the Bug Reports board to bring it to the attention of our developers.
Title: Re: Undefined array key every day
Post by: TheBom on February 20, 2024, 03:15:50 AM
Quote from: Arantor on February 19, 2024, 01:00:41 PMIn ScheduledTasks.php, find that troublesome code on the line indicated.

This adds a new bit above the first if statement you found, and will solve the problem (I added the first if block for reference how it should look)

if (!isset($notifyPrefs[$row['id_member']]))
continue;

if ($notifyPrefs[$row['id_member']] & 0x02)
sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);

Thank you sir!

I have updated the code and will let you know if the error persists tomorrow.

But i'm wondering in the first place
A) why did this happen
B) shouldn't we fix the main cause instead of working on error hiding
C) What is the downside?
Title: Re: Undefined array key every day
Post by: Arantor on February 20, 2024, 03:30:58 AM
A) Somehow you got users who have subscriptions but no preferences for those subscriptions.
B) It's a data error not a code error.
C) I don't see one.
Title: Re: Undefined array key every day
Post by: TheBom on February 20, 2024, 04:17:51 AM
Quote from: Arantor on February 20, 2024, 03:30:58 AMA) Somehow you got users who have subscriptions but no preferences for those subscriptions.
B) It's a data error not a code error.
C) I don't see one.
Okay, but how did they do A in the first place? Isn't that the main bug that the data of B is missing?
Title: Re: Undefined array key every day
Post by: Arantor on February 20, 2024, 04:21:05 AM
*shrug* I could see a failure state if the people in question took out subscriptions but never went to the notification settings page.

The reality is that, honestly, I don't care to investigate it that hard. I already regret how much time I sank into 2.1 as it was.

All my code change did was say "if there's no notification settings for this user, skip them". A sensible precaution in all cases, frankly.
Title: Re: Undefined array key every day
Post by: Steve on February 20, 2024, 02:33:18 PM
Quote from: Kindred on February 14, 2024, 04:11:48 PMmods installed?
Quote from: TheBom on February 14, 2024, 06:00:05 AMNo mods
Title: Re: Undefined array key every day
Post by: Max22 on March 16, 2024, 04:16:42 PM
Just for the record, there is a related issue about ScheduledTasks: #7784 (https://github.com/SimpleMachines/SMF/issues/7784)