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