]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/UpgradeWizardCommon.php
Release 6.4.0
[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-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 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 function extractFile( $zip_file, $file_in_zip ){
81     global $base_tmp_upgrade_dir;
82         if(empty($base_tmp_upgrade_dir)){
83         $base_tmp_upgrade_dir   = sugar_cached("upgrades/temp");
84     }
85     $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
86     unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
87     return( "$my_zip_dir/$file_in_zip" );
88 }
89
90 function extractManifest( $zip_file ){
91     return( extractFile( $zip_file, "manifest.php" ) );
92 }
93
94 function getInstallType( $type_string ){
95     // detect file type
96     global $subdirs;
97
98     foreach( $subdirs as $subdir ){
99         if( preg_match( "#/$subdir/#", $type_string ) ){
100             return( $subdir );
101         }
102     }
103     // return empty if no match
104     return( "" );
105 }
106
107 function getImageForType( $type ){
108
109     $icon = "";
110     switch( $type ){
111         case "full":
112             $icon = SugarThemeRegistry::current()->getImage("Upgrade", "",null,null,'.gif',$mod_strings['LBL_DST_UPGRADE']);
113             break;
114         case "langpack":
115             $icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "",null,null,'.gif',$mod_strings['LBL_LANGUAGE_PACKS'] );
116             break;
117         case "module":
118             $icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "",null,null,'.gif',$mod_strings['LBL_MODULE_LOADER_TITLE']);
119             break;
120         case "patch":
121             $icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "",null,null,'.gif',$mod_strings['LBL_PATCH_UPGRADES'] );
122             break;
123         case "theme":
124             $icon = SugarThemeRegistry::current()->getImage("Themes", "",null,null,'.gif',$mod_strings['LBL_THEME_SETTINGS'] );
125             break;
126         default:
127             break;
128     }
129     return( $icon );
130 }
131
132 function getLanguagePackName( $the_file ){
133     global $app_list_strings;
134     require_once( "$the_file" );
135     if( isset( $app_list_strings["language_pack_name"] ) ){
136         return( $app_list_strings["language_pack_name"] );
137     }
138     return( "" );
139 }
140
141 function getUITextForType( $type ){
142         $type = 'LBL_UW_TYPE_'.strtoupper($type);
143         global $mod_strings;
144         return $mod_strings[$type];
145 }
146
147 function getUITextForMode( $mode ){
148     $mode = 'LBL_UW_MODE_'.strtoupper($mode);
149     global $mod_strings;
150     return $mod_strings[$mode];
151 }
152
153 function validate_manifest( $manifest ){
154     // takes a manifest.php manifest array and validates contents
155     global $subdirs;
156     global $sugar_version;
157     global $sugar_flavor;
158         global $mod_strings;
159
160     if( !isset($manifest['type']) ){
161         die($mod_strings['ERROR_MANIFEST_TYPE']);
162     }
163     $type = $manifest['type'];
164     if( getInstallType( "/$type/" ) == "" ){
165         die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
166     }
167
168     if( isset($manifest['acceptable_sugar_versions']) ){
169         $version_ok = false;
170         $matches_empty = true;
171         if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
172             $matches_empty = false;
173             foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
174                 if( $match == $sugar_version ){
175                     $version_ok = true;
176                 }
177             }
178         }
179         if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
180             $matches_empty = false;
181             foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
182                 if( preg_match( "/$match/", $sugar_version ) ){
183                     $version_ok = true;
184                 }
185             }
186         }
187
188         if( !$matches_empty && !$version_ok ){
189             die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
190         }
191     }
192
193     if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
194         $flavor_ok = false;
195         foreach( $manifest['acceptable_sugar_flavors'] as $match ){
196             if( $match == $sugar_flavor ){
197                 $flavor_ok = true;
198             }
199         }
200         if( !$flavor_ok ){
201             die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
202         }
203     }
204 }
205
206 function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = ''){
207         //require_once($unzip_dir . '/manifest.php');
208         global $installdefs;
209         if(!empty($previous_version)){
210                 //check if the upgrade path exists
211                 if(!empty($upgrade_manifest)){
212                         if(!empty($upgrade_manifest['upgrade_paths'])){
213                                 if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
214                                         $installdefs =  $upgrade_manifest['upgrade_paths'][$previous_version];
215                                 }
216                         }//fi
217                 }//fi
218         }//fi
219         $modified_files = array();
220         if(!empty($installdefs['copy'])){
221                 foreach($installdefs['copy'] as $cp){
222                         $cp['to'] = clean_path(str_replace('<basepath>', $unzip_dir, $cp['to']));
223                         $restore_path = remove_file_extension(urldecode($install_file))."-restore/";
224                         $backup_path = clean_path($restore_path.$cp['to'] );
225                         //check if this file exists in the -restore directory
226                         if(file_exists($backup_path)){
227                                 //since the file exists, then we want do an md5 of the install version and the file system version
228                                 $from = $backup_path;
229                                 $needle = $restore_path;
230                                 if(!$is_install){
231                                         $from = str_replace('<basepath>', $unzip_dir, $cp['from']);
232                                         $needle = $unzip_dir;
233                                 }
234                                 $files_found = md5DirCompare($from.'/', $cp['to'].'/', array('.svn'), false);
235                                 if(count($files_found > 0)){
236                                         foreach($files_found as $key=>$value){
237                                                 $modified_files[] = str_replace($needle, '', $key);
238                                         }
239                                 }
240                         }//fi
241                 }//rof
242         }//fi
243         return $modified_files;
244 }
245 ?>