]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/MB/ModuleBuilder.php
Release 6.2.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-2011 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     function getPackage ($name)
73     {
74         if (! empty ( $this->packages [ $name ] ))
75             return $this->packages [ $name ] ;
76         $this->packages [ $name ] = new MBPackage ( $name ) ;
77     }
78     
79     function getPackageKey ($name)
80     {
81         $manifestPath = MB_PACKAGE_PATH . '/' . $name . '/manifest.php' ;
82         if (file_exists ( $manifestPath ))
83         {
84             require( $manifestPath ) ;
85             if(!empty($manifest))
86                 return $manifest['key'];
87         }
88         return false ;
89     }
90
91     function &getPackageModule ($package , $module)
92     {
93         $this->getPackage ( $package ) ;
94         $this->packages [ $package ]->getModule ( $module ) ;
95         return $this->packages [ $package ]->modules [ $module ] ;
96     }
97
98     function save ()
99     {
100         $packages = array_keys ( $this->packages ) ;
101         foreach ( $packages as $package )
102         {
103             $this->packages [ $package ]->save () ;
104         }
105     }
106
107     function build ()
108     {
109         $packages = array_keys ( $this->packages ) ;
110         foreach ( $packages as $package )
111         {
112             if (count ( $packages ) == 1)
113             {
114                 $this->packages [ $package ]->build ( true ) ;
115             } else
116             {
117                 $this->packages [ $package ]->build ( false ) ;
118             }
119         }
120     }
121
122     function getPackages ()
123     {
124         if (empty ( $this->packages ))
125         {
126             $list = $this->getPackageList () ;
127             foreach ( $list as $package )
128             {
129                 if (! empty ( $this->packages [ $package ] ))
130                     continue ;
131                 $this->packages [ $package ] = new MBPackage ( $package ) ;
132             }
133         }
134     }
135
136     function getNodes ()
137     {
138         $this->getPackages () ;
139         $nodes = array ( ) ;
140         foreach ( array_keys ( $this->packages ) as $name )
141         {
142             $nodes [] = $this->packages [ $name ]->getNodes () ;
143         }
144         return $nodes ;
145     }
146
147 }
148 ?>