Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | define('CRM_ENCRYPT', 1); | |
35 | define('CRM_SETNULL', 2); | |
36 | function encryptDB() { | |
37 | $tables = array( | |
38 | 'civicrm_contact' => array( | |
39 | 'first_name' => CRM_ENCRYPT, | |
40 | 'last_name' => CRM_ENCRYPT, | |
41 | 'organization_name' => CRM_ENCRYPT, | |
42 | 'household_name' => CRM_ENCRYPT, | |
43 | 'sort_name' => CRM_ENCRYPT, | |
44 | 'display_name' => CRM_ENCRYPT, | |
45 | 'legal_name' => CRM_ENCRYPT, | |
46 | ), | |
47 | 'civicrm_address' => array( | |
48 | 'street_address' => CRM_ENCRYPT, | |
49 | 'supplemental_address_1' => CRM_ENCRYPT, | |
50 | 'supplemental_address_2' => CRM_ENCRYPT, | |
51 | 'city' => CRM_ENCRYPT, | |
52 | 'postal_code' => CRM_SETNULL, | |
53 | 'postal_code_suffix' => CRM_SETNULL, | |
54 | 'geo_code_1' => CRM_SETNULL, | |
55 | 'geo_code_2' => CRM_SETNULL, | |
56 | ), | |
57 | 'civicrm_website' => array( | |
58 | 'url' => CRM_ENCRYPT, | |
59 | ), | |
60 | 'civicrm_email' => array( | |
61 | 'email' => CRM_ENCRYPT, | |
62 | ), | |
63 | 'civicrm_phone' => array( | |
64 | 'phone' => CRM_ENCRYPT, | |
65 | ), | |
66 | ); | |
67 | ||
68 | foreach ($tables as $tableName => $fields) { | |
69 | $clauses = array(); | |
70 | foreach ($fields as $fieldName => $action) { | |
71 | if ($action == CRM_ENCRYPT) { | |
72 | $clauses[] = "$fieldName = md5($fieldName)"; | |
73 | } | |
74 | elseif ($action == CRM_SETNULL) { | |
75 | $clauses[] = "$fieldName = null"; | |
76 | } | |
77 | } | |
78 | ||
79 | if (!empty($clauses)) { | |
80 | $clause = implode(',', $clauses); | |
81 | $query = "UPDATE $tableName SET $clause"; | |
82 | CRM_Core_DAO::executeQuery($query); | |
83 | } | |
84 | } | |
85 | } | |
86 | ||
87 | function run() { | |
88 | session_start(); | |
89 | ||
90 | require_once '../civicrm.config.php'; | |
91 | require_once 'CRM/Core/Config.php'; | |
92 | $config = CRM_Core_Config::singleton(); | |
93 | ||
94 | // this does not return on failure | |
95 | CRM_Utils_System::authenticateScript(TRUE); | |
96 | ||
97 | encryptDB(); | |
98 | } | |
99 | ||
100 | run(); |