]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/UpgradeWizardCommon.php
Release 6.5.15
[Github/sugarcrm.git] / modules / Administration / UpgradeWizardCommon.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-2013 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 require_once('include/utils/zip_utils.php');
43
44 // increase the cuttoff time to 1 hour
45 ini_set("max_execution_time", "3600");
46
47 if( isset( $_REQUEST['view'] ) && ($_REQUEST['view'] != "") ){
48     $view = $_REQUEST['view'];
49     if( $view != "default" && $view != "module" ){
50         die($mod_strings['ERR_UW_INVALID_VIEW']);
51     }
52 }
53 else{
54     die($mod_strings['ERR_UW_NO_VIEW']);
55 }
56 $form_action = "index.php?module=Administration&view=" . $view . "&action=UpgradeWizard";
57
58
59 $base_upgrade_dir       = "upload://upgrades";
60 $base_tmp_upgrade_dir   = sugar_cached('upgrades/temp');
61
62 $GLOBALS['subdirs'] = array('full', 'langpack', 'module', 'patch', 'theme');
63 // array of special scripts that are executed during (un)installation-- key is type of script, value is filename
64
65 if(!defined('SUGARCRM_PRE_INSTALL_FILE'))
66 {
67         define('SUGARCRM_PRE_INSTALL_FILE', 'scripts/pre_install.php');
68         define('SUGARCRM_POST_INSTALL_FILE', 'scripts/post_install.php');
69         define('SUGARCRM_PRE_UNINSTALL_FILE', 'scripts/pre_uninstall.php');
70         define('SUGARCRM_POST_UNINSTALL_FILE', 'scripts/post_uninstall.php');
71 }
72 $script_files = array(
73         "pre-install" => constant('SUGARCRM_PRE_INSTALL_FILE'),
74         "post-install" => constant('SUGARCRM_POST_INSTALL_FILE'),
75         "pre-uninstall" => constant('SUGARCRM_PRE_UNINSTALL_FILE'),
76         "post-uninstall" => constant('SUGARCRM_POST_UNINSTALL_FILE'),
77 );
78
79
80
81 function extractFile( $zip_file, $file_in_zip ){
82     global $base_tmp_upgrade_dir;
83         if(empty($base_tmp_upgrade_dir)){
84         $base_tmp_upgrade_dir   = sugar_cached("upgrades/temp");
85     }
86     $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
87     register_shutdown_function('rmdir_recursive', $my_zip_dir);
88     unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
89     return( "$my_zip_dir/$file_in_zip" );
90 }
91
92 function extractManifest( $zip_file ){
93     return( extractFile( $zip_file, "manifest.php" ) );
94 }
95
96 function getInstallType( $type_string ){
97     // detect file type
98     global $subdirs;
99
100     foreach( $subdirs as $subdir ){
101         if( preg_match( "#/$subdir/#", $type_string ) ){
102             return( $subdir );
103         }
104     }
105     // return empty if no match
106     return( "" );
107 }
108
109 function getImageForType( $type ){
110
111     $icon = "";
112     switch( $type ){
113         case "full":
114             $icon = SugarThemeRegistry::current()->getImage("Upgrade", "",null,null,'.gif',$mod_strings['LBL_DST_UPGRADE']);
115             break;
116         case "langpack":
117             $icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "",null,null,'.gif',$mod_strings['LBL_LANGUAGE_PACKS'] );
118             break;
119         case "module":
120             $icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "",null,null,'.gif',$mod_strings['LBL_MODULE_LOADER_TITLE']);
121             break;
122         case "patch":
123             $icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "",null,null,'.gif',$mod_strings['LBL_PATCH_UPGRADES'] );
124             break;
125         case "theme":
126             $icon = SugarThemeRegistry::current()->getImage("Themes", "",null,null,'.gif',$mod_strings['LBL_THEME_SETTINGS'] );
127             break;
128         default:
129             break;
130     }
131     return( $icon );
132 }
133
134 function getLanguagePackName( $the_file ){
135     global $app_list_strings;
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 function validate_manifest( $manifest ){
156     // takes a manifest.php manifest array and validates contents
157     global $subdirs;
158     global $sugar_version;
159     global $sugar_flavor;
160         global $mod_strings;
161
162     if( !isset($manifest['type']) ){
163         die($mod_strings['ERROR_MANIFEST_TYPE']);
164     }
165     $type = $manifest['type'];
166     if( getInstallType( "/$type/" ) == "" ){
167         die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
168     }
169
170     if( isset($manifest['acceptable_sugar_versions']) ){
171         $version_ok = false;
172         $matches_empty = true;
173         if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
174             $matches_empty = false;
175             foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
176                 if( $match == $sugar_version ){
177                     $version_ok = true;
178                 }
179             }
180         }
181         if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
182             $matches_empty = false;
183             foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
184                 if( preg_match( "/$match/", $sugar_version ) ){
185                     $version_ok = true;
186                 }
187             }
188         }
189
190         if( !$matches_empty && !$version_ok ){
191             die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
192         }
193     }
194
195     if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
196         $flavor_ok = false;
197         foreach( $manifest['acceptable_sugar_flavors'] as $match ){
198             if( $match == $sugar_flavor ){
199                 $flavor_ok = true;
200             }
201         }
202         if( !$flavor_ok ){
203             die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
204         }
205     }
206 }
207
208 function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = ''){
209         //require_once($unzip_dir . '/manifest.php');
210         global $installdefs;
211         if(!empty($previous_version)){
212                 //check if the upgrade path exists
213                 if(!empty($upgrade_manifest)){
214                         if(!empty($upgrade_manifest['upgrade_paths'])){
215                                 if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
216                                         $installdefs =  $upgrade_manifest['upgrade_paths'][$previous_version];
217                                 }
218                         }//fi
219                 }//fi
220         }//fi
221         $modified_files = array();
222         if(!empty($installdefs['copy'])){
223                 foreach($installdefs['copy'] as $cp){
224                         $cp['to'] = clean_path(str_replace('<basepath>', $unzip_dir, $cp['to']));
225                         $restore_path = remove_file_extension(urldecode($install_file))."-restore/";
226                         $backup_path = clean_path($restore_path.$cp['to'] );
227                         //check if this file exists in the -restore directory
228                         if(file_exists($backup_path)){
229                                 //since the file exists, then we want do an md5 of the install version and the file system version
230                                 $from = $backup_path;
231                                 $needle = $restore_path;
232                                 if(!$is_install){
233                                         $from = str_replace('<basepath>', $unzip_dir, $cp['from']);
234                                         $needle = $unzip_dir;
235                                 }
236                                 $files_found = md5DirCompare($from.'/', $cp['to'].'/', array('.svn'), false);
237                                 if(count($files_found > 0)){
238                                         foreach($files_found as $key=>$value){
239                                                 $modified_files[] = str_replace($needle, '', $key);
240                                         }
241                                 }
242                         }//fi
243                 }//rof
244         }//fi
245         return $modified_files;
246 }
247
248 ?>