-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find email duplicates API #3828
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d7f06cd
new view to find dup emails
DawoudIO 5b87c6b
added email APIs
DawoudIO 58b0b84
added find email dup apis
DawoudIO fbf1f56
Merge branch 'master' into feature/find-email-dups
crossan007 09b485b
fixed SQL query case
DawoudIO 48a9247
added missing crate emails_duplicate view
DawoudIO 8fae29a
Merge branch 'feature/find-email-dups' of https://github.com/ChurchCR…
DawoudIO aae132f
Merge branch 'master' into feature/find-email-dups
DawoudIO a8c8035
Merge branch 'master' into feature/find-email-dups
crossan007 1d04f22
Merge branch 'master' into feature/find-email-dups
DawoudIO dd625c3
Merge branch 'master' into feature/find-email-dups
DawoudIO ef1d9dd
added 2.10.0-email view
DawoudIO 928eae4
redoing the views to work with older mysql dbs
DawoudIO 574d536
updating post schema update
DawoudIO 1047b4d
Merge branch 'feature/find-email-dups' of https://github.com/ChurchCR…
DawoudIO b087d80
Merge branch 'master' into feature/find-email-dups
crossan007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
use Propel\Runtime\Propel; | ||
use ChurchCRM\PersonQuery; | ||
use ChurchCRM\FamilyQuery; | ||
use Slim\Http\Request; | ||
use Slim\Http\Response; | ||
|
||
$app->group('/emails', function () { | ||
$this->get('/duplicates', 'getEmailDupes'); | ||
}); | ||
|
||
|
||
/** | ||
* A method that review dup emails in the db and returns families and people where that email is used. | ||
* | ||
* @param \Slim\Http\Request $p_request The request. | ||
* @param \Slim\Http\Response $p_response The response. | ||
* @param array $p_args Arguments | ||
* @return \Slim\Http\Response The augmented response. | ||
*/ | ||
function getEmailDupes(Request $request, Response $response, array $p_args) | ||
{ | ||
$connection = Propel::getConnection(); | ||
$dupEmailsSQL = "select email from emails_duplicate;"; | ||
$statement = $connection->prepare($dupEmailsSQL); | ||
$statement->execute(); | ||
$dupEmails = $statement->fetchAll(); | ||
|
||
$emails = []; | ||
foreach ($dupEmails as $dbEmail) { | ||
$email = $dbEmail['email']; | ||
$dbPeople = PersonQuery::create()->filterByEmail($email)->_or()->filterByWorkEmail($email)->find(); | ||
$people = []; | ||
foreach ($dbPeople as $person) { | ||
array_push($people, ["id" => $person->getId(), "name" => $person->getFullName()]); | ||
} | ||
$families = []; | ||
$dbFamilies = FamilyQuery::create()->findByEmail($email); | ||
foreach ($dbFamilies as $family) { | ||
array_push($families, ["id" => $family->getId(), "nane" => $family->getName()]); | ||
} | ||
$emails[$email] = [ | ||
"people" => $people, | ||
"families" => $families | ||
]; | ||
} | ||
|
||
return $response->withJson($emails); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CREATE VIEW emails_duplicate AS | ||
SELECT | ||
email, total | ||
FROM | ||
(SELECT | ||
email, COUNT(*) AS total | ||
FROM | ||
(SELECT | ||
fam_Email AS email, 'family' AS type, fam_id AS id | ||
FROM | ||
family_fam | ||
WHERE | ||
fam_email IS NOT NULL | ||
AND fam_email != '' UNION SELECT | ||
per_email AS email, 'person_home' AS type, per_id AS id | ||
FROM | ||
person_per | ||
WHERE | ||
per_email IS NOT NULL | ||
AND per_email != '' UNION SELECT | ||
per_WorkEmail AS email, 'person_work' AS type, per_id AS id | ||
FROM | ||
person_per | ||
WHERE | ||
per_WorkEmail IS NOT NULL | ||
AND per_WorkEmail != '') emails | ||
GROUP BY email) AS emailTotals | ||
WHERE | ||
total > 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make the SQL statements CAPITALIZED to keep with standard SQL convention.