Skip to main content
Topic: Can't add users to subscriptions (Read 5619 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Can't add users to subscriptions

Reply #1

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.
Bugs creator.
Features destroyer.
Template killer.

Re: Can't add users to subscriptions

Reply #2

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.

Re: Can't add users to subscriptions

Reply #3

What is set to the duration of the subscription?
Bugs creator.
Features destroyer.
Template killer.

Re: Can't add users to subscriptions

Reply #4

Quote from: emanuele – What is set to the duration of the subscription?
One year.  For example from today in 2019 to the same day in 2020.

Re: Can't add users to subscriptions

Reply #5

Could you please run this query:
Code: [Select]
		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.
Bugs creator.
Features destroyer.
Template killer.

Re: Can't add users to subscriptions

Reply #6

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

Re: Can't add users to subscriptions

Reply #7

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:
Code: [Select]
		// 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:
Code: [Select]
		// 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:
Code: [Select]
		if ($row['length'] != 'F' && isset($match[2]))
I think it could even only be:
Code: [Select]
		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?
Bugs creator.
Features destroyer.
Template killer.

Re: Can't add users to subscriptions

Reply #8

Quote from: emanuele – Okay, I had to fix some other bugs in my dev code because I cannot use 1.1 due to php 7.3.
We do use 1.1 with php7.3, so what do you actually mean? Your dev code doesn't work with php7.3?

Re: Can't add users to subscriptions

Reply #9

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
Bugs creator.
Features destroyer.
Template killer.

Re: Can't add users to subscriptions

Reply #10

@emanuele Your changes to the code fixed the problem.  Thanks!

Re: Can't add users to subscriptions

Reply #11

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

Code: [Select]
		$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 = '??';
}
}

Re: Can't add users to subscriptions

Reply #12

I would define also $num_length at the beginning (set to 0), apart from that it looks good!
Bugs creator.
Features destroyer.
Template killer.

Re: Can't add users to subscriptions

Reply #13

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.

Re: Can't add users to subscriptions

Reply #14

Actually, this should be for 1.1.6 I think. O:-)
Bugs creator.
Features destroyer.
Template killer.