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