Merge pull request #9308 from fuzionnz/case_api_case_id
[civicrm-core.git] / bin / encryptDB.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 27
c5d44ae3
TO
28die("This script is disabled because it is dangerous. If you need it, please duplicate it elsewhere and provide your own secure workflow. This example file will be removed in the future.");
29
30// TIP: If/when we do delete this file, take care to affirmatively check for
31// deletion as part of the status-check infrastructure. Some upgrade workflows
32// don't clear out old files properly, and there's no telling the history
33// of upgrades that have been performed.
34
6a488035
TO
35/**
36 *
37 * @package CRM
fa938177 38 * @copyright CiviCRM LLC (c) 2004-2016
6a488035
TO
39 */
40
41define('CRM_ENCRYPT', 1);
42define('CRM_SETNULL', 2);
43function encryptDB() {
44 $tables = array(
45 'civicrm_contact' => array(
46 'first_name' => CRM_ENCRYPT,
47 'last_name' => CRM_ENCRYPT,
48 'organization_name' => CRM_ENCRYPT,
49 'household_name' => CRM_ENCRYPT,
50 'sort_name' => CRM_ENCRYPT,
51 'display_name' => CRM_ENCRYPT,
52 'legal_name' => CRM_ENCRYPT,
53 ),
54 'civicrm_address' => array(
55 'street_address' => CRM_ENCRYPT,
56 'supplemental_address_1' => CRM_ENCRYPT,
57 'supplemental_address_2' => CRM_ENCRYPT,
58 'city' => CRM_ENCRYPT,
59 'postal_code' => CRM_SETNULL,
60 'postal_code_suffix' => CRM_SETNULL,
61 'geo_code_1' => CRM_SETNULL,
62 'geo_code_2' => CRM_SETNULL,
63 ),
64 'civicrm_website' => array(
65 'url' => CRM_ENCRYPT,
66 ),
67 'civicrm_email' => array(
68 'email' => CRM_ENCRYPT,
69 ),
70 'civicrm_phone' => array(
71 'phone' => CRM_ENCRYPT,
72 ),
73 );
74
75 foreach ($tables as $tableName => $fields) {
76 $clauses = array();
77 foreach ($fields as $fieldName => $action) {
78 if ($action == CRM_ENCRYPT) {
79 $clauses[] = "$fieldName = md5($fieldName)";
80 }
81 elseif ($action == CRM_SETNULL) {
82 $clauses[] = "$fieldName = null";
83 }
84 }
85
86 if (!empty($clauses)) {
87 $clause = implode(',', $clauses);
88 $query = "UPDATE $tableName SET $clause";
89 CRM_Core_DAO::executeQuery($query);
90 }
91 }
92}
93
94function run() {
95 session_start();
96
97 require_once '../civicrm.config.php';
98 require_once 'CRM/Core/Config.php';
99 $config = CRM_Core_Config::singleton();
100
101 // this does not return on failure
102 CRM_Utils_System::authenticateScript(TRUE);
6d1ac482
TO
103 if (!CRM_Core_Permission::check('administer CiviCRM')) {
104 CRM_Utils_System::authenticateAbort("User does not have required permission (administer CiviCRM).\n", TRUE);
105 }
6a488035
TO
106
107 encryptDB();
108}
109
110run();