// don't filter with 'and c.is_test = 0' because these may be useful for FSF staff
'query_membership' => "select c.status_id from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_membership c on b.contact_id=c.contact_id inner join civicrm.civicrm_contact d on c.contact_id=d.id where a.status = 1 and d.is_deleted = 0 and c.status_id is not NULL and a.name = :username and (c.status_id = 1 or c.status_id = 2 or c.status_id = 3 or c.status_id = 4) order by c.status_id limit 10;",
'query_staff' => "select a.name as is_fsf_staff from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_contact c on b.contact_id=c.id inner join civicrm.civicrm_relationship d on c.id=d.contact_id_a where a.name=:username and a.status=1 and c.is_deleted=0 and d.relationship_type_id=4 and d.contact_id_b=FOOBAR and d.is_active=1 and (d.end_date>NOW() or d.end_date is NULL) limit 1;",
- 'query_long_term_member' => "select c.join_date from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_membership c on b.contact_id=c.contact_id inner join civicrm.civicrm_contact d on c.contact_id=d.id where a.name = :username and c.status_id is not NULL and (c.status_id = 1 or c.status_id = 2 or c.status_id = 3 or c.status_id = 4) and c.join_date <= :member_long_term_date order by c.join_date limit 1;",
+ 'query_membership_long_term' => "select c.join_date from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_membership c on b.contact_id=c.contact_id inner join civicrm.civicrm_contact d on c.contact_id=d.id where a.name = :username and c.status_id is not NULL and (c.status_id = 1 or c.status_id = 2 or c.status_id = 3 or c.status_id = 4) and c.join_date <= :member_long_term_date order by c.join_date limit 1;",
],
private $query_main;
private $query_membership;
private $query_staff;
+ private $query_membership_long_term;
/**
* Date for determining whether someone is a long-term member or not
parent::__construct($info, $config);
// Make sure that all required parameters are present.
- foreach (['dsn', 'username', 'password', 'query_main', 'query_membership', 'query_staff', 'member_long_term_date'] as $param) {
+ foreach (['dsn', 'username', 'password', 'query_main', 'query_membership', 'query_staff', 'query_membership_long_term', 'member_long_term_date'] as $param) {
if (!array_key_exists($param, $config)) {
throw new Exception('Missing required attribute \''.$param.
'\' for authentication source '.$this->authId);
$this->query_main = $config['query_main'];
$this->query_membership = $config['query_membership'];
$this->query_staff = $config['query_staff'];
+ $this->query_membership_long_term = $config['query_membership_long_term'];
$this->member_long_term_date = $config['member_long_term_date'];
if (isset($config['options'])) {
$this->options = $config['options'];
* query the database with arbitrary queries that only require a user name.
*
*/
- private function query_db($queryname, $username)
+ private function query_db($queryname, $query_params)
{
assert(is_string($queryname));
assert(is_string($username));
}
try {
- $sth->execute(['username' => $username]);
+ $sth->execute($query_params);
} catch (PDOException $e) {
throw new Exception('fsfdrupalauth:'.$this->authId.
': - Failed to execute queryname: '.$queryname.': '.$e->getMessage());
// query on membership
//
- $membership_data = $this->query_db('query_membership', $username);
+ $membership_data = $this->query_db('query_membership', ['username' => $username]);
if (count($membership_data) === 0) {
// No rows returned - invalid username
// query on first membership join date
//
- $membership_date_data = $this->query_db('query_membership_date', $username, $member_long_term_date);
+ $membership_date_data = $this->query_db('query_membership_long_term', ['username' => $username, 'member_long_term_date' => $member_long_term_date]);
if (count($membership_date_data) === 0) {
// No rows returned - no old membership start
// query on staff
//
- $staff_data = $this->query_db('query_staff', $username);
+ $staff_data = $this->query_db('query_staff', ['username' => $username]);
if (count($staff_data) === 0) {
// No rows returned - invalid username
//Logger::debug('fsfdrupalauth:'.$this->authId.': entered password: '.$password);
- $user_data = $this->query_db('query_main', $username);
+ $user_data = $this->query_db('query_main', ['username' => $username]);
if (count($user_data) === 0) {