The following function when looking back through the versions used the isset() line to prevent the database from being hit with multiple requests for the same result. Since then, the function has been utilized in a loop where the request is changing the ID each time. However, the isset() will now just ignore that fact and return the same result all the time. Clearly, this is going to cause a problem and the module will not work correctly for anyone who uses more than one PayPal Subscription Role.

I have a fix for this below the following code as well. I have never done patches or CVS (this is my first time submitting a fix) so if someone could incorporate this into the versioning that would be great.

PREVIOUS CODE:
function _paypal_subscription_load($id) {
static $result;

if (!isset($result)) {
$result = db_fetch_object(db_query('SELECT pps.*, r.name AS role_name FROM {paypal_subscription} pps LEFT JOIN {role} r ON pps.role=r.rid WHERE pps.subscription_id=%d', $id));
_paypal_debug_var($result, 'Subscription details loaded for id='.$id);
}

return $result;
}

NEW CODE:
function _paypal_subscription_load($id) {
static $result;
static $prevID;

if ($id != $prevID) {
$result = db_fetch_object(db_query('SELECT pps.*, r.name AS role_name FROM {paypal_subscription} pps LEFT JOIN {role} r ON pps.role=r.rid WHERE pps.subscription_id=%d', $id));
$prevID = $id;
_paypal_debug_var($result, 'Subscription details loaded for id='.$id);
}
return $result;
}

CommentFileSizeAuthor
#1 paypal_subscription.module_1.patch3.67 KBreg

Comments

reg’s picture

Title: Bug fix for PalyPal_Subscription » Bug fix for PalyPal_Subscription - Patch
Category: bug » task
Status: Fixed » Needs review
StatusFileSize
new3.67 KB

Some more tweaking was needed to make this module work consistently with 4.7 and enough has been changed to where I created a patch for anyone who needs this module.

The following has been fixed in this patch:
-The fix described in the comment above
-$payer->payment rounded (two decimal places) for comparisons so that equality can be achieved consistantly.
-Line removed for proper date/time calculations with different timezones

The following has been added for efficiency:
-Implementation of hook_user - insert
The cron hook is used to grant and retract user membership status.
So that a newly registered user gets their paid for membership status
immediately upon registration without running the cron every minute
we implement this hook to call the cron function upon each user registration.

telex4’s picture

Is this patch:

a) Still valid
b) Ready for prime time?

I'm eager to use this module but I don't want to even start playing with it if the patched 4.7.0 version is known to particularly buggy.

Ariadoss’s picture

This patch didn't work for me:
Hunk #1 succeeded at 114 (offset -12 lines).
Hunk #2 FAILED at 144.
Hunk #3 succeeded at 172 with fuzz 2 (offset -1 lines).
Hunk #4 FAILED at 436.
Hunk #5 FAILED at 748.
Hunk #6 succeeded at 587 (offset -192 lines).

Is any progress actually being done to make this module work in 4.7?

reg’s picture

This patch relies on other patches which may be the problem.

In any case I have made some small addtions and once it has undergone some testing (over next week or two) I will make the complete code available instead of as a patch. That way issues of patches upon patches will not be factor and perhaps whoever maintains this module could incorporate the fixes into a release.

One note I found you may wish to keep in mind. My ISP was running PHP in safe mode and that broke the code when it tried to verify with PayPal that a transaction had occurred.

dbr’s picture

Status: Needs review » Fixed

This patch has been commited to CVS (HEAD only at the moment).

I have contacted Reg about his further enhancements, but no answer yet :-(

Anonymous’s picture

Status: Fixed » Closed (fixed)