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