]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - install/performSetup.php
Release 6.5.0
[Github/sugarcrm.git] / install / performSetup.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 // This file will load the configuration settings from session data,
41 // write to the config file, and execute any necessary database steps.
42 $GLOBALS['installing'] = true;
43 if( !isset( $install_script ) || !$install_script ){
44     die($mod_strings['ERR_NO_DIRECT_SCRIPT']);
45 }
46 ini_set("output_buffering","0");
47 set_time_limit(3600);
48 // flush after each output so the user can see the progress in real-time
49 ob_implicit_flush();
50
51
52
53
54
55 require_once('install/install_utils.php');
56
57 require_once('modules/TableDictionary.php');
58
59
60 $trackerManager = TrackerManager::getInstance();
61 $trackerManager->pause();
62
63
64 $cache_dir                          = sugar_cached("");
65 $line_entry_format                  = "&nbsp&nbsp&nbsp&nbsp&nbsp<b>";
66 $line_exit_format                   = "... &nbsp&nbsp</b>";
67 $rel_dictionary                 = $dictionary; // sourced by modules/TableDictionary.php
68 $render_table_close             = "";
69 $render_table_open                  = "";
70 $setup_db_admin_password            = $_SESSION['setup_db_admin_password'];
71 $setup_db_admin_user_name           = $_SESSION['setup_db_admin_user_name'];
72 $setup_db_create_database           = $_SESSION['setup_db_create_database'];
73 $setup_db_create_sugarsales_user    = $_SESSION['setup_db_create_sugarsales_user'];
74 $setup_db_database_name             = $_SESSION['setup_db_database_name'];
75 $setup_db_drop_tables               = $_SESSION['setup_db_drop_tables'];
76 $setup_db_host_instance             = $_SESSION['setup_db_host_instance'];
77 $setup_db_port_num                  = $_SESSION['setup_db_port_num'];
78 $setup_db_host_name                 = $_SESSION['setup_db_host_name'];
79 $demoData                           = $_SESSION['demoData'];
80 $setup_db_sugarsales_password       = $_SESSION['setup_db_sugarsales_password'];
81 $setup_db_sugarsales_user           = $_SESSION['setup_db_sugarsales_user'];
82 $setup_site_admin_user_name         = $_SESSION['setup_site_admin_user_name'];
83 $setup_site_admin_password          = $_SESSION['setup_site_admin_password'];
84 $setup_site_guid                    = (isset($_SESSION['setup_site_specify_guid']) && $_SESSION['setup_site_specify_guid'] != '') ? $_SESSION['setup_site_guid'] : '';
85 $setup_site_url                     = $_SESSION['setup_site_url'];
86 $parsed_url                         = parse_url($setup_site_url);
87 $setup_site_host_name               = $parsed_url['host'];
88 $setup_site_log_dir                 = isset($_SESSION['setup_site_custom_log_dir']) ? $_SESSION['setup_site_log_dir'] : '.';
89 $setup_site_log_file                = 'sugarcrm.log';  // may be an option later
90 $setup_site_session_path            = isset($_SESSION['setup_site_custom_session_path']) ? $_SESSION['setup_site_session_path'] : '';
91 $setup_site_log_level                           ='fatal';
92
93 sugar_cache_clear('TeamSetsCache');
94 if ( file_exists($cache_dir .'modules/Teams/TeamSetCache.php') ) {
95         unlink($cache_dir.'modules/Teams/TeamSetCache.php');
96 }
97
98 sugar_cache_clear('TeamSetsMD5Cache');
99 if ( file_exists($cache_dir.'modules/Teams/TeamSetMD5Cache.php') ) {
100         unlink($cache_dir.'modules/Teams/TeamSetMD5Cache.php');
101 }
102 $langHeader = get_language_header();
103 $out =<<<EOQ
104 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
105 <html {$langHeader}>
106 <head>
107    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
108    <meta http-equiv="Content-Script-Type" content="text/javascript">
109    <meta http-equiv="Content-Style-Type" content="text/css">
110     <title>{$mod_strings['LBL_WIZARD_TITLE']} {$mod_strings['LBL_PERFORM_TITLE']}</title>
111    <link REL="SHORTCUT ICON" HREF="$icon">
112    <link rel="stylesheet" href="$css" type="text/css" />
113    <script type="text/javascript" src="$common"></script>
114 </head>
115 <body onload="javascript:document.getElementById('button_next2').focus();">
116 <table cellspacing="0" cellpadding="0" border="0" align="center" class="shell">
117       <tr><td colspan="2" id="help"><a href="{$help_url}" target='_blank'>{$mod_strings['LBL_HELP']} </a></td></tr>
118     <tr>
119       <th width="500">
120                 <p>
121                 <img src="{$sugar_md}" alt="SugarCRM" border="0">
122                 </p>
123                 {$mod_strings['LBL_PERFORM_TITLE']}</th>
124     <th width="200" style="text-align: right;"><a href="http://www.sugarcrm.com" target="_blank">
125     <IMG src="$loginImage" alt="SugarCRM" border="0"></a></th>
126 </tr>
127 <tr>
128    <td colspan="2">
129 EOQ;
130 echo $out;
131 installLog("calling handleSugarConfig()");
132 $bottle = handleSugarConfig();
133 installLog("calling handleLog4Php()");
134 handleLog4Php();
135
136 $server_software = $_SERVER["SERVER_SOFTWARE"];
137 if(strpos($server_software,'Microsoft-IIS') !== false)
138 {
139     installLog("calling handleWebConfig()");
140         handleWebConfig();
141 } else {
142         installLog("calling handleHtaccess()");
143     handleHtaccess();
144 }
145
146 ///////////////////////////////////////////////////////////////////////////////
147 ////    START TABLE STUFF
148 echo "<br>";
149 echo "<b>{$mod_strings['LBL_PERFORM_TABLES']}</b>";
150 echo "<br>";
151
152 // create the SugarCRM database
153 if($setup_db_create_database) {
154     installLog("calling handleDbCreateDatabase()");
155     installerHook('pre_handleDbCreateDatabase');
156     handleDbCreateDatabase();
157     installerHook('post_handleDbCreateDatabase');
158 } else {
159
160 // ensure the charset and collation are utf8
161     installLog("calling handleDbCharsetCollation()");
162     installerHook('pre_handleDbCharsetCollation');
163     handleDbCharsetCollation();
164     installerHook('post_handleDbCharsetCollation');
165 }
166
167 // create the SugarCRM database user
168 if($setup_db_create_sugarsales_user){
169     installerHook('pre_handleDbCreateSugarUser');
170     handleDbCreateSugarUser();
171     installerHook('post_handleDbCreateSugarUser');
172 }
173
174 foreach( $beanFiles as $bean => $file ){
175     require_once( $file );
176 }
177
178 // load up the config_override.php file.
179 // This is used to provide default user settings
180 if( is_file("config_override.php") ){
181     require_once("config_override.php");
182 }
183
184 $db                 = DBManagerFactory::getInstance();
185 $startTime          = microtime(true);
186 $focus              = 0;
187 $processed_tables   = array(); // for keeping track of the tables we have worked on
188 $empty              = '';
189 $new_tables     = 1; // is there ever a scenario where we DON'T create the admin user?
190 $new_config         = 1;
191 $new_report     = 1;
192
193 // add non-module Beans to this array to keep the installer from erroring.
194 $nonStandardModules = array (
195     //'Tracker',
196 );
197
198
199 /**
200  * loop through all the Beans and create their tables
201  */
202  installLog("looping through all the Beans and create their tables");
203  //start by clearing out the vardefs
204  VardefManager::clearVardef();
205 installerHook('pre_createAllModuleTables');
206 foreach( $beanFiles as $bean => $file ) {
207         $doNotInit = array('Scheduler', 'SchedulersJob', 'ProjectTask');
208
209         if(in_array($bean, $doNotInit)) {
210                 $focus = new $bean(false);
211         } else {
212             $focus = new $bean();
213         }
214
215         if ( $bean == 'Configurator' )
216             continue;
217
218     $table_name = $focus->table_name;
219      installLog("processing table ".$focus->table_name);
220     // check to see if we have already setup this table
221     if(!in_array($table_name, $processed_tables)) {
222         if(!file_exists("modules/".$focus->module_dir."/vardefs.php")){
223             continue;
224         }
225         if(!in_array($bean, $nonStandardModules)) {
226             require_once("modules/".$focus->module_dir."/vardefs.php"); // load up $dictionary
227             if($dictionary[$focus->object_name]['table'] == 'does_not_exist') {
228                 continue; // support new vardef definitions
229             }
230         } else {
231                 continue; //no further processing needed for ignored beans.
232         }
233
234         // table has not been setup...we will do it now and remember that
235         $processed_tables[] = $table_name;
236
237         $focus->db->database = $db->database; // set db connection so we do not need to reconnect
238
239         if($setup_db_drop_tables) {
240             drop_table_install($focus);
241             installLog("dropping table ".$focus->table_name);
242         }
243
244         if(create_table_if_not_exist($focus)) {
245             installLog("creating table ".$focus->table_name);
246             if( $bean == "User" ){
247                 $new_tables = 1;
248             }
249             if($bean == "Administration")
250                 $new_config = 1;
251
252
253         }
254
255         installLog("creating Relationship Meta for ".$focus->getObjectName());
256         installerHook('pre_createModuleTable', array('module' => $focus->getObjectName()));
257         SugarBean::createRelationshipMeta($focus->getObjectName(), $db, $table_name, $empty, $focus->module_dir);
258         installerHook('post_createModuleTable', array('module' => $focus->getObjectName()));
259                 echo ".";
260
261     } // end if()
262 }
263 installerHook('post_createAllModuleTables');
264
265 echo "<br>";
266 ////    END TABLE STUFF
267
268 ///////////////////////////////////////////////////////////////////////////////
269 ////    START RELATIONSHIP CREATION
270
271     ksort($rel_dictionary);
272     foreach( $rel_dictionary as $rel_name => $rel_data ){
273         $table = $rel_data['table'];
274
275         if( $setup_db_drop_tables ){
276             if( $db->tableExists($table) ){
277                 $db->dropTableName($table);
278             }
279         }
280
281         if( !$db->tableExists($table) ){
282             $db->createTableParams($table, $rel_data['fields'], $rel_data['indices']);
283         }
284
285         SugarBean::createRelationshipMeta($rel_name,$db,$table,$rel_dictionary,'');
286     }
287
288 ///////////////////////////////////////////////////////////////////////////////
289 ////    START CREATE DEFAULTS
290     echo "<br>";
291     echo "<b>{$mod_strings['LBL_PERFORM_CREATE_DEFAULT']}</b><br>";
292     echo "<br>";
293     installLog("Begin creating Defaults");
294     installerHook('pre_createDefaultSettings');
295     if ($new_config) {
296         installLog("insert defaults into config table");
297         insert_default_settings();
298     }
299     installerHook('post_createDefaultSettings');
300
301
302
303
304
305     installerHook('pre_createUsers');
306     if ($new_tables) {
307         echo $line_entry_format.$mod_strings['LBL_PERFORM_DEFAULT_USERS'].$line_exit_format;
308         installLog($mod_strings['LBL_PERFORM_DEFAULT_USERS']);
309         create_default_users();
310         echo $mod_strings['LBL_PERFORM_DONE'];
311     } else {
312         echo $line_entry_format.$mod_strings['LBL_PERFORM_ADMIN_PASSWORD'].$line_exit_format;
313         installLog($mod_strings['LBL_PERFORM_ADMIN_PASSWORD']);
314         $db->setUserName($setup_db_sugarsales_user);
315         $db->setUserPassword($setup_db_sugarsales_password);
316         set_admin_password($setup_site_admin_password);
317         echo $mod_strings['LBL_PERFORM_DONE'];
318     }
319     installerHook('post_createUsers');
320
321
322
323
324     // default OOB schedulers
325
326     echo $line_entry_format.$mod_strings['LBL_PERFORM_DEFAULT_SCHEDULER'].$line_exit_format;
327     installLog($mod_strings['LBL_PERFORM_DEFAULT_SCHEDULER']);
328     $scheduler = new Scheduler();
329     installerHook('pre_createDefaultSchedulers');
330     $scheduler->rebuildDefaultSchedulers();
331     installerHook('post_createDefaultSchedulers');
332
333
334     echo $mod_strings['LBL_PERFORM_DONE'];
335
336
337
338 // Enable Sugar Feeds and add all feeds by default
339 installLog("Enable SugarFeeds");
340 enableSugarFeeds();
341
342
343 // Enable the InsideView connector and add all modules
344 installLog("Enable InsideView Connector");
345 enableInsideViewConnector();
346
347 // Install the logic hook for FTS
348 installLog("Creating FTS logic hook");
349 if (!function_exists('createFTSLogicHook')) {
350     function createFTSLogicHook($filePath = 'application/Ext/LogicHooks/logichooks.ext.php')
351     {
352         $customFileLoc = create_custom_directory($filePath);
353         $fp = sugar_fopen($customFileLoc, 'wb');
354         $contents = <<<CIA
355 <?php
356 if (!isset(\$hook_array) || !is_array(\$hook_array)) {
357     \$hook_array = array();
358 }
359 if (!isset(\$hook_array['after_save']) || !is_array(\$hook_array['after_save'])) {
360     \$hook_array['after_save'] = array();
361 }
362 \$hook_array['after_save'][] = array(1, 'fts', 'include/SugarSearchEngine/SugarSearchEngineQueueManager.php', 'SugarSearchEngineQueueManager', 'populateIndexQueue');
363 CIA;
364
365         fwrite($fp,$contents);
366         fclose($fp);
367
368     }
369 }
370 createFTSLogicHook();
371 // also write it to Extension directory so it won't be lost when rebuilding extensions
372 createFTSLogicHook('Extension/application/Ext/LogicHooks/SugarFTSHooks.php');
373
374 ///////////////////////////////////////////////////////////////////////////////
375 ////    START DEMO DATA
376
377     // populating the db with seed data
378     installLog("populating the db with seed data");
379     if( $_SESSION['demoData'] != 'no' ){
380         installerHook('pre_installDemoData');
381         set_time_limit( 301 );
382
383       echo "<br>";
384         echo "<b>{$mod_strings['LBL_PERFORM_DEMO_DATA']}</b>";
385         echo "<br><br>";
386
387         print( $render_table_close );
388         print( $render_table_open );
389
390         global $current_user;
391         $current_user = new User();
392         $current_user->retrieve(1);
393         include("install/populateSeedData.php");
394         installerHook('post_installDemoData');
395     }
396
397     $endTime = microtime(true);
398     $deltaTime = $endTime - $startTime;
399
400
401
402 ///////////////////////////////////////////////////////////////////////////
403 ////    FINALIZE LANG PACK INSTALL
404     if(isset($_SESSION['INSTALLED_LANG_PACKS']) && is_array($_SESSION['INSTALLED_LANG_PACKS']) && !empty($_SESSION['INSTALLED_LANG_PACKS'])) {
405         updateUpgradeHistory();
406     }
407
408     ///////////////////////////////////////////////////////////////////////////
409     ////    HANDLE SUGAR VERSIONS
410     require_once('modules/Versions/InstallDefaultVersions.php');
411
412
413
414     require_once('modules/Connectors/InstallDefaultConnectors.php');
415
416         ///////////////////////////////////////////////////////////////////////////////
417         ////    INSTALL PASSWORD TEMPLATES
418     include('install/seed_data/Advanced_Password_SeedData.php');
419
420 ///////////////////////////////////////////////////////////////////////////////
421 ////    SETUP DONE
422 installLog("Installation has completed *********");
423 $memoryUsed = '';
424     if(function_exists('memory_get_usage')) {
425     $memoryUsed = $mod_strings['LBL_PERFORM_OUTRO_5'].memory_get_usage().$mod_strings['LBL_PERFORM_OUTRO_6'];
426     }
427
428
429 $errTcpip = '';
430     $fp = @fsockopen("www.sugarcrm.com", 80, $errno, $errstr, 3);
431     if (!$fp) {
432     $errTcpip = "<p>{$mod_strings['ERR_PERFORM_NO_TCPIP']}</p>";
433     }
434    if ($fp && (!isset( $_SESSION['oc_install']) ||  $_SESSION['oc_install'] == false)) {
435       @fclose($fp);
436       if ( $next_step == 9999 )
437           $next_step = 8;
438     $fpResult =<<<FP
439      <form action="install.php" method="post" name="form" id="form">
440      <input type="hidden" name="current_step" value="{$next_step}">
441      <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
442        <tr>
443          <td>
444             &nbsp;
445          </td>
446          <td><input class="button" type="submit" name="goto" value="{$mod_strings['LBL_NEXT']}" id="button_next2"/></td>
447        </tr>
448      </table>
449      </form>
450 FP;
451    } else {
452         $fpResult =<<<FP
453      <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
454        <tr>
455          <td>&nbsp;</td>
456          <td>
457             <form action="index.php" method="post" name="formFinish" id="formFinish">
458                 <input type="hidden" name="default_user_name" value="admin" />
459                 <input class="button" type="submit" name="next" value="{$mod_strings['LBL_PERFORM_FINISH']}" id="button_next2"/>
460             </form>
461          </td>
462        </tr>
463      </table>
464 FP;
465    }
466
467     if( isset($_SESSION['setup_site_sugarbeet_automatic_checks']) && $_SESSION['setup_site_sugarbeet_automatic_checks'] == true){
468         set_CheckUpdates_config_setting('automatic');
469     }else{
470         set_CheckUpdates_config_setting('manual');
471     }
472     if(!empty($_SESSION['setup_system_name'])){
473         $admin=new Administration();
474         $admin->saveSetting('system','name',$_SESSION['setup_system_name']);
475     }
476
477
478     // Bug 28601 - Set the default list of tabs to show
479     $enabled_tabs = array();
480     $enabled_tabs[] = 'Home';
481
482     $enabled_tabs[] = 'Accounts';
483     $enabled_tabs[] = 'Contacts';
484     $enabled_tabs[] = 'Opportunities';
485     $enabled_tabs[] = 'Leads';
486     $enabled_tabs[] = 'Calendar';
487     $enabled_tabs[] = 'Documents';
488     $enabled_tabs[] = 'Emails';
489     $enabled_tabs[] = 'Campaigns';
490     $enabled_tabs[] = 'Calls';
491     $enabled_tabs[] = 'Meetings';
492     $enabled_tabs[] = 'Tasks';
493     $enabled_tabs[] = 'Notes';
494     $enabled_tabs[] = 'Cases';
495     $enabled_tabs[] = 'Prospects';
496     $enabled_tabs[] = 'ProspectLists';
497
498
499     installerHook('pre_setSystemTabs');
500     require_once('modules/MySettings/TabController.php');
501     $tabs = new TabController();
502     $tabs->set_system_tabs($enabled_tabs);
503     installerHook('post_setSystemTabs');
504
505 post_install_modules();
506
507 //Call rebuildSprites
508 if(function_exists('imagecreatetruecolor'))
509 {
510     require_once('modules/UpgradeWizard/uw_utils.php');
511     rebuildSprites(true);
512 }
513
514 if( count( $bottle ) > 0 ){
515     foreach( $bottle as $bottle_message ){
516         $bottleMsg .= "{$bottle_message}\n";
517     }
518 } else {
519     $bottleMsg = $mod_strings['LBL_PERFORM_SUCCESS'];
520 }
521 installerHook('post_installModules');
522
523
524
525 $out =<<<EOQ
526 <br><p><b>{$mod_strings['LBL_PERFORM_OUTRO_1']} {$setup_sugar_version} {$mod_strings['LBL_PERFORM_OUTRO_2']}</b></p>
527
528 {$mod_strings['LBL_PERFORM_OUTRO_3']} {$deltaTime} {$mod_strings['LBL_PERFORM_OUTRO_4']}<br />
529 {$memoryUsed}
530 {$errTcpip}
531     </td>
532 </tr>
533 <tr>
534 <td align="right" colspan="2">
535 <hr>
536 <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
537 <tr>
538 <td>
539 {$fpResult}
540 </td>
541 </tr>
542 </table>
543 </td>
544 </tr>
545 </table>
546 </body>
547 </html>
548 <!--
549 <bottle>{$bottleMsg}</bottle>
550 -->
551 EOQ;
552
553 echo $out;
554
555
556 ?>