Every time I try to add users to subscriptions, I get this error:
http://www.65creedmoor.com/index.php?action=admin;area=paidsubscribe;sa=modifyuser;sid=6;lid=0
File: /home/creedmoo/public_html/sources/subs/PaidSubscriptions.subs.php
Line: 348
Sorry for the late reply.
Something is missing from the error... the exact message of the error. ;)
I guess it's something to do with numbers not in the proper format for the sum, but better be sure.
Sorry, the error is:
Warning: A non-numeric value encountered
The user is not added to the subscription, but it is added to an user group for subscribers.
What is set to the duration of the subscription?
One year. For example from today in 2019 to the same day in 2020.
Could you please run this query:
SELECT
id_subscribe, cost, length, id_group, add_groups, active, repeatable
FROM {db_prefix}subscriptions
of course changing {db_prefix} to the prefix you are actually using?
I'd like to see what was stored in the db before working out anything.
Here you go:
id_subscribe cost length id_group add_groups active repeatable
5 a:4:{s:3:"day";s:4:"1.00";s:4:"week";s:4:"3.00";s:... F 0 9 0 1
6 a:4:{s:3:"day";s:4:"1.00";s:4:"week";s:4:"3.00";s:... F 9 1 1
hmm...
Okay, I had to fix some other bugs in my dev code because I cannot use 1.1 due to php 7.3.
I tracked back this to two errors.
In sources/subs/PaidSubscription.subs.php please find:
// Do the span.
preg_match('~(\d*)(\w)~', $row['length'], $match);
if (isset($match[2]))
{
$num_length = $match[1];
$length = $match[1] . ' ';
switch ($match[2])
{
case 'D':
$length .= $txt['paid_mod_span_days'];
$num_length *= 86400;
break;
case 'W':
$length .= $txt['paid_mod_span_weeks'];
$num_length *= 604800;
break;
case 'M':
$length .= $txt['paid_mod_span_months'];
$num_length *= 2629743;
break;
case 'Y':
$length .= $txt['paid_mod_span_years'];
$num_length *= 31556926;
break;
}
}
else
$length = '??';
and replace the block with:
// Do the span.
preg_match('~(\d*)(\w)~', $row['length'], $match);
if ($row['length'] != 'F' && isset($match[2]))
{
$num_length = (int) $match[1];
$length = $match[1] . ' ';
switch ($match[2])
{
case 'D':
$length .= $txt['paid_mod_span_days'];
$num_length *= 86400;
break;
case 'W':
$length .= $txt['paid_mod_span_weeks'];
$num_length *= 604800;
break;
case 'M':
$length .= $txt['paid_mod_span_months'];
$num_length *= 2629743;
break;
case 'Y':
$length .= $txt['paid_mod_span_years'];
$num_length *= 31556926;
break;
}
}
else
{
$length = '??';
$num_length = 0;
}
The code is between line 458 and 488.
@Spuds what do you think of my change:
if ($row['length'] != 'F' && isset($match[2]))
I think it could even only be:
if ($row['length'] != 'F')
because as far as I can see, $match[2] is always set, because the first capture is either empty of a number, so the index 2 will always be there.
Am I missing something?
We do use 1.1 with php7.3, so what do you actually mean? Your dev code doesn't work with php7.3?
No, 1.1 master doesn't work with 7.3. It throws out tons of errors due to a couple of issues here and there.
dev instead had other issues I had to fix before being able to use. xD
@emanuele Your changes to the code fixed the problem. Thanks!
I think you are right that we don't need to check both conditions. I think we could also tweak the regex to be more restrictive and simply the code a tiny bit more .... What do you think of
$length = '??';
if (preg_match('~^(\d*)([DWFMY]$)~', $row['length'], $match) === 1)
{
$num_length = $match[1];
$length = $match[1] . ' ';
switch ($match[2])
{
case 'D':
$length .= $txt['paid_mod_span_days'];
$num_length *= 86400;
break;
case 'W':
$length .= $txt['paid_mod_span_weeks'];
$num_length *= 604800;
break;
case 'M':
$length .= $txt['paid_mod_span_months'];
$num_length *= 2629743;
break;
case 'Y':
$length .= $txt['paid_mod_span_years'];
$num_length *= 31556926;
break;
default:
$length = '??';
}
}
I would define also $num_length at the beginning (set to 0), apart from that it looks good!
Good point ! ... added to my local, I'll stuff it in 2.0 when I start another branch.
I need to PR the pacman stuff for review, but just to note its only a start, unraveling that code was laborious and did not lead to the cleanest refactor since I had to keep chasing odd things.
Actually, this should be for 1.1.6 I think. O:-)
Yup, I just did not have 1.1.6 open when I looked O:-) ... I updated an old bug report on github ... https://github.com/elkarte/Elkarte/issues/3084 ... pointing to this thread so we don't loose track of the fixes