PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Administration/UpgradeWizardCommon.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 251 lines | 179 code | 26 blank | 46 comment | 39 complexity | 9edfe8266fbc04ae1d151a295c32ee1d MD5 | raw file
  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. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  7. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU Affero General Public License version 3 as published by the
  11. * Free Software Foundation with the addition of the following permission added
  12. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  13. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  14. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License along with
  22. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  23. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24. * 02110-1301 USA.
  25. *
  26. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  27. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  28. *
  29. * The interactive user interfaces in modified source and object code versions
  30. * of this program must display Appropriate Legal Notices, as required under
  31. * Section 5 of the GNU Affero General Public License version 3.
  32. *
  33. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  34. * these Appropriate Legal Notices must retain the display of the "Powered by
  35. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  36. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  37. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  38. ********************************************************************************/
  39. if (!is_admin($GLOBALS['current_user'])) {
  40. sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
  41. }
  42. require_once('include/utils/db_utils.php');
  43. require_once('include/utils/zip_utils.php');
  44. // increase the cuttoff time to 1 hour
  45. ini_set("max_execution_time", "3600");
  46. if( isset( $_REQUEST['view'] ) && ($_REQUEST['view'] != "") ){
  47. $view = $_REQUEST['view'];
  48. if( $view != "default" && $view != "module" ){
  49. die($mod_strings['ERR_UW_INVALID_VIEW']);
  50. }
  51. }
  52. else{
  53. die($mod_strings['ERR_UW_NO_VIEW']);
  54. }
  55. $form_action = "index.php?module=Administration&view=" . $view . "&action=UpgradeWizard";
  56. $base_upgrade_dir = "upload://upgrades";
  57. $base_tmp_upgrade_dir = sugar_cached('upgrades/temp');
  58. $GLOBALS['subdirs'] = array('full', 'langpack', 'module', 'patch', 'theme');
  59. // array of special scripts that are executed during (un)installation-- key is type of script, value is filename
  60. if(!defined('SUGARCRM_PRE_INSTALL_FILE'))
  61. {
  62. define('SUGARCRM_PRE_INSTALL_FILE', 'scripts/pre_install.php');
  63. define('SUGARCRM_POST_INSTALL_FILE', 'scripts/post_install.php');
  64. define('SUGARCRM_PRE_UNINSTALL_FILE', 'scripts/pre_uninstall.php');
  65. define('SUGARCRM_POST_UNINSTALL_FILE', 'scripts/post_uninstall.php');
  66. }
  67. $script_files = array(
  68. "pre-install" => constant('SUGARCRM_PRE_INSTALL_FILE'),
  69. "post-install" => constant('SUGARCRM_POST_INSTALL_FILE'),
  70. "pre-uninstall" => constant('SUGARCRM_PRE_UNINSTALL_FILE'),
  71. "post-uninstall" => constant('SUGARCRM_POST_UNINSTALL_FILE'),
  72. );
  73. function extractFile( $zip_file, $file_in_zip ){
  74. global $base_tmp_upgrade_dir;
  75. if(empty($base_tmp_upgrade_dir)){
  76. $base_tmp_upgrade_dir = sugar_cached("upgrades/temp");
  77. }
  78. $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
  79. register_shutdown_function('rmdir_recursive', $my_zip_dir);
  80. unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
  81. return( "$my_zip_dir/$file_in_zip" );
  82. }
  83. function extractManifest( $zip_file ){
  84. return( extractFile( $zip_file, "manifest.php" ) );
  85. }
  86. function getInstallType( $type_string ){
  87. // detect file type
  88. global $subdirs;
  89. foreach( $subdirs as $subdir ){
  90. if( preg_match( "#/$subdir/#", $type_string ) ){
  91. return( $subdir );
  92. }
  93. }
  94. // return empty if no match
  95. return( "" );
  96. }
  97. function getImageForType( $type ){
  98. $icon = "";
  99. switch( $type ){
  100. case "full":
  101. $icon = SugarThemeRegistry::current()->getImage("Upgrade", "",null,null,'.gif',$mod_strings['LBL_DST_UPGRADE']);
  102. break;
  103. case "langpack":
  104. $icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "",null,null,'.gif',$mod_strings['LBL_LANGUAGE_PACKS'] );
  105. break;
  106. case "module":
  107. $icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "",null,null,'.gif',$mod_strings['LBL_MODULE_LOADER_TITLE']);
  108. break;
  109. case "patch":
  110. $icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "",null,null,'.gif',$mod_strings['LBL_PATCH_UPGRADES'] );
  111. break;
  112. case "theme":
  113. $icon = SugarThemeRegistry::current()->getImage("Themes", "",null,null,'.gif',$mod_strings['LBL_THEME_SETTINGS'] );
  114. break;
  115. default:
  116. break;
  117. }
  118. return( $icon );
  119. }
  120. function getLanguagePackName( $the_file ){
  121. global $app_list_strings;
  122. require_once( "$the_file" );
  123. if( isset( $app_list_strings["language_pack_name"] ) ){
  124. return( $app_list_strings["language_pack_name"] );
  125. }
  126. return( "" );
  127. }
  128. function getUITextForType( $type ){
  129. $type = 'LBL_UW_TYPE_'.strtoupper($type);
  130. global $mod_strings;
  131. return $mod_strings[$type];
  132. }
  133. function getUITextForMode( $mode ){
  134. $mode = 'LBL_UW_MODE_'.strtoupper($mode);
  135. global $mod_strings;
  136. return $mod_strings[$mode];
  137. }
  138. function validate_manifest( $manifest ){
  139. // takes a manifest.php manifest array and validates contents
  140. global $subdirs;
  141. global $sugar_version;
  142. global $sugar_flavor;
  143. global $mod_strings;
  144. if( !isset($manifest['type']) ){
  145. die($mod_strings['ERROR_MANIFEST_TYPE']);
  146. }
  147. $type = $manifest['type'];
  148. if( getInstallType( "/$type/" ) == "" ){
  149. die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
  150. }
  151. if( isset($manifest['acceptable_sugar_versions']) ){
  152. $version_ok = false;
  153. $matches_empty = true;
  154. if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
  155. $matches_empty = false;
  156. foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
  157. if( $match == $sugar_version ){
  158. $version_ok = true;
  159. }
  160. }
  161. }
  162. if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
  163. $matches_empty = false;
  164. foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
  165. if( preg_match( "/$match/", $sugar_version ) ){
  166. $version_ok = true;
  167. }
  168. }
  169. }
  170. if( !$matches_empty && !$version_ok ){
  171. die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
  172. }
  173. }
  174. if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
  175. $flavor_ok = false;
  176. foreach( $manifest['acceptable_sugar_flavors'] as $match ){
  177. if( $match == $sugar_flavor ){
  178. $flavor_ok = true;
  179. }
  180. }
  181. if( !$flavor_ok ){
  182. die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
  183. }
  184. }
  185. }
  186. function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = ''){
  187. //require_once($unzip_dir . '/manifest.php');
  188. global $installdefs;
  189. if(!empty($previous_version)){
  190. //check if the upgrade path exists
  191. if(!empty($upgrade_manifest)){
  192. if(!empty($upgrade_manifest['upgrade_paths'])){
  193. if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
  194. $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version];
  195. }
  196. }//fi
  197. }//fi
  198. }//fi
  199. $modified_files = array();
  200. if(!empty($installdefs['copy'])){
  201. foreach($installdefs['copy'] as $cp){
  202. $cp['to'] = clean_path(str_replace('<basepath>', $unzip_dir, $cp['to']));
  203. $restore_path = remove_file_extension(urldecode($install_file))."-restore/";
  204. $backup_path = clean_path($restore_path.$cp['to'] );
  205. //check if this file exists in the -restore directory
  206. if(file_exists($backup_path)){
  207. //since the file exists, then we want do an md5 of the install version and the file system version
  208. $from = $backup_path;
  209. $needle = $restore_path;
  210. if(!$is_install){
  211. $from = str_replace('<basepath>', $unzip_dir, $cp['from']);
  212. $needle = $unzip_dir;
  213. }
  214. $files_found = md5DirCompare($from.'/', $cp['to'].'/', array('.svn'), false);
  215. if(count($files_found > 0)){
  216. foreach($files_found as $key=>$value){
  217. $modified_files[] = str_replace($needle, '', $key);
  218. }
  219. }
  220. }//fi
  221. }//rof
  222. }//fi
  223. return $modified_files;
  224. }