2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once('modules/ModuleBuilder/MB/MBModule.php');
41 var $is_uninstallable = true;
42 var $description = '';
43 var $has_images = true;
44 var $modules = array();
45 var $date_modified = '';
49 function MBPackage($name){
54 function loadModules($force=false){
55 if(!file_exists(MB_PACKAGE_PATH . '/' . $this->name .'/modules'))return;
56 $d = dir(MB_PACKAGE_PATH . '/' . $this->name .'/modules');
57 while($e = $d->read()){
58 if(substr($e, 0, 1) != '.' && is_dir(MB_PACKAGE_PATH . '/'. $this->name. '/modules/' . $e)){
59 $this->getModule($e, $force);
65 * Loads the translated module titles from the selected language into.
66 * Will override currently loaded string to reflect undeployed label changes.
69 * @param $languge String language identifyer
71 function loadModuleTitles($languge = '')
75 $language = $GLOBALS['current_language'];
77 global $app_list_strings;
78 $packLangFilePath = $this->getPackageDir() . "/language/application/" . $language . ".lang.php";
79 if (file_exists($packLangFilePath))
82 require($packLangFilePath);
91 function getModule($name, $force=true){
92 if(!$force && !empty($this->modules[$name]))
93 return $this->modules[$name];
95 $path = $this->getPackageDir();
96 $this->modules[$name] = new MBModule($name, $path, $this->name, $this->key);
98 return $this->modules[$name];
102 * Returns an MBModule by the given full name (package key + module name)
103 * if it exists in this package
105 * @param string $name
108 public function getModuleByFullName($name){
109 foreach($this->modules as $mname => $module) {
110 if ($this->key . "_" . $mname == $name)
115 function deleteModule($name){
116 $this->modules[$name]->delete();
117 unset($this->modules[$name]);
120 function getManifest($version_specific = false, $for_export = false){
121 //If we are exporting the package, we must ensure a different install key
122 $pre = $for_export ? MB_EXPORTPREPEND : "";
123 $date = TimeDate::getInstance()->nowDb();
125 $this->description = to_html($this->description);
126 $is_uninstallable = ($this->is_uninstallable ? true : false);
127 if($GLOBALS['sugar_flavor'] == 'CE') {
128 $flavors = array('CE','PRO','ENT');
130 $flavors = array($GLOBALS['sugar_flavor']);
132 $version = (!empty($version_specific))?$GLOBALS['sugar_version']:'';
134 // Build an array and use var_export to build this file
136 array('acceptable_sugar_versions' => array($version)),
137 array('acceptable_sugar_flavors' => $flavors),
138 'readme' => $this->readme,
140 'author' => $this->author,
141 'description' => $this->description,
143 'is_uninstallable' => $is_uninstallable,
144 'name' => $pre.$this->name,
145 'published_date' => $date,
148 'remove_tables' => 'prompt',
153 $header = file_get_contents('modules/ModuleBuilder/MB/header.php');
155 return $header."\n// THIS CONTENT IS GENERATED BY MBPackage.php\n".'$manifest = '.var_export_helper($manifest).";\n\n";
160 'acceptable_sugar_versions' =>
164 'acceptable_sugar_flavors' =>
168 'readme'=>'$this->readme',
170 'author' => '$this->author',
171 'description' => '$this->description',
173 'is_uninstallable' => $is_uninstallable,
174 'name' => '$pre$this->name',
175 'published_date' => '$date',
177 'version' => '$time',
178 'remove_tables' => 'prompt',
184 function buildInstall($path){
185 $installdefs = array ('id' => $this->name,
187 'layoutdefs'=>array(),
188 'relationships'=>array(),
190 if($this->has_images){
191 $installdefs['image_dir'] = '<basepath>/icons';
193 foreach(array_keys($this->modules) as $module){
194 $this->modules[$module]->build($path);
195 $this->modules[$module]->addInstallDefs($installdefs);
197 $this->path = $this->getPackageDir();
198 if(file_exists($this->path . '/language')){
199 $d= dir($this->path . '/language');
200 while($e = $d->read()){
201 $lang_path = $this->path .'/language/' . $e;
202 if(substr($e, 0, 1) != '.' && is_dir($lang_path)){
203 $f = dir($lang_path);
204 while($g = $f->read()){
205 if(substr($g, 0, 1) != '.' && is_file($lang_path.'/'. $g)){
206 $lang = substr($g, 0, strpos($g, '.'));
207 $installdefs['language'][] = array(
208 'from'=> '<basepath>/SugarModules/language/'.$e . '/'. $g,
217 copy_recursive( $this->path . '/language/', $path . '/language/');
218 $icon_path = $path . '/../icons/default/images/';
219 mkdir_recursive($icon_path);
220 copy_recursive($this->path . '/icons/', $icon_path);
222 return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
226 function getPackageDir(){
227 return MB_PACKAGE_PATH . '/' . $this->name;
230 function getBuildDir(){
231 return MB_PACKAGE_BUILD . DIRECTORY_SEPARATOR . $this->name;
234 function getZipDir(){
235 return $this->getPackageDir() . '/zips';
240 $path = $this->getPackageDir();
241 if(file_exists($path .'/manifest.php')){
242 require($path . '/manifest.php');
243 if(!empty($manifest)){
244 $this->date_modified = $manifest['published_date'];
245 $this->is_uninstallable = $manifest['is_uninstallable'];
246 $this->author = $manifest['author'];
247 $this->key = $manifest['key'];
248 $this->description = $manifest['description'];
249 if(!empty($manifest['readme']))
250 $this->readme = $manifest['readme'];
253 $this->loadModules(true);
257 $path = $this->getPackageDir();
258 if(mkdir_recursive($path)){
259 //Save all the modules when we save a package
260 $this->updateModulesMetaData(true);
261 sugar_file_put_contents_atomic($path .'/manifest.php', $this->getManifest());
265 function build($export=true, $clean = false){
266 $this->loadModules();
267 require_once('include/utils/zip_utils.php');
268 $package_path = $this->getPackageDir();
269 $path = $this->getBuildDir() . '/SugarModules';
270 if($clean && file_exists($path))rmdir_recursive($path);
271 if(mkdir_recursive($path)){
273 $manifest = $this->getManifest().$this->buildInstall($path);
274 $fp = sugar_fopen($this->getBuildDir() .'/manifest.php', 'w');
275 fwrite($fp, $manifest);
279 if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
280 copy('modules/ModuleBuilder/MB/LICENSE.txt', $this->getBuildDir() . '/LICENSE.txt');
281 }else if(file_exists('LICENSE.txt')){
282 copy('LICENSE.txt', $this->getBuildDir() . '/LICENSE.txt');
284 $package_dir = $this->getPackageDir();
285 $date = date('Y_m_d_His');
286 $zipDir = $this->getZipDir();
287 if(!file_exists($zipDir))mkdir_recursive($zipDir);
289 chdir($this->getBuildDir());
290 zip_dir('.',$cwd . '/'. $zipDir. '/'. $this->name. $date. '.zip');
293 header('Location:' . $zipDir. '/'. $this->name. $date. '.zip');
296 'zip'=>$zipDir. '/'. $this->name. $date. '.zip',
297 'manifest'=>$this->getBuildDir(). '/manifest.php',
298 'name'=>$this->name. $date,
304 $this->loadModules();
305 $node = array('name'=>$this->name, 'action'=>'module=ModuleBuilder&action=package&package=' . $this->name, 'children'=>array());
306 foreach(array_keys($this->modules) as $module){
307 $node['children'][] = $this->modules[$module]->getNodes();
312 function populateFromPost(){
313 $this->description = trim($_REQUEST['description']);
314 $this->author = trim($_REQUEST['author']);
315 $this->key = trim($_REQUEST['key']);
316 $this->readme = trim($_REQUEST['readme']);
319 function rename($new_name){
320 $old= $this->getPackageDir();
321 $this->name = $new_name;
322 $new = $this->getPackageDir();
323 if(file_exists($new)){
326 if(rename($old, $new)){
333 function updateModulesMetaData($save=false){
334 foreach(array_keys($this->modules) as $module){
335 $old_name = $this->modules[$module]->key_name;
336 $this->modules[$module]->key_name = $this->key . '_' . $this->modules[$module]->name;
337 $this->modules[$module]->renameMetaData($this->modules[$module]->getModuleDir(), $old_name);
338 $this->modules[$module]->renameLanguageFiles($this->modules[$module]->getModuleDir());
339 if($save)$this->modules[$module]->save();
344 function copy($new_name){
345 $old= $this->getPackageDir();
348 $this->name = $new_name;
349 $new= $this->getPackageDir();
350 while(file_exists($new)){
352 $this->name = $new_name . $count;
353 $new= $this->getPackageDir();
356 $new = $this->getPackageDir();
357 if(copy_recursive($old, $new)){
358 $this->updateModulesMetaData();
366 return rmdir_recursive($this->getPackageDir());
370 //creation of the installdefs[] array for the manifest when exporting customizations
371 function customBuildInstall($modules, $path, $extensions = array()){
372 $columns=$this->getColumnsName();
373 $installdefs = array ('id' => $this->name, 'relationships' => array());
374 $include_path="$path/SugarModules/include/language";
375 if(file_exists($include_path) && is_dir($include_path)){
376 $dd= dir($include_path);
377 while($gg = $dd->read()){
378 if(substr($gg, 0, 1) != '.' && is_file($include_path . '/' . $gg)){
379 $lang = substr($gg, 0, strpos($gg, '.'));
380 $installdefs['language'][] = array(
381 'from'=> '<basepath>/SugarModules/include/language/'. $gg,
382 'to_module'=> 'application',
389 foreach($modules as $value){
390 $custom_module = $this->getCustomModules($value);
391 foreach($custom_module as $va){
392 if ($va == 'language'){
393 $this->getLanguageManifestForModule($value, $installdefs);
394 $this->getCustomFieldsManifestForModule($value, $installdefs);
396 if($va == 'metadata'){
397 $this->getCustomMetadataManifestForModule($value, $installdefs);
400 $relationshipsMetaFiles = $this->getCustomRelationshipsMetaFilesByModuleName($value, true, true);
401 if($relationshipsMetaFiles)
403 foreach ($relationshipsMetaFiles as $file)
405 $installdefs['relationships'][] = array('meta_data' => str_replace('custom', '<basepath>', $file));
409 if (is_dir($path . DIRECTORY_SEPARATOR . 'Extension'))
411 $this->getExtensionsManifestForPackage($path, $installdefs);
413 return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
416 private function getLanguageManifestForModule($module, &$installdefs)
418 $lang_path = 'custom' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'language';
419 foreach(scandir($lang_path) as $langFile)
421 if(substr($langFile, 0, 1) != '.' && is_file($lang_path . DIRECTORY_SEPARATOR . $langFile)){
422 $lang = substr($langFile, 0, strpos($langFile, '.'));
423 $installdefs['language'][] = array(
424 'from'=> '<basepath>/SugarModules/modules/' . $module . '/language/'. $langFile,
425 'to_module'=> $module,
432 private function getCustomFieldsManifestForModule($module, &$installdefs)
434 $db = DBManagerFactory::getInstance();
435 $result=$db->query("SELECT * FROM fields_meta_data where custom_module='$module'");
436 while($row = $db->fetchByAssoc($result)){
438 foreach($row as $col=>$res){
440 case 'custom_module':
441 $installdefs['custom_fields'][$name]['module'] = $res;
444 $installdefs['custom_fields'][$name]['require_option'] = $res;
447 $installdefs['custom_fields'][$name]['label'] = $res;
450 $installdefs['custom_fields'][$name]['require_option'] = $res;
453 $installdefs['custom_fields'][$name]['mass_update'] = $res;
456 $installdefs['custom_fields'][$name]['comments'] = $res;
459 $installdefs['custom_fields'][$name]['help'] = $res;
462 $installdefs['custom_fields'][$name]['max_size'] = $res;
465 $installdefs['custom_fields'][$name][$col] = $res;
471 private function getCustomMetadataManifestForModule($module, &$installdefs)
473 $meta_path = 'custom/modules/' . $module . '/metadata';
474 foreach(scandir($meta_path) as $meta_file)
476 if(substr($meta_file, 0, 1) != '.' && is_file($meta_path . '/' . $meta_file)){
477 if($meta_file == 'listviewdefs.php'){
478 $installdefs['copy'][] = array(
479 'from'=> '<basepath>/SugarModules/modules/'. $module . '/metadata/'. $meta_file,
480 'to'=> 'custom/modules/'. $module . '/metadata/' . $meta_file,
484 $installdefs['copy'][] = array(
485 'from'=> '<basepath>/SugarModules/modules/'. $module . '/metadata/'. $meta_file,
486 'to'=> 'custom/modules/'. $module . '/metadata/' . $meta_file,
488 $installdefs['copy'][] = array(
489 'from'=> '<basepath>/SugarModules/modules/'. $module . '/metadata/'. $meta_file,
490 'to'=> 'custom/working/modules/'. $module . '/metadata/' . $meta_file,
498 * @todo private changed protected for testing purposes.
500 * @param string $path
501 * @param array $installdefs link
503 protected function getExtensionsManifestForPackage($path, &$installdefs)
505 $installdefs['copy'] = array();
506 $generalPath = DIRECTORY_SEPARATOR . 'Extension' . DIRECTORY_SEPARATOR . 'modules';
508 $recursiveIterator = new RecursiveIteratorIterator(
509 new RecursiveDirectoryIterator($path . $generalPath),
510 RecursiveIteratorIterator::SELF_FIRST
513 /* @var $fInfo SplFileInfo */
514 foreach (new RegexIterator($recursiveIterator, "/\.php$/i") as $fInfo)
517 $newPath = substr($fInfo->getPathname(), strrpos($fInfo->getPathname(), $generalPath));
519 $installdefs['copy'][] = array(
520 'from' => '<basepath>' . $newPath,
521 'to' => 'custom' . $newPath
526 //return an array which contain the name of fields_meta_data table's columns
527 function getColumnsName(){
529 $meta = new FieldsMetaData();
531 foreach($meta->getFieldDefinitions() as $key=>$value) {
538 //creation of the custom fields ZIP file (use getmanifest() and customBuildInstall() )
539 function exportCustom($modules, $export=true, $clean = true){
541 $relationshipFiles = array();
543 $path = $this->getBuildDir();
544 if ($clean && file_exists($path)) {
545 rmdir_recursive($path);
547 //Copy the custom files to the build dir
548 foreach ($modules as $module) {
549 $pathmod = "$path/SugarModules/modules/$module";
550 if (mkdir_recursive($pathmod)) {
551 if (file_exists("custom/modules/$module")) {
552 copy_recursive("custom/modules/$module", "$pathmod");
553 //Don't include cached extension files
554 if (is_dir("$pathmod/Ext"))
555 rmdir_recursive("$pathmod/Ext");
557 //Convert modstring files to extension compatible arrays
558 $this->convertLangFilesToExtensions("$pathmod/language");
561 $extensions = $this->getExtensionsList($module, $modules);
562 $relMetaFiles = $this->getCustomRelationshipsMetaFilesByModuleName($module, true);
563 $extensions = array_merge($extensions, $relMetaFiles);
565 foreach ($extensions as $file) {
566 $fileInfo = new SplFileInfo($file);
567 $trimmedPath = ltrim($fileInfo->getPath(), 'custom');
569 sugar_mkdir($path . $trimmedPath, NULL, true);
570 copy($file, $path . $trimmedPath . '/' . $fileInfo->getFilename());
574 $this->copyCustomDropdownValuesForModules($modules,$path);
575 if(file_exists($path)){
576 $manifest = $this->getManifest(true).$this->customBuildInstall($modules,$path);
577 sugar_file_put_contents($path .'/manifest.php', $manifest);
579 if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
580 copy('modules/ModuleBuilder/MB/LICENSE.txt', $path . '/LICENSE.txt');
582 else if(file_exists('LICENSE.txt')){
583 copy('LICENSE.txt', $path . '/LICENSE.txt');
585 require_once('include/utils/zip_utils.php');
586 $date = date('Y_m_d_His');
587 $zipDir = $this->getZipDir();
588 if(!file_exists($zipDir))mkdir_recursive($zipDir);
590 chdir($this->getBuildDir());
591 zip_dir('.',$cwd . '/'. $zipDir. '/'. $this->name. $date. '.zip');
593 if($clean && file_exists($this->getBuildDir()))rmdir_recursive($this->getBuildDir());
595 header('Location:' . $zipDir. '/'. $this->name. $date. '.zip');
597 return $zipDir. '/'. $this->name. $date. '.zip';
600 private function convertLangFilesToExtensions($langDir)
602 if (is_dir($langDir))
604 foreach(scandir($langDir) as $langFile)
606 $mod_strings = array();
607 if (strcasecmp(substr($langFile, -4), ".php") != 0)
609 include("$langDir/$langFile");
610 $out = "<?php \n // created: " . date('Y-m-d H:i:s') . "\n";
611 foreach($mod_strings as $lbl_key => $lbl_val )
613 $out .= override_value_to_string("mod_strings", $lbl_key, $lbl_val) . "\n";
616 sugar_file_put_contents("$langDir/$langFile", $out);
620 private function copyCustomDropdownValuesForModules($modules, $path)
622 if(file_exists("custom/include/language")){
623 if(mkdir_recursive("$path/SugarModules/include")){
624 global $app_list_strings;
625 $backStrings = $app_list_strings;
626 foreach(scandir("custom/include/language") as $langFile)
628 $app_list_strings = array();
629 if (strcasecmp(substr($langFile, -4), ".php") != 0)
631 include("custom/include/language/$langFile");
633 $lang = substr($langFile, 0, -9);
634 $options = $this->getCustomDropDownStringsForModules($modules, $app_list_strings);
635 foreach($options as $name => $arr) {
636 $out .= override_value_to_string('app_list_strings', $name, $arr);
638 mkdir_recursive("$path/SugarModules/include/language/");
639 sugar_file_put_contents("$path/SugarModules/include/language/$lang.$this->name.php", $out);
641 $app_list_strings = $backStrings;
646 function getCustomDropDownStringsForModules($modules, $list_strings) {
647 global $beanList, $beanFiles;
649 foreach($modules as $module)
651 if (!empty($beanList[$module]))
653 require_once($beanFiles[$beanList[$module]]);
654 $bean = new $beanList[$module]();
655 foreach($bean->field_defs as $field => $def)
657 if (isset($def['options']) && isset($list_strings[$def['options']]))
659 $options[$def['options']] = $list_strings[$def['options']];
669 //if $module=false : return an array with custom module and there customizations.
670 //if $module=!false : return an array with the directories of custom/module/$module.
671 function getCustomModules($module=false){
673 $path='custom/modules/';
674 $extPath = 'custom/Extension/modules/';
675 if(!file_exists($path) || !is_dir($path)){
676 return array($mod_strings['LBL_EC_NOCUSTOM'] => "");
679 if ($module != false ){
680 $path=$path . $module . '/';
682 $scanlisting = scandir($path);
683 $dirlisting = array();
684 foreach ($scanlisting as $value){
685 if(is_dir($path . $value) == true && $value != '.' && $value != '..') {
686 $dirlisting[] = $value;
689 if(empty($dirlisting)){
690 return array($mod_strings['LBL_EC_NOCUSTOM'] => "");
692 if ($module == false ){
693 foreach ($dirlisting as $value){
694 if(!file_exists('modules/' . $value . '/metadata/studio.php'))
696 $custommodules[$value]=$this->getCustomModules($value);
697 foreach ($custommodules[$value] as $va){
700 $return[$value][$va] = $mod_strings['LBL_EC_CUSTOMFIELD'];
703 $return[$value][$va] = $mod_strings['LBL_EC_CUSTOMLAYOUT'];
707 $return[$value][$va] = $mod_strings['LBL_EC_CUSTOMFIELD'];
710 $return[$value . " " . $mod_strings['LBL_EC_EMPTYCUSTOM']] = "";
713 $return[$value][$va] = $mod_strings['LBL_UNDEFINED'];
726 * Get _custom_ extensions for module.
727 * Default path - custom/Extension/modules/$module/Ext.
729 * @param array $module Name.
730 * @param mixed $includeRelationships ARRAY - relationships files between $module and names in array;
731 * TRUE - with all relationships files;
732 * @return array Paths.
734 protected function getExtensionsList($module, $includeRelationships = true)
736 if (BeanFactory::getBeanName($module) === false)
742 $includeMask = false;
743 $extPath = sprintf('custom%1$sExtension%1$smodules%1$s' . $module . '%1$sExt', DIRECTORY_SEPARATOR);
745 if (is_array($includeRelationships))
747 $includeMask = array();
748 $customRels = $this->getCustomRelationshipsByModuleName($module);
750 $includeRelationships[] = $module;
752 foreach ($customRels as $k => $v)
755 in_array($v->getLhsModule(), $includeRelationships) &&
756 in_array($v->getRhsModule(), $includeRelationships)
764 $recursiveIterator = new RecursiveIteratorIterator(
765 new RecursiveDirectoryIterator($extPath),
766 RecursiveIteratorIterator::SELF_FIRST
769 /* @var $fileInfo SplFileInfo */
770 foreach ($recursiveIterator as $fileInfo)
773 if ($fileInfo->isFile() && !in_array($fileInfo->getPathname(), $result))
775 if ($includeMask === false)
777 $result[] = $fileInfo->getPathname();
781 foreach ($includeMask as $v)
783 if (strpos($fileInfo->getFilename(), $v) !== false)
785 $result[] = $fileInfo->getPathname();
797 * Returns a set of field defs for fields that will exist when this package is deployed
798 * based on the relationships in all of its modules.
800 * @param $moduleName (module must be from whithin this package)
801 * @return array Field defs
803 function getRelationshipsForModule($moduleName) {
805 if (isset($this->modules[$moduleName])) {
806 $keyName = $this->modules[$moduleName]->key_name;
807 foreach($this->modules as $mName => $module) {
808 $rels = $module->getRelationships();
809 $relList = $rels->getRelationshipList();
810 foreach($relList as $rName ) {
811 $rel = $rels->get ( $rName ) ;
812 if ($rel->lhs_module == $keyName || $rel->rhs_module == $keyName) {
823 function exportProjectInstall($package, $for_export){
824 $pre = $for_export ? MB_EXPORTPREPEND : "";
825 $installdefs = array ('id' => $pre . $this->name);
826 $installdefs['copy'][] = array(
827 'from'=> '<basepath>/' . $this->name,
828 'to'=> 'custom/modulebuilder/packages/'. $this->name,
830 return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
836 function exportProject($package, $export=true, $clean = true){
837 $tmppath="custom/modulebuilder/projectTMP/";
838 if(file_exists($this->getPackageDir())){
839 if(mkdir_recursive($tmppath)){
840 copy_recursive($this->getPackageDir(), $tmppath ."/". $this->name);
841 $manifest = $this->getManifest(true, $export).$this->exportProjectInstall($package, $export);
842 $fp = sugar_fopen($tmppath .'/manifest.php', 'w');
843 fwrite($fp, $manifest);
845 if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
846 copy('modules/ModuleBuilder/MB/LICENSE.txt', $tmppath . '/LICENSE.txt');
848 else if(file_exists('LICENSE.txt')){
849 copy('LICENSE.txt', $tmppath . '/LICENSE.txt');
851 $readme_contents = $this->readme;
852 $readmefp = sugar_fopen($tmppath.'/README.txt','w');
853 fwrite($readmefp, $readme_contents);
857 require_once('include/utils/zip_utils.php');
858 $date = date('Y_m_d_His');
859 $zipDir = "custom/modulebuilder/packages/ExportProjectZips";
860 if(!file_exists($zipDir))mkdir_recursive($zipDir);
863 zip_dir('.',$cwd . '/'. $zipDir. '/project_'. $this->name. $date. '.zip');
865 if($clean && file_exists($tmppath))rmdir_recursive($tmppath);
867 header('Location:' . $zipDir. '/project_'. $this->name. $date. '.zip');
869 return $zipDir. '/project_'. $this->name. $date. '.zip';
873 * @param string $moduleName
874 * @param bool $lhs Return relationships where $moduleName - left module in join.
875 * @return mixed Array or false when module name is wrong.
877 protected function getCustomRelationshipsByModuleName($moduleName, $lhs = false)
879 if (BeanFactory::getBeanName($moduleName) === false)
886 $module = new StudioModule($moduleName);
888 /* @var $rel DeployedRelationships */
889 $rel = $module->getRelationships();
891 $relList = $rel->getRelationshipList();
893 foreach ($relList as $relationshipName)
895 $relation = $rel->get($relationshipName);
897 if ($relation->getFromStudio())
899 if ($lhs && $relation->getLhsModule() != $moduleName)
903 $result[$relationshipName] = $relation;
911 * @param string $moduleName
912 * @param bool $lhs Return relationships where $moduleName - left module in join.
913 * @param bool $metadataOnly Return only relationships metadata file.
916 protected function getCustomRelationshipsMetaFilesByModuleName($moduleName, $lhs = false, $metadataOnly = false)
919 $path = $metadataOnly ?
920 'custom' . DIRECTORY_SEPARATOR . 'metadata' . DIRECTORY_SEPARATOR :
921 'custom' . DIRECTORY_SEPARATOR;
924 $relationships = $this->getCustomRelationshipsByModuleName($moduleName, $lhs);
931 $recursiveIterator = new RecursiveIteratorIterator(
932 new RecursiveDirectoryIterator($path),
933 RecursiveIteratorIterator::SELF_FIRST
937 * @var $fileInfo SplFileInfo
939 foreach ($recursiveIterator as $fileInfo)
941 if ($fileInfo->isFile() && !in_array($fileInfo->getPathname(), $result))
943 foreach ($relationships as $k => $v)
946 if (strpos($fileInfo->getFilename(), $k) !== false)
948 $result[] = $fileInfo->getPathname();
958 public function deleteBuild()
960 return rmdir_recursive($this->getBuildDir());