2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 //Check if current user has admin access
39 if(is_admin($current_user)) {
42 //echo out processing message
43 echo '<br>'.$mod_strings['LBL_REPAIR_FIELD_CASING_PROCESSING'];
45 //store the affected entries
46 $database_entries = array();
47 $module_entries = array();
49 $query = "SELECT * FROM fields_meta_data";
50 $result = $GLOBALS['db']->query($query);
51 while($row = $GLOBALS['db']->fetchByAssoc($result)) {
54 $module_entries[$row['custom_module']] = true;
56 //Only run database SQL where the name or id casing does is not lowercased
57 if($name != strtolower($row['name'])) {
58 $database_entries[$row['custom_module']][$name] = $row;
62 //If we have database entries to process
63 if(!empty($database_entries)) {
65 foreach($database_entries as $module=>$entries) {
66 $table_name = strtolower($module) . '_cstm';
68 foreach($entries as $original_col_name=>$entry) {
69 echo '<br>'. string_format($mod_strings['LBL_REPAIR_FIELD_CASING_SQL_FIELD_META_DATA'], array($entry['name']));
70 $update_sql = "UPDATE fields_meta_data SET id = '" . $entry['custom_module'] . strtolower($entry['name']) . "', name = '" . strtolower($entry['name']) . "' WHERE id = '" . $entry['id'] . "'";
71 $GLOBALS['db']->query($update_sql);
73 echo '<br>'. string_format($mod_strings['LBL_REPAIR_FIELD_CASING_SQL_CUSTOM_TABLE'], array($entry['name'], $table_name));
75 $GLOBALS['db']->query($GLOBALS['db']->renameColumnSQL($table_name, $entry['name'], strtolower($entry['name'])));
80 //If we have metadata files to alter
81 if(!empty($module_entries)) {
82 $modules = array_keys($module_entries);
83 $views = array('basic_search', 'advanced_search', 'detailview', 'editview', 'quickcreate');
84 $class_names = array();
86 require_once ('include/TemplateHandler/TemplateHandler.php') ;
87 require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
89 foreach($modules as $module) {
90 if(isset($GLOBALS['beanList'][$module])) {
91 $class_names[] = $GLOBALS['beanList'][$module];
94 $repairClass->module_list[] = $module;
95 foreach($views as $view) {
97 $parser = ParserFactory::getParser($view, $module);
100 $GLOBALS['log']->fatal("Caught exception in RepairFieldCasing script: ".$e->getMessage());
103 if(isset($parser->_viewdefs['panels'])) {
104 foreach($parser->_viewdefs['panels'] as $panel_id=>$panel) {
105 foreach($panel as $row_id=>$row) {
106 foreach($row as $entry_id=>$entry) {
107 if(is_array($entry) && isset($entry['name'])) {
108 $parser->_viewdefs['panels'][$panel_id][$row_id][$entry_id]['name'] = strtolower($entry['name']);
114 //For basic_search and advanced_search views, just process the fields
115 foreach($parser->_viewdefs as $entry_id=>$entry) {
116 if(is_array($entry) && isset($entry['name'])) {
117 $parser->_viewdefs[$entry_id]['name'] = strtolower($entry['name']);
123 $parser->handleSave(false);
126 //Now clear the cache of the .tpl files
127 TemplateHandler::clearCache($module);
132 echo '<br>'.$mod_strings['LBL_CLEAR_VARDEFS_DATA_CACHE_TITLE'];
133 require_once('modules/Administration/QuickRepairAndRebuild.php');
134 $repair = new RepairAndClear();
135 $repair->show_output = false;
136 $repair->module_list = array($class_names);
137 $repair->clearVardefs();
140 echo '<br>'.$mod_strings['LBL_DIAGNOSTIC_DONE'];