PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/ModuleInstall/ModuleInstaller.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 2396 lines | 1893 code | 209 blank | 294 comment | 442 complexity | 8b09838949b4e3c9bae139b607c81cdd MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause

Large files files are truncated, but you can click here to view the full 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-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. /*
  38. * ModuleInstaller - takes an installation package from files in the custom/Extension/X directories, and moves them into custom/X to install them.
  39. * If a directory has multiple files they are concatenated together.
  40. * Relevant directories (X) are Layoutdefs, Vardefs, Include (bean stuff), Language, TableDictionary (relationships)
  41. *
  42. * Installation steps that involve more than just copying files:
  43. * 1. installing custom fields - calls bean->custom_fields->addField
  44. * 2. installing relationships - calls createTableParams to build the relationship table, and createRelationshipMeta to add the relationship to the relationship table
  45. * 3. rebuilding the relationships - at almost the last step in install(), calls modules/Administration/RebuildRelationship.php
  46. * 4. repair indices - uses "modules/Administration/RepairIndex.php";
  47. */
  48. require_once('include/utils/progress_bar_utils.php');
  49. require_once('ModuleInstall/ModuleScanner.php');
  50. define('DISABLED_PATH', 'Disabled');
  51. class ModuleInstaller{
  52. var $modules = array();
  53. var $silent = false;
  54. var $base_dir = '';
  55. var $modulesInPackage = array();
  56. public $disabled_path = DISABLED_PATH;
  57. function ModuleInstaller(){
  58. $this->ms = new ModuleScanner();
  59. $this->modules = get_module_dir_list();
  60. $this->db = & DBManagerFactory::getInstance();
  61. include("ModuleInstall/extensions.php");
  62. $this->extensions = $extensions;
  63. }
  64. /*
  65. * ModuleInstaller->install includes the manifest.php from the base directory it has been given. If it has been asked to do an upgrade it checks to see if there is
  66. * an upgrade_manifest defined in the manifest; if not it errors. It then adds the bean into the custom/Extension/application/Ext/Include/<module>.php - sets beanList, beanFiles
  67. * and moduleList - and then calls ModuleInstaller->merge_files('Ext/Include', 'modules.ext.php', '', true) to merge the individual module files into a combined file
  68. * /custom/Extension/application/Ext/Include/modules.ext.php (which now contains a list of all $beanList, $beanFiles and $moduleList for all extension modules) -
  69. * this file modules.ext.php is included at the end of modules.php.
  70. *
  71. * Finally it runs over a list of defined tasks; then install_beans, then install_custom_fields, then clear the Vardefs, run a RepairAndClear, then finally call rebuild_relationships.
  72. */
  73. function install($base_dir, $is_upgrade = false, $previous_version = ''){
  74. if(defined('TEMPLATE_URL'))SugarTemplateUtilities::disableCache();
  75. if(!empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan'])){
  76. $this->ms->scanPackage($base_dir);
  77. if($this->ms->hasIssues()){
  78. $this->ms->displayIssues();
  79. sugar_cleanup(true);
  80. }
  81. }
  82. // workaround for bug 45812 - refresh vardefs cache before unpacking to avoid partial vardefs in cache
  83. global $beanList;
  84. foreach ($this->modules as $module_name) {
  85. if (!empty($beanList[$module_name])) {
  86. $objectName = BeanFactory::getObjectName($module_name);
  87. VardefManager::loadVardef($module_name, $objectName);
  88. }
  89. }
  90. global $app_strings, $mod_strings;
  91. $this->base_dir = $base_dir;
  92. $total_steps = 5; //minimum number of steps with no tasks
  93. $current_step = 0;
  94. $tasks = array(
  95. 'pre_execute',
  96. 'install_copy',
  97. 'install_extensions',
  98. 'install_images',
  99. 'install_dcactions',
  100. 'install_dashlets',
  101. 'install_connectors',
  102. 'install_layoutfields',
  103. 'install_relationships',
  104. 'enable_manifest_logichooks',
  105. 'post_execute',
  106. 'reset_opcodes',
  107. );
  108. $total_steps += count($tasks);
  109. if(file_exists($this->base_dir . '/manifest.php')){
  110. if(!$this->silent){
  111. $current_step++;
  112. display_progress_bar('install', $current_step, $total_steps);
  113. echo '<div id ="displayLoglink" ><a href="#" onclick="document.getElementById(\'displayLog\').style.display=\'\'">'
  114. .$app_strings['LBL_DISPLAY_LOG'].'</a> </div><div id="displayLog" style="display:none">';
  115. }
  116. include($this->base_dir . '/manifest.php');
  117. if($is_upgrade && !empty($previous_version)){
  118. //check if the upgrade path exists
  119. if(!empty($upgrade_manifest)){
  120. if(!empty($upgrade_manifest['upgrade_paths'])){
  121. if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
  122. $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version];
  123. }else{
  124. $errors[] = 'No Upgrade Path Found in manifest.';
  125. $this->abort($errors);
  126. }//fi
  127. }//fi
  128. }//fi
  129. }//fi
  130. $this->id_name = $installdefs['id'];
  131. $this->installdefs = $installdefs;
  132. if(!$this->silent){
  133. $current_step++;
  134. update_progress_bar('install', $current_step, $total_steps);
  135. }
  136. foreach($tasks as $task){
  137. $this->$task();
  138. if(!$this->silent){
  139. $current_step++;
  140. update_progress_bar('install', $current_step, $total_steps);
  141. }
  142. }
  143. $this->install_beans($this->installed_modules);
  144. if(!$this->silent){
  145. $current_step++;
  146. update_progress_bar('install', $total_steps, $total_steps);
  147. }
  148. if(isset($installdefs['custom_fields'])){
  149. $this->log(translate('LBL_MI_IN_CUSTOMFIELD'));
  150. $this->install_custom_fields($installdefs['custom_fields']);
  151. }
  152. if(!$this->silent){
  153. $current_step++;
  154. update_progress_bar('install', $current_step, $total_steps);
  155. echo '</div>';
  156. }
  157. if(!$this->silent){
  158. $current_step++;
  159. update_progress_bar('install', $current_step, $total_steps);
  160. echo '</div>';
  161. }
  162. $selectedActions = array(
  163. 'clearTpls',
  164. 'clearJsFiles',
  165. 'clearDashlets',
  166. 'clearVardefs',
  167. 'clearJsLangFiles',
  168. 'rebuildAuditTables',
  169. 'repairDatabase',
  170. );
  171. VardefManager::clearVardef();
  172. global $beanList, $beanFiles, $moduleList;
  173. if (file_exists('custom/application/Ext/Include/modules.ext.php'))
  174. {
  175. include('custom/application/Ext/Include/modules.ext.php');
  176. }
  177. require_once("modules/Administration/upgrade_custom_relationships.php");
  178. upgrade_custom_relationships($this->installed_modules);
  179. $this->rebuild_all(true);
  180. require_once('modules/Administration/QuickRepairAndRebuild.php');
  181. $rac = new RepairAndClear();
  182. $rac->repairAndClearAll($selectedActions, $this->installed_modules,true, false);
  183. $this->rebuild_relationships();
  184. UpdateSystemTabs('Add',$this->tab_modules);
  185. //Clear out all the langauge cache files.
  186. clearAllJsAndJsLangFilesWithoutOutput();
  187. $cache_key = 'app_list_strings.'.$GLOBALS['current_language'];
  188. sugar_cache_clear($cache_key );
  189. sugar_cache_reset();
  190. //clear the unified_search_module.php file
  191. require_once('modules/Home/UnifiedSearchAdvanced.php');
  192. UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
  193. $this->log('<br><b>' . translate('LBL_MI_COMPLETE') . '</b>');
  194. }else{
  195. die("No \$installdefs Defined In $this->base_dir/manifest.php");
  196. }
  197. }
  198. function install_user_prefs($module, $hide_from_user=false){
  199. UserPreference::updateAllUserPrefs('display_tabs', $module, '', true, !$hide_from_user);
  200. UserPreference::updateAllUserPrefs('hide_tabs', $module, '', true, $hide_from_user);
  201. UserPreference::updateAllUserPrefs('remove_tabs', $module, '', true, $hide_from_user);
  202. }
  203. function uninstall_user_prefs($module){
  204. UserPreference::updateAllUserPrefs('display_tabs', $module, '', true, true);
  205. UserPreference::updateAllUserPrefs('hide_tabs', $module, '', true, true);
  206. UserPreference::updateAllUserPrefs('remove_tabs', $module, '', true, true);
  207. }
  208. function pre_execute(){
  209. require_once($this->base_dir . '/manifest.php');
  210. if(isset($this->installdefs['pre_execute']) && is_array($this->installdefs['pre_execute'])){
  211. foreach($this->installdefs['pre_execute'] as $includefile){
  212. require_once(str_replace('<basepath>', $this->base_dir, $includefile));
  213. }
  214. }
  215. }
  216. function post_execute(){
  217. require_once($this->base_dir . '/manifest.php');
  218. if(isset($this->installdefs['post_execute']) && is_array($this->installdefs['post_execute'])){
  219. foreach($this->installdefs['post_execute'] as $includefile){
  220. require_once(str_replace('<basepath>', $this->base_dir, $includefile));
  221. }
  222. }
  223. }
  224. function pre_uninstall(){
  225. require_once($this->base_dir . '/manifest.php');
  226. if(isset($this->installdefs['pre_uninstall']) && is_array($this->installdefs['pre_uninstall'])){
  227. foreach($this->installdefs['pre_uninstall'] as $includefile){
  228. require_once(str_replace('<basepath>', $this->base_dir, $includefile));
  229. }
  230. }
  231. }
  232. function post_uninstall(){
  233. require_once($this->base_dir . '/manifest.php');
  234. if(isset($this->installdefs['post_uninstall']) && is_array($this->installdefs['post_uninstall'])){
  235. foreach($this->installdefs['post_uninstall'] as $includefile){
  236. require_once(str_replace('<basepath>', $this->base_dir, $includefile));
  237. }
  238. }
  239. }
  240. /*
  241. * ModuleInstaller->install_copy gets the copy section of installdefs in the manifest and calls copy_path to copy each path (file or directory) to its final location
  242. * (specified as from and to in the manifest), replacing <basepath> by the base_dir value passed in to install.
  243. */
  244. function install_copy(){
  245. if(isset($this->installdefs['copy'])){
  246. /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:11 PM */
  247. $backup_path = clean_path( remove_file_extension(urldecode(hashToFile($_REQUEST['install_file'])))."-restore" );
  248. /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  249. foreach($this->installdefs['copy'] as $cp){
  250. $GLOBALS['log']->debug("Copying ..." . $cp['from']. " to " .$cp['to'] );
  251. /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:11 PM */
  252. //$this->copy_path($cp['from'], $cp['to']);
  253. $this->copy_path($cp['from'], $cp['to'], $backup_path);
  254. /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  255. }
  256. //here we should get the module list again as we could have copied something to the modules dir
  257. $this->modules = get_module_dir_list();
  258. }
  259. }
  260. function uninstall_copy(){
  261. if(!empty($this->installdefs['copy'])){
  262. foreach($this->installdefs['copy'] as $cp){
  263. $cp['to'] = clean_path(str_replace('<basepath>', $this->base_dir, $cp['to']));
  264. $cp['from'] = clean_path(str_replace('<basepath>', $this->base_dir, $cp['from']));
  265. $GLOBALS['log']->debug('Unlink ' . $cp['to']);
  266. /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:11 PM */
  267. //rmdir_recursive($cp['to']);
  268. $backup_path = clean_path( remove_file_extension(urldecode(hashToFile($_REQUEST['install_file'])))."-restore/".$cp['to'] );
  269. $this->uninstall_new_files($cp, $backup_path);
  270. $this->copy_path($backup_path, $cp['to'], $backup_path, true);
  271. /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  272. }
  273. $backup_path = clean_path( remove_file_extension(urldecode(hashToFile($_REQUEST['install_file'])))."-restore");
  274. if(file_exists($backup_path))
  275. rmdir_recursive($backup_path);
  276. }
  277. }
  278. /**
  279. * Removes any files that were added by the loaded module. If the files already existed prior to install
  280. * it will be handled by copy_path with the uninstall parameter.
  281. *
  282. */
  283. function uninstall_new_files($cp, $backup_path){
  284. $zip_files = $this->dir_get_files($cp['from'],$cp['from']);
  285. $backup_files = $this->dir_get_files($backup_path, $backup_path);
  286. foreach($zip_files as $k=>$v){
  287. //if it's not a backup then it is probably a new file but we'll check that it is not in the md5.files first
  288. if(!isset($backup_files[$k])){
  289. $to = $cp['to'] . $k;
  290. //if it's not a sugar file then we remove it otherwise we can't restor it
  291. if(!$this->ms->sugarFileExists($to)){
  292. $GLOBALS['log']->debug('ModuleInstaller[uninstall_new_file] deleting file ' . $to);
  293. if(file_exists($to)) {
  294. unlink($to);
  295. }
  296. }else{
  297. $GLOBALS['log']->fatal('ModuleInstaller[uninstall_new_file] Could not remove file ' . $to . ' as no backup file was found to restore to');
  298. }
  299. }
  300. }
  301. //lets check if the directory is empty if it is we will delete it as well
  302. $files_remaining = $this->dir_file_count($cp['to']);
  303. if(file_exists($cp['to']) && $files_remaining == 0){
  304. $GLOBALS['log']->debug('ModuleInstaller[uninstall_new_file] deleting directory ' . $cp['to']);
  305. rmdir_recursive($cp['to']);
  306. }
  307. }
  308. /**
  309. * Get directory where module's extensions go
  310. * @param string $module Module name
  311. */
  312. public function getExtDir($module)
  313. {
  314. if($module == 'application') {
  315. return "custom/Extension/application/Ext";
  316. } else {
  317. return "custom/Extension/modules/$module/Ext";
  318. }
  319. }
  320. /**
  321. * Install file(s) into Ext/ part
  322. * @param string $section Name of the install file section
  323. * @param string $extname Name in Ext directory
  324. * @param string $module This extension belongs to a specific module
  325. */
  326. public function installExt($section, $extname, $module = '')
  327. {
  328. if(isset($this->installdefs[$section])){
  329. $this->log(sprintf(translate("LBL_MI_IN_EXT"), $section));
  330. foreach($this->installdefs[$section] as $item){
  331. if(isset($item['from'])) {
  332. $from = str_replace('<basepath>', $this->base_dir, $item['from']);
  333. } else {
  334. $from = '';
  335. }
  336. if(!empty($module)) {
  337. $item['to_module'] = $module;
  338. }
  339. $GLOBALS['log']->debug("Installing section $section from $from for " .$item['to_module'] );
  340. if($item['to_module'] == 'application') {
  341. $path = "custom/Extension/application/Ext/$extname";
  342. } else {
  343. $path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
  344. }
  345. if(!file_exists($path)){
  346. mkdir_recursive($path, true);
  347. }
  348. if(isset($item["name"])) {
  349. $target = $item["name"];
  350. } else if (!empty($from)){
  351. $target = basename($from, ".php");
  352. } else {
  353. $target = $this->id_name;
  354. }
  355. if(!empty($from)) {
  356. copy_recursive($from , "$path/$target.php");
  357. }
  358. }
  359. }
  360. }
  361. /**
  362. * Uninstall file(s) into Ext/ part
  363. * @param string $section Name of the install file section
  364. * @param string $extname Name in Ext directory
  365. * @param string $module This extension belongs to a specific module
  366. */
  367. public function uninstallExt($section, $extname, $module = '')
  368. {
  369. if(isset($this->installdefs[$section])){
  370. $this->log(sprintf(translate("LBL_MI_UN_EXT"), $section));
  371. foreach($this->installdefs[$section] as $item){
  372. if(isset($item['from'])) {
  373. $from = str_replace('<basepath>', $this->base_dir, $item['from']);
  374. } else {
  375. $from = '';
  376. }
  377. if(!empty($module)) {
  378. $item['to_module'] = $module;
  379. }
  380. $GLOBALS['log']->debug("Uninstalling section $section from $from for " .$item['to_module'] );
  381. if($item['to_module'] == 'application') {
  382. $path = "custom/Extension/application/Ext/$extname";
  383. } else {
  384. $path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
  385. }
  386. if(isset($item["name"])) {
  387. $target = $item["name"];
  388. } else if (!empty($from)){
  389. $target = basename($from, ".php");
  390. } else {
  391. $target = $this->id_name;
  392. }
  393. $disabled_path = $path.'/'.DISABLED_PATH;
  394. if (file_exists("$path/$target.php")) {
  395. rmdir_recursive("$path/$target.php");
  396. } else if (file_exists("$disabled_path/$target.php")) {
  397. rmdir_recursive("$disabled_path/$target.php");
  398. } else if (!empty($from) && file_exists($path . '/'. basename($from))) {
  399. rmdir_recursive( $path . '/'. basename($from));
  400. } else if (!empty($from) && file_exists($disabled_path . '/'. basename($from))) {
  401. rmdir_recursive( $disabled_path . '/'. basename($from));
  402. }
  403. }
  404. }
  405. }
  406. /**
  407. * Rebuild generic extension
  408. * @param string $ext Extension directory
  409. * @param string $filename Target filename
  410. */
  411. public function rebuildExt($ext, $filename)
  412. {
  413. $this->log(translate('LBL_MI_REBUILDING') . " $ext...");
  414. $this->merge_files("Ext/$ext/", $filename);
  415. }
  416. /**
  417. * Disable generic extension
  418. * @param string $section Install file section name
  419. * @param string $extname Extension directory
  420. * @param string $module This extension belongs to a specific module
  421. */
  422. public function disableExt($section, $extname, $module = '')
  423. {
  424. if(isset($this->installdefs[$section])) {
  425. foreach($this->installdefs[$section] as $item) {
  426. if(isset($item['from'])) {
  427. $from = str_replace('<basepath>', $this->base_dir, $item['from']);
  428. } else {
  429. $from = '';
  430. }
  431. if(!empty($module)) {
  432. $item['to_module'] = $module;
  433. }
  434. $GLOBALS['log']->debug("Disabling $extname ... from $from for " .$item['to_module']);
  435. if($item['to_module'] == 'application') {
  436. $path = "custom/Extension/application/Ext/$extname";
  437. } else {
  438. $path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
  439. }
  440. if(isset($item["name"])) {
  441. $target = $item["name"];
  442. } else if (!empty($from)){
  443. $target = basename($from, ".php");
  444. }else {
  445. $target = $this->id_name;
  446. }
  447. $disabled_path = $path.'/'.DISABLED_PATH;
  448. if (file_exists("$path/$target.php")) {
  449. mkdir_recursive($disabled_path, true);
  450. rename("$path/$target.php", "$disabled_path/$target.php");
  451. } else if (!empty($from) && file_exists($path . '/'. basename($from))) {
  452. mkdir_recursive($disabled_path, true);
  453. rename( $path . '/'. basename($from), $disabled_path.'/'. basename($from));
  454. }
  455. }
  456. }
  457. }
  458. /**
  459. * Enable generic extension
  460. * @param string $section Install file section name
  461. * @param string $extname Extension directory
  462. * @param string $module This extension belongs to a specific module
  463. */
  464. public function enableExt($section, $extname, $module = '')
  465. {
  466. if(isset($this->installdefs[$section])) {
  467. foreach($this->installdefs[$section] as $item) {
  468. if(isset($item['from'])) {
  469. $from = str_replace('<basepath>', $this->base_dir, $item['from']);
  470. } else {
  471. $from = '';
  472. }
  473. if(!empty($module)) {
  474. $item['to_module'] = $module;
  475. }
  476. $GLOBALS['log']->debug("Enabling $extname ... from $from for " .$item['to_module']);
  477. if($item['to_module'] == 'application') {
  478. $path = "custom/Extension/application/Ext/$extname";
  479. } else {
  480. $path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
  481. }
  482. if(isset($item["name"])) {
  483. $target = $item["name"];
  484. } else if (!empty($from)){
  485. $target = basename($from, ".php");
  486. } else {
  487. $target = $this->id_name;
  488. }
  489. if(!file_exists($path)) {
  490. mkdir_recursive($path, true);
  491. }
  492. $disabled_path = $path.'/'.DISABLED_PATH;
  493. if (file_exists("$disabled_path/$target.php")) {
  494. rename("$disabled_path/$target.php", "$path/$target.php");
  495. }
  496. if (!empty($from) && file_exists($disabled_path . '/'. basename($from))) {
  497. rename($disabled_path.'/'. basename($from), $path . '/'. basename($from));
  498. }
  499. }
  500. }
  501. }
  502. /**
  503. * Method removes module from global search configurations
  504. *
  505. * return bool
  506. */
  507. public function uninstall_global_search()
  508. {
  509. if (empty($this->installdefs['beans']))
  510. {
  511. return true;
  512. }
  513. if (is_file('custom/modules/unified_search_modules_display.php') == false)
  514. {
  515. return true;
  516. }
  517. $user = new User();
  518. $users = get_user_array();
  519. $unified_search_modules_display = array();
  520. require('custom/modules/unified_search_modules_display.php');
  521. foreach($this->installdefs['beans'] as $beanDefs)
  522. {
  523. if (array_key_exists($beanDefs['module'], $unified_search_modules_display) == false)
  524. {
  525. continue;
  526. }
  527. unset($unified_search_modules_display[$beanDefs['module']]);
  528. foreach($users as $userId => $userName)
  529. {
  530. if (empty($userId))
  531. {
  532. continue;
  533. }
  534. $user->retrieve($userId);
  535. $prefs = $user->getPreference('globalSearch', 'search');
  536. if (array_key_exists($beanDefs['module'], $prefs) == false)
  537. {
  538. continue;
  539. }
  540. unset($prefs[$beanDefs['module']]);
  541. $user->setPreference('globalSearch', $prefs, 0, 'search');
  542. $user->savePreferencesToDB();
  543. }
  544. }
  545. if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display, 'custom/modules/unified_search_modules_display.php') == false)
  546. {
  547. global $app_strings;
  548. $msg = string_format($app_strings['ERR_FILE_WRITE'], array('custom/modules/unified_search_modules_display.php'));
  549. $GLOBALS['log']->error($msg);
  550. throw new Exception($msg);
  551. return false;
  552. }
  553. return true;
  554. }
  555. /**
  556. * Method enables module in global search configurations by disabled_module_visible key
  557. *
  558. * return bool
  559. */
  560. public function enable_global_search()
  561. {
  562. if (empty($this->installdefs['beans']))
  563. {
  564. return true;
  565. }
  566. if (is_file('custom/modules/unified_search_modules_display.php') == false)
  567. {
  568. return true;
  569. }
  570. $unified_search_modules_display = array();
  571. require('custom/modules/unified_search_modules_display.php');
  572. foreach($this->installdefs['beans'] as $beanDefs)
  573. {
  574. if (array_key_exists($beanDefs['module'], $unified_search_modules_display) == false)
  575. {
  576. continue;
  577. }
  578. if (isset($unified_search_modules_display[$beanDefs['module']]['disabled_module_visible']) == false)
  579. {
  580. continue;
  581. }
  582. $unified_search_modules_display[$beanDefs['module']]['visible'] = $unified_search_modules_display[$beanDefs['module']]['disabled_module_visible'];
  583. unset($unified_search_modules_display[$beanDefs['module']]['disabled_module_visible']);
  584. }
  585. if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display, 'custom/modules/unified_search_modules_display.php') == false)
  586. {
  587. global $app_strings;
  588. $msg = string_format($app_strings['ERR_FILE_WRITE'], array('custom/modules/unified_search_modules_display.php'));
  589. $GLOBALS['log']->error($msg);
  590. throw new Exception($msg);
  591. return false;
  592. }
  593. return true;
  594. }
  595. /**
  596. * Method disables module in global search configurations by disabled_module_visible key
  597. *
  598. * return bool
  599. */
  600. public function disable_global_search()
  601. {
  602. if (empty($this->installdefs['beans']))
  603. {
  604. return true;
  605. }
  606. if (is_file('custom/modules/unified_search_modules_display.php') == false)
  607. {
  608. return true;
  609. }
  610. $unified_search_modules_display = array();
  611. require('custom/modules/unified_search_modules_display.php');
  612. foreach($this->installdefs['beans'] as $beanDefs)
  613. {
  614. if (array_key_exists($beanDefs['module'], $unified_search_modules_display) == false)
  615. {
  616. continue;
  617. }
  618. if (isset($unified_search_modules_display[$beanDefs['module']]['visible']) == false)
  619. {
  620. continue;
  621. }
  622. $unified_search_modules_display[$beanDefs['module']]['disabled_module_visible'] = $unified_search_modules_display[$beanDefs['module']]['visible'];
  623. $unified_search_modules_display[$beanDefs['module']]['visible'] = false;
  624. }
  625. if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display, 'custom/modules/unified_search_modules_display.php') == false)
  626. {
  627. global $app_strings;
  628. $msg = string_format($app_strings['ERR_FILE_WRITE'], array('custom/modules/unified_search_modules_display.php'));
  629. $GLOBALS['log']->error($msg);
  630. throw new Exception($msg);
  631. return false;
  632. }
  633. return true;
  634. }
  635. public function install_extensions()
  636. {
  637. foreach($this->extensions as $extname => $ext) {
  638. $install = "install_$extname";
  639. if(method_exists($this, $install)) {
  640. // non-standard function
  641. $this->$install();
  642. } else {
  643. if(!empty($ext["section"])) {
  644. $module = isset($ext['module'])?$ext['module']:'';
  645. $this->installExt($ext["section"], $ext["extdir"], $module);
  646. }
  647. }
  648. }
  649. $this->rebuild_extensions();
  650. }
  651. public function uninstall_extensions()
  652. {
  653. foreach($this->extensions as $extname => $ext) {
  654. $func = "uninstall_$extname";
  655. if(method_exists($this, $func)) {
  656. // non-standard function
  657. $this->$func();
  658. } else {
  659. if(!empty($ext["section"])) {
  660. $module = isset($ext['module'])?$ext['module']:'';
  661. $this->uninstallExt($ext["section"], $ext["extdir"], $module);
  662. }
  663. }
  664. }
  665. $this->rebuild_extensions();
  666. }
  667. public function rebuild_extensions()
  668. {
  669. foreach($this->extensions as $extname => $ext) {
  670. $func = "rebuild_$extname";
  671. if(method_exists($this, $func)) {
  672. // non-standard function
  673. $this->$func();
  674. } else {
  675. $this->rebuildExt($ext["extdir"], $ext["file"]);
  676. }
  677. }
  678. }
  679. public function disable_extensions()
  680. {
  681. foreach($this->extensions as $extname => $ext) {
  682. $func = "disable_$extname";
  683. if(method_exists($this, $func)) {
  684. // non-standard install
  685. $this->$func();
  686. } else {
  687. if(!empty($ext["section"])) {
  688. $module = isset($ext['module'])?$ext['module']:'';
  689. $this->disableExt($ext["section"], $ext["extdir"], $module);
  690. }
  691. }
  692. }
  693. $this->rebuild_extensions();
  694. }
  695. public function enable_extensions()
  696. {
  697. foreach($this->extensions as $extname => $ext) {
  698. $func = "enable_$extname";
  699. if(method_exists($this, $func)) {
  700. // non-standard install
  701. $this->$func();
  702. } else {
  703. if(!empty($ext["section"])) {
  704. $module = isset($ext['module'])?$ext['module']:'';
  705. $this->enableExt($ext["section"], $ext["extdir"], $module);
  706. }
  707. }
  708. }
  709. $this->rebuild_extensions();
  710. }
  711. function install_dashlets()
  712. {
  713. if(isset($this->installdefs['dashlets'])){
  714. foreach($this->installdefs['dashlets'] as $cp){
  715. $this->log(translate('LBL_MI_IN_DASHLETS') . $cp['name']);
  716. $cp['from'] = str_replace('<basepath>', $this->base_dir, $cp['from']);
  717. $path = 'custom/modules/Home/Dashlets/' . $cp['name'] . '/';
  718. $GLOBALS['log']->debug("Installing Dashlet " . $cp['name'] . "..." . $cp['from'] );
  719. if(!file_exists($path)){
  720. mkdir_recursive($path, true);
  721. }
  722. copy_recursive($cp['from'] , $path);
  723. }
  724. include('modules/Administration/RebuildDashlets.php');
  725. }
  726. }
  727. function uninstall_dashlets(){
  728. if(isset($this->installdefs['dashlets'])){
  729. foreach($this->installdefs['dashlets'] as $cp){
  730. $this->log(translate('LBL_MI_UN_DASHLETS') . $cp['name']);
  731. $path = 'custom/modules/Home/Dashlets/' . $cp['name'];
  732. $GLOBALS['log']->debug('Unlink ' .$path);
  733. if (file_exists($path))
  734. rmdir_recursive($path);
  735. }
  736. include('modules/Administration/RebuildDashlets.php');
  737. }
  738. }
  739. function install_images(){
  740. if(isset($this->installdefs['image_dir'])){
  741. $this->log( translate('LBL_MI_IN_IMAGES') );
  742. $this->copy_path($this->installdefs['image_dir'] , 'custom/themes');
  743. }
  744. }
  745. function install_dcactions(){
  746. if(isset($this->installdefs['dcaction'])){
  747. $this->log(translate('LBL_MI_IN_MENUS'));
  748. foreach($this->installdefs['dcaction'] as $action){
  749. $action['from'] = str_replace('<basepath>', $this->base_dir, $action['from']);
  750. $GLOBALS['log']->debug("Installing DCActions ..." . $action['from']);
  751. $path = 'custom/Extension/application/Ext/DashletContainer/Containers';
  752. if(!file_exists($path)){
  753. mkdir_recursive($path, true);
  754. }
  755. copy_recursive($action['from'] , $path . '/'. $this->id_name . '.php');
  756. }
  757. $this->rebuild_dashletcontainers();
  758. }
  759. }
  760. function uninstall_dcactions(){
  761. if(isset($this->installdefs['dcaction'])){
  762. $this->log(translate('LBL_MI_UN_MENUS'));
  763. foreach($this->installdefs['dcaction'] as $action){
  764. $action['from'] = str_replace('<basepath>', $this->base_dir, $action['from']);
  765. $GLOBALS['log']->debug("Uninstalling DCActions ..." . $action['from'] );
  766. $path = 'custom/Extension/application/Ext/DashletContainer/Containers';
  767. if (sugar_is_file($path . '/'. $this->id_name . '.php', 'w'))
  768. {
  769. rmdir_recursive( $path . '/'. $this->id_name . '.php');
  770. }
  771. else if (sugar_is_file($path . '/'. DISABLED_PATH . '/'. $this->id_name . '.php', 'w'))
  772. {
  773. rmdir_recursive( $path . '/'. DISABLED_PATH . '/'. $this->id_name . '.php');
  774. }
  775. }
  776. $this->rebuild_dashletcontainers();
  777. }
  778. }
  779. function install_connectors(){
  780. if(isset($this->installdefs['connectors'])){
  781. foreach($this->installdefs['connectors'] as $cp){
  782. $this->log(translate('LBL_MI_IN_CONNECTORS') . $cp['name']);
  783. $dir = str_replace('_','/',$cp['name']);
  784. $cp['connector'] = str_replace('<basepath>', $this->base_dir, $cp['connector']);
  785. $source_path = 'custom/modules/Connectors/connectors/sources/' . $dir. '/';
  786. $GLOBALS['log']->debug("Installing Connector " . $cp['name'] . "..." . $cp['connector'] );
  787. if(!file_exists($source_path)){
  788. mkdir_recursive($source_path, true);
  789. }
  790. copy_recursive($cp['connector'] , $source_path);
  791. //Install optional formatter code if it is specified
  792. if(!empty($cp['formatter'])) {
  793. $cp['formatter'] = str_replace('<basepath>', $this->base_dir, $cp['formatter']);
  794. $formatter_path = 'custom/modules/Connectors/connectors/formatters/' . $dir. '/';
  795. if(!file_exists($formatter_path)){
  796. mkdir_recursive($formatter_path, true);
  797. }
  798. copy_recursive($cp['formatter'] , $formatter_path);
  799. }
  800. }
  801. require_once('include/connectors/utils/ConnectorUtils.php');
  802. ConnectorUtils::installSource($cp['name']);
  803. }
  804. }
  805. function uninstall_connectors(){
  806. if(isset($this->installdefs['connectors'])){
  807. foreach($this->installdefs['connectors'] as $cp){
  808. $this->log(translate('LBL_MI_UN_CONNECTORS') . $cp['name']);
  809. $dir = str_replace('_','/',$cp['name']);
  810. $source_path = 'custom/modules/Connectors/connectors/sources/' . $dir;
  811. $formatter_path = 'custom/modules/Connectors/connectors/formatters/' . $dir;
  812. $GLOBALS['log']->debug('Unlink ' .$source_path);
  813. rmdir_recursive($source_path);
  814. rmdir_recursive($formatter_path);
  815. }
  816. require_once('include/connectors/utils/ConnectorUtils.php');
  817. //ConnectorUtils::getConnectors(true);
  818. ConnectorUtils::uninstallSource($cp['name']);
  819. }
  820. }
  821. function install_vardef($from, $to_module)
  822. {
  823. $GLOBALS['log']->debug("Installing Vardefs ..." . $from . " for " .$to_module);
  824. $path = 'custom/Extension/modules/' . $to_module. '/Ext/Vardefs';
  825. if($to_module == 'application'){
  826. $path ='custom/Extension/' . $to_module. '/Ext/Vardefs';
  827. }
  828. if(!file_exists($path)){
  829. mkdir_recursive($path, true);
  830. }
  831. copy_recursive($from , $path.'/'. basename($from));
  832. }
  833. function install_layoutdef($from, $to_module){
  834. $GLOBALS['log']->debug("Installing Layout Defs ..." . $from . " for " .$to_module);
  835. $path = 'custom/Extension/modules/' . $to_module. '/Ext/Layoutdefs';
  836. if($to_module == 'application'){
  837. $path ='custom/Extension/' . $to_module. '/Ext/Layoutdefs';
  838. }
  839. if(!file_exists($path)){
  840. mkdir_recursive($path, true);
  841. }
  842. copy_recursive($from , $path.'/'. basename($from));
  843. }
  844. // Non-standard - needs special rebuild call
  845. function install_languages()
  846. {
  847. $languages = array();
  848. if(isset($this->installdefs['language']))
  849. {
  850. $this->log(translate('LBL_MI_IN_LANG') );
  851. foreach($this->installdefs['language'] as $packs)
  852. {
  853. $modules[]=$packs['to_module'];
  854. $languages[$packs['language']] = $packs['language'];
  855. $packs['from'] = str_replace('<basepath>', $this->base_dir, $packs['from']);
  856. $GLOBALS['log']->debug("Installing Language Pack ..." . $packs['from'] . " for " .$packs['to_module']);
  857. $path = 'custom/Extension/modules/' . $packs['to_module']. '/Ext/Language';
  858. if($packs['to_module'] == 'application'){
  859. $path ='custom/Extension/' . $packs['to_module']. '/Ext/Language';
  860. }
  861. if(!file_exists($path)){
  862. mkdir_recursive($path, true);
  863. }
  864. copy_recursive($packs['from'] , $path.'/'.$packs['language'].'.'. $this->id_name . '.php');
  865. }
  866. $this->rebuild_languages($languages, $modules);
  867. }
  868. }
  869. // Non-standard, needs special rebuild
  870. function uninstall_languages(){
  871. $languages = array();
  872. if(isset($this->installdefs['language'])){
  873. $this->log(translate('LBL_MI_UN_LANG') );
  874. foreach($this->installdefs['language'] as $packs){
  875. $modules[]=$packs['to_module'];
  876. $languages[$packs['language']] = $packs['language'];
  877. $packs['from'] = str_replace('<basepath>', $this->base_dir, $packs['from']);
  878. $GLOBALS['log']->debug("Uninstalling Language Pack ..." . $packs['from'] . " for " .$packs['to_module']);
  879. $path = 'custom/Extension/modules/' . $packs['to_module']. '/Ext/Language';
  880. if($packs['to_module'] == 'application'){
  881. $path ='custom/Extension/' . $packs['to_module']. '/Ext/Language';
  882. }
  883. if (sugar_is_file($path.'/'.$packs['language'].'.'. $this->id_name . '.php', 'w')) {
  884. rmdir_recursive( $path.'/'.$packs['language'].'.'. $this->id_name . '.php');
  885. } else if (sugar_is_file($path.'/'.DISABLED_PATH.'/'.$packs['language'].'.'. $this->id_name . '.php', 'w')) {
  886. rmdir_recursive($path.'/'.DISABLED_PATH.'/'.$packs['language'].'.'. $this->id_name . '.php', 'w');
  887. }
  888. }
  889. $this->rebuild_languages($languages, $modules);
  890. }
  891. }
  892. // Non-standard, needs special rebuild
  893. public function disable_languages()
  894. {
  895. if(isset($this->installdefs['language'])) {
  896. $languages = $modules = array();
  897. foreach($this->installdefs['language'] as $item) {
  898. $from = str_replace('<basepath>', $this->base_dir, $item['from']);
  899. $GLOBALS['log']->debug("Disabling Language {$item['language']}... from $from for " .$item['to_module']);
  900. $modules[]=$item['to_module'];
  901. $languages[$item['language']] = $item['language'];
  902. if($item['to_module'] == 'application') {
  903. $path = "custom/Extension/application/Ext/Language";
  904. } else {
  905. $path = "custom/Extension/modules/{$item['to_module']}/Ext/Language";
  906. }
  907. if(isset($item["name"])) {
  908. $target = $item["name"];
  909. } else {
  910. $target = $this->id_name;
  911. }
  912. $target = "{$item['language']}.$target";
  913. $disabled_path = $path.'/'.DISABLED_PATH;
  914. if (file_exists("$path/$target.php")) {
  915. mkdir_recursive($disabled_path, true);
  916. rename("$path/$target.php", "$disabled_path/$target.php");
  917. } else if (file_exists($path . '/'. basename($from))) {
  918. mkdir_recursive($disabled_path, true);
  919. rename( $path . '/'. basename($from), $disabled_path.'/'. basename($from));
  920. }
  921. }
  922. $this->rebuild_languages($languages, $modules);
  923. }
  924. }
  925. // Non-standard, needs special rebuild
  926. public function enable_languages()
  927. {
  928. if(isset($this->installdefs['language'])) {
  929. foreach($this->installdefs['language'] as $item) {
  930. $from = str_replace('<basepath>', $this->base_dir, $item['from']);
  931. $GLOBALS['log']->debug("Enabling Language {$item['language']}... from $from for " .$item['to_module']);
  932. $modules[]=$item['to_module'];
  933. $languages[$item['language']] = $item['language'];
  934. if(!empty($module)) {
  935. $item['to_module'] = $module;
  936. }
  937. if($item['to_module'] == 'application') {
  938. $path = "custom/Extension/application/Ext/Language";
  939. } else {
  940. $path = "custom/Extension/modules/{$item['to_module']}/Ext/Language";
  941. }
  942. if(isset($item["name"])) {
  943. $target = $item["name"];
  944. } else {
  945. $target = $this->id_name;
  946. }
  947. $target = "{$item['language']}.$target";
  948. if(!file_exists($path)) {
  949. mkdir_recursive($path, true);
  950. }
  951. $disabled_path = $path.'/'.DISABLED_PATH;
  952. if (file_exists("$disabled_path/$target.php")) {
  953. rename("$disabled_path/$target.php", "$path/$target.php");
  954. }
  955. if (file_exists($disabled_path . '/'. basename($from))) {
  956. rename($disabled_path.'/'. basename($from), $path . '/'. basename($from));
  957. }
  958. }
  959. $this->rebuild_languages($languages, $modules);
  960. }
  961. }
  962. // Functions for adding and removing logic hooks from uploaded files
  963. // Since one class/file can be used by multiple logic hooks, I'm not going to touch the file labeled in the logic_hook entry
  964. /* The module hook definition should look like this:
  965. $installdefs = array(
  966. ... blah blah ...
  967. 'logic_hooks' => array(
  968. array('module' => 'Accounts',
  969. 'hook' => 'after_save',
  970. 'order' => 99,
  971. 'description' => 'Account sample logic hook',
  972. 'file' => 'modules/Sample/sample_account_logic_hook_file.php',
  973. 'class' => 'SampleLogicClass',
  974. 'function' => 'accountAfterSave',
  975. ),
  976. ),
  977. ... blah blah ...
  978. );
  979. */
  980. function enable_manifest_logichooks() {
  981. if(empty($this->installdefs['logic_hooks']) || !is_array($this->installdefs['logic_hooks'])) {
  982. return;
  983. }
  984. foreach($this->installdefs['logic_hooks'] as $hook ) {
  985. check_logic_hook_file($hook['module'], $hook['hook'], array($hook['order'], $hook['description'], $hook['file'], $hook['class'], $hook['function']));
  986. }
  987. }
  988. function disable_manifest_logichooks() {
  989. if(empty($this->installdefs['logic_hooks']) || !is_array($this->installdefs['logic_hooks'])) {
  990. return;
  991. }
  992. foreach($this->installdefs['logic_hooks'] as $hook ) {
  993. remove_logic_hook($hook['module'], $hook['hook'], array($hook['order'], $hook['description'], $hook['file'], $hook['class'], $hook['function']));
  994. }
  995. }
  996. /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  997. function copy_path($from, $to, $backup_path='', $uninstall=false){
  998. //function copy_path($from, $to){
  999. /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  1000. $to = str_replace('<basepath>', $this->base_dir, $to);
  1001. if(!$uninstall) {
  1002. $from = str_replace('<basepath>', $this->base_dir, $from);
  1003. $GLOBALS['log']->debug('Copy ' . $from);
  1004. }
  1005. else {
  1006. $from = str_replace('<basepath>', $backup_path, $from);
  1007. //$GLOBALS['log']->debug('Restore ' . $from);
  1008. }
  1009. $from = clean_path($from);
  1010. $to = clean_path($to);
  1011. $dir = dirname($to);
  1012. //there are cases where if we need to create a directory in the root directory
  1013. if($dir == '.' && is_dir($from)){
  1014. $dir = $to;
  1015. }
  1016. if(!sugar_is_dir($dir, 'instance'))
  1017. mkdir_recursive($dir, true);
  1018. /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  1019. if(empty($backup_path)) {
  1020. /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  1021. if(!copy_recursive($from, $to)){
  1022. die('Failed to copy ' . $from. ' ' . $to);
  1023. }
  1024. /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  1025. }
  1026. elseif(!$this->copy_recursive_with_backup($from, $to, $backup_path, $uninstall)){
  1027. die('Failed to copy ' . $from. ' to ' . $to);
  1028. }
  1029. /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
  1030. }
  1031. function install_custom_fields($fields){
  1032. global $beanList, $beanFiles;
  1033. include('include/modules.php');
  1034. require_once('modules/DynamicFields/FieldCases.php');
  1035. foreach($fields as $field){
  1036. $installed = false;
  1037. if(isset($beanList[ $field['module']])){
  1038. $class = $beanList[ $field['module']];
  1039. if(!isset($field['ext4']))$field['ext4'] = '';
  1040. if(!isset($field['mass_update']))$field['mass_update'] = 0;
  1041. if(!isset($field['duplicate_merge']))$field['duplicate_merge'] = 0;
  1042. if(!isset($field['help']))$field['help'] = '';
  1043. //Merge contents of the sugar field extension if we copied one over
  1044. if (file_exists("custom/Extension/modules/{$field['module']}/Ext/Vardefs/sugarfield_{$field['name']}.php"))
  1045. {
  1046. $dictionary = array();
  1047. include ("custom/Extension/modules/{$field['module']}/Ext/Vardefs/sugarfield_{$field['name']}.php");
  1048. $obj = BeanFactory::getObjectName($field['module']);
  1049. if (!empty($dictionary[$obj]['fields'][$field['name']])) {
  1050. $field = array_merge($dictionary[$obj]['fields'][$field['name']], $field);
  1051. }
  1052. }
  1053. if(file_exists($beanFiles[$class])){
  1054. require_once($beanFiles[$class]);
  1055. $mod = new $class();
  1056. $installed = true;
  1057. $fieldObject = get_widget($field['type']);
  1058. $fieldObject->populateFromRow($field);
  1059. $mod->custom_fields->use_existing_labels = true;
  1060. $mod->custom_fields->addFieldObject($fieldObject);
  1061. }
  1062. }
  1063. if(!$installed){
  1064. $GLOBALS['log']->debug('Could not install custom field ' . $field['name'] . ' for module ' . $field['module'] . ': Module does not exist');
  1065. }
  1066. }
  1067. }
  1068. function uninstall_custom_fields($fields){
  1069. global $beanList, $beanFiles;
  1070. require_once('modules/DynamicFields/DynamicField.php');
  1071. $dyField = new DynamicField();
  1072. foreach($fields as $field){
  1073. $class = $beanList[ $field['module']];
  1074. if(file_exists($beanFiles[$class])){
  1075. require_once($beanFiles[$class]);
  1076. $mod = new $class();
  1077. $dyField->bean = $mod;
  1078. $dyField->module = $field['module'];
  1079. $dyField->deleteField($field['name']);
  1080. }
  1081. }
  1082. }
  1083. /*
  1084. * ModuleInstaller->install_relationships calls install_relationship for every file included in the module package that defines a relationship, and then
  1085. * writes a custom/Extension/application/Ext/TableDictionary/$module.php file containing an include_once for every relationship metadata file passed to install_relationship.
  1086. * Next it calls install_vardef and install_layoutdef. Finally, it rebuilds the vardefs and layoutdefs (by calling merge_files as usual), and then calls merge_files to merge
  1087. * everything in 'Ext/TableDictionary/' into 'tabledictionary.ext.php'
  1088. */
  1089. function install_relationships ()
  1090. {
  1091. if (isset ( $this->installdefs [ 'relationships' ] ))
  1092. {
  1093. $this->log ( translate ( 'LBL_MI_IN_RELATIONSHIPS' ) ) ;
  1094. $str = "<?php \n //WARNING: The contents of this file are auto-generated\n" ;
  1095. $save_table_dictionary = false ;
  1096. if (! file_exists ( "custom/Extension/application/Ext/TableDictionary" ))
  1097. {
  1098. mkdir_recursive ( "custom/Extension/application/Ext/TableDictionary", true ) ;
  1099. }
  1100. foreach ( $this->installdefs [ 'relationships' ] as $key => $relationship )
  1101. {
  1102. $filename = basename ( $relationship [ 'meta_data' ] ) ;
  1103. $this->copy_path ( $relationship [ 'meta_data' ], 'custom/metadata/' . $filename ) ;
  1104. $this->install_relationship ( 'custom/metadata/' . $filename ) ;
  1105. $save_table_dictionary = true ;
  1106. if (! empty ( $relationship [ 'module_vardefs' ] ))
  1107. {
  1108. $relationship [ 'module_vardefs' ] = str_replace ( '<basepath>', $this->base_dir, $relationship [ 'module_vardefs' ] ) ;
  1109. $this->install_vardef ( $relationship [ 'module_vardefs' ], $relationship [ 'module' ] ) ;
  1110. }
  1111. if (! empty ( $relationship [ 'module_layoutdefs' ] ))
  1112. {
  1113. $relationship [ 'module_layoutdefs' ] = str_replace ( '<basepath>', $this->base_dir, $relationship [ 'module_layoutdefs' ] ) ;
  1114. $this->install_layoutdef ( $relationship [ 'module_layoutdefs' ], $relationship [ 'module' ] ) ;
  1115. }
  1116. $relName = strpos($filename, "MetaData") !== false ? substr($filename, 0, strlen($filename) - 12) : $filename;
  1117. $out = sugar_fopen ( "custom/Extension/application/Ext/TableDictionary/$relName.php", 'w' ) ;
  1118. fwrite ( $out, $str . "include('custom/metadata/$filename');\n\n?>" ) ;
  1119. fclose ( $out ) ;
  1120. }
  1121. Relationship::delete_cache();
  1122. $this->rebuild_vardefs () ;
  1123. $this->rebuild_layoutdefs () ;
  1124. if ($save_table_dictionary)
  1125. {
  1126. $this->rebuild_tabledictionary () ;
  1127. }
  1128. require_once("data/Relationships/RelationshipFactory.php");
  1129. SugarRelationshipFactory::deleteCache();
  1130. }
  1131. }
  1132. /*
  1133. * Install_relationship obtains a set of relationship definitions from the filename passed in as a parameter.
  1134. * For each definition it calls db->createTableParams to build the relationships table if it does not exist,
  1135. * and SugarBean::createRelationshipMeta to add the relationship into the 'relationships' table.
  1136. */
  1137. function install_relationship($file)
  1138. {
  1139. $_REQUEST['moduleInstaller'] = true;
  1140. if(!file_exists($file))
  1141. {
  1142. $GLOBALS['log']->debug( 'File does not exists : '.$file);
  1143. return;
  1144. }
  1145. include($file);
  1146. $rel_dictionary = $dictionary;
  1147. foreach ($rel_dictionary as $rel_name => $rel_data)
  1148. {
  1149. $table = ''; // table is actually optional
  1150. // check if we have a table definition - not all relationships require a join table
  1151. if ( isset( $rel_data[ 'table' ] ) )
  1152. {
  1153. $table = $rel_data[ 'table' ];
  1154. if(!$this->db->tableExists($table))
  1155. {
  1156. $this->db->createTableParams($table, $rel_data[ 'fields' ], $rel_data[ 'indices' ]);
  1157. }
  1158. }
  1159. if(!$this->silent)
  1160. $GLOBALS['log']->debug("Processing relationship meta for ". $rel_name."...");
  1161. SugarBean::createRelationshipMeta($rel_name, $this->db,$table,$rel_dictionary,'');
  1162. Relationship::delete_cache();
  1163. if(!$this->silent)
  1164. $GLOBALS['log']->debug( 'done<br>');
  1165. }
  1166. }
  1167. function install_layoutfields() {
  1168. if (!empty ( $this->installdefs [ 'layoutfields' ] ))
  1169. {
  1170. foreach ( $this->installdefs [ 'layoutfields' ] as $fieldSet )
  1171. {
  1172. if (!empty($fieldSet['additional_fields']))
  1173. {
  1174. $this->addFieldsToLayout($fieldSet['additional_fields']);
  1175. }
  1176. }
  1177. }
  1178. }
  1179. function uninstall_layoutfields() {
  1180. if (!empty ( $this->installdefs [ 'layoutfields' ] ))
  1181. {
  1182. fo

Large files files are truncated, but you can click here to view the full file