Enotice compliance for mailing test
[civicrm-core.git] / bin / encryptDB.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 define('CRM_ENCRYPT', 1);
37 define('CRM_SETNULL', 2);
38 function encryptDB() {
39 $tables = array(
40 'civicrm_contact' => array(
41 'first_name' => CRM_ENCRYPT,
42 'last_name' => CRM_ENCRYPT,
43 'organization_name' => CRM_ENCRYPT,
44 'household_name' => CRM_ENCRYPT,
45 'sort_name' => CRM_ENCRYPT,
46 'display_name' => CRM_ENCRYPT,
47 'legal_name' => CRM_ENCRYPT,
48 ),
49 'civicrm_address' => array(
50 'street_address' => CRM_ENCRYPT,
51 'supplemental_address_1' => CRM_ENCRYPT,
52 'supplemental_address_2' => CRM_ENCRYPT,
53 'city' => CRM_ENCRYPT,
54 'postal_code' => CRM_SETNULL,
55 'postal_code_suffix' => CRM_SETNULL,
56 'geo_code_1' => CRM_SETNULL,
57 'geo_code_2' => CRM_SETNULL,
58 ),
59 'civicrm_website' => array(
60 'url' => CRM_ENCRYPT,
61 ),
62 'civicrm_email' => array(
63 'email' => CRM_ENCRYPT,
64 ),
65 'civicrm_phone' => array(
66 'phone' => CRM_ENCRYPT,
67 ),
68 );
69
70 foreach ($tables as $tableName => $fields) {
71 $clauses = array();
72 foreach ($fields as $fieldName => $action) {
73 if ($action == CRM_ENCRYPT) {
74 $clauses[] = "$fieldName = md5($fieldName)";
75 }
76 elseif ($action == CRM_SETNULL) {
77 $clauses[] = "$fieldName = null";
78 }
79 }
80
81 if (!empty($clauses)) {
82 $clause = implode(',', $clauses);
83 $query = "UPDATE $tableName SET $clause";
84 CRM_Core_DAO::executeQuery($query);
85 }
86 }
87 }
88
89 function run() {
90 session_start();
91
92 require_once '../civicrm.config.php';
93 require_once 'CRM/Core/Config.php';
94 $config = CRM_Core_Config::singleton();
95
96 // this does not return on failure
97 CRM_Utils_System::authenticateScript(TRUE);
98
99 encryptDB();
100 }
101
102 run();
103