2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3 die ( 'Not A Valid Entry Point' ) ;
4 /*********************************************************************************
5 * SugarCRM is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
39 include ('include/modules.php') ;
43 global $db, $mod_strings ;
44 $log = & $GLOBALS [ 'log' ] ;
46 $query = "DELETE FROM relationships" ;
47 $db->query ( $query ) ;
49 //clear cache before proceeding..
50 VardefManager::clearVardef () ;
52 // loop through all of the modules and create entries in the Relationships table (the relationships metadata) for every standard relationship, that is, relationships defined in the /modules/<module>/vardefs.php
53 // SugarBean::createRelationshipMeta just takes the relationship definition in a file and inserts it as is into the Relationships table
54 // It does not override or recreate existing relationships
55 foreach ( $GLOBALS['beanFiles'] as $bean => $file )
57 if (strlen ( $file ) > 0 && file_exists ( $file ))
59 if (! class_exists ( $bean ))
63 $focus = new $bean ( ) ;
64 if ( $focus instanceOf SugarBean ) {
65 $table_name = $focus->table_name ;
67 if (empty ( $_REQUEST [ 'silent' ] ))
68 echo $mod_strings [ 'LBL_REBUILD_REL_PROC_META' ] . $focus->table_name . "..." ;
69 SugarBean::createRelationshipMeta ( $focus->getObjectName (), $db, $table_name, $empty, $focus->module_dir ) ;
70 if (empty ( $_REQUEST [ 'silent' ] ))
71 echo $mod_strings [ 'LBL_DONE' ] . '<br>' ;
76 // do the same for custom relationships (true in the last parameter to SugarBean::createRelationshipMeta) - that is, relationships defined in the custom/modules/<modulename>/Ext/vardefs/ area
77 foreach ( $GLOBALS['beanFiles'] as $bean => $file )
79 //skip this file if it does not exist
80 if(!file_exists($file)) continue;
82 if (! class_exists ( $bean ))
86 $focus = new $bean ( ) ;
87 if ( $focus instanceOf SugarBean ) {
88 $table_name = $focus->table_name ;
90 if (empty ( $_REQUEST [ 'silent' ] ))
91 echo $mod_strings [ 'LBL_REBUILD_REL_PROC_C_META' ] . $focus->table_name . "..." ;
92 SugarBean::createRelationshipMeta ( $focus->getObjectName (), $db, $table_name, $empty, $focus->module_dir, true ) ;
93 if (empty ( $_REQUEST [ 'silent' ] ))
94 echo $mod_strings [ 'LBL_DONE' ] . '<br>' ;
98 // finally, whip through the list of relationships defined in TableDictionary.php, that is all the relationships in the metadata directory, and install those
99 $dictionary = array ( ) ;
100 require ('modules/TableDictionary.php') ;
101 //for module installer incase we alredy loaded the table dictionary
102 if (file_exists ( 'custom/application/Ext/TableDictionary/tabledictionary.ext.php' ))
104 include ('custom/application/Ext/TableDictionary/tabledictionary.ext.php') ;
106 $rel_dictionary = $dictionary ;
107 foreach ( $rel_dictionary as $rel_name => $rel_data )
109 $table = $rel_data [ 'table' ] ;
111 if (empty ( $_REQUEST [ 'silent' ] ))
112 echo $mod_strings [ 'LBL_REBUILD_REL_PROC_C_META' ] . $rel_name . "..." ;
113 SugarBean::createRelationshipMeta ( $rel_name, $db, $table, $rel_dictionary, '' ) ;
114 if (empty ( $_REQUEST [ 'silent' ] ))
115 echo $mod_strings [ 'LBL_DONE' ] . '<br>' ;
118 //clean relationship cache..will be rebuilt upon first access.
119 if (empty ( $_REQUEST [ 'silent' ] ))
120 echo $mod_strings [ 'LBL_REBUILD_REL_DEL_CACHE' ] ;
121 Relationship::delete_cache () ;
123 //////////////////////////////////////////////////////////////////////////////
124 // Remove the "Rebuild Relationships" red text message on admin logins
127 if (empty ( $_REQUEST [ 'silent' ] ))
128 echo $mod_strings [ 'LBL_REBUILD_REL_UPD_WARNING' ] ;
130 // clear the database row if it exists (just to be sure)
131 $query = "DELETE FROM versions WHERE name='Rebuild Relationships'" ;
132 $log->info ( $query ) ;
133 $db->query ( $query ) ;
135 // insert a new database row to show the rebuild relationships is done
136 $id = create_guid () ;
137 $gmdate = gmdate ($GLOBALS['timedate']->get_db_date_time_format()) ;
138 $date_entered = db_convert ( "'$gmdate'", 'datetime' ) ;
139 $query = 'INSERT INTO versions (id, deleted, date_entered, date_modified, modified_user_id, created_by, name, file_version, db_version) ' . "VALUES ('$id', '0', $date_entered, $date_entered, '1', '1', 'Rebuild Relationships', '4.0.0', '4.0.0')" ;
140 $log->info ( $query ) ;
141 $db->query ( $query ) ;
143 // unset the session variable so it is not picked up in DisplayWarnings.php
144 if (isset ( $_SESSION [ 'rebuild_relationships' ] ))
146 unset ( $_SESSION [ 'rebuild_relationships' ] ) ;
149 if (empty ( $_REQUEST [ 'silent' ] ))
150 echo $mod_strings [ 'LBL_DONE' ] ;