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.
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.
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
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
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.
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.
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 ********************************************************************************/
41 require_once('include/utils/db_utils.php');
43 require_once('include/utils/zip_utils.php');
48 // increase the cuttoff time to 1 hour
49 ini_set("max_execution_time", "3600");
51 if( isset( $_REQUEST['view'] ) && ($_REQUEST['view'] != "") ){
52 $view = $_REQUEST['view'];
53 if( $view != "default" && $view != "module" ){
54 die($mod_strings['ERR_UW_INVALID_VIEW']);
58 die($mod_strings['ERR_UW_NO_VIEW']);
60 $form_action = "index.php?module=Administration&view=" . $view . "&action=UpgradeWizard";
63 $base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
64 $base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
65 $GLOBALS['subdirs'] = array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
66 // array of special scripts that are executed during (un)installation-- key is type of script, value is filename
68 if(!defined('SUGARCRM_PRE_INSTALL_FILE'))
70 define('SUGARCRM_PRE_INSTALL_FILE', 'scripts/pre_install.php');
71 define('SUGARCRM_POST_INSTALL_FILE', 'scripts/post_install.php');
72 define('SUGARCRM_PRE_UNINSTALL_FILE', 'scripts/pre_uninstall.php');
73 define('SUGARCRM_POST_UNINSTALL_FILE', 'scripts/post_uninstall.php');
75 $script_files = array(
76 "pre-install" => constant('SUGARCRM_PRE_INSTALL_FILE'),
77 "post-install" => constant('SUGARCRM_POST_INSTALL_FILE'),
78 "pre-uninstall" => constant('SUGARCRM_PRE_UNINSTALL_FILE'),
79 "post-uninstall" => constant('SUGARCRM_POST_UNINSTALL_FILE'),
83 function extractFile( $zip_file, $file_in_zip ){
84 global $base_tmp_upgrade_dir;
85 if(empty($base_tmp_upgrade_dir)){
86 $base_tmp_upgrade_dir = $GLOBALS['sugar_config']['upload_dir'] . "upgrades/temp";
88 $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
89 unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
90 return( "$my_zip_dir/$file_in_zip" );
93 function extractManifest( $zip_file ){
94 return( extractFile( $zip_file, "manifest.php" ) );
97 function getInstallType( $type_string ){
101 foreach( $subdirs as $subdir ){
102 if( preg_match( "#/$subdir/#", $type_string ) ){
106 // return empty if no match
110 function getImageForType( $type ){
115 $icon = SugarThemeRegistry::current()->getImage("Upgrade", "" );
118 $icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "" );
121 $icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "" );
124 $icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "" );
127 $icon = SugarThemeRegistry::current()->getImage("Themes", "" );
135 function getLanguagePackName( $the_file ){
136 require_once( "$the_file" );
137 if( isset( $app_list_strings["language_pack_name"] ) ){
138 return( $app_list_strings["language_pack_name"] );
143 function getUITextForType( $type ){
144 $type = 'LBL_UW_TYPE_'.strtoupper($type);
146 return $mod_strings[$type];
149 function getUITextForMode( $mode ){
150 $mode = 'LBL_UW_MODE_'.strtoupper($mode);
152 return $mod_strings[$mode];
157 * @todo this function doesn't seemed to be used anymore; trying kill this off
159 function run_upgrade_wizard_sql( $script ){
161 global $sugar_config;
163 $db_type = $sugar_config['dbconfig']['db_type'];
164 $script = str_replace( "%db_type%", $db_type, $script );
165 if( !run_sql_file( "$unzip_dir/$script" ) ){
166 die( "{$mod_strings['ERR_UW_RUN_SQL']} $unzip_dir/$script" );
170 function validate_manifest( $manifest ){
171 // takes a manifest.php manifest array and validates contents
173 global $sugar_version;
174 global $sugar_flavor;
177 if( !isset($manifest['type']) ){
178 die($mod_strings['ERROR_MANIFEST_TYPE']);
180 $type = $manifest['type'];
181 if( getInstallType( "/$type/" ) == "" ){
182 die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
185 if( isset($manifest['acceptable_sugar_versions']) ){
187 $matches_empty = true;
188 if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
189 $matches_empty = false;
190 foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
191 if( $match == $sugar_version ){
196 if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
197 $matches_empty = false;
198 foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
199 if( preg_match( "/$match/", $sugar_version ) ){
205 if( !$matches_empty && !$version_ok ){
206 die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
210 if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
212 foreach( $manifest['acceptable_sugar_flavors'] as $match ){
213 if( $match == $sugar_flavor ){
218 die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
223 function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = ''){
224 //require_once($unzip_dir . '/manifest.php');
226 if(!empty($previous_version)){
227 //check if the upgrade path exists
228 if(!empty($upgrade_manifest)){
229 if(!empty($upgrade_manifest['upgrade_paths'])){
230 if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
231 $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version];
236 $modified_files = array();
237 if(!empty($installdefs['copy'])){
238 foreach($installdefs['copy'] as $cp){
239 $cp['to'] = clean_path(str_replace('<basepath>', $unzip_dir, $cp['to']));
240 $restore_path = remove_file_extension(urldecode($install_file))."-restore/";
241 $backup_path = clean_path($restore_path.$cp['to'] );
242 //check if this file exists in the -restore directory
243 if(file_exists($backup_path)){
244 //since the file exists, then we want do an md5 of the install version and the file system version
245 $from = $backup_path;
246 $needle = $restore_path;
248 $from = str_replace('<basepath>', $unzip_dir, $cp['from']);
249 $needle = $unzip_dir;
251 $files_found = md5DirCompare($from.'/', $cp['to'].'/', array('.svn'), false);
252 if(count($files_found > 0)){
253 foreach($files_found as $key=>$value){
254 $modified_files[] = str_replace($needle, '', $key);
260 return $modified_files;