]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/MB/ModuleBuilder.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / MB / ModuleBuilder.php
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 /*********************************************************************************
39
40  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
41  * All Rights Reserved.
42  * Contributor(s): ______________________________________..
43  ********************************************************************************/
44  
45
46 define ( 'MB_PACKAGE_PATH', 'custom/modulebuilder/packages' ) ;
47 define ( 'MB_PACKAGE_BUILD', 'custom/modulebuilder/builds' ) ;
48 require_once ('modules/ModuleBuilder/MB/MBPackage.php') ;
49
50 class ModuleBuilder
51 {
52     var $packages = array ( ) ;
53
54     function getPackageList ()
55     {
56         static $list = array ( ) ;
57         if (! empty ( $list ) || ! file_exists ( MB_PACKAGE_PATH ))
58             return $list ;
59         $d = dir ( MB_PACKAGE_PATH ) ;
60         while ( $e = $d->read () )
61         {
62             if (file_exists ( MB_PACKAGE_PATH . '/' . $e . '/manifest.php' ))
63             {
64                 $list [] = $e ;
65             }
66         }
67         sort ( $list ) ; // order important as generate_nodes_array in Tree.php later loops over this by foreach to generate the package list
68         return $list ;
69     
70     }
71
72     /**
73      * @param $name
74      * @return MBPackage
75      */
76     function getPackage ($name)
77     {
78         if (empty ( $this->packages [ $name ] ))
79             $this->packages [ $name ] = new MBPackage ( $name ) ;
80
81         return $this->packages [ $name ] ;
82     }
83     
84     function getPackageKey ($name)
85     {
86         $manifestPath = MB_PACKAGE_PATH . '/' . $name . '/manifest.php' ;
87         if (file_exists ( $manifestPath ))
88         {
89             require( $manifestPath ) ;
90             if(!empty($manifest))
91                 return $manifest['key'];
92         }
93         return false ;
94     }
95
96     function &getPackageModule ($package , $module)
97     {
98         $this->getPackage ( $package ) ;
99         $this->packages [ $package ]->getModule ( $module ) ;
100         return $this->packages [ $package ]->modules [ $module ] ;
101     }
102
103     function save ()
104     {
105         $packages = array_keys ( $this->packages ) ;
106         foreach ( $packages as $package )
107         {
108             $this->packages [ $package ]->save () ;
109         }
110     }
111
112     function build ()
113     {
114         $packages = array_keys ( $this->packages ) ;
115         foreach ( $packages as $package )
116         {
117             if (count ( $packages ) == 1)
118             {
119                 $this->packages [ $package ]->build ( true ) ;
120             } else
121             {
122                 $this->packages [ $package ]->build ( false ) ;
123             }
124         }
125     }
126
127     function getPackages ()
128     {
129         if (empty ( $this->packages ))
130         {
131             $list = $this->getPackageList () ;
132             foreach ( $list as $package )
133             {
134                 if (! empty ( $this->packages [ $package ] ))
135                     continue ;
136                 $this->packages [ $package ] = new MBPackage ( $package ) ;
137             }
138         }
139     }
140
141     function getNodes ()
142     {
143         $this->getPackages () ;
144         $nodes = array ( ) ;
145         foreach ( array_keys ( $this->packages ) as $name )
146         {
147             $nodes [] = $this->packages [ $name ]->getNodes () ;
148         }
149         return $nodes ;
150     }
151
152 }
153 ?>