summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Lieverdink2013-05-21 21:29:35 (GMT)
committer Peter Lieverdink2013-05-21 21:29:35 (GMT)
commita87c9c951984fe6158ac8ebdb1944799ae61e90d (patch)
treee400c1a8d79f963c668bfebfccb014e28e27d10b
parent3720d029cb1ab1bd9c0e3f15020ce110622049e5 (diff)
Fix an SQL query double WHERE. Closes [#2001226] by Bastlynn.HEAD7.x-1.0-beta37.x-1.x
-rw-r--r--userpoints_evaporate.module29
1 files changed, 11 insertions, 18 deletions
diff --git a/userpoints_evaporate.module b/userpoints_evaporate.module
index 90b6654..c13143e 100644
--- a/userpoints_evaporate.module
+++ b/userpoints_evaporate.module
@@ -102,12 +102,10 @@ function userpoints_evaporate_cron() {
':operation' => 'evaporate',
);
- // Create the query to remove points.
- // The named placeholder for number managed to get quoted as a string, even
- // though it is a number, so instead we're in-lining the value without a
- // placeholder. Casting to int should make this safe-ish.
- $query_ttl = "UPDATE {userpoints} SET points = points - ". intval($setting['number']) ." WHERE tid = :tid";
- $args_ttl = array(':tid' => $tid);
+ // Create the query to remove points from the per-type total.
+ $query_ttl = db_update('userpoints')
+ ->expression('points', 'points - :number', array(':number' => $setting['number']))
+ ->condition('tid', $tid);
// If only for inactive users, check for last activity. This must be done
// before checking for nonegative, as the INNER JOIN is more efficient than
@@ -122,8 +120,11 @@ function userpoints_evaporate_cron() {
$args_txn[':delta'] = time() - $delta;
// Add a subquery where clause to limit this to inactive users.
- $query_ttl .= " AND uid IN (SELECT uid FROM {users} WHERE access < :delta)";
- $args_ttl[':delta'] = time() - $delta;
+ $subquery_ttl = db_select('users', 'u')
+ ->fields(array('uid'))
+ ->condition('access', (time() - $delta), '<');
+
+ $query_ttl->condition('uid', $subquery_ttl, 'IN');
}
// Limit tnx insert to records with the current tid only.
@@ -134,21 +135,14 @@ function userpoints_evaporate_cron() {
$query_txn .= " AND up.points >= :balance";
$args_txn[':balance'] = $setting['number'];
- if ($setting['inactive']['enabled']) {
- $query_ttl .= " AND points >= :balance";
- $args_ttl[':balance'] = $setting['number'];
- }
- else {
- $query_ttl .= " WHERE points >= :balance";
- $args_ttl[':balance'] = $setting['number'];
- }
+ $query_ttl->condition('points', $setting['number'], '>=');
}
// Run the query to add relevant entries in the {userpoints_txn} table.
db_query($query_txn, $args_txn);
// Run the update query to evaporate some points from the {userpoints} table.
- db_query($query_ttl, $args_ttl);
+ $query_ttl->execute();
// Now save the settings with the updated timestamp, so hook_cron knows
// we ran and finished for this term.
@@ -184,4 +178,3 @@ function _userpoints_evaporate_default_settings() {
),
);
}
-