2013-09-23 19:30:44 +00:00
< ? php
2018-07-12 10:40:10 +00:00
if ( ! defined ( 'sugarEntry' ) || ! sugarEntry ) {
die ( 'Not A Valid Entry Point' );
}
2018-08-01 19:14:25 +00:00
/**
*
2013-09-23 19:30:44 +00:00
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM , Inc . Copyright ( C ) 2004 - 2013 SugarCRM Inc .
2018-08-01 19:14:25 +00:00
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd .
* Copyright ( C ) 2011 - 2018 SalesAgility Ltd .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7 ( a ) : FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM , SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
2018-08-01 19:14:25 +00:00
* FOR A PARTICULAR PURPOSE . See the GNU Affero General Public License for more
2013-09-23 19:30:44 +00:00
* details .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* You should have received a copy of the GNU Affero General Public License along with
* this program ; if not , see http :// www . gnu . org / licenses or write to the Free
* Software Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA
* 02110 - 1301 USA .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* You can contact SugarCRM , Inc . headquarters at 10050 North Wolfe Road ,
* SW2 - 130 , Cupertino , CA 95014 , USA . or at email address contact @ sugarcrm . com .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices , as required under
* Section 5 of the GNU Affero General Public License version 3.
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* In accordance with Section 7 ( b ) of the GNU Affero General Public License version 3 ,
* these Appropriate Legal Notices must retain the display of the " Powered by
2014-07-07 15:33:23 +00:00
* SugarCRM " logo and " Supercharged by SuiteCRM " logo. If the display of the logos is not
2018-08-01 19:14:25 +00:00
* reasonably feasible for technical reasons , the Appropriate Legal Notices must
* display the words " Powered by SugarCRM " and " Supercharged by SuiteCRM " .
*/
2013-09-23 19:30:44 +00:00
//Check if current user has admin access
2019-01-25 13:51:46 +00:00
if ( is_admin ( $current_user )) {
2013-09-23 19:30:44 +00:00
global $mod_strings ;
//echo out processing message
echo '<br>' . $mod_strings [ 'LBL_REPAIR_FIELD_CASING_PROCESSING' ];
//store the affected entries
$database_entries = array ();
$module_entries = array ();
$query = " SELECT * FROM fields_meta_data " ;
2018-04-03 15:25:21 +00:00
$result = DBManagerFactory :: getInstance () -> query ( $query );
2019-01-25 13:51:46 +00:00
while ( $row = DBManagerFactory :: getInstance () -> fetchByAssoc ( $result )) {
$name = $row [ 'name' ];
$id = $row [ 'id' ];
$module_entries [ $row [ 'custom_module' ]] = true ;
//Only run database SQL where the name or id casing does is not lowercased
if ( $name != strtolower ( $row [ 'name' ])) {
$database_entries [ $row [ 'custom_module' ]][ $name ] = $row ;
}
2013-09-23 19:30:44 +00:00
}
//If we have database entries to process
2019-01-25 13:51:46 +00:00
if ( ! empty ( $database_entries )) {
foreach ( $database_entries as $module => $entries ) {
$table_name = strtolower ( $module ) . '_cstm' ;
2018-07-31 14:24:44 +00:00
2019-01-25 13:51:46 +00:00
foreach ( $entries as $original_col_name => $entry ) {
echo '<br>' . string_format ( $mod_strings [ 'LBL_REPAIR_FIELD_CASING_SQL_FIELD_META_DATA' ], array ( $entry [ 'name' ]));
$update_sql = " UPDATE fields_meta_data SET id = ' " . $entry [ 'custom_module' ] . strtolower ( $entry [ 'name' ]) . " ', name = ' " . strtolower ( $entry [ 'name' ]) . " ' WHERE id = ' " . $entry [ 'id' ] . " ' " ;
DBManagerFactory :: getInstance () -> query ( $update_sql );
2013-09-23 19:30:44 +00:00
2019-01-25 13:51:46 +00:00
echo '<br>' . string_format ( $mod_strings [ 'LBL_REPAIR_FIELD_CASING_SQL_CUSTOM_TABLE' ], array ( $entry [ 'name' ], $table_name ));
2013-09-23 19:30:44 +00:00
2019-01-25 13:51:46 +00:00
DBManagerFactory :: getInstance () -> query ( DBManagerFactory :: getInstance () -> renameColumnSQL ( $table_name , $entry [ 'name' ], strtolower ( $entry [ 'name' ])));
}
}
2013-09-23 19:30:44 +00:00
}
//If we have metadata files to alter
2019-01-25 13:51:46 +00:00
if ( ! empty ( $module_entries )) {
$modules = array_keys ( $module_entries );
$views = array ( 'basic_search' , 'advanced_search' , 'detailview' , 'editview' , 'quickcreate' );
$class_names = array ();
2018-07-31 14:24:44 +00:00
2019-01-25 14:22:15 +00:00
require_once ( 'include/TemplateHandler/TemplateHandler.php' ) ;
2019-01-25 13:51:46 +00:00
require_once ( 'modules/ModuleBuilder/parsers/ParserFactory.php' );
2018-07-31 14:24:44 +00:00
2019-01-25 13:51:46 +00:00
foreach ( $modules as $module ) {
if ( isset ( $GLOBALS [ 'beanList' ][ $module ])) {
$class_names [] = $GLOBALS [ 'beanList' ][ $module ];
}
2018-07-31 14:24:44 +00:00
2019-01-25 13:51:46 +00:00
$repairClass -> module_list [] = $module ;
foreach ( $views as $view ) {
try {
2013-09-23 19:30:44 +00:00
$parser = ParserFactory :: getParser ( $view , $module );
2019-01-25 13:51:46 +00:00
} catch ( Exception $e ) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> fatal ( " Caught exception in RepairFieldCasing script: " . $e -> getMessage ());
continue ;
}
2019-01-25 13:51:46 +00:00
if ( isset ( $parser -> _viewdefs [ 'panels' ])) {
foreach ( $parser -> _viewdefs [ 'panels' ] as $panel_id => $panel ) {
foreach ( $panel as $row_id => $row ) {
foreach ( $row as $entry_id => $entry ) {
if ( is_array ( $entry ) && isset ( $entry [ 'name' ])) {
$parser -> _viewdefs [ 'panels' ][ $panel_id ][ $row_id ][ $entry_id ][ 'name' ] = strtolower ( $entry [ 'name' ]);
}
}
}
}
} else {
//For basic_search and advanced_search views, just process the fields
foreach ( $parser -> _viewdefs as $entry_id => $entry ) {
if ( is_array ( $entry ) && isset ( $entry [ 'name' ])) {
$parser -> _viewdefs [ $entry_id ][ 'name' ] = strtolower ( $entry [ 'name' ]);
}
}
}
//Save the changes
$parser -> handleSave ( false );
} //foreach
//Now clear the cache of the .tpl files
TemplateHandler :: clearCache ( $module );
} //foreach
echo '<br>' . $mod_strings [ 'LBL_CLEAR_VARDEFS_DATA_CACHE_TITLE' ];
require_once ( 'modules/Administration/QuickRepairAndRebuild.php' );
2013-09-23 19:30:44 +00:00
$repair = new RepairAndClear ();
$repair -> show_output = false ;
$repair -> module_list = array ( $class_names );
$repair -> clearVardefs ();
}
echo '<br>' . $mod_strings [ 'LBL_DIAGNOSTIC_DONE' ];
}