mbpackage.php
来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 580 行 · 第 1/2 页
PHP
580 行
if(copy_recursive($old, $new)){ $this->updateModulesMetaData(); return true; } return false;
}
function delete(){
return rmdir_recursive($this->getPackageDir());
}
//creation of the installdefs[] array
function customBuildInstall($modules, $path){
$columns=$this->getColumnsName();
$installdefs = array ('id' => $this->name);
$include_path="$path/SugarModules/include/language";
if(file_exists($include_path) && is_dir($include_path)){
$dd= dir($include_path);
while($gg = $dd->read()){
if(substr($gg, 0, 1) != '.' && is_file($include_path . '/' . $gg)){
$lang = substr($gg, 0, strpos($gg, '.'));
$installdefs['language'][] = array(
'from'=> '<basepath>/SugarModules/include/language/'. $gg,
'to_module'=> 'application',
'language'=>$lang
);
}
}
}
$db = & PearDatabase::getInstance();
foreach($modules as $value){
$custom_module = $this->getCustomModules($value);
foreach($custom_module as $va){
if ($va == 'language'){
$lang_path = 'custom/modules/' . $value . '/language';
$d= dir($lang_path);
while($g = $d->read()){
if(substr($g, 0, 1) != '.' && is_file($lang_path . '/' . $g)){
$lang = substr($g, 0, strpos($g, '.'));
$installdefs['language'][] = array(
'from'=> '<basepath>/SugarModules/modules/' . $value . '/language/'. $g,
'to_module'=> $value,
'language'=>$lang
);
}
}
$result=$db->query("SELECT * FROM fields_meta_data where custom_module='$value'");
while($row = $db->fetchByAssoc($result)){
$name = $row['id'];
foreach($row as $col=>$res){
switch ($col) {
case 'custom_module':
$installdefs['custom_fields'][$name]['module'] = $res;
break;
case 'required':
$installdefs['custom_fields'][$name]['require_option'] = $res;
break;
case 'vname':
$installdefs['custom_fields'][$name]['label'] = $res;
break;
case 'required':
$installdefs['custom_fields'][$name]['require_option'] = $res;
break;
case 'massupdate':
$installdefs['custom_fields'][$name]['mass_update'] = $res;
break;
case 'comments':
$installdefs['custom_fields'][$name]['comments'] = $res;
break;
case 'help':
$installdefs['custom_fields'][$name]['help'] = $res;
break;
case 'len':
$installdefs['custom_fields'][$name]['max_size'] = $res;
break;
default:
$installdefs['custom_fields'][$name][$col] = $res;
}//switch
}//foreach
}//while
}//fi
if($va == 'metadata'){
$meta_path = 'custom/modules/' . $value . '/metadata';
$m= dir($meta_path);
while($ggg = $m->read()){
if(substr($ggg, 0, 1) != '.' && is_file($meta_path . '/' . $ggg)){
if($ggg == 'listviewdefs.php'){
$installdefs['copy'][] = array(
'from'=> '<basepath>/SugarModules/modules/'. $value . '/metadata/'. $ggg,
'to'=> 'custom/modules/'. $value . '/metadata/' . $ggg,
);
}
else{
$installdefs['copy'][] = array(
'from'=> '<basepath>/SugarModules/modules/'. $value . '/metadata/'. $ggg,
'to'=> 'custom/modules/'. $value . '/metadata/' . $ggg,
);
$installdefs['copy'][] = array(
'from'=> '<basepath>/SugarModules/modules/'. $value . '/metadata/'. $ggg,
'to'=> 'custom/working/modules/'. $value . '/metadata/' . $ggg,
);
}
}
}
}//fi
}//foreach
}//foreach
return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
}
//return an array which contain the name of fields_meta_data table's columns
function getColumnsName(){
require_once('modules/EditCustomFields/FieldsMetaData.php');
$meta = new FieldsMetaData();
$arr = array();
foreach($meta->getFieldDefinitions() as $key=>$value) {
$arr[] = $key;
}
return $arr;
}
//creation of the custom fields ZIP file (use getmanifest() and customBuildInstall() )
function exportCustom($modules, $export=true, $clean = true){
$path=$this->getBuildDir();
if($clean && file_exists($path))rmdir_recursive($path);
foreach($modules as $mod){
$pathmod="$path/SugarModules/modules/$mod";
if(mkdir_recursive($pathmod)){
if(file_exists("custom/modules/$mod")){
copy_recursive("custom/modules/$mod", "$pathmod");
}
else{
print( "ERROR: One module is not a custom module.\n" );
return(false);
}
}
}
if(file_exists("custom/include")){
if(mkdir_recursive("$path/SugarModules/include")){
copy_recursive("custom/include", "$path/SugarModules/include");
}
}
if(file_exists($path)){
$manifest = $this->getManifest(true).$this->customBuildInstall($modules,$path);
$fp = sugar_fopen($path .'/manifest.php', 'w');
fwrite($fp, $manifest);
fclose($fp);
}
if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
copy('modules/ModuleBuilder/MB/LICENSE.txt', $path . '/LICENSE.txt');
}
else if(file_exists('LICENSE.txt')){
copy('LICENSE.txt', $path . '/LICENSE.txt');
}
require_once('include/utils/zip_utils.php');
$date = date('Y_m_d_His');
$zipDir = $this->getZipDir();
if(!file_exists($zipDir))mkdir_recursive($zipDir);
$cwd = getcwd();
chdir($this->getBuildDir());
zip_dir('.',$cwd . '/'. $zipDir. '/'. $this->name. $date. '.zip');
chdir($cwd);
if($clean && file_exists($this->getBuildDir()))rmdir_recursive($this->getBuildDir());
if($export){
header('Location:' . $zipDir. '/'. $this->name. $date. '.zip');
}
return $zipDir. '/'. $this->name. $date. '.zip';
}
//if $module=false : return an array with custom module and there customizations.
//if $module=!false : return an array with the directories of custom/module/$module.
function getCustomModules($module=false){
global $mod_strings;
$path='custom/modules/';
if(!file_exists($path) || !is_dir($path)){
return array($mod_strings['LBL_EC_NOCUSTOM'] => "");
}
else{
if ($module != false ){
$path=$path . $module . '/';
}
// Bug 15177 : scandir() is a php 5 only function.
//$scanlisting = scandir($path);
$scandirectory=opendir($path);
while (false !== ($filename = readdir($scandirectory))) {
$scanlisting[] = $filename;
}
sort($scanlisting);
$dirlisting = array();
foreach ($scanlisting as $value){
if(is_dir($path . $value) == true && $value != '.' && $value != '..') {
$dirlisting[] = $value;
}
}
if(empty($dirlisting)){
return array($mod_strings['LBL_EC_NOCUSTOM'] => "");
}
if ($module == false ){
foreach ($dirlisting as $value){
$custommodules[$value]=$this->getCustomModules($value);
foreach ($custommodules[$value] as $va){
switch ($va) {
case 'language':
$return[$value][$va] = $mod_strings['LBL_EC_CUSTOMFIELD'];
break;
case 'metadata':
$return[$value][$va] = $mod_strings['LBL_EC_CUSTOMLAYOUT'];
break;
case 'Ext':
//$return[$value][$va] = $mod_strings['LBL_EC_CUSTOMFIELD'];
break;
case '':
$return[$value . " " . $mod_strings['LBL_EC_EMPTYCUSTOM']] = "";
break;
default:
$return[$value][$va] = $mod_strings['LBL_UNDEFINED'];
}
}
}
return $return;
}
else{
return $dirlisting;
}
}
}
function exportProjectInstall($package){
$installdefs = array ('id' => $this->name);
$installdefs['copy'][] = array(
'from'=> '<basepath>/' . $this->name,
'to'=> 'custom/modulebuilder/packages/'. $this->name,
);
return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
}
function exportProject($package, $export=true, $clean = true){
$tmppath="custom/modulebuilder/projectTMP/";
if(file_exists($this->getPackageDir())){
if(mkdir_recursive($tmppath)){
copy_recursive($this->getPackageDir(), $tmppath ."/". $this->name);
$manifest = $this->getManifest(true).$this->exportProjectInstall($package);
$fp = sugar_fopen($tmppath .'/manifest.php', 'w');
fwrite($fp, $manifest);
fclose($fp);
if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
copy('modules/ModuleBuilder/MB/LICENSE.txt', $tmppath . '/LICENSE.txt');
}
else if(file_exists('LICENSE.txt')){
copy('LICENSE.txt', $tmppath . '/LICENSE.txt');
}
$readme_contents = $this->readme;
$readmefp = sugar_fopen($tmppath.'/README.txt','w');
fwrite($readmefp, $readme_contents);
fclose($readmefp);
}
}
require_once('include/utils/zip_utils.php');
$date = date('Y_m_d_His');
$zipDir = "custom/modulebuilder/packages/ExportProjectZips";
if(!file_exists($zipDir))mkdir_recursive($zipDir);
$cwd = getcwd();
chdir($tmppath);
zip_dir('.',$cwd . '/'. $zipDir. '/project_'. $this->name. $date. '.zip');
chdir($cwd);
if($clean && file_exists($tmppath))rmdir_recursive($tmppath);
if($export){
header('Location:' . $zipDir. '/project_'. $this->name. $date. '.zip');
}
return $zipDir. '/project_'. $this->name. $date. '.zip';
}
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?