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