Escolar Documentos
Profissional Documentos
Cultura Documentos
php
/
*****************************************************************************
****
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* This program is distributed in the hope that it will be useful, but WITHOUT
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
* You should have received a copy of the GNU Affero General Public License along with
* 02110-1301 USA.
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* The interactive user interfaces in modified source and object code versions
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*****************************************************************************
***/
/*
* Relevant directories (X) are Layoutdefs, Vardefs, Include (bean stuff), Language,
TableDictionary (relationships)
*/
require_once('include/utils/progress_bar_utils.php');
require_once('ModuleInstall/ModuleScanner.php');
define('DISABLED_PATH', 'Disabled');
class ModuleInstaller{
public $id_name;
function ModuleInstaller(){
$this->modules = get_module_dir_list();
include("ModuleInstall/extensions.php");
$this->extensions = $extensions;
/*
* 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
* 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
* 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.
*/
if(defined('TEMPLATE_URL'))SugarTemplateUtilities::disableCache();
if ((defined('MODULE_INSTALLER_PACKAGE_SCAN') &&
MODULE_INSTALLER_PACKAGE_SCAN)
|| !empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan'])) {
$this->ms->scanPackage($base_dir);
if($this->ms->hasIssues()){
$this->ms->displayIssues();
sugar_cleanup(true);
// workaround for bug 45812 - refresh vardefs cache before unpacking to avoid partial vardefs in
cache
global $beanList;
if (!empty($beanList[$module_name])) {
$objectName = BeanFactory::getObjectName($module_name);
VardefManager::loadVardef($module_name, $objectName);
$this->base_dir = $base_dir;
$current_step = 0;
$tasks = array(
'pre_execute',
'install_copy',
'install_extensions',
'install_images',
'install_dcactions',
'install_dashlets',
'install_connectors',
'install_layoutfields',
'install_relationships',
'enable_manifest_logichooks',
'post_execute',
'reset_opcodes',
);
$total_steps += count($tasks);
if(file_exists($this->base_dir . '/manifest.php')){
if(!$this->silent){
$current_step++;
include($this->base_dir . '/manifest.php');
if(!empty($upgrade_manifest)){
if(!empty($upgrade_manifest['upgrade_paths'])){
if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
$installdefs = $upgrade_manifest['upgrade_paths'][$previous_version];
}else{
$this->abort($errors);
}//fi
}//fi
}//fi
}//fi
$this->id_name = $installdefs['id'];
$this->installdefs = $installdefs;
if(!$this->silent){
$current_step++;
foreach($tasks as $task){
$this->$task();
if(!$this->silent){
$current_step++;
$this->install_beans($this->installed_modules);
if(!$this->silent){
$current_step++;
if(isset($installdefs['custom_fields'])){
$this->log(translate('LBL_MI_IN_CUSTOMFIELD'));
$this->install_custom_fields($installdefs['custom_fields']);
if(!$this->silent){
$current_step++;
echo '</div>';
if(!$this->silent){
$current_step++;
echo '</div>';
$selectedActions = array(
'clearTpls',
'clearJsFiles',
'clearDashlets',
'clearVardefs',
'clearJsLangFiles',
'rebuildAuditTables',
'repairDatabase',
);
VardefManager::clearVardef();
if (file_exists('custom/application/Ext/Include/modules.ext.php'))
include('custom/application/Ext/Include/modules.ext.php');
require_once("modules/Administration/upgrade_custom_relationships.php");
upgrade_custom_relationships($this->installed_modules);
$this->rebuild_all(true);
require_once('modules/Administration/QuickRepairAndRebuild.php');
$this->rebuild_relationships();
UpdateSystemTabs('Add',$this->tab_modules);
clearAllJsAndJsLangFilesWithoutOutput();
$cache_key = 'app_list_strings.'.$GLOBALS['current_language'];
sugar_cache_clear($cache_key );
sugar_cache_reset();
require_once('modules/Home/UnifiedSearchAdvanced.php');
UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
}else{
function uninstall_user_prefs($module){
function pre_execute(){
require_once($this->base_dir . '/manifest.php');
foreach($this->installdefs['pre_execute'] as $includefile){
function post_execute(){
require_once($this->base_dir . '/manifest.php');
foreach($this->installdefs['post_execute'] as $includefile){
function pre_uninstall(){
require_once($this->base_dir . '/manifest.php');
foreach($this->installdefs['pre_uninstall'] as $includefile){
function post_uninstall(){
require_once($this->base_dir . '/manifest.php');
foreach($this->installdefs['post_uninstall'] as $includefile){
/*
* 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
* (specified as from and to in the manifest), replacing <basepath> by the base_dir value passed
in to install.
*/
function install_copy(){
if(isset($this->installdefs['copy'])){
foreach($this->installdefs['copy'] as $cp){
//$this->copy_path($cp['from'], $cp['to']);
//here we should get the module list again as we could have copied something to the modules dir
$this->modules = get_module_dir_list();
function uninstall_copy(){
if(!empty($this->installdefs['copy'])){
foreach($this->installdefs['copy'] as $cp){
//rmdir_recursive($cp['to']);
$backup_path =
clean_path( remove_file_extension(urldecode(hashToFile($_REQUEST['install_file'])))."restore/".$cp['to'] );
$this->uninstall_new_files($cp, $backup_path);
$backup_path =
clean_path( remove_file_extension(urldecode(hashToFile($_REQUEST['install_file'])))."restore");
if(file_exists($backup_path))
rmdir_recursive($backup_path);
/**
* Removes any files that were added by the loaded module. If the files already existed prior to
install
*/
$zip_files = $this->dir_get_files($cp['from'],$cp['from']);
foreach($zip_files as $k=>$v){
//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
if(!isset($backup_files[$k])){
//if it's not a sugar file then we remove it otherwise we can't restor it
if(!$this->ms->sugarFileExists($to)){
if(file_exists($to)) {
unlink($to);
}else{
$files_remaining = $this->dir_file_count($cp['to']);
rmdir_recursive($cp['to']);
/**
*/
if($module == 'application') {
return "custom/Extension/application/Ext";
} else {
return "custom/Extension/modules/$module/Ext";
/**
*/
if(isset($this->installdefs[$section])){
$this->log(sprintf(translate("LBL_MI_IN_EXT"), $section));
foreach($this->installdefs[$section] as $item){
if(isset($item['from'])) {
} else {
$from = '';
if(!empty($module)) {
$item['to_module'] = $module;
if($item['to_module'] == 'application') {
$path = "custom/Extension/application/Ext/$extname";
} else {
$path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
if(!file_exists($path)){
mkdir_recursive($path, true);
if(isset($item["name"])) {
$target = $item["name"];
} else if (!empty($from)){
} else {
$target = $this->id_name;
if(!empty($from)) {
copy_recursive($from , "$path/$target.php");
/**
*/
if(isset($this->installdefs[$section])){
$this->log(sprintf(translate("LBL_MI_UN_EXT"), $section));
foreach($this->installdefs[$section] as $item){
if(isset($item['from'])) {
} else {
$from = '';
if(!empty($module)) {
$item['to_module'] = $module;
if($item['to_module'] == 'application') {
$path = "custom/Extension/application/Ext/$extname";
} else {
$path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
if(isset($item["name"])) {
$target = $item["name"];
} else if (!empty($from)){
} else {
$target = $this->id_name;
$disabled_path = $path.'/'.DISABLED_PATH;
if (file_exists("$path/$target.php")) {
rmdir_recursive("$path/$target.php");
} else if (file_exists("$disabled_path/$target.php")) {
rmdir_recursive("$disabled_path/$target.php");
/**
*/
$this->merge_files("Ext/$ext/", $filename);
/**
*/
if(isset($this->installdefs[$section])) {
foreach($this->installdefs[$section] as $item) {
if(isset($item['from'])) {
} else {
$from = '';
if(!empty($module)) {
$item['to_module'] = $module;
if($item['to_module'] == 'application') {
$path = "custom/Extension/application/Ext/$extname";
} else {
$path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
if(isset($item["name"])) {
$target = $item["name"];
} else if (!empty($from)){
}else {
$target = $this->id_name;
$disabled_path = $path.'/'.DISABLED_PATH;
if (file_exists("$path/$target.php")) {
mkdir_recursive($disabled_path, true);
rename("$path/$target.php", "$disabled_path/$target.php");
mkdir_recursive($disabled_path, true);
/**
*/
if(isset($this->installdefs[$section])) {
foreach($this->installdefs[$section] as $item) {
if(isset($item['from'])) {
} else {
$from = '';
if(!empty($module)) {
$item['to_module'] = $module;
if($item['to_module'] == 'application') {
$path = "custom/Extension/application/Ext/$extname";
} else {
$path = "custom/Extension/modules/{$item['to_module']}/Ext/$extname";
if(isset($item["name"])) {
$target = $item["name"];
} else if (!empty($from)){
} else {
$target = $this->id_name;
if(!file_exists($path)) {
mkdir_recursive($path, true);
$disabled_path = $path.'/'.DISABLED_PATH;
if (file_exists("$disabled_path/$target.php")) {
rename("$disabled_path/$target.php", "$path/$target.php");
/**
* return bool
*/
if (empty($this->installdefs['beans']))
return true;
if (is_file('custom/modules/unified_search_modules_display.php') == false)
return true;
$users = get_user_array();
$unified_search_modules_display = array();
require('custom/modules/unified_search_modules_display.php');
foreach($this->installdefs['beans'] as $beanDefs)
continue;
unset($unified_search_modules_display[$beanDefs['module']]);
if (empty($userId))
continue;
$user->retrieve($userId);
continue;
unset($prefs[$beanDefs['module']]);
$user->savePreferencesToDB();
if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display,
'custom/modules/unified_search_modules_display.php') == false)
global $app_strings;
$msg = string_format($app_strings['ERR_FILE_WRITE'],
array('custom/modules/unified_search_modules_display.php'));
$GLOBALS['log']->error($msg);
return false;
return true;
/**
* return bool
*/
if (empty($this->installdefs['beans']))
return true;
if (is_file('custom/modules/unified_search_modules_display.php') == false)
return true;
$unified_search_modules_display = array();
require('custom/modules/unified_search_modules_display.php');
foreach($this->installdefs['beans'] as $beanDefs)
continue;
if (isset($unified_search_modules_display[$beanDefs['module']]['disabled_module_visible']) ==
false)
continue;
$unified_search_modules_display[$beanDefs['module']]['visible'] =
$unified_search_modules_display[$beanDefs['module']]['disabled_module_visible'];
unset($unified_search_modules_display[$beanDefs['module']]['disabled_module_visible']);
if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display,
'custom/modules/unified_search_modules_display.php') == false)
global $app_strings;
$msg = string_format($app_strings['ERR_FILE_WRITE'],
array('custom/modules/unified_search_modules_display.php'));
$GLOBALS['log']->error($msg);
return false;
return true;
/**
* return bool
*/
if (empty($this->installdefs['beans']))
return true;
if (is_file('custom/modules/unified_search_modules_display.php') == false)
return true;
$unified_search_modules_display = array();
require('custom/modules/unified_search_modules_display.php');
foreach($this->installdefs['beans'] as $beanDefs)
continue;
if (isset($unified_search_modules_display[$beanDefs['module']]['visible']) == false)
continue;
$unified_search_modules_display[$beanDefs['module']]['disabled_module_visible'] =
$unified_search_modules_display[$beanDefs['module']]['visible'];
$unified_search_modules_display[$beanDefs['module']]['visible'] = false;
if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display,
'custom/modules/unified_search_modules_display.php') == false)
global $app_strings;
$msg = string_format($app_strings['ERR_FILE_WRITE'],
array('custom/modules/unified_search_modules_display.php'));
$GLOBALS['log']->error($msg);
return false;
return true;
$install = "install_$extname";
if(method_exists($this, $install)) {
// non-standard function
$this->$install();
} else {
if(!empty($ext["section"])) {
$module = isset($ext['module'])?$ext['module']:'';
$this->rebuild_extensions();
$func = "uninstall_$extname";
if(method_exists($this, $func)) {
// non-standard function
$this->$func();
} else {
if(!empty($ext["section"])) {
$module = isset($ext['module'])?$ext['module']:'';
$this->rebuild_extensions();
$func = "rebuild_$extname";
if(method_exists($this, $func)) {
// non-standard function
$this->$func();
} else {
$this->rebuildExt($ext["extdir"], $ext["file"]);
$func = "disable_$extname";
if(method_exists($this, $func)) {
// non-standard install
$this->$func();
} else {
if(!empty($ext["section"])) {
$module = isset($ext['module'])?$ext['module']:'';
$this->rebuild_extensions();
$func = "enable_$extname";
if(method_exists($this, $func)) {
// non-standard install
$this->$func();
} else {
if(!empty($ext["section"])) {
$module = isset($ext['module'])?$ext['module']:'';
$this->rebuild_extensions();
function install_dashlets()
if(isset($this->installdefs['dashlets'])){
foreach($this->installdefs['dashlets'] as $cp){
$this->log(translate('LBL_MI_IN_DASHLETS') . $cp['name']);
if(!file_exists($path)){
mkdir_recursive($path, true);
copy_recursive($cp['from'] , $path);
include('modules/Administration/RebuildDashlets.php');
function uninstall_dashlets(){
if(isset($this->installdefs['dashlets'])){
foreach($this->installdefs['dashlets'] as $cp){
$this->log(translate('LBL_MI_UN_DASHLETS') . $cp['name']);
if (file_exists($path))
rmdir_recursive($path);
include('modules/Administration/RebuildDashlets.php');
function install_images(){
if(isset($this->installdefs['image_dir'])){
$this->log( translate('LBL_MI_IN_IMAGES') );
$this->copy_path($this->installdefs['image_dir'] , 'custom/themes');
function install_dcactions(){
if(isset($this->installdefs['dcaction'])){
$this->log(translate('LBL_MI_IN_MENUS'));
foreach($this->installdefs['dcaction'] as $action){
$path = 'custom/Extension/application/Ext/DashletContainer/Containers';
if(!file_exists($path)){
mkdir_recursive($path, true);
$this->rebuild_dashletcontainers();
function uninstall_dcactions(){
if(isset($this->installdefs['dcaction'])){
$this->log(translate('LBL_MI_UN_MENUS'));
foreach($this->installdefs['dcaction'] as $action){
$path = 'custom/Extension/application/Ext/DashletContainer/Containers';
$this->rebuild_dashletcontainers();
function install_connectors(){
if(isset($this->installdefs['connectors'])){
foreach($this->installdefs['connectors'] as $cp){
$this->log(translate('LBL_MI_IN_CONNECTORS') . $cp['name']);
$dir = str_replace('_','/',$cp['name']);
if(!file_exists($source_path)){
mkdir_recursive($source_path, true);
copy_recursive($cp['connector'] , $source_path);
if(!empty($cp['formatter'])) {
if(!file_exists($formatter_path)){
mkdir_recursive($formatter_path, true);
copy_recursive($cp['formatter'] , $formatter_path);
require_once('include/connectors/utils/ConnectorUtils.php');
ConnectorUtils::installSource($cp['name']);
function uninstall_connectors(){
if(isset($this->installdefs['connectors'])){
foreach($this->installdefs['connectors'] as $cp){
$this->log(translate('LBL_MI_UN_CONNECTORS') . $cp['name']);
$dir = str_replace('_','/',$cp['name']);
rmdir_recursive($source_path);
rmdir_recursive($formatter_path);
require_once('include/connectors/utils/ConnectorUtils.php');
//ConnectorUtils::getConnectors(true);
ConnectorUtils::uninstallSource($cp['name']);
if($to_module == 'application'){
if(!file_exists($path)){
mkdir_recursive($path, true);
if($to_module == 'application'){
if(!file_exists($path)){
mkdir_recursive($path, true);
function install_languages()
$languages = array();
if(isset($this->installdefs['language']))
$this->log(translate('LBL_MI_IN_LANG') );
foreach($this->installdefs['language'] as $packs)
$modules[]=$packs['to_module'];
$languages[$packs['language']] = $packs['language'];
$path = $this->getInstallLanguagesPath($packs);
if (!file_exists(dirname($path))) {
mkdir_recursive(dirname($path), true);
copy_recursive($packs['from'], $path);
$this->rebuild_languages($languages, $modules);
/**
* @param $packs
* @return string
*/
if($packs['to_module'] == 'application'){
return $path;
function uninstall_languages(){
$languages = array();
if(isset($this->installdefs['language'])){
$this->log(translate('LBL_MI_UN_LANG') );
foreach($this->installdefs['language'] as $packs){
$modules[]=$packs['to_module'];
$languages[$packs['language']] = $packs['language'];
if($packs['to_module'] == 'application'){
$this->rebuild_languages($languages, $modules);
if(isset($this->installdefs['language'])) {
foreach($this->installdefs['language'] as $item) {
$modules[]=$item['to_module'];
$languages[$item['language']] = $item['language'];
if($item['to_module'] == 'application') {
$path = "custom/Extension/application/Ext/Language";
} else {
$path = "custom/Extension/modules/{$item['to_module']}/Ext/Language";
if(isset($item["name"])) {
$target = $item["name"];
} else {
$target = $this->id_name;
$target = "{$item['language']}.$target";
$disabled_path = $path.'/'.DISABLED_PATH;
if (file_exists("$path/$target.php")) {