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