PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Administration/UpgradeWizardCommon.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 245 lines | 176 code | 26 blank | 43 comment | 38 complexity | 6692078482ee14f39d6120ed762a83d8 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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-2012 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. require_once('include/utils/db_utils.php');
  38. require_once('include/utils/zip_utils.php');
  39. // increase the cuttoff time to 1 hour
  40. ini_set("max_execution_time", "3600");
  41. if( isset( $_REQUEST['view'] ) && ($_REQUEST['view'] != "") ){
  42. $view = $_REQUEST['view'];
  43. if( $view != "default" && $view != "module" ){
  44. die($mod_strings['ERR_UW_INVALID_VIEW']);
  45. }
  46. }
  47. else{
  48. die($mod_strings['ERR_UW_NO_VIEW']);
  49. }
  50. $form_action = "index.php?module=Administration&view=" . $view . "&action=UpgradeWizard";
  51. $base_upgrade_dir = "upload://upgrades";
  52. $base_tmp_upgrade_dir = sugar_cached('upgrades/temp');
  53. $GLOBALS['subdirs'] = array('full', 'langpack', 'module', 'patch', 'theme');
  54. // array of special scripts that are executed during (un)installation-- key is type of script, value is filename
  55. if(!defined('SUGARCRM_PRE_INSTALL_FILE'))
  56. {
  57. define('SUGARCRM_PRE_INSTALL_FILE', 'scripts/pre_install.php');
  58. define('SUGARCRM_POST_INSTALL_FILE', 'scripts/post_install.php');
  59. define('SUGARCRM_PRE_UNINSTALL_FILE', 'scripts/pre_uninstall.php');
  60. define('SUGARCRM_POST_UNINSTALL_FILE', 'scripts/post_uninstall.php');
  61. }
  62. $script_files = array(
  63. "pre-install" => constant('SUGARCRM_PRE_INSTALL_FILE'),
  64. "post-install" => constant('SUGARCRM_POST_INSTALL_FILE'),
  65. "pre-uninstall" => constant('SUGARCRM_PRE_UNINSTALL_FILE'),
  66. "post-uninstall" => constant('SUGARCRM_POST_UNINSTALL_FILE'),
  67. );
  68. function extractFile( $zip_file, $file_in_zip ){
  69. global $base_tmp_upgrade_dir;
  70. if(empty($base_tmp_upgrade_dir)){
  71. $base_tmp_upgrade_dir = sugar_cached("upgrades/temp");
  72. }
  73. $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
  74. unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
  75. return( "$my_zip_dir/$file_in_zip" );
  76. }
  77. function extractManifest( $zip_file ){
  78. return( extractFile( $zip_file, "manifest.php" ) );
  79. }
  80. function getInstallType( $type_string ){
  81. // detect file type
  82. global $subdirs;
  83. foreach( $subdirs as $subdir ){
  84. if( preg_match( "#/$subdir/#", $type_string ) ){
  85. return( $subdir );
  86. }
  87. }
  88. // return empty if no match
  89. return( "" );
  90. }
  91. function getImageForType( $type ){
  92. $icon = "";
  93. switch( $type ){
  94. case "full":
  95. $icon = SugarThemeRegistry::current()->getImage("Upgrade", "",null,null,'.gif',$mod_strings['LBL_DST_UPGRADE']);
  96. break;
  97. case "langpack":
  98. $icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "",null,null,'.gif',$mod_strings['LBL_LANGUAGE_PACKS'] );
  99. break;
  100. case "module":
  101. $icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "",null,null,'.gif',$mod_strings['LBL_MODULE_LOADER_TITLE']);
  102. break;
  103. case "patch":
  104. $icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "",null,null,'.gif',$mod_strings['LBL_PATCH_UPGRADES'] );
  105. break;
  106. case "theme":
  107. $icon = SugarThemeRegistry::current()->getImage("Themes", "",null,null,'.gif',$mod_strings['LBL_THEME_SETTINGS'] );
  108. break;
  109. default:
  110. break;
  111. }
  112. return( $icon );
  113. }
  114. function getLanguagePackName( $the_file ){
  115. global $app_list_strings;
  116. require_once( "$the_file" );
  117. if( isset( $app_list_strings["language_pack_name"] ) ){
  118. return( $app_list_strings["language_pack_name"] );
  119. }
  120. return( "" );
  121. }
  122. function getUITextForType( $type ){
  123. $type = 'LBL_UW_TYPE_'.strtoupper($type);
  124. global $mod_strings;
  125. return $mod_strings[$type];
  126. }
  127. function getUITextForMode( $mode ){
  128. $mode = 'LBL_UW_MODE_'.strtoupper($mode);
  129. global $mod_strings;
  130. return $mod_strings[$mode];
  131. }
  132. function validate_manifest( $manifest ){
  133. // takes a manifest.php manifest array and validates contents
  134. global $subdirs;
  135. global $sugar_version;
  136. global $sugar_flavor;
  137. global $mod_strings;
  138. if( !isset($manifest['type']) ){
  139. die($mod_strings['ERROR_MANIFEST_TYPE']);
  140. }
  141. $type = $manifest['type'];
  142. if( getInstallType( "/$type/" ) == "" ){
  143. die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
  144. }
  145. if( isset($manifest['acceptable_sugar_versions']) ){
  146. $version_ok = false;
  147. $matches_empty = true;
  148. if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
  149. $matches_empty = false;
  150. foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
  151. if( $match == $sugar_version ){
  152. $version_ok = true;
  153. }
  154. }
  155. }
  156. if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
  157. $matches_empty = false;
  158. foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
  159. if( preg_match( "/$match/", $sugar_version ) ){
  160. $version_ok = true;
  161. }
  162. }
  163. }
  164. if( !$matches_empty && !$version_ok ){
  165. die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
  166. }
  167. }
  168. if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
  169. $flavor_ok = false;
  170. foreach( $manifest['acceptable_sugar_flavors'] as $match ){
  171. if( $match == $sugar_flavor ){
  172. $flavor_ok = true;
  173. }
  174. }
  175. if( !$flavor_ok ){
  176. die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
  177. }
  178. }
  179. }
  180. function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = ''){
  181. //require_once($unzip_dir . '/manifest.php');
  182. global $installdefs;
  183. if(!empty($previous_version)){
  184. //check if the upgrade path exists
  185. if(!empty($upgrade_manifest)){
  186. if(!empty($upgrade_manifest['upgrade_paths'])){
  187. if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
  188. $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version];
  189. }
  190. }//fi
  191. }//fi
  192. }//fi
  193. $modified_files = array();
  194. if(!empty($installdefs['copy'])){
  195. foreach($installdefs['copy'] as $cp){
  196. $cp['to'] = clean_path(str_replace('<basepath>', $unzip_dir, $cp['to']));
  197. $restore_path = remove_file_extension(urldecode($install_file))."-restore/";
  198. $backup_path = clean_path($restore_path.$cp['to'] );
  199. //check if this file exists in the -restore directory
  200. if(file_exists($backup_path)){
  201. //since the file exists, then we want do an md5 of the install version and the file system version
  202. $from = $backup_path;
  203. $needle = $restore_path;
  204. if(!$is_install){
  205. $from = str_replace('<basepath>', $unzip_dir, $cp['from']);
  206. $needle = $unzip_dir;
  207. }
  208. $files_found = md5DirCompare($from.'/', $cp['to'].'/', array('.svn'), false);
  209. if(count($files_found > 0)){
  210. foreach($files_found as $key=>$value){
  211. $modified_files[] = str_replace($needle, '', $key);
  212. }
  213. }
  214. }//fi
  215. }//rof
  216. }//fi
  217. return $modified_files;
  218. }
  219. ?>