PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/UpgradeWizard/end.php

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