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-2013 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 require_once('modules/DynamicFields/FieldCases.php');
39 require_once('modules/DynamicFields/DynamicField.php');
42 $db = DBManagerFactory::getInstance();
44 $result = $db->query( 'SELECT * FROM fields_meta_data WHERE deleted = 0 ORDER BY custom_module');
47 * get the real field_meta_data
49 while($row = $db->fetchByAssoc($result)){
50 $the_modules = $row['custom_module'];
51 if(!isset($modules[$the_modules])){
52 $modules[$the_modules] = array();
54 $modules[$the_modules][$row['name']] = $row['name'];
58 if(!isset($_REQUEST['run'])){
60 echo "SIMULATION MODE - NO CHANGES WILL BE MADE EXCEPT CLEARING CACHE";
63 foreach($modules as $the_module=>$fields){
64 if(isset($beanList[$the_module]))
66 $class_name = $beanList[$the_module];
67 echo "<br><br>Scanning $the_module <br>";
69 require_once($beanFiles[$class_name]);
70 $mod = new $class_name();
71 if(!$db->tableExists($mod->table_name . "_cstm")){
72 $mod->custom_fields = new DynamicField();
73 $mod->custom_fields->setup($mod);
74 $mod->custom_fields->createCustomTable();
77 $result = $db->query("DESCRIBE $mod->table_name" . "_cstm");
79 while($row = $db->fetchByAssoc($result)){
84 $fieldDef = $mod->getFieldDefinition($col);
85 $the_field = get_widget($fieldDef['type']);
86 $the_field->set($fieldDef);
88 if(!isset($fields[$col]) && $col != 'id_c'){
89 if(!$simulate)$db->query("ALTER TABLE $mod->table_name" . "_cstm DROP COLUMN $col");
91 echo "Dropping Column $col from $mod->table_name" . "_cstm for module $the_module<br>";
94 if(trim($the_field->get_db_type()) != trim($type)){
96 echo "Fixing Column Type for $col changing $type to ". $the_field->get_db_type() . "<br>";
97 if(!$simulate)$db->query($the_field->get_db_modify_alter_table($mod->table_name . '_cstm'));
101 unset($fields[$col]);
106 echo sizeof($fields) . " field(s) missing from $mod->table_name" . "_cstm<br>";
107 foreach($fields as $field){
108 echo "Adding Column $field to $mod->table_name" . "_cstm<br>";
110 $the_field = $mod->getFieldDefinition($field);
111 $field = get_widget($the_field['type']);
112 $field->set($the_field);
113 $query = $field->get_db_add_alter_table($mod->table_name . '_cstm');
116 $mod->db->query($query);
124 DynamicField::deleteCache();
127 echo '<a href="index.php?module=Administration&action=UpgradeFields&run=true">Execute non-simulation mode</a>';