Use the field paidExpiryDate to check if the user is premium

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
Currently the script uses the field level_id to check if the user is premium and the background task downgrade_account.cron.php is supposed to run every day at midnight downgrading accounts.

The problem is that if the user account expires at 0:10 he will have 1 day free because the task will not execute until the next day. You can set the task to run every hour, but the users will still have up to 1 extra hour. I didn't test this task in a site with thousands of active users so I can't tell the performance impacts of running it every hour.

The ideal is to use the paidExpiryDate field to check if the user is premium. The level_id may still exists to identify admin and other types of users.
 

sukhman21

Member
YetiShare User
Jan 26, 2015
508
3
18
0 * * * * php /path/to/admin/tasks/downgrade_accounts.cron.php >> /dev/null 2>&1

Just make the script run hourly instead of daily..
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
sukhman21 said:
0 * * * * php /path/to/admin/tasks/downgrade_accounts.cron.php >> /dev/null 2>&1

Just make the script run hourly instead of daily..
You didn't read the entire post.
 

sukhman21

Member
YetiShare User
Jan 26, 2015
508
3
18
you are right, i didnt.. this is what happens you are tired.
Anyways, i don't think there will be much performance issue even when dealing with thousands of accounts because all this is doing is executing single SQL command. I have a test site with 5000 dummy users on it and i just upgraded everybody's accounts to premium and then used this background task to downgrade. No load on CPU or RAM so i would say it will work just fine.
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
sukhman21 said:
you are right, i didnt.. this is what happens you are tired.
Anyways, i don't think there will be much performance issue even when dealing with thousands of accounts because all this is doing is executing single SQL command. I have a test site with 5000 dummy users on it and i just upgraded everybody's accounts to premium and then used this background task to downgrade. No load on CPU or RAM so i would say it will work just fine.
The performance impact on a live website will be different. There are issues with table locks, cache, other threads doing other queries and so on. Just testing a single query on a test db will just point obvious mistakes such as not using indexes.

And 5k isn't much. I have sites with 40k users (related to filesharing, but not using yetishare).
 

sukhman21

Member
YetiShare User
Jan 26, 2015
508
3
18
gotcha!! well admins will be able to help more regarding this.. I am curious about this too now..
 

paypal1352

New Member
YetiShare User
Wurlie User
Mar 2, 2012
297
2
0
I dont know if this would be the most efficient way to do this but why not create another php file called lets say checker.php and in it put

<?php if ($Auth->level_id >= 2): ?>
<?php
$expire = coreFunctions::formatDate($Auth->paidExpiryDate);
$today = **Assign current time stamp to this variable, corefunctions.class has convertDateToTimestamp
?>
<?php if ($expire<$today)
{
$exp=true;
}
?>

of course actually replace **... in today variable with actual code to check todays date and use converdatetotimestamp if required and then include this php when needed and check if exp variable is true to disallow certain things if required.

as to how efficient this would be i have no idea, thats something im sure Adam can shed light on.

another method would be to add something to account_home page to check the current timestamp in comparison to the expiration date of the premium account, and then check the db and if the user hasnt been downgraded already then to go ahead and do it, although im gonna guess doing it this way seems very inefficient
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
paypal1352 said:
I dont know if this would be the most efficient way to do this but why not create another php file called lets say checker.php and in it put

<?php if ($Auth->level_id >= 2): ?>
<?php
$expire = coreFunctions::formatDate($Auth->paidExpiryDate);
$today = **Assign current time stamp to this variable, corefunctions.class has convertDateToTimestamp
?>
<?php if ($expire<$today)
{
$exp=true;
}
?>

of course actually replace **... in today variable with actual code to check todays date and use converdatetotimestamp if required and then include this php when needed and check if exp variable is true to disallow certain things if required.

as to how efficient this would be i have no idea, thats something im sure Adam can shed light on.

another method would be to add something to account_home page to check the current timestamp in comparison to the expiration date of the premium account, and then check the db and if the user hasnt been downgraded already then to go ahead and do it, although im gonna guess doing it this way seems very inefficient
This would work. But the php time and the mysql time must be the same. The Auth class can do this verification and set $this->level_id = 1 internally.
 

paypal1352

New Member
YetiShare User
Wurlie User
Mar 2, 2012
297
2
0
wouldnt just running the cron every 5 min though be ultimately more efficient that this, im thinking the above would work but what happens when you have thousands of users.