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-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php' ;
40 require_once 'modules/ModuleBuilder/parsers/views/AbstractMetaDataImplementation.php' ;
41 require_once 'modules/ModuleBuilder/parsers/views/MetaDataImplementationInterface.php' ;
42 require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php' ;
43 require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ;
44 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
46 class UndeployedMetaDataImplementation extends AbstractMetaDataImplementation implements MetaDataImplementationInterface
49 private $_packageName ;
54 * @param string $moduleName
55 * @throws Exception Thrown if the provided view doesn't exist for this module
58 function __construct ($view , $moduleName , $packageName)
62 if (! isset ( $this->_fileVariables [ $view ] ))
64 sugar_die ( get_class ( $this ) . ": View $view is not supported" ) ;
68 $this->_view = strtolower ( $view ) ;
69 $this->_moduleName = $moduleName ;
70 $this->_packageName = $packageName ;
72 //get the bean from ModuleBuilder
73 $mb = new ModuleBuilder ( ) ;
74 $this->module = $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
75 $pak = $mb->getPackage($packageName);
76 $module->mbvardefs->updateVardefs () ;
78 // Set the list of fields associated with this module
79 $fielddefs = array_change_key_case ( $module->mbvardefs->vardefs [ 'fields' ] ) ;
81 // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
82 $selected_lang = 'en_us';
83 if(isset($GLOBALS['current_language']) &&!empty($GLOBALS['current_language'])) {
84 $selected_lang = $GLOBALS['current_language'];
86 $GLOBALS [ 'mod_strings' ] = array_merge ( $GLOBALS [ 'mod_strings' ], $module->getModStrings ($selected_lang) ) ;
88 //Load relationshhip based fields and labels
89 $moduleRels = $pak->getRelationshipsForModule($moduleName);
90 foreach($moduleRels as $rName => $rel ) {
91 $varDefsSet = $rel->buildVardefs();
92 if (!empty($varDefsSet[$module->key_name])) {
93 foreach ($varDefsSet[$module->key_name] as $def) {
94 $fielddefs[$def['name']] = $def;
97 $labels = $rel->buildLabels();
98 foreach ($labels as $def) {
99 if ($def['module'] == $module->key_name) {
100 $GLOBALS [ 'mod_strings' ][$def['system_label']] = $def['display_label'];
107 foreach ( array ( MB_BASEMETADATALOCATION , MB_HISTORYMETADATALOCATION ) as $type )
109 $this->_sourceFilename = $this->getFileName ( $view, $moduleName, $packageName , $type ) ;
110 if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
111 $layout = $this->_loadFromPopupFile ( $this->_sourceFilename , null, $view);
113 $layout = $this->_loadFromFile ( $this->_sourceFilename );
115 if ( null !== $layout )
117 // merge in the fielddefs from this layout
118 $this->_mergeFielddefs ( $fielddefs , $layout ) ;
123 if ($loaded === null)
125 throw new Exception ( get_class ( $this ) . ": view definitions for View $this->_view and Module $this->_moduleName are missing" ) ;
128 $this->_viewdefs = $loaded ;
129 $sourceFilename = $this->getFileName ( $view, $moduleName, $packageName, MB_BASEMETADATALOCATION );
130 if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
131 $layout = $this->_loadFromPopupFile ( $sourceFilename , null, $view);
133 $layout = $this->_loadFromFile ($sourceFilename) ;
135 $this->_originalViewdefs = $layout ;
136 $this->_fielddefs = $fielddefs ;
137 $this->_history = new History ( $this->getFileName ( $view, $moduleName, $packageName, MB_HISTORYMETADATALOCATION ) ) ;
140 function getLanguage ()
142 return $this->_packageName . $this->_moduleName ;
147 * @param array defs Layout definition in the same format as received by the constructor
149 function deploy ($defs)
151 //If we are pulling from the History Location, that means we did a restore, and we need to save the history for the previous file.
152 if ($this->_sourceFilename == $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_HISTORYMETADATALOCATION )
153 && file_exists($this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_BASEMETADATALOCATION ))) {
154 $this->_history->append ( $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_BASEMETADATALOCATION )) ;
156 $this->_history->append ( $this->_sourceFilename ) ;
158 $filename = $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_BASEMETADATALOCATION ) ;
159 $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->deploy(): writing to " . $filename ) ;
160 $this->_saveToFile ( $filename, $defs ) ;
164 * Construct a full pathname for the requested metadata
165 * @param string view The view type, that is, EditView, DetailView etc
166 * @param string modulename The name of the module that will use this layout
169 public static function getFileName ($view , $moduleName , $packageName , $type = MB_BASEMETADATALOCATION)
172 $type = strtolower ( $type ) ;
175 if ($type != MB_BASEMETADATALOCATION && $type != MB_HISTORYMETADATALOCATION)
177 // just warn rather than die
178 $GLOBALS [ 'log' ]->warning ( "UndeployedMetaDataImplementation->getFileName(): view type $type is not recognized" ) ;
182 $filenames = array ( MB_DASHLETSEARCH => 'dashletviewdefs',
183 MB_DASHLET => 'dashletviewdefs',
184 MB_LISTVIEW => 'listviewdefs' ,
185 MB_BASICSEARCH => 'searchdefs' ,
186 MB_ADVANCEDSEARCH => 'searchdefs' ,
187 MB_EDITVIEW => 'editviewdefs' ,
188 MB_DETAILVIEW => 'detailviewdefs' ,
189 MB_QUICKCREATE => 'quickcreatedefs',
190 MB_POPUPSEARCH => 'popupdefs',
191 MB_POPUPLIST => 'popupdefs',
196 case MB_HISTORYMETADATALOCATION :
197 return 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . $filenames [ $view ] . '.php' ;
199 // get the module again, all so we can call this method statically without relying on the module stored in the class variables
200 $mb = new ModuleBuilder ( ) ;
201 $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
202 return $module->getModuleDir () . '/metadata/' . $filenames [ $view ] . '.php' ;
207 public function getModuleDir(){
208 return $this->module->key_name;