Permalink
Browse files

Make active users mailout target all verified e-mail addresses

Remove unused external user mailout options
  • Loading branch information...
hoyes committed Feb 11, 2019
1 parent 6918649 commit ad3d8b0d667f777f1d4dad1e079c997fc69aecd6
@@ -39,17 +39,13 @@ public function indexAction(Request $request)
{
$repo = $this->getDoctrine()->getRepository('ActsCamdramSecurityBundle:User');
$numActiveUsers = count($repo->findActiveUsersForMailOut());
$numPasswordOnlyCam = count($repo->findActiveCamUsersWithoutExternalUser());
$numPasswordOnlyOther = count($repo->findActiveNonCamUsersWithoutExternalUser());
$numAdmins = count($repo->findOrganisationAdmins());
$form = $this->createFormBuilder()
->add('subject', TextType::class)
->add('recipients', ChoiceType::class, [
'choices' => [
"All Active Users ($numActiveUsers)" => 'active',
"Active cam.ac.uk users without an external login ($numPasswordOnlyCam)" => 'password_only_cam',
"Other active users without an external login ($numPasswordOnlyOther)" => 'password_only_other',
"Society and venue admins ($numAdmins)" => 'admins',
"Just me (1)" => 'me'
],
@@ -77,12 +73,6 @@ private function sendEmails($data)
case 'active':
$users = $repo->findActiveUsersForMailOut();
break;
case 'password_only_cam':
$users = $repo->findActiveCamUsersWithoutExternalUser();
break;
case 'password_only_other':
$users = $repo->findActiveNonCamUsersWithoutExternalUser();
break;
case 'admins':
$users = $repo->findOrganisationAdmins();
break;
@@ -47,63 +47,8 @@ public function findOrganisationAdmins()
public function findActiveUsersForMailOut()
{
$loginThreshold = new \DateTime('-2 years');
$qb = $this->createQueryBuilder('u');
$query = $qb->where('u.is_email_verified = true')
->andWhere('u.last_login_at >= :loginThreshold')
->setParameter('loginThreshold', $loginThreshold)
->getQuery();
return $query->getResult();
}
public function findActiveUsersWithoutExternalUser()
{
$loginThreshold = new \DateTime('-2 years');
$qb = $this->createQueryBuilder('u');
$query = $qb->leftJoin('u.external_users', 'e')
->groupBy('u')
->having('COUNT(e) = 0')
->andWhere($qb->expr()->orX('u.last_login_at >= :loginThreshold', 'u.registered_at >= :loginThreshold'))
->andWhere('u.email NOT LIKE :domain')
->setParameter('loginThreshold', $loginThreshold)
->setParameter('domain', "%@cam.ac.uk")
->getQuery();
return $query->getResult();
}
public function findActiveCamUsersWithoutExternalUser()
{
$loginThreshold = new \DateTime('-2 years');
$qb = $this->createQueryBuilder('u');
$query = $qb->leftJoin('u.external_users', 'e')
->groupBy('u')
->having('COUNT(e) = 0')
->andWhere($qb->expr()->orX('u.last_login_at >= :loginThreshold', 'u.registered_at >= :loginThreshold'))
->andWhere('u.email LIKE :domain')
->setParameter('loginThreshold', $loginThreshold)
->setParameter('domain', "%@cam.ac.uk")
->getQuery();
return $query->getResult();
}
public function findActiveNonCamUsersWithoutExternalUser()
{
$loginThreshold = new \DateTime('-2 years');
$qb = $this->createQueryBuilder('u');
$query = $qb->leftJoin('u.external_users', 'e')
->groupBy('u')
->having('COUNT(e) = 0')
->andWhere($qb->expr()->orX('u.last_login_at >= :loginThreshold', 'u.registered_at >= :loginThreshold'))
->andWhere('u.email NOT LIKE :domain')
->setParameter('loginThreshold', $loginThreshold)
->setParameter('domain', "%@cam.ac.uk")
->getQuery();
return $query->getResult();

1 comment on commit ad3d8b0

@philosophicles

This comment has been minimized.

Copy link
Member

philosophicles commented on ad3d8b0 Feb 11, 2019

🥇

Please sign in to comment.