]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/RebuildRelationship.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Administration / RebuildRelationship.php
1 <?php
2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3     die ( 'Not A Valid Entry Point' ) ;
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7  * 
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.
14  * 
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
18  * details.
19  * 
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
23  * 02110-1301 USA.
24  * 
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.
27  * 
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.
31  * 
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  ********************************************************************************/
38
39 include ('include/modules.php') ;
40
41
42
43 global $db, $mod_strings ;
44 $log = & $GLOBALS [ 'log' ] ;
45
46 $query = "DELETE FROM relationships" ;
47 $db->query ( $query ) ;
48
49 //clear cache before proceeding..
50 VardefManager::clearVardef () ;
51
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 )
56 {
57     if (strlen ( $file ) > 0 && file_exists ( $file ))
58     {
59         if (! class_exists ( $bean ))
60         {
61             require ($file) ;
62         }
63         $focus = new $bean ( ) ;
64         if ( $focus instanceOf SugarBean ) {
65             $table_name = $focus->table_name ;
66             $empty = array() ;
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>' ;
72         }
73     }
74 }
75
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 )
78 {
79         //skip this file if it does not exist
80         if(!file_exists($file)) continue;
81
82         if (! class_exists ( $bean ))
83     {
84         require ($file) ;
85     }
86     $focus = new $bean ( ) ;
87     if ( $focus instanceOf SugarBean ) {
88         $table_name = $focus->table_name ;
89         $empty = array() ;
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>' ;
95     }
96 }
97
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 already loaded the table dictionary
102     if (file_exists ( 'custom/application/Ext/TableDictionary/tabledictionary.ext.php' ))
103     {
104         include ('custom/application/Ext/TableDictionary/tabledictionary.ext.php') ;
105     }
106     $rel_dictionary = $dictionary ;
107     foreach ( $rel_dictionary as $rel_name => $rel_data )
108     {
109         $table = isset($rel_data [ 'table' ]) ? $rel_data [ 'table' ] : "" ;
110
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>' ;
116     }
117
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 () ;
122
123 //////////////////////////////////////////////////////////////////////////////
124 // Remove the "Rebuild Relationships" red text message on admin logins
125
126
127 if (empty ( $_REQUEST [ 'silent' ] ))
128     echo $mod_strings [ 'LBL_REBUILD_REL_UPD_WARNING' ] ;
129
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 ) ;
134
135 // insert a new database row to show the rebuild relationships is done
136 $id = create_guid () ;
137 $gmdate = gmdate('Y-m-d H:i:s');
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 ) ;
142
143 $rel = new Relationship();
144 Relationship::delete_cache();
145 $rel->build_relationship_cache();
146
147 // unset the session variable so it is not picked up in DisplayWarnings.php
148 if (isset ( $_SESSION [ 'rebuild_relationships' ] ))
149 {
150     unset ( $_SESSION [ 'rebuild_relationships' ] ) ;
151 }
152
153 if (empty ( $_REQUEST [ 'silent' ] ))
154     echo $mod_strings [ 'LBL_DONE' ] ;
155 ?>