Commit | Line | Data |
---|---|---|
0546ea74 AE |
1 | #! /usr/bin/python3 |
2 | ||
3 | # SPDX-FileCopyrightText: 2023 Andrew Engelbrecht | |
4 | # | |
5 | # SPDX-License-Identifier: GPL-3.0-or-later | |
6 | ||
7 | import mysql.connector | |
8 | ||
9 | mydb = mysql.connector.connect( | |
10 | host="localhost", | |
11 | user="root", | |
12 | password="liFor2Sh", | |
13 | database="civicrm" | |
14 | ) | |
15 | ||
16 | mycursor0 = mydb.cursor(buffered=True) | |
17 | mycursor1 = mydb.cursor(buffered=True) | |
18 | mycursor2 = mydb.cursor(buffered=True) | |
19 | ||
20 | mycursor0.execute( | |
21 | """ | |
22 | select c.id, c.external_identifier, x.* | |
23 | from civicrm_contact c inner join civicrm_email e on c.id = e.contact_id | |
24 | inner join ( | |
25 | select i.id, i.external_identifier, j.email, count(*) as qty | |
26 | from civicrm_contact i inner join civicrm_email j on i.id = j.contact_id | |
27 | group by email | |
28 | having count(*) > 1 | |
29 | ) x on e.email = x.email and c.external_identifier is not NULL and x.external_identifier is not NULL and c.external_identifier != x.external_identifier; | |
30 | """ | |
31 | ) | |
32 | ||
33 | for row in mycursor0: | |
34 | id1 = row[0] # c.id | |
35 | id2 = row[2] # x.id | |
36 | ||
37 | mycursor1.execute("select count(*) from civicrm_dedupe_exception where (contact_id1 = %s and contact_id2 = %s) or (contact_id1 = %s and contact_id2 = %s);", (id1, id2, id2, id1)) | |
38 | ||
39 | count = mycursor1.fetchone()[0] | |
40 | if count == 0: | |
41 | print('inserting:', id1, id2) | |
42 | mycursor2.execute("INSERT INTO civicrm_dedupe_exception (contact_id1, contact_id2) VALUES (%s, %s)", (id1, id2)) | |
43 | ||
44 | #print("only do one for now, for debugging purposes") | |
45 | #break | |
46 | ||
47 | mydb.commit() | |
48 |