]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/UpgradeWizardCommon.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Administration / UpgradeWizardCommon.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
41 require_once('include/utils/db_utils.php');
42
43 require_once('include/utils/zip_utils.php');
44
45
46
47
48 // increase the cuttoff time to 1 hour
49 ini_set("max_execution_time", "3600");
50
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']);
55     }
56 }
57 else{
58     die($mod_strings['ERR_UW_NO_VIEW']);
59 }
60 $form_action = "index.php?module=Administration&view=" . $view . "&action=UpgradeWizard";
61
62
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
67
68 if(!defined('SUGARCRM_PRE_INSTALL_FILE'))
69 {
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');
74 }
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'),
80 );
81
82
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";
87     }
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" );
91 }
92
93 function extractManifest( $zip_file ){
94     return( extractFile( $zip_file, "manifest.php" ) );
95 }
96
97 function getInstallType( $type_string ){
98     // detect file type
99     global $subdirs;
100         
101     foreach( $subdirs as $subdir ){
102         if( preg_match( "#/$subdir/#", $type_string ) ){
103             return( $subdir );
104         }
105     }
106     // return empty if no match
107     return( "" );
108 }
109
110 function getImageForType( $type ){
111     
112     $icon = "";
113     switch( $type ){
114         case "full":
115             $icon = SugarThemeRegistry::current()->getImage("Upgrade", "" );
116             break;
117         case "langpack":
118             $icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "" );
119             break;
120         case "module":
121             $icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "" );
122             break;
123         case "patch":
124             $icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "" );
125             break;
126         case "theme":
127             $icon = SugarThemeRegistry::current()->getImage("Themes", "" );
128             break;
129         default:
130             break;
131     }
132     return( $icon );
133 }
134
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"] );
139     }
140     return( "" );
141 }
142
143 function getUITextForType( $type ){
144         $type = 'LBL_UW_TYPE_'.strtoupper($type);
145         global $mod_strings;
146         return $mod_strings[$type];
147 }
148
149 function getUITextForMode( $mode ){
150     $mode = 'LBL_UW_MODE_'.strtoupper($mode);
151     global $mod_strings;
152     return $mod_strings[$mode];
153 }
154
155 /**
156  * @deprecated
157  * @todo this function doesn't seemed to be used anymore; trying kill this off
158  */
159 function run_upgrade_wizard_sql( $script ){
160     global $unzip_dir;
161     global $sugar_config;
162
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" );
167     }
168 }
169
170 function validate_manifest( $manifest ){
171     // takes a manifest.php manifest array and validates contents
172     global $subdirs;
173     global $sugar_version;
174     global $sugar_flavor;
175         global $mod_strings;
176
177     if( !isset($manifest['type']) ){
178         die($mod_strings['ERROR_MANIFEST_TYPE']);
179     }
180     $type = $manifest['type'];
181     if( getInstallType( "/$type/" ) == "" ){
182         die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
183     }
184
185     if( isset($manifest['acceptable_sugar_versions']) ){
186         $version_ok = false;
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 ){
192                     $version_ok = true;
193                 }
194             }
195         }
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 ) ){
200                     $version_ok = true;
201                 }
202             }
203         }
204
205         if( !$matches_empty && !$version_ok ){
206             die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
207         }
208     }
209
210     if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
211         $flavor_ok = false;
212         foreach( $manifest['acceptable_sugar_flavors'] as $match ){
213             if( $match == $sugar_flavor ){
214                 $flavor_ok = true;
215             }
216         }
217         if( !$flavor_ok ){
218             die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
219         }
220     }
221 }
222
223 function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = ''){
224         //require_once($unzip_dir . '/manifest.php');
225         global $installdefs;
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];
232                                 }
233                         }//fi
234                 }//fi
235         }//fi
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;
247                                 if(!$is_install){
248                                         $from = str_replace('<basepath>', $unzip_dir, $cp['from']);
249                                         $needle = $unzip_dir;
250                                 }
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);
255                                         }
256                                 }
257                         }//fi
258                 }//rof
259         }//fi
260         return $modified_files;         
261 }
262 ?>