ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: txcas on March 04, 2019, 09:41:11 am

Title: Can't add users to subscriptions
Post by: txcas on March 04, 2019, 09:41:11 am
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
Title: Re: Can't add users to subscriptions
Post by: emanuele on March 05, 2019, 05:09:20 pm
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.
Title: Re: Can't add users to subscriptions
Post by: txcas on March 07, 2019, 12:30:10 pm
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.
Title: Re: Can't add users to subscriptions
Post by: emanuele on March 10, 2019, 09:29:25 am
What is set to the duration of the subscription?
Title: Re: Can't add users to subscriptions
Post by: txcas on March 11, 2019, 10:35:34 am
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.
Title: Re: Can't add users to subscriptions
Post by: emanuele on March 12, 2019, 08:03:12 am
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.
Title: Re: Can't add users to subscriptions
Post by: txcas on March 12, 2019, 09:08:06 am
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
Title: Re: Can't add users to subscriptions
Post by: emanuele on March 13, 2019, 06:21:20 pm
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?
Title: Re: Can't add users to subscriptions
Post by: ahrasis on March 13, 2019, 06:52:09 pm
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?
Title: Re: Can't add users to subscriptions
Post by: emanuele on March 14, 2019, 03:21:35 am
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
Title: Re: Can't add users to subscriptions
Post by: txcas on March 14, 2019, 09:18:12 am
@emanuele Your changes to the code fixed the problem.  Thanks!
Title: Re: Can't add users to subscriptions
Post by: Spuds on March 14, 2019, 02:24:46 pm
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 = '??';
}
}
Title: Re: Can't add users to subscriptions
Post by: emanuele on March 14, 2019, 04:11:30 pm
I would define also $num_length at the beginning (set to 0), apart from that it looks good!
Title: Re: Can't add users to subscriptions
Post by: Spuds on March 14, 2019, 05:49:22 pm
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.
Title: Re: Can't add users to subscriptions
Post by: emanuele on March 14, 2019, 06:26:07 pm
Actually, this should be for 1.1.6 I think. O:-)
Title: Re: Can't add users to subscriptions
Post by: Spuds on March 14, 2019, 07:34:16 pm
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