]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/end.php
Release 6.3.0
[Github/sugarcrm.git] / modules / UpgradeWizard / end.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
42  * Reserved. Contributor(s): ______________________________________..
43  * *******************************************************************************/
44 logThis('[At end.php]');
45 global $unzip_dir;
46 global $path;
47 global $sugar_config;
48
49 if($unzip_dir == null ) {
50         $unzip_dir = $_SESSION['unzip_dir'];
51 }
52
53 //First repair the databse to ensure it is up to date with the new vardefs/tabledefs
54 logThis('About to repair the database.', $path);
55 //Use Repair and rebuild to update the database.
56 global $dictionary, $beanFiles;
57
58 require_once('modules/Trackers/TrackerManager.php');
59 $trackerManager = TrackerManager::getInstance();
60 $trackerManager->pause();
61 $trackerManager->unsetMonitors();
62
63 require_once("modules/Administration/QuickRepairAndRebuild.php");
64 $rac = new RepairAndClear();
65 $rac->clearVardefs();
66 $rac->rebuildExtensions();
67 //bug: 44431 - defensive check to ensure the method exists since upgrades to 6.2.0 may not have this method define yet.
68 if(method_exists($rac, 'clearExternalAPICache'))
69 {
70     $rac->clearExternalAPICache();
71 }
72
73 $repairedTables = array();
74
75 foreach ($beanFiles as $bean => $file) {
76         if(file_exists($file)){
77                 require_once ($file);
78                 unset($GLOBALS['dictionary'][$bean]);
79                 $focus = new $bean ();
80                 if (($focus instanceOf SugarBean))
81                 {
82                         if(!isset($repairedTables[$focus->table_name]))
83                         {
84                                 $sql = $GLOBALS['db']->repairTable($focus, true);
85                                 logThis('Running sql:' . $sql, $path);
86                                 $repairedTables[$focus->table_name] = true;
87                         }
88
89                         //Check to see if we need to create the audit table
90                     if($focus->is_AuditEnabled() && !$focus->db->tableExists($focus->get_audit_table_name())){
91                        logThis('Creating audit table:' . $focus->get_audit_table_name(), $path);
92                $focus->create_audit_table();
93             }
94                 }
95         }
96 }
97
98 $olddictionary = $dictionary;
99
100 unset ($dictionary);
101 include ('modules/TableDictionary.php');
102 foreach ($dictionary as $meta) {
103         $tablename = $meta['table'];
104         if (isset($repairedTables[$tablename])) continue;
105         $fielddefs = $meta['fields'];
106         $indices = $meta['indices'];
107         $sql = $GLOBALS['db']->repairTableParams($tablename, $fielddefs, $indices, true);
108         logThis('Running sql:' . $sql, $path);
109         $repairedTables[$tablename] = true;
110 }
111
112                 $dictionary = $olddictionary;
113
114 logThis('database repaired', $path);
115
116 $ce_to_pro_ent = isset($_SESSION['upgrade_from_flavor']) && ($_SESSION['upgrade_from_flavor'] == 'SugarCE to SugarPro' || $_SESSION['upgrade_from_flavor'] == 'SugarCE to SugarEnt' || $_SESSION['upgrade_from_flavor'] == 'SugarCE to SugarCorp' || $_SESSION['upgrade_from_flavor'] == 'SugarCE to SugarUlt');
117
118
119 logThis(" Start Rebuilding the config file again", $path);
120
121 //check and set the logger before rebuilding config
122 if(!isset($sugar_config['logger'])){
123         $sugar_config['logger'] =array (
124                 'level'=>'fatal',
125             'file' =>
126               array (
127                       'ext' => '.log',
128                       'name' => 'sugarcrm',
129                       'dateFormat' => '%c',
130                       'maxSize' => '10MB',
131                       'maxLogs' => 10,
132                       'suffix' => '%m_%Y',
133                   ),
134         );
135 }
136 //for upgraded version, set default lead conversion activity option to 'copy'
137 if(!isset($sugar_config['lead_conv_activity_opt'])) {
138     $sugar_config['lead_conv_activity_opt'] = 'copy';
139 }
140
141 if(!rebuildConfigFile($sugar_config, $sugar_version)) {
142         logThis('*** WARNING: could not write config.php!', $path);
143 }
144 logThis(" Finish Rebuilding the config file again", $path);
145
146 set_upgrade_progress('end','in_progress');
147
148
149 if(isset($_SESSION['current_db_version']) && isset($_SESSION['target_db_version'])){
150         if($_SESSION['current_db_version'] != $_SESSION['target_db_version']){
151                 logThis("Upgrading multienum data", $path);
152         require_once("$unzip_dir/scripts/upgrade_multienum_data.php");
153         upgrade_multienum_data();
154          }
155
156
157          //keeping separate. making easily visible and readable
158          if($_SESSION['current_db_version'] == $_SESSION['target_db_version']){
159             $_REQUEST['upgradeWizard'] = true;
160             ob_start();
161                         include('modules/ACL/install_actions.php');
162                         include_once('include/Smarty/internals/core.write_file.php');
163                 ob_end_clean();
164                 $db =& DBManagerFactory::getInstance();
165                 if($ce_to_pro_ent){
166                 //Also set license information
167                         $admin = new Administration();
168                         $category = 'license';
169                         $value = '0';
170                         $admin->saveSetting($category, 'users', $value);
171                         $key = array('num_lic_oc','key','expire_date');
172                         $value = '';
173                         foreach($key as $k){
174                                 $admin->saveSetting($category, $k, $value);
175                         }
176                 }
177         }
178 }
179
180 // Mark the instance as having gone thru the admin wizard
181 $admin = new Administration();
182 $admin->saveSetting('system','adminwizard',1);
183
184  /////////////////////////Old Logger settings///////////////////////////////////////
185 ///////////////////////////////////////////////////////////////////////////////
186 if(file_exists('modules/Configurator/Configurator.php')){
187         require_once('include/utils/array_utils.php');
188         require_once('modules/Configurator/Configurator.php');
189         $Configurator = new Configurator();
190         $Configurator->parseLoggerSettings();
191 }
192 //unset the logger previously instantiated
193 if(file_exists('include/SugarLogger/LoggerManager.php')){
194
195         unset($GLOBALS['log']);
196         $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
197 }
198
199
200 //Upgrade connectors
201 if($_SESSION['current_db_version'] < '610' && function_exists('upgrade_connectors'))
202 {
203    upgrade_connectors($path);
204 }
205
206 // Enable the InsideView connector by default
207 if($_SESSION['current_db_version'] < '621' && function_exists('upgradeEnableInsideViewConnector')) {
208     upgradeEnableInsideViewConnector();
209 }
210
211 if ($_SESSION['current_db_version'] < '620' && ($sugar_config['dbconfig']['db_type'] == 'mssql' || $sugar_config['dbconfig']['db_type'] == 'oci8'))
212 {
213     repair_long_relationship_names($path);
214 }
215
216 //Global search support
217 if($_SESSION['current_db_version'] < '620' && function_exists('add_unified_search_to_custom_modules_vardefs'))
218 {
219    logThis('Add global search for custom modules start .', $path);
220    add_unified_search_to_custom_modules_vardefs();
221    logThis('Add global search for custom modules finished .', $path);
222 }
223
224 //Upgrade system displayed tabs and subpanels
225 if(function_exists('upgradeDisplayedTabsAndSubpanels'))
226 {
227         upgradeDisplayedTabsAndSubpanels($_SESSION['current_db_version']);
228 }
229
230
231 //Unlink files that have been removed
232 if(function_exists('unlinkUpgradeFiles'))
233 {
234         unlinkUpgradeFiles($_SESSION['current_db_version']);
235 }
236
237 require_once('modules/Administration/upgrade_custom_relationships.php');
238 upgrade_custom_relationships();
239
240 require_once('modules/UpgradeWizard/uw_utils.php');
241 if($_SESSION['current_db_version'] < '620')
242 {
243         upgradeDateTimeFields($path);
244         upgradeDocumentTypeFields($path);
245 }
246
247 //Update the license
248 logThis('Start Updating the license ', $path);
249 ob_start();
250
251    check_now(get_sugarbeat());
252 ob_end_clean();
253 logThis('End Updating the license ', $path);
254
255 set_upgrade_progress('end','done');
256
257 logThis('Cleaning up the session.  Goodbye.');
258 unlinkTempFiles();
259 logThis('Cleaning up the session.  Goodbye.');
260 resetUwSession();
261 // flag to say upgrade has completed
262 $_SESSION['upgrade_complete'] = true;
263
264 //Clear any third party caches
265 sugar_cache_reset_full();
266
267 //add the clean vardefs here
268 if(!class_exists('VardefManager')){
269
270 }
271 VardefManager::clearVardef();
272
273 require_once('include/TemplateHandler/TemplateHandler.php');
274 TemplateHandler::clearAll();
275
276 //also add the cache cleaning here.
277 if(function_exists('deleteCache')){
278         deleteCache();
279 }
280
281 global $mod_strings;
282 global $current_language;
283
284 if(!isset($current_language) || ($current_language == null)){
285         $current_language = 'en_us';
286 }
287 if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null)){
288         $current_language = $GLOBALS['current_language'];
289 }
290 $mod_strings = return_module_language($current_language, 'UpgradeWizard');
291 $stop = false;
292
293
294 $httpHost               = $_SERVER['HTTP_HOST'];  // cn: 8472 - HTTP_HOST includes port in some cases
295 if($colon = strpos($httpHost, ':')) {
296         $httpHost       = substr($httpHost, 0, $colon);
297 }
298 $parsedSiteUrl  = parse_url($sugar_config['site_url']);
299 $host                   = ($parsedSiteUrl['host'] != $httpHost) ? $httpHost : $parsedSiteUrl['host'];
300
301 // aw: 9747 - use SERVER_PORT for users who don't plug in the site_url at install correctly
302 if ($_SERVER['SERVER_PORT'] != 80){
303         $port = ":".$_SERVER['SERVER_PORT'];
304 }
305 else if (isset($parsedSiteUrl['port']) && $parsedSiteUrl['port'] != 80){
306         $port = ":".$parsedSiteUrl['port'];
307 }
308 else{
309         $port = '';
310 }
311 $path                   = $parsedSiteUrl['path'];
312 $cleanUrl               = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}/index.php";
313
314 $uwMain =<<<eoq
315 <table cellpadding="3" cellspacing="0" border="0">
316
317         <tr>
318                 <td align="left">
319                         <p>
320                         <br>
321                         {$mod_strings['LBL_UW_END_LOGOUT_PRE2']}
322                         <br>
323                         <br>
324             <b>{$mod_strings['LBL_UW_END_LOGOUT_PRE']}</b> {$mod_strings['LBL_UW_END_LOGOUT']}
325                         </p>
326                 </td>
327         </tr>
328 </table>
329
330 <script>
331  function deleteCacheAjax(){
332         //AJAX call for checking the file size and comparing with php.ini settings.
333         var callback = {
334                  success:function(r) {
335                      //alert(r.responseText);
336                  }
337         }
338         postData = '&module=UpgradeWizard&action=deleteCache&to_pdf=1';
339         YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, postData);
340 }
341 </script>
342 eoq;
343
344 $showBack               = false;
345 $showCancel             = false;
346 $showRecheck    = false;
347 $showNext               = false;
348 $showDone       = true;
349
350 $stepBack               = 0;
351 $stepNext               = 0;
352 $stepCancel     = 0;
353 $stepRecheck    = 0;
354
355 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = ($stop) ? 'failed' : 'success';
356 unset($_SESSION['current_db_version']);
357 unset($_SESSION['target_db_version']);