Help with Subscriptions

Started by Onfroi, November 18, 2014, 10:03:34 PM

Previous topic - Next topic

Onfroi

I just need to know where in Subscriptions.php (unless it's in some other script) it tells me when the subscription was bought correctly. Basically, when the user finished paying.

Arantor


Onfroi

Quote from: Arantor on November 19, 2014, 05:09:36 AM
Curious... why?
Because I need to put some mysql code in there to set the subscription in a game as well.

Arantor

Um... still not seeing why you'd need to change SMF's code, could you not just query the main tables instead?

Trying to avoid changing core SMF code is usually better in terms of upgrades and maintenance down the line, but that tends to require knowing what you're actually trying to do rather than how you think you might have to do it.

Biology Forums

Have you checked the /Sources/ folder?

Sir Osis of Liver

Sounds like OP wants the subscription to set a value in a separate table related to a game, not SMF.  Take a look in /Sources/ManagePaid.php, maybe here -



// Actually put the subscription in place.
if ($status == 1)
addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
else
{
$smcFunc['db_insert']('',
'{db_prefix}log_subscribed',
array(
'id_subscribe' => 'int', 'id_member' => 'int', 'old_id_group' => 'int', 'start_time' => 'int',
'end_time' => 'int', 'status' => 'int',
),
array(
$context['sub_id'], $id_member, $id_group, $starttime,
$endtime, $status,
),
array('id_sublog')
);
}


Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Onfroi

Quote from: Krash on November 19, 2014, 11:31:30 PM
Sounds like OP wants the subscription to set a value in a separate table related to a game, not SMF.  Take a look in /Sources/ManagePaid.php, maybe here -



// Actually put the subscription in place.
if ($status == 1)
addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
else
{
$smcFunc['db_insert']('',
'{db_prefix}log_subscribed',
array(
'id_subscribe' => 'int', 'id_member' => 'int', 'old_id_group' => 'int', 'start_time' => 'int',
'end_time' => 'int', 'status' => 'int',
),
array(
$context['sub_id'], $id_member, $id_group, $starttime,
$endtime, $status,
),
array('id_sublog')
);
}


Exactly , thanks a lot!  ;D

Arantor

That's actually the wrong place but never mind. That's where it sets up when doing it manually.

The reason I point this out is because modifying a subscription in the manner the OP wants requires modifications potentially in multiple places and I was trying to establish if that really was the best course of action, but I'm only a former dev of the software, I wouldn't know about that sort of thing or anything :P

Sir Osis of Liver

Don't think he wants to modify the subscription, just add separate query for a different table that executes when a new subscription is logged.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Sir Osis of Liver

There's also this -



/// Otherwise a very simple insert.
$endtime = time() + $duration;
if ($forceEndTime != 0)
$endtime = $forceEndTime;

if ($forceStartTime == 0)
$starttime = time();
else
$starttime = $forceStartTime;

$smcFunc['db_insert']('',
'{db_prefix}log_subscribed',
array(
'id_subscribe' => 'int', 'id_member' => 'int', 'old_id_group' => 'int', 'start_time' => 'int',
'end_time' => 'int', 'status' => 'int', 'pending_details' => 'string',
),
array(
$id_subscribe, $id_member, $old_id_group, $starttime,
$endtime, 1, '',
),
array('id_sublog')
);



Don't see anything else that logs a new subscription.


Quote from: Arantor on November 21, 2014, 03:47:30 AM
I wouldn't know about that sort of thing or anything :P

Don't fret, Arantor.  Another 60,000 posts and you'll get the hang of it.  I don't think this internet stuff will catch on, anyway.

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Quote from: Krash on November 21, 2014, 12:37:17 PM
Don't think he wants to modify the subscription, just add separate query for a different table that executes when a new subscription is logged.


Yes but it still requires handling the database in multiple places, something that has not currently been accounted for in any of the code currently mentioned. There are very good reasons not to touch the code and to query the database on demand (like manually issued subscriptions, edited subscriptions, cancelled subscriptions, none of which will be taken into account with modified code...)

Also, sarcasm says hi to Krash.

Sir Osis of Liver

I understand what you're getting at, but depending on what OP is trying to do (which hasn't been explained), simplest case would be to update a db field that belongs to a mod when a new sub is activated, so it wouldn't change anything that SMF does.  I did something similar to add a couple of features to a simple gallery mod by piggybacking a couple of new queries on existing queries (without touching the originals), to update a couple of new fields I added to the mod tables.  There are also edit and delete functions, but it wasn't necessary to fool with those.  Basically, when A happens, B happens, without affecting A.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Yes but what happens when the subscription expires exactly?

Sir Osis of Liver

That depends on what the OP is doing with it, which is currently unknown, but should be able to do something similiar by locating the query that updates log_subscriptions to expire the sub, and adding a query to update the game field.  When C happens (sub expires), D happens (whatever), without affecting C.

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Or you just query the tables for current state and avoid all of this?

Advertisement: